'Processes and validates requested security groups for allocation.
Iterates over the list of requested security groups, validating the
request and filtering out the list of security group IDs to use for
port allocation.
:param instance: allocate networks on this instance
:type instance: nova.objects.Instance
:param neutron: neutron client session
:type neutron: neutronclient.v2_0.client.Client
:param security_groups: list of requested security group name or IDs
to use when allocating new ports for the instance
:return: list of security group IDs to use when allocating new ports
:raises nova.exception.NoUniqueMatch: If multiple security groups
are requested with the same name.
:raises nova.exception.SecurityGroupNotFound: If a requested security
group is not in the tenant-filtered list of available security
groups in Neutron.'

def _process_security_groups(self, instance, neutron, security_groups):

    security_group_ids = []
    if len(security_groups):
        search_opts = {'tenant_id': instance.project_id}
        user_security_groups = neutron.list_security_groups(**search_opts).get('security_groups')
        for security_group in security_groups:
            name_match = None
            uuid_match = None
            for user_security_group in user_security_groups:
                if (user_security_group['name'] == security_group):
                    if name_match:
                        raise exception.NoUniqueMatch((_("Multiple    security    groups    found    matching    '%s'.    Use    an    ID    to    be    more    specific.") % security_group))
                    name_match = user_security_group['id']
                if (user_security_group['id'] == security_group):
                    uuid_match = user_security_group['id']
            if name_match:
                security_group_ids.append(name_match)
            elif uuid_match:
                security_group_ids.append(uuid_match)
            else:
                raise exception.SecurityGroupNotFound(security_group_id=security_group)
    return security_group_ids
