summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/utils/neutron_utils.py
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-07-17 09:09:12 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-07-17 09:09:12 -0600
commit18158509660d6604502a1b079b2fe2b83b59caf7 (patch)
treeee98b8fc98988ad5b959b2754cc7a7aa5b39bd0a /snaps/openstack/utils/neutron_utils.py
parentde6536ff2ba4faa1a3d4ed27e93d692cae20e5d2 (diff)
Created new class NeutronException.
Raising NeutronException in neutron_utils.py instead of Exception. JIRA: SNAPS-128 Change-Id: I567db38a5dfcaae9bbfc6c74558521b0e28d9d46 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
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 dfae98b..5407338 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):
@@ -133,8 +132,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):
@@ -180,7 +178,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):
@@ -220,8 +218,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)
@@ -229,8 +228,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):
@@ -266,9 +266,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}
@@ -487,8 +489,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):
@@ -534,3 +536,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
+ """