'Gets security groups of an instance.
:returns: List of SecurityGroup objects associated with the instance'

@profiler.trace
def list_by_instance(self, instance_id):

    ports = port_list(self.request, device_id=instance_id)
    sg_ids = []
    for p in ports:
        sg_ids += p.security_groups
    return (self._list(id=set(sg_ids)) if sg_ids else [])
