+ Returns the first subnet object that fits the query else None including
+ if subnet_settings or subnet_name parameters are None.
+ :param neutron: the Neutron client
+ :param keystone: the Keystone client
+ :param subnet_name: the name of the subnet to retrieve
+ :param project_name: the name of the associated project to the subnet to
+ retrieve
+ :return: a SNAPS-OO Subnet domain object or None
+ """
+ sub_filter = {'name': subnet_name}
+ subnets = neutron.list_subnets(**sub_filter)
+ for subnet in subnets['subnets']:
+ subnet = Subnet(**subnet)
+ if project_name:
+ project = keystone_utils.get_project_by_id(
+ keystone, subnet.project_id)
+ if project and project.name == project_name:
+ return subnet
+ else:
+ return subnet
+
+
+def get_subnet_by_id(neutron, subnet_id):
+ """
+ Returns a SNAPS-OO Subnet domain object for a given ID
+ :param neutron: the OpenStack neutron client
+ :param subnet_id: the subnet ID
+ :return: a Subnet object
+ """
+ os_subnet = neutron.show_subnet(subnet_id)
+ if os_subnet and 'subnet' in os_subnet:
+ return Subnet(**os_subnet['subnet'])
+
+
+def get_subnets_by_network(neutron, network):
+ """
+ Returns a list of SNAPS-OO Subnet domain objects
+ :param neutron: the OpenStack neutron client
+ :param network: the SNAPS-OO Network domain object
+ :return: a list of Subnet objects
+ """
+ return get_subnets_by_network_id(neutron, network.id)
+
+
+def get_subnets_by_network_id(neutron, network_id):
+ """
+ Returns a list of SNAPS-OO Subnet domain objects
+ :param neutron: the OpenStack neutron client
+ :param network_id: the subnet's ID
+ :return: a list of Subnet objects
+ """
+ out = list()
+
+ os_subnets = neutron.list_subnets(network_id=network_id)
+
+ for os_subnet in os_subnets['subnets']:
+ out.append(Subnet(**os_subnet))
+
+ return out