def get_security_group_ids(context, security_groups, **kwargs): if not security_groups: return None else: neutron = clients.OpenStackClients(context).neutron() search_opts = {'tenant_id': context.project_id} security_groups_list = neutron.list_security_groups( **search_opts).get('security_groups', []) security_group_ids = [item['id'] for item in security_groups_list if item['name'] in security_groups or item['id'] in security_groups] if len(security_group_ids) >= len(security_groups): return security_group_ids else: raise exception.ZunException(_( "Any of the security group in %s is not found ") % security_groups)