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

This commit is contained in:
codemeup @ Work 2016-06-03 06:37:09 -07:00 committed by Toshio Kuratomi
parent d0a955452a
commit 18455b2e72
11 changed files with 73 additions and 73 deletions

View file

@ -150,7 +150,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'),
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)
return client
@ -158,7 +158,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, client, endpoint_type):
try:
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)
return endpoint
@ -172,7 +172,7 @@ def _get_glance_client(module, kwargs):
}
try:
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)
return client
@ -183,7 +183,7 @@ def _glance_image_present(module, params, client):
if image.name == params['name']:
return image.id
return None
except Exception, e:
except Exception as e:
module.fail_json(msg="Error in fetching image list: %s" % e.message)
@ -207,7 +207,7 @@ def _glance_image_create(module, params, client):
if image.status == 'active':
break
time.sleep(5)
except Exception, e:
except Exception as e:
module.fail_json(msg="Error in creating image: %s" % e.message)
if image.status == 'active':
module.exit_json(changed=True, result=image.status, id=image.id)
@ -220,7 +220,7 @@ def _glance_delete_image(module, params, client):
for image in client.images.list():
if image.name == params['name']:
client.images.delete(image)
except Exception, e:
except Exception as e:
module.fail_json(msg="Error in deleting image: %s" % e.message)
module.exit_json(changed=True, result="Deleted")

View file

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

View file

@ -286,7 +286,7 @@ def _delete_server(module, nova):
if server_list:
server = [x for x in server_list if x.name == module.params['name']]
nova.servers.delete(server.pop())
except Exception, e:
except Exception as e:
module.fail_json( msg = "Error in deleting vm: %s" % e.message)
if module.params['wait'] == 'no':
module.exit_json(changed = True, result = "deleted")
@ -333,7 +333,7 @@ def _add_floating_ip_from_pool(module, nova, server):
if not pool_ips:
try:
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))
pool_ips.append(new_ip.ip)
# Add to the main list
@ -348,7 +348,7 @@ def _add_floating_ip_from_pool(module, nova, server):
# race condition and some other cloud operation may have
# stolen an available floating ip
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))
@ -357,7 +357,7 @@ def _add_floating_ip_list(module, server, ips):
for ip in ips:
try:
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))
@ -393,7 +393,7 @@ def _add_floating_ip(module, nova, server):
# a recent server object if the above code path exec'd
try:
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)
return server
@ -438,14 +438,14 @@ def _create_server(module, nova):
try:
server = nova.servers.create(*bootargs, **bootkwargs)
server = nova.servers.get(server.id)
except Exception, e:
except Exception as e:
module.fail_json( msg = "Error in creating instance: %s " % e.message)
if module.params['wait'] == 'yes':
expire = time.time() + int(module.params['wait_for'])
while time.time() < expire:
try:
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)
if server.status == 'ACTIVE':
server = _add_floating_ip(module, nova, server)
@ -514,7 +514,7 @@ def _get_server_state(module, nova):
servers = [x for x in servers if x.name == module.params['name']]
if servers:
server = servers[0]
except Exception, e:
except Exception as e:
module.fail_json(msg = "Error in getting the server list: %s" % e.message)
if server and module.params['state'] == 'present':
if server.status != 'ACTIVE':
@ -577,9 +577,9 @@ def main():
service_type='compute')
try:
nova.authenticate()
except exceptions.Unauthorized, e:
except exceptions.Unauthorized as e:
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)
if module.params['state'] == 'present':

View file

@ -112,9 +112,9 @@ def main():
service_type='compute')
try:
nova.authenticate()
except exc.Unauthorized, e:
except exc.Unauthorized as e:
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)
if module.params['state'] == 'present':
@ -126,7 +126,7 @@ def main():
module.exit_json(changed = False, result = "Key present")
try:
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)
if not module.params['public_key']:
module.exit_json(changed = True, key = key.private_key)
@ -136,7 +136,7 @@ def main():
if key.name == module.params['name']:
try:
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.exit_json( changed = True, result = "deleted")
module.exit_json(changed = False, result = "not present")

View file

@ -108,7 +108,7 @@ def _get_ksclient(module, kwargs):
tenant_name=kwargs.get('login_tenant_name'),
auth_url=kwargs.get('auth_url'),
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)
global _os_keystone
_os_keystone = kclient
@ -118,7 +118,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient):
try:
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)
return endpoint
@ -132,7 +132,7 @@ def _get_neutron_client(module, kwargs):
}
try:
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)
return neutron
@ -148,7 +148,7 @@ def _get_server_state(module, nova):
module.fail_json( msg="The VM is available but not Active. state:" + info['status'])
server_info = info
break
except Exception, e:
except Exception as e:
module.fail_json(msg = "Error in getting the server list: %s" % e.message)
return server_info, server
@ -169,7 +169,7 @@ def _get_port_info(neutron, module, instance_id, internal_network_name=None):
}
try:
ports = neutron.list_ports(**kwargs)
except Exception, e:
except Exception as e:
module.fail_json( msg = "Error in listing ports: %s" % e.message)
if subnet_id:
port = next(port for port in ports['ports'] if port['fixed_ips'][0]['subnet_id'] == subnet_id)
@ -188,7 +188,7 @@ def _get_floating_ip(module, neutron, fixed_ip_address, network_name):
}
try:
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)
if not ips['floatingips']:
return None, None
@ -211,7 +211,7 @@ def _create_floating_ip(neutron, module, port_id, net_id, fixed_ip):
}
try:
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.exit_json(changed=True, result=result, public_ip=result['floatingip']['floating_ip_address'])
@ -221,7 +221,7 @@ def _get_net_id(neutron, module):
}
try:
networks = neutron.list_networks(**kwargs)
except Exception, e:
except Exception as e:
module.fail_json("Error in listing neutron networks: %s" % e.message)
if not networks['networks']:
return None
@ -233,7 +233,7 @@ def _update_floating_ip(neutron, module, port_id, floating_ip_id):
}
try:
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.exit_json(changed=True, result=result)
@ -256,7 +256,7 @@ def main():
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')
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)
server_info, server_obj = _get_server_state(module, nova)

View file

@ -102,7 +102,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'),
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)
global _os_keystone
_os_keystone = kclient
@ -112,7 +112,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient):
try:
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)
return endpoint
@ -126,7 +126,7 @@ def _get_neutron_client(module, kwargs):
}
try:
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)
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'])
server_info = info
break
except Exception, e:
except Exception as e:
module.fail_json(msg = "Error in getting the server list: %s" % e.message)
return server_info, server
@ -150,7 +150,7 @@ def _get_port_id(neutron, module, instance_id):
kwargs = dict(device_id = instance_id)
try:
ports = neutron.list_ports(**kwargs)
except Exception, e:
except Exception as e:
module.fail_json( msg = "Error in listing ports: %s" % e.message)
if not ports['ports']:
return None
@ -162,7 +162,7 @@ def _get_floating_ip_id(module, neutron):
}
try:
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)
if not ips['floatingips']:
module.fail_json(msg = "Could find the ip specified in parameter, Please check")
@ -179,7 +179,7 @@ def _update_floating_ip(neutron, module, port_id, floating_ip_id):
}
try:
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.exit_json(changed = True, result = result, public_ip=module.params['ip_address'])
@ -199,7 +199,7 @@ def main():
try:
nova = nova_client.Client(module.params['login_username'], module.params['login_password'],
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)
neutron = _get_neutron_client(module, module.params)
state, floating_ip_id = _get_floating_ip_id(module, neutron)

View file

@ -133,7 +133,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'),
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)
global _os_keystone
_os_keystone = kclient
@ -143,7 +143,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient):
try:
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)
return endpoint
@ -157,7 +157,7 @@ def _get_neutron_client(module, kwargs):
}
try:
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)
return neutron
@ -182,7 +182,7 @@ def _get_net_id(neutron, module):
}
try:
networks = neutron.list_networks(**kwargs)
except Exception, e:
except Exception as e:
module.fail_json(msg = "Error in listing neutron networks: %s" % e.message)
if not networks['networks']:
return None
@ -220,7 +220,7 @@ def _create_network(module, neutron):
try:
net = neutron.create_network({'network':network})
except Exception, e:
except Exception as e:
module.fail_json(msg = "Error in creating network: %s" % e.message)
return net['network']['id']
@ -228,7 +228,7 @@ def _delete_network(module, net_id, neutron):
try:
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)
return True

View file

@ -105,7 +105,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'),
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)
global _os_keystone
_os_keystone = kclient
@ -115,7 +115,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient):
try:
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)
return endpoint
@ -129,7 +129,7 @@ def _get_neutron_client(module, kwargs):
}
try:
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)
return neutron
@ -154,7 +154,7 @@ def _get_router_id(module, neutron):
}
try:
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)
if not routers['routers']:
return None
@ -168,7 +168,7 @@ def _create_router(module, neutron):
}
try:
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)
return new_router['router']['id']

View file

@ -96,7 +96,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'),
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)
global _os_keystone
_os_keystone = kclient
@ -106,7 +106,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient):
try:
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)
return endpoint
@ -120,7 +120,7 @@ def _get_neutron_client(module, kwargs):
}
try:
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)
return neutron
@ -130,7 +130,7 @@ def _get_router_id(module, neutron):
}
try:
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)
if not routers['routers']:
return None
@ -143,7 +143,7 @@ def _get_net_id(neutron, module):
}
try:
networks = neutron.list_networks(**kwargs)
except Exception, e:
except Exception as e:
module.fail_json("Error in listing neutron networks: %s" % e.message)
if not networks['networks']:
return None
@ -156,7 +156,7 @@ def _get_port_id(neutron, module, router_id, network_id):
}
try:
ports = neutron.list_ports(**kwargs)
except Exception, e:
except Exception as e:
module.fail_json( msg = "Error in listing ports: %s" % e.message)
if not ports['ports']:
return None
@ -168,14 +168,14 @@ def _add_gateway_router(neutron, module, router_id, network_id):
}
try:
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)
return True
def _remove_gateway_router(neutron, module, router_id):
try:
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)
return True

View file

@ -107,7 +107,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'),
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)
global _os_keystone
_os_keystone = kclient
@ -117,7 +117,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient):
try:
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)
return endpoint
@ -131,7 +131,7 @@ def _get_neutron_client(module, kwargs):
}
try:
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)
return neutron
@ -155,7 +155,7 @@ def _get_router_id(module, neutron):
}
try:
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)
if not routers['routers']:
return None
@ -170,7 +170,7 @@ def _get_subnet_id(module, neutron):
}
try:
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)
if not subnets['subnets']:
return None
@ -183,7 +183,7 @@ def _get_port_id(neutron, module, router_id, subnet_id):
}
try:
ports = neutron.list_ports(**kwargs)
except Exception, e:
except Exception as e:
module.fail_json( msg = "Error in listing ports: %s" % e.message)
if not ports['ports']:
return None
@ -199,7 +199,7 @@ def _add_interface_router(neutron, module, router_id, subnet_id):
}
try:
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)
return True
@ -209,7 +209,7 @@ def _remove_interface_router(neutron, module, router_id, subnet_id):
}
try:
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)
return True

View file

@ -139,7 +139,7 @@ def _get_ksclient(module, kwargs):
password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'),
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)
global _os_keystone
_os_keystone = kclient
@ -149,7 +149,7 @@ def _get_ksclient(module, kwargs):
def _get_endpoint(module, ksclient):
try:
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)
return endpoint
@ -163,7 +163,7 @@ def _get_neutron_client(module, kwargs):
}
try:
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)
return neutron
@ -188,7 +188,7 @@ def _get_net_id(neutron, module):
}
try:
networks = neutron.list_networks(**kwargs)
except Exception, e:
except Exception as e:
module.fail_json("Error in listing neutron networks: %s" % e.message)
if not networks['networks']:
return None
@ -208,7 +208,7 @@ def _get_subnet_id(module, neutron):
}
try:
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)
if not subnets['subnets']:
return None
@ -242,7 +242,7 @@ def _create_subnet(module, neutron):
subnet.pop('dns_nameservers')
try:
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)
return new_subnet['subnet']['id']
@ -250,7 +250,7 @@ def _create_subnet(module, neutron):
def _delete_subnet(module, neutron, subnet_id):
try:
neutron.delete_subnet(subnet_id)
except Exception, e:
except Exception as e:
module.fail_json( msg = "Error in deleting subnet: %s" % e.message)
return True