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'),
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
@ -150,7 +150,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
@ -164,7 +164,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
@ -175,7 +175,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)
@ -199,7 +199,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)
@ -212,7 +212,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")

@ -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,

@ -283,7 +283,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")
@ -330,7 +330,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
@ -345,7 +345,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))
@ -354,7 +354,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))
@ -390,7 +390,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
@ -435,14 +435,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)
@ -511,7 +511,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':
@ -571,9 +571,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':

@ -107,9 +107,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':
@ -121,7 +121,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)
@ -131,7 +131,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")

@ -102,7 +102,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
@ -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
@ -163,7 +163,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)
@ -182,7 +182,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
@ -205,7 +205,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'])
@ -215,7 +215,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
@ -227,7 +227,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)
@ -247,7 +247,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)

@ -97,7 +97,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
@ -107,7 +107,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
@ -121,7 +121,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
@ -137,7 +137,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
@ -145,7 +145,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
@ -157,7 +157,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")
@ -174,7 +174,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'])
@ -191,7 +191,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)

@ -129,7 +129,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
@ -139,7 +139,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
@ -153,7 +153,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
@ -178,7 +178,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
@ -216,7 +216,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']
@ -224,7 +224,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

@ -101,7 +101,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
@ -111,7 +111,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
@ -125,7 +125,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
@ -150,7 +150,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
@ -164,7 +164,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']

@ -91,7 +91,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
@ -101,7 +101,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
@ -115,7 +115,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
@ -125,7 +125,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
@ -138,7 +138,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
@ -151,7 +151,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
@ -163,14 +163,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

@ -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
@ -150,7 +150,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
@ -165,7 +165,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
@ -178,7 +178,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
@ -194,7 +194,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
@ -204,7 +204,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

@ -135,7 +135,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
@ -145,7 +145,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
@ -159,7 +159,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
@ -184,7 +184,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
@ -204,7 +204,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
@ -238,7 +238,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']
@ -246,7 +246,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

Loading…
Cancel
Save