'Returns a dict of security groups keyed by their ids.'

def _get_secgroups_from_port_list(self, ports, neutron):

    def _chunk_by_ids(sg_ids, limit):
        sg_id_list = []
        for sg_id in sg_ids:
            sg_id_list.append(sg_id)
            if (len(sg_id_list) >= limit):
                (yield sg_id_list)
                sg_id_list = []
        if sg_id_list:
            (yield sg_id_list)
    sg_ids = set()
    for port in ports:
        sg_ids.update(port.get('security_groups', []))
    security_groups = {}
    for sg_id_list in _chunk_by_ids(sg_ids, MAX_SEARCH_IDS):
        sg_search_opts = {'id': sg_id_list}
        search_results = neutron.list_security_groups(**sg_search_opts)
        for sg in search_results.get('security_groups'):
            security_groups[sg['id']] = sg
    return security_groups
