code: def update_instance_security_group(self, instance_id,
                                         new_security_group_ids):
          
          ports = port_list(self.request, device_id=instance_id)
          for p in ports:
              params = {'security_groups': new_security_group_ids}
              port_update(self.request, p.id, **params)
docs: Update security groups of a specified instance.