Fixing open stack compile time errors irt exception handling for Python 3 (#3848)

pull/18777/head
@ 9 years ago committed by Matt Clay
parent 13bebda244
commit 7960e99310

@ -142,7 +142,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'), password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'), tenant_name=kwargs.get('login_tenant_name'),
auth_url=kwargs.get('auth_url')) auth_url=kwargs.get('auth_url'))
except Exception, e: except Exception as e:
module.fail_json(msg="Error authenticating to the keystone: %s " % e.message) module.fail_json(msg="Error authenticating to the keystone: %s " % e.message)
return client return client
@ -150,7 +150,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, client, endpoint_type): def _get_endpoint(module, client, endpoint_type):
try: try:
endpoint = client.service_catalog.url_for(service_type='image', endpoint_type=endpoint_type) endpoint = client.service_catalog.url_for(service_type='image', endpoint_type=endpoint_type)
except Exception, e: except Exception as e:
module.fail_json(msg="Error getting endpoint for glance: %s" % e.message) module.fail_json(msg="Error getting endpoint for glance: %s" % e.message)
return endpoint return endpoint
@ -164,7 +164,7 @@ def _get_glance_client(module, kwargs):
} }
try: try:
client = glanceclient.Client('1', endpoint, **kwargs) client = glanceclient.Client('1', endpoint, **kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg="Error in connecting to glance: %s" % e.message) module.fail_json(msg="Error in connecting to glance: %s" % e.message)
return client return client
@ -175,7 +175,7 @@ def _glance_image_present(module, params, client):
if image.name == params['name']: if image.name == params['name']:
return image.id return image.id
return None return None
except Exception, e: except Exception as e:
module.fail_json(msg="Error in fetching image list: %s" % e.message) module.fail_json(msg="Error in fetching image list: %s" % e.message)
@ -199,7 +199,7 @@ def _glance_image_create(module, params, client):
if image.status == 'active': if image.status == 'active':
break break
time.sleep(5) time.sleep(5)
except Exception, e: except Exception as e:
module.fail_json(msg="Error in creating image: %s" % e.message) module.fail_json(msg="Error in creating image: %s" % e.message)
if image.status == 'active': if image.status == 'active':
module.exit_json(changed=True, result=image.status, id=image.id) module.exit_json(changed=True, result=image.status, id=image.id)
@ -212,7 +212,7 @@ def _glance_delete_image(module, params, client):
for image in client.images.list(): for image in client.images.list():
if image.name == params['name']: if image.name == params['name']:
client.images.delete(image) client.images.delete(image)
except Exception, e: except Exception as e:
module.fail_json(msg="Error in deleting image: %s" % e.message) module.fail_json(msg="Error in deleting image: %s" % e.message)
module.exit_json(changed=True, result="Deleted") module.exit_json(changed=True, result="Deleted")

@ -368,7 +368,7 @@ def main():
d = dispatch(keystone, user, password, tenant, tenant_description, d = dispatch(keystone, user, password, tenant, tenant_description,
email, role, state, endpoint, token, login_user, email, role, state, endpoint, token, login_user,
login_password, check_mode) login_password, check_mode)
except Exception, e: except Exception as e:
if check_mode: if check_mode:
# If we have a failure in check mode # If we have a failure in check mode
module.exit_json(changed=True, module.exit_json(changed=True,

@ -283,7 +283,7 @@ def _delete_server(module, nova):
if server_list: if server_list:
server = [x for x in server_list if x.name == module.params['name']] server = [x for x in server_list if x.name == module.params['name']]
nova.servers.delete(server.pop()) nova.servers.delete(server.pop())
except Exception, e: except Exception as e:
module.fail_json( msg = "Error in deleting vm: %s" % e.message) module.fail_json( msg = "Error in deleting vm: %s" % e.message)
if module.params['wait'] == 'no': if module.params['wait'] == 'no':
module.exit_json(changed = True, result = "deleted") module.exit_json(changed = True, result = "deleted")
@ -330,7 +330,7 @@ def _add_floating_ip_from_pool(module, nova, server):
if not pool_ips: if not pool_ips:
try: try:
new_ip = nova.floating_ips.create(pool) new_ip = nova.floating_ips.create(pool)
except Exception, e: except Exception as e:
module.fail_json(msg = "Unable to create floating ip: %s" % (e.message)) module.fail_json(msg = "Unable to create floating ip: %s" % (e.message))
pool_ips.append(new_ip.ip) pool_ips.append(new_ip.ip)
# Add to the main list # Add to the main list
@ -345,7 +345,7 @@ def _add_floating_ip_from_pool(module, nova, server):
# race condition and some other cloud operation may have # race condition and some other cloud operation may have
# stolen an available floating ip # stolen an available floating ip
break break
except Exception, e: except Exception as e:
module.fail_json(msg = "Error attaching IP %s to instance %s: %s " % (ip, server.id, e.message)) module.fail_json(msg = "Error attaching IP %s to instance %s: %s " % (ip, server.id, e.message))
@ -354,7 +354,7 @@ def _add_floating_ip_list(module, server, ips):
for ip in ips: for ip in ips:
try: try:
server.add_floating_ip(ip) server.add_floating_ip(ip)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error attaching IP %s to instance %s: %s " % (ip, server.id, e.message)) module.fail_json(msg = "Error attaching IP %s to instance %s: %s " % (ip, server.id, e.message))
@ -390,7 +390,7 @@ def _add_floating_ip(module, nova, server):
# a recent server object if the above code path exec'd # a recent server object if the above code path exec'd
try: try:
server = nova.servers.get(server.id) server = nova.servers.get(server.id)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in getting info from instance: %s " % e.message) module.fail_json(msg = "Error in getting info from instance: %s " % e.message)
return server return server
@ -435,14 +435,14 @@ def _create_server(module, nova):
try: try:
server = nova.servers.create(*bootargs, **bootkwargs) server = nova.servers.create(*bootargs, **bootkwargs)
server = nova.servers.get(server.id) server = nova.servers.get(server.id)
except Exception, e: except Exception as e:
module.fail_json( msg = "Error in creating instance: %s " % e.message) module.fail_json( msg = "Error in creating instance: %s " % e.message)
if module.params['wait'] == 'yes': if module.params['wait'] == 'yes':
expire = time.time() + int(module.params['wait_for']) expire = time.time() + int(module.params['wait_for'])
while time.time() < expire: while time.time() < expire:
try: try:
server = nova.servers.get(server.id) server = nova.servers.get(server.id)
except Exception, e: except Exception as e:
module.fail_json( msg = "Error in getting info from instance: %s" % e.message) module.fail_json( msg = "Error in getting info from instance: %s" % e.message)
if server.status == 'ACTIVE': if server.status == 'ACTIVE':
server = _add_floating_ip(module, nova, server) server = _add_floating_ip(module, nova, server)
@ -511,7 +511,7 @@ def _get_server_state(module, nova):
servers = [x for x in servers if x.name == module.params['name']] servers = [x for x in servers if x.name == module.params['name']]
if servers: if servers:
server = servers[0] server = servers[0]
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in getting the server list: %s" % e.message) module.fail_json(msg = "Error in getting the server list: %s" % e.message)
if server and module.params['state'] == 'present': if server and module.params['state'] == 'present':
if server.status != 'ACTIVE': if server.status != 'ACTIVE':
@ -571,9 +571,9 @@ def main():
service_type='compute') service_type='compute')
try: try:
nova.authenticate() nova.authenticate()
except exceptions.Unauthorized, e: except exceptions.Unauthorized as e:
module.fail_json(msg = "Invalid OpenStack Nova credentials.: %s" % e.message) module.fail_json(msg = "Invalid OpenStack Nova credentials.: %s" % e.message)
except exceptions.AuthorizationFailure, e: except exceptions.AuthorizationFailure as e:
module.fail_json(msg = "Unable to authorize user: %s" % e.message) module.fail_json(msg = "Unable to authorize user: %s" % e.message)
if module.params['state'] == 'present': if module.params['state'] == 'present':

@ -107,9 +107,9 @@ def main():
service_type='compute') service_type='compute')
try: try:
nova.authenticate() nova.authenticate()
except exc.Unauthorized, e: except exc.Unauthorized as e:
module.fail_json(msg = "Invalid OpenStack Nova credentials.: %s" % e.message) module.fail_json(msg = "Invalid OpenStack Nova credentials.: %s" % e.message)
except exc.AuthorizationFailure, e: except exc.AuthorizationFailure as e:
module.fail_json(msg = "Unable to authorize user: %s" % e.message) module.fail_json(msg = "Unable to authorize user: %s" % e.message)
if module.params['state'] == 'present': if module.params['state'] == 'present':
@ -121,7 +121,7 @@ def main():
module.exit_json(changed = False, result = "Key present") module.exit_json(changed = False, result = "Key present")
try: try:
key = nova.keypairs.create(module.params['name'], module.params['public_key']) key = nova.keypairs.create(module.params['name'], module.params['public_key'])
except Exception, e: except Exception as e:
module.exit_json(msg = "Error in creating the keypair: %s" % e.message) module.exit_json(msg = "Error in creating the keypair: %s" % e.message)
if not module.params['public_key']: if not module.params['public_key']:
module.exit_json(changed = True, key = key.private_key) module.exit_json(changed = True, key = key.private_key)
@ -131,7 +131,7 @@ def main():
if key.name == module.params['name']: if key.name == module.params['name']:
try: try:
nova.keypairs.delete(module.params['name']) nova.keypairs.delete(module.params['name'])
except Exception, e: except Exception as e:
module.fail_json(msg = "The keypair deletion has failed: %s" % e.message) module.fail_json(msg = "The keypair deletion has failed: %s" % e.message)
module.exit_json( changed = True, result = "deleted") module.exit_json( changed = True, result = "deleted")
module.exit_json(changed = False, result = "not present") module.exit_json(changed = False, result = "not present")

@ -102,7 +102,7 @@ def _get_ksclient(module, kwargs):
tenant_name=kwargs.get('login_tenant_name'), tenant_name=kwargs.get('login_tenant_name'),
auth_url=kwargs.get('auth_url'), auth_url=kwargs.get('auth_url'),
region_name=kwargs.get('region_name')) region_name=kwargs.get('region_name'))
except Exception, e: except Exception as e:
module.fail_json(msg = "Error authenticating to the keystone: %s " % e.message) module.fail_json(msg = "Error authenticating to the keystone: %s " % e.message)
global _os_keystone global _os_keystone
_os_keystone = kclient _os_keystone = kclient
@ -112,7 +112,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient): def _get_endpoint(module, ksclient):
try: try:
endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL') endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL')
except Exception, e: except Exception as e:
module.fail_json(msg = "Error getting network endpoint: %s" % e.message) module.fail_json(msg = "Error getting network endpoint: %s" % e.message)
return endpoint return endpoint
@ -126,7 +126,7 @@ def _get_neutron_client(module, kwargs):
} }
try: try:
neutron = client.Client('2.0', **kwargs) neutron = client.Client('2.0', **kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in connecting to neutron: %s " % e.message) module.fail_json(msg = "Error in connecting to neutron: %s " % e.message)
return neutron return neutron
@ -142,7 +142,7 @@ def _get_server_state(module, nova):
module.fail_json( msg="The VM is available but not Active. state:" + info['status']) module.fail_json( msg="The VM is available but not Active. state:" + info['status'])
server_info = info server_info = info
break break
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in getting the server list: %s" % e.message) module.fail_json(msg = "Error in getting the server list: %s" % e.message)
return server_info, server return server_info, server
@ -163,7 +163,7 @@ def _get_port_info(neutron, module, instance_id, internal_network_name=None):
} }
try: try:
ports = neutron.list_ports(**kwargs) ports = neutron.list_ports(**kwargs)
except Exception, e: except Exception as e:
module.fail_json( msg = "Error in listing ports: %s" % e.message) module.fail_json( msg = "Error in listing ports: %s" % e.message)
if subnet_id: if subnet_id:
port = next(port for port in ports['ports'] if port['fixed_ips'][0]['subnet_id'] == subnet_id) port = next(port for port in ports['ports'] if port['fixed_ips'][0]['subnet_id'] == subnet_id)
@ -182,7 +182,7 @@ def _get_floating_ip(module, neutron, fixed_ip_address, network_name):
} }
try: try:
ips = neutron.list_floatingips(**kwargs) ips = neutron.list_floatingips(**kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "error in fetching the floatingips's %s" % e.message) module.fail_json(msg = "error in fetching the floatingips's %s" % e.message)
if not ips['floatingips']: if not ips['floatingips']:
return None, None return None, None
@ -205,7 +205,7 @@ def _create_floating_ip(neutron, module, port_id, net_id, fixed_ip):
} }
try: try:
result = neutron.create_floatingip({'floatingip': kwargs}) result = neutron.create_floatingip({'floatingip': kwargs})
except Exception, e: except Exception as e:
module.fail_json(msg="There was an error in updating the floating ip address: %s" % e.message) module.fail_json(msg="There was an error in updating the floating ip address: %s" % e.message)
module.exit_json(changed=True, result=result, public_ip=result['floatingip']['floating_ip_address']) module.exit_json(changed=True, result=result, public_ip=result['floatingip']['floating_ip_address'])
@ -215,7 +215,7 @@ def _get_net_id(neutron, module):
} }
try: try:
networks = neutron.list_networks(**kwargs) networks = neutron.list_networks(**kwargs)
except Exception, e: except Exception as e:
module.fail_json("Error in listing neutron networks: %s" % e.message) module.fail_json("Error in listing neutron networks: %s" % e.message)
if not networks['networks']: if not networks['networks']:
return None return None
@ -227,7 +227,7 @@ def _update_floating_ip(neutron, module, port_id, floating_ip_id):
} }
try: try:
result = neutron.update_floatingip(floating_ip_id, {'floatingip': kwargs}) result = neutron.update_floatingip(floating_ip_id, {'floatingip': kwargs})
except Exception, e: except Exception as e:
module.fail_json(msg="There was an error in updating the floating ip address: %s" % e.message) module.fail_json(msg="There was an error in updating the floating ip address: %s" % e.message)
module.exit_json(changed=True, result=result) module.exit_json(changed=True, result=result)
@ -247,7 +247,7 @@ def main():
nova = nova_client.Client(module.params['login_username'], module.params['login_password'], nova = nova_client.Client(module.params['login_username'], module.params['login_password'],
module.params['login_tenant_name'], module.params['auth_url'], region_name=module.params['region_name'], service_type='compute') module.params['login_tenant_name'], module.params['auth_url'], region_name=module.params['region_name'], service_type='compute')
neutron = _get_neutron_client(module, module.params) neutron = _get_neutron_client(module, module.params)
except Exception, e: except Exception as e:
module.fail_json(msg="Error in authenticating to nova: %s" % e.message) module.fail_json(msg="Error in authenticating to nova: %s" % e.message)
server_info, server_obj = _get_server_state(module, nova) server_info, server_obj = _get_server_state(module, nova)

@ -97,7 +97,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'), password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'), tenant_name=kwargs.get('login_tenant_name'),
auth_url=kwargs.get('auth_url')) auth_url=kwargs.get('auth_url'))
except Exception, e: except Exception as e:
module.fail_json(msg = "Error authenticating to the keystone: %s " % e.message) module.fail_json(msg = "Error authenticating to the keystone: %s " % e.message)
global _os_keystone global _os_keystone
_os_keystone = kclient _os_keystone = kclient
@ -107,7 +107,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient): def _get_endpoint(module, ksclient):
try: try:
endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL') endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL')
except Exception, e: except Exception as e:
module.fail_json(msg = "Error getting network endpoint: %s" % e.message) module.fail_json(msg = "Error getting network endpoint: %s" % e.message)
return endpoint return endpoint
@ -121,7 +121,7 @@ def _get_neutron_client(module, kwargs):
} }
try: try:
neutron = client.Client('2.0', **kwargs) neutron = client.Client('2.0', **kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in connecting to neutron: %s " % e.message) module.fail_json(msg = "Error in connecting to neutron: %s " % e.message)
return neutron return neutron
@ -137,7 +137,7 @@ def _get_server_state(module, nova):
module.fail_json(msg="The VM is available but not Active. state:" + info['status']) module.fail_json(msg="The VM is available but not Active. state:" + info['status'])
server_info = info server_info = info
break break
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in getting the server list: %s" % e.message) module.fail_json(msg = "Error in getting the server list: %s" % e.message)
return server_info, server return server_info, server
@ -145,7 +145,7 @@ def _get_port_id(neutron, module, instance_id):
kwargs = dict(device_id = instance_id) kwargs = dict(device_id = instance_id)
try: try:
ports = neutron.list_ports(**kwargs) ports = neutron.list_ports(**kwargs)
except Exception, e: except Exception as e:
module.fail_json( msg = "Error in listing ports: %s" % e.message) module.fail_json( msg = "Error in listing ports: %s" % e.message)
if not ports['ports']: if not ports['ports']:
return None return None
@ -157,7 +157,7 @@ def _get_floating_ip_id(module, neutron):
} }
try: try:
ips = neutron.list_floatingips(**kwargs) ips = neutron.list_floatingips(**kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "error in fetching the floatingips's %s" % e.message) module.fail_json(msg = "error in fetching the floatingips's %s" % e.message)
if not ips['floatingips']: if not ips['floatingips']:
module.fail_json(msg = "Could find the ip specified in parameter, Please check") module.fail_json(msg = "Could find the ip specified in parameter, Please check")
@ -174,7 +174,7 @@ def _update_floating_ip(neutron, module, port_id, floating_ip_id):
} }
try: try:
result = neutron.update_floatingip(floating_ip_id, {'floatingip': kwargs}) result = neutron.update_floatingip(floating_ip_id, {'floatingip': kwargs})
except Exception, e: except Exception as e:
module.fail_json(msg = "There was an error in updating the floating ip address: %s" % e.message) module.fail_json(msg = "There was an error in updating the floating ip address: %s" % e.message)
module.exit_json(changed = True, result = result, public_ip=module.params['ip_address']) module.exit_json(changed = True, result = result, public_ip=module.params['ip_address'])
@ -191,7 +191,7 @@ def main():
try: try:
nova = nova_client.Client(module.params['login_username'], module.params['login_password'], nova = nova_client.Client(module.params['login_username'], module.params['login_password'],
module.params['login_tenant_name'], module.params['auth_url'], service_type='compute') module.params['login_tenant_name'], module.params['auth_url'], service_type='compute')
except Exception, e: except Exception as e:
module.fail_json( msg = " Error in authenticating to nova: %s" % e.message) module.fail_json( msg = " Error in authenticating to nova: %s" % e.message)
neutron = _get_neutron_client(module, module.params) neutron = _get_neutron_client(module, module.params)
state, floating_ip_id = _get_floating_ip_id(module, neutron) state, floating_ip_id = _get_floating_ip_id(module, neutron)

@ -129,7 +129,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'), password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'), tenant_name=kwargs.get('login_tenant_name'),
auth_url=kwargs.get('auth_url')) auth_url=kwargs.get('auth_url'))
except Exception, e: except Exception as e:
module.fail_json(msg = "Error authenticating to the keystone: %s" %e.message) module.fail_json(msg = "Error authenticating to the keystone: %s" %e.message)
global _os_keystone global _os_keystone
_os_keystone = kclient _os_keystone = kclient
@ -139,7 +139,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient): def _get_endpoint(module, ksclient):
try: try:
endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL') endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL')
except Exception, e: except Exception as e:
module.fail_json(msg = "Error getting network endpoint: %s " %e.message) module.fail_json(msg = "Error getting network endpoint: %s " %e.message)
return endpoint return endpoint
@ -153,7 +153,7 @@ def _get_neutron_client(module, kwargs):
} }
try: try:
neutron = client.Client('2.0', **kwargs) neutron = client.Client('2.0', **kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = " Error in connecting to neutron: %s " %e.message) module.fail_json(msg = " Error in connecting to neutron: %s " %e.message)
return neutron return neutron
@ -178,7 +178,7 @@ def _get_net_id(neutron, module):
} }
try: try:
networks = neutron.list_networks(**kwargs) networks = neutron.list_networks(**kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in listing neutron networks: %s" % e.message) module.fail_json(msg = "Error in listing neutron networks: %s" % e.message)
if not networks['networks']: if not networks['networks']:
return None return None
@ -216,7 +216,7 @@ def _create_network(module, neutron):
try: try:
net = neutron.create_network({'network':network}) net = neutron.create_network({'network':network})
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in creating network: %s" % e.message) module.fail_json(msg = "Error in creating network: %s" % e.message)
return net['network']['id'] return net['network']['id']
@ -224,7 +224,7 @@ def _delete_network(module, net_id, neutron):
try: try:
id = neutron.delete_network(net_id) id = neutron.delete_network(net_id)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in deleting the network: %s" % e.message) module.fail_json(msg = "Error in deleting the network: %s" % e.message)
return True return True

@ -101,7 +101,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'), password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'), tenant_name=kwargs.get('login_tenant_name'),
auth_url=kwargs.get('auth_url')) auth_url=kwargs.get('auth_url'))
except Exception, e: except Exception as e:
module.fail_json(msg = "Error authenticating to the keystone: %s " % e.message) module.fail_json(msg = "Error authenticating to the keystone: %s " % e.message)
global _os_keystone global _os_keystone
_os_keystone = kclient _os_keystone = kclient
@ -111,7 +111,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient): def _get_endpoint(module, ksclient):
try: try:
endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL') endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL')
except Exception, e: except Exception as e:
module.fail_json(msg = "Error getting network endpoint: %s" % e.message) module.fail_json(msg = "Error getting network endpoint: %s" % e.message)
return endpoint return endpoint
@ -125,7 +125,7 @@ def _get_neutron_client(module, kwargs):
} }
try: try:
neutron = client.Client('2.0', **kwargs) neutron = client.Client('2.0', **kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in connecting to neutron: %s " % e.message) module.fail_json(msg = "Error in connecting to neutron: %s " % e.message)
return neutron return neutron
@ -150,7 +150,7 @@ def _get_router_id(module, neutron):
} }
try: try:
routers = neutron.list_routers(**kwargs) routers = neutron.list_routers(**kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in getting the router list: %s " % e.message) module.fail_json(msg = "Error in getting the router list: %s " % e.message)
if not routers['routers']: if not routers['routers']:
return None return None
@ -164,7 +164,7 @@ def _create_router(module, neutron):
} }
try: try:
new_router = neutron.create_router(dict(router=router)) new_router = neutron.create_router(dict(router=router))
except Exception, e: except Exception as e:
module.fail_json( msg = "Error in creating router: %s" % e.message) module.fail_json( msg = "Error in creating router: %s" % e.message)
return new_router['router']['id'] return new_router['router']['id']

@ -91,7 +91,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'), password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'), tenant_name=kwargs.get('login_tenant_name'),
auth_url=kwargs.get('auth_url')) auth_url=kwargs.get('auth_url'))
except Exception, e: except Exception as e:
module.fail_json(msg = "Error authenticating to the keystone: %s " % e.message) module.fail_json(msg = "Error authenticating to the keystone: %s " % e.message)
global _os_keystone global _os_keystone
_os_keystone = kclient _os_keystone = kclient
@ -101,7 +101,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient): def _get_endpoint(module, ksclient):
try: try:
endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL') endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL')
except Exception, e: except Exception as e:
module.fail_json(msg = "Error getting network endpoint: %s" % e.message) module.fail_json(msg = "Error getting network endpoint: %s" % e.message)
return endpoint return endpoint
@ -115,7 +115,7 @@ def _get_neutron_client(module, kwargs):
} }
try: try:
neutron = client.Client('2.0', **kwargs) neutron = client.Client('2.0', **kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in connecting to neutron: %s " % e.message) module.fail_json(msg = "Error in connecting to neutron: %s " % e.message)
return neutron return neutron
@ -125,7 +125,7 @@ def _get_router_id(module, neutron):
} }
try: try:
routers = neutron.list_routers(**kwargs) routers = neutron.list_routers(**kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in getting the router list: %s " % e.message) module.fail_json(msg = "Error in getting the router list: %s " % e.message)
if not routers['routers']: if not routers['routers']:
return None return None
@ -138,7 +138,7 @@ def _get_net_id(neutron, module):
} }
try: try:
networks = neutron.list_networks(**kwargs) networks = neutron.list_networks(**kwargs)
except Exception, e: except Exception as e:
module.fail_json("Error in listing neutron networks: %s" % e.message) module.fail_json("Error in listing neutron networks: %s" % e.message)
if not networks['networks']: if not networks['networks']:
return None return None
@ -151,7 +151,7 @@ def _get_port_id(neutron, module, router_id, network_id):
} }
try: try:
ports = neutron.list_ports(**kwargs) ports = neutron.list_ports(**kwargs)
except Exception, e: except Exception as e:
module.fail_json( msg = "Error in listing ports: %s" % e.message) module.fail_json( msg = "Error in listing ports: %s" % e.message)
if not ports['ports']: if not ports['ports']:
return None return None
@ -163,14 +163,14 @@ def _add_gateway_router(neutron, module, router_id, network_id):
} }
try: try:
neutron.add_gateway_router(router_id, kwargs) neutron.add_gateway_router(router_id, kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in adding gateway to router: %s" % e.message) module.fail_json(msg = "Error in adding gateway to router: %s" % e.message)
return True return True
def _remove_gateway_router(neutron, module, router_id): def _remove_gateway_router(neutron, module, router_id):
try: try:
neutron.remove_gateway_router(router_id) neutron.remove_gateway_router(router_id)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in removing gateway to router: %s" % e.message) module.fail_json(msg = "Error in removing gateway to router: %s" % e.message)
return True return True

@ -102,7 +102,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'), password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'), tenant_name=kwargs.get('login_tenant_name'),
auth_url=kwargs.get('auth_url')) auth_url=kwargs.get('auth_url'))
except Exception, e: except Exception as e:
module.fail_json(msg = "Error authenticating to the keystone: %s " % e.message) module.fail_json(msg = "Error authenticating to the keystone: %s " % e.message)
global _os_keystone global _os_keystone
_os_keystone = kclient _os_keystone = kclient
@ -112,7 +112,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient): def _get_endpoint(module, ksclient):
try: try:
endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL') endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL')
except Exception, e: except Exception as e:
module.fail_json(msg = "Error getting network endpoint: %s" % e.message) module.fail_json(msg = "Error getting network endpoint: %s" % e.message)
return endpoint return endpoint
@ -126,7 +126,7 @@ def _get_neutron_client(module, kwargs):
} }
try: try:
neutron = client.Client('2.0', **kwargs) neutron = client.Client('2.0', **kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in connecting to neutron: %s " % e.message) module.fail_json(msg = "Error in connecting to neutron: %s " % e.message)
return neutron return neutron
@ -150,7 +150,7 @@ def _get_router_id(module, neutron):
} }
try: try:
routers = neutron.list_routers(**kwargs) routers = neutron.list_routers(**kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in getting the router list: %s " % e.message) module.fail_json(msg = "Error in getting the router list: %s " % e.message)
if not routers['routers']: if not routers['routers']:
return None return None
@ -165,7 +165,7 @@ def _get_subnet_id(module, neutron):
} }
try: try:
subnets = neutron.list_subnets(**kwargs) subnets = neutron.list_subnets(**kwargs)
except Exception, e: except Exception as e:
module.fail_json( msg = " Error in getting the subnet list:%s " % e.message) module.fail_json( msg = " Error in getting the subnet list:%s " % e.message)
if not subnets['subnets']: if not subnets['subnets']:
return None return None
@ -178,7 +178,7 @@ def _get_port_id(neutron, module, router_id, subnet_id):
} }
try: try:
ports = neutron.list_ports(**kwargs) ports = neutron.list_ports(**kwargs)
except Exception, e: except Exception as e:
module.fail_json( msg = "Error in listing ports: %s" % e.message) module.fail_json( msg = "Error in listing ports: %s" % e.message)
if not ports['ports']: if not ports['ports']:
return None return None
@ -194,7 +194,7 @@ def _add_interface_router(neutron, module, router_id, subnet_id):
} }
try: try:
neutron.add_interface_router(router_id, kwargs) neutron.add_interface_router(router_id, kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = "Error in adding interface to router: %s" % e.message) module.fail_json(msg = "Error in adding interface to router: %s" % e.message)
return True return True
@ -204,7 +204,7 @@ def _remove_interface_router(neutron, module, router_id, subnet_id):
} }
try: try:
neutron.remove_interface_router(router_id, kwargs) neutron.remove_interface_router(router_id, kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg="Error in removing interface from router: %s" % e.message) module.fail_json(msg="Error in removing interface from router: %s" % e.message)
return True return True

@ -135,7 +135,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'), password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'), tenant_name=kwargs.get('login_tenant_name'),
auth_url=kwargs.get('auth_url')) auth_url=kwargs.get('auth_url'))
except Exception, e: except Exception as e:
module.fail_json(msg = "Error authenticating to the keystone: %s" %e.message) module.fail_json(msg = "Error authenticating to the keystone: %s" %e.message)
global _os_keystone global _os_keystone
_os_keystone = kclient _os_keystone = kclient
@ -145,7 +145,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient): def _get_endpoint(module, ksclient):
try: try:
endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL') endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL')
except Exception, e: except Exception as e:
module.fail_json(msg = "Error getting network endpoint: %s" % e.message) module.fail_json(msg = "Error getting network endpoint: %s" % e.message)
return endpoint return endpoint
@ -159,7 +159,7 @@ def _get_neutron_client(module, kwargs):
} }
try: try:
neutron = client.Client('2.0', **kwargs) neutron = client.Client('2.0', **kwargs)
except Exception, e: except Exception as e:
module.fail_json(msg = " Error in connecting to neutron: %s" % e.message) module.fail_json(msg = " Error in connecting to neutron: %s" % e.message)
return neutron return neutron
@ -184,7 +184,7 @@ def _get_net_id(neutron, module):
} }
try: try:
networks = neutron.list_networks(**kwargs) networks = neutron.list_networks(**kwargs)
except Exception, e: except Exception as e:
module.fail_json("Error in listing neutron networks: %s" % e.message) module.fail_json("Error in listing neutron networks: %s" % e.message)
if not networks['networks']: if not networks['networks']:
return None return None
@ -204,7 +204,7 @@ def _get_subnet_id(module, neutron):
} }
try: try:
subnets = neutron.list_subnets(**kwargs) subnets = neutron.list_subnets(**kwargs)
except Exception, e: except Exception as e:
module.fail_json( msg = " Error in getting the subnet list:%s " % e.message) module.fail_json( msg = " Error in getting the subnet list:%s " % e.message)
if not subnets['subnets']: if not subnets['subnets']:
return None return None
@ -238,7 +238,7 @@ def _create_subnet(module, neutron):
subnet.pop('dns_nameservers') subnet.pop('dns_nameservers')
try: try:
new_subnet = neutron.create_subnet(dict(subnet=subnet)) new_subnet = neutron.create_subnet(dict(subnet=subnet))
except Exception, e: except Exception as e:
module.fail_json(msg = "Failure in creating subnet: %s" % e.message) module.fail_json(msg = "Failure in creating subnet: %s" % e.message)
return new_subnet['subnet']['id'] return new_subnet['subnet']['id']
@ -246,7 +246,7 @@ def _create_subnet(module, neutron):
def _delete_subnet(module, neutron, subnet_id): def _delete_subnet(module, neutron, subnet_id):
try: try:
neutron.delete_subnet(subnet_id) neutron.delete_subnet(subnet_id)
except Exception, e: except Exception as e:
module.fail_json( msg = "Error in deleting subnet: %s" % e.message) module.fail_json( msg = "Error in deleting subnet: %s" % e.message)
return True return True

Loading…
Cancel
Save