summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/utils/neutron_utils.py
diff options
context:
space:
mode:
authorSteven Pisarski <s.pisarski@cablelabs.com>2017-07-18 13:47:58 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-18 13:47:58 +0000
commit0050ed771d89f6a758a387a930feeb616dceecec (patch)
tree41059f3ca65e27f97225132bccb7c7b65da2bf1d /snaps/openstack/utils/neutron_utils.py
parent841b5699185442f2cc6f87a776fd707045be5587 (diff)
parent18158509660d6604502a1b079b2fe2b83b59caf7 (diff)
Merge "Created new class NeutronException."
Diffstat (limited to 'snaps/openstack/utils/neutron_utils.py')
-rw-r--r--snaps/openstack/utils/neutron_utils.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py
index 61afa75..d93faa0 100644
--- a/snaps/openstack/utils/neutron_utils.py
+++ b/snaps/openstack/utils/neutron_utils.py
@@ -59,8 +59,7 @@ def create_network(neutron, os_creds, network_settings):
os_network = neutron.create_network(body=json_body)
return Network(**os_network['network'])
else:
- logger.error("Failed to create network")
- raise Exception
+ raise NeutronException('Failded to create network')
def delete_network(neutron, network):
@@ -130,8 +129,7 @@ def create_subnet(neutron, subnet_settings, os_creds, network=None):
subnets = neutron.create_subnet(body=json_body)
return Subnet(**subnets['subnets'][0])
else:
- logger.error("Failed to create subnet.")
- raise Exception
+ raise NeutronException('Failed to create subnet')
def delete_subnet(neutron, subnet):
@@ -177,7 +175,7 @@ def create_router(neutron, os_creds, router_settings):
return Router(**os_router['router'])
else:
logger.error("Failed to create router.")
- raise Exception
+ raise NeutronException('Failed to create router')
def delete_router(neutron, router):
@@ -217,8 +215,9 @@ def add_interface_router(neutron, router, subnet=None, port=None):
:return: the interface router object
"""
if subnet and port:
- raise Exception('Cannot add interface to the router. Both subnet and '
- 'port were sent in. Either or please.')
+ raise NeutronException(
+ 'Cannot add interface to the router. Both subnet and '
+ 'port were sent in. Either or please.')
if neutron and router and (router or subnet):
logger.info('Adding interface to router with name ' + router.name)
@@ -226,8 +225,9 @@ def add_interface_router(neutron, router, subnet=None, port=None):
router=router.id, body=__create_port_json_body(subnet, port))
return InterfaceRouter(**os_intf_router)
else:
- raise Exception('Unable to create interface router as neutron client,'
- ' router or subnet were not created')
+ raise NeutronException(
+ 'Unable to create interface router as neutron client,'
+ ' router or subnet were not created')
def remove_interface_router(neutron, router, subnet=None, port=None):
@@ -263,9 +263,11 @@ def __create_port_json_body(subnet=None, port=None):
:return: the dict
"""
if subnet and port:
- raise Exception('Cannot create JSON body with both subnet and port')
+ raise NeutronException(
+ 'Cannot create JSON body with both subnet and port')
if not subnet and not port:
- raise Exception('Cannot create JSON body without subnet or port')
+ raise NeutronException(
+ 'Cannot create JSON body without subnet or port')
if subnet:
return {"subnet_id": subnet.id}
@@ -486,8 +488,8 @@ def create_floating_ip(neutron, ext_net_name):
return FloatingIp(inst_id=fip['floatingip']['id'],
ip=fip['floatingip']['floating_ip_address'])
else:
- raise Exception('Cannot create floating IP, '
- 'external network not found')
+ raise NeutronException(
+ 'Cannot create floating IP, external network not found')
def get_floating_ip(neutron, floating_ip):
@@ -533,3 +535,9 @@ def delete_floating_ip(neutron, floating_ip):
logger.debug('Attempting to delete existing floating ip with IP - %s',
floating_ip.ip)
return neutron.delete_floatingip(floating_ip.id)
+
+
+class NeutronException(Exception):
+ """
+ Exception when calls to the Keystone client cannot be served properly
+ """