summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/utils/neutron_utils.py
diff options
context:
space:
mode:
authorSteven Pisarski <s.pisarski@cablelabs.com>2017-08-07 14:33:41 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-08-07 14:33:41 +0000
commit463dc2cd59bb26150f15e57a0e94fafbbf8634d4 (patch)
tree8f92f831c428bc4542cb181a6eee4443e601fba1 /snaps/openstack/utils/neutron_utils.py
parent48f714f7dc56433148197b5fefb3d9253928a8b3 (diff)
parente73caa67417ab6c628cf8fac1ac730e550de7bbc (diff)
Merge "Refactored neutron_utils#get_subnet_by_name() to get_subnet()"
Diffstat (limited to 'snaps/openstack/utils/neutron_utils.py')
-rw-r--r--snaps/openstack/utils/neutron_utils.py45
1 files changed, 35 insertions, 10 deletions
diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py
index d892504..01408fe 100644
--- a/snaps/openstack/utils/neutron_utils.py
+++ b/snaps/openstack/utils/neutron_utils.py
@@ -147,19 +147,44 @@ def delete_subnet(neutron, subnet):
neutron.delete_subnet(subnet.id)
-def get_subnet_by_name(neutron, subnet_name):
+def get_subnet(neutron, subnet_settings=None, subnet_name=None):
"""
- Returns the first subnet object (dictionary) found with a given name
+ Returns the first subnet object that fits the query else None including
+ if subnet_settings or subnet_name parameters are None.
:param neutron: the client
- :param subnet_name: the name of the network to retrieve
- :return: a SNAPS-OO Subnet domain object
+ :param subnet_settings: the subnet settings of the object to retrieve
+ :param subnet_name: the name of the subnet to retrieve
+ :return: a SNAPS-OO Subnet domain object or None
"""
- subnets = neutron.list_subnets(**{'name': subnet_name})
- for subnet, subnetInst in subnets.items():
- for inst in subnetInst:
- if inst['name'] == subnet_name:
- return Subnet(**inst)
- return None
+ sub_filter = dict()
+ if subnet_settings:
+ sub_filter['name'] = subnet_settings.name
+ sub_filter['cidr'] = subnet_settings.cidr
+ if subnet_settings.gateway_ip:
+ sub_filter['gateway_ip'] = subnet_settings.gateway_ip
+
+ if subnet_settings.enable_dhcp is not None:
+ sub_filter['enable_dhcp'] = subnet_settings.enable_dhcp
+
+ if subnet_settings.destination:
+ sub_filter['destination'] = subnet_settings.destination
+
+ if subnet_settings.nexthop:
+ sub_filter['nexthop'] = subnet_settings.nexthop
+
+ if subnet_settings.ipv6_ra_mode:
+ sub_filter['ipv6_ra_mode'] = subnet_settings.ipv6_ra_mode
+
+ if subnet_settings.ipv6_address_mode:
+ sub_filter['ipv6_address_mode'] = subnet_settings.ipv6_address_mode
+ elif subnet_name:
+ sub_filter['name'] = subnet_name
+ else:
+ return None
+
+ subnets = neutron.list_subnets(**sub_filter)
+ for subnet in subnets['subnets']:
+ return Subnet(**subnet)
def create_router(neutron, os_creds, router_settings):