def update_named_ports(mig, named_ports):
 changed = False
 existing_ports = []
 new_ports = []
 if hasattr(mig.instance_group, 'named_ports'):
  existing_ports = sorted(mig.instance_group.named_ports, key=(lambda x: x['name']))
 if (named_ports is not None):
  new_ports = sorted(named_ports, key=(lambda x: x['name']))
 if (existing_ports != new_ports):
  if mig.instance_group.set_named_ports(named_ports):
   changed = True
 return changed

def update_named_ports ( mig , named_ports ) : changed = False existing_ports = [ ] new_ports = [ ] if hasattr ( mig . instance_group , 'named_ports' ) : existing_ports = sorted ( mig . instance_group . named_ports , key = ( lambda x : x [ 'name' ] ) ) if ( named_ports is not None ) : new_ports = sorted ( named_ports , key = ( lambda x : x [ 'name' ] ) ) if ( existing_ports != new_ports ) : if mig . instance_group . set_named_ports ( named_ports ) : changed = True return changed
set the named ports on a managed instance group .