Fixing Rackspace compile time errors irt exception handling for Python 3 (#3849)

reviewable/pr18780/r1
codemeup @ Work 9 years ago committed by Toshio Kuratomi
parent 18455b2e72
commit a51a896d20

@ -291,7 +291,7 @@ def create(module, names=[], flavor=None, image=None, meta={}, key_name=None,
f = open(user_data) f = open(user_data)
user_data = f.read() user_data = f.read()
f.close() f.close()
except Exception, e: except Exception as e:
module.fail_json(msg='Failed to load %s' % user_data) module.fail_json(msg='Failed to load %s' % user_data)
# Handle the file contents # Handle the file contents
@ -301,7 +301,7 @@ def create(module, names=[], flavor=None, image=None, meta={}, key_name=None,
fileobj = open(lpath, 'r') fileobj = open(lpath, 'r')
files[rpath] = fileobj.read() files[rpath] = fileobj.read()
fileobj.close() fileobj.close()
except Exception, e: except Exception as e:
module.fail_json(msg='Failed to load %s' % lpath) module.fail_json(msg='Failed to load %s' % lpath)
try: try:
servers = [] servers = []
@ -316,7 +316,7 @@ def create(module, names=[], flavor=None, image=None, meta={}, key_name=None,
userdata=user_data, userdata=user_data,
block_device_mapping_v2=bdmv2, block_device_mapping_v2=bdmv2,
**extra_create_args)) **extra_create_args))
except Exception, e: except Exception as e:
if e.message: if e.message:
msg = str(e.message) msg = str(e.message)
else: else:
@ -398,7 +398,7 @@ def delete(module, instance_ids=[], wait=True, wait_timeout=300, kept=[]):
for server in servers: for server in servers:
try: try:
server.delete() server.delete()
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
changed = True changed = True
@ -546,7 +546,7 @@ def cloudservers(module, state=None, name=None, flavor=None, image=None,
# %d to the end # %d to the end
try: try:
name % 0 name % 0
except TypeError, e: except TypeError as e:
if e.message.startswith('not all'): if e.message.startswith('not all'):
name = '%s%%d' % name name = '%s%%d' % name
else: else:
@ -636,7 +636,7 @@ def cloudservers(module, state=None, name=None, flavor=None, image=None,
# %d to the end # %d to the end
try: try:
name % 0 name % 0
except TypeError, e: except TypeError as e:
if e.message.startswith('not all'): if e.message.startswith('not all'):
name = '%s%%d' % name name = '%s%%d' % name
else: else:

@ -151,7 +151,7 @@ def cloud_block_storage(module, state, name, description, meta, size,
metadata=meta, metadata=meta,
snapshot_id=snapshot_id, **kwargs) snapshot_id=snapshot_id, **kwargs)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
if wait: if wait:
@ -180,7 +180,7 @@ def cloud_block_storage(module, state, name, description, meta, size,
try: try:
volume.delete() volume.delete()
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
module.exit_json(changed=changed, volume=instance) module.exit_json(changed=changed, volume=instance)

@ -120,7 +120,7 @@ def cloud_block_storage_attachments(module, state, volume, server, device,
try: try:
volume.attach_to_instance(server, mountpoint=device) volume.attach_to_instance(server, mountpoint=device)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
volume.get() volume.get()
@ -159,7 +159,7 @@ def cloud_block_storage_attachments(module, state, volume, server, device,
interval=3, attempts=0, interval=3, attempts=0,
verbose=False) verbose=False)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
volume.get() volume.get()

@ -136,7 +136,7 @@ def save_instance(module, name, flavor, volume, cdb_type, cdb_version, wait,
try: try:
instance = cdb.create(name=name, flavor=flavor, volume=volume, instance = cdb.create(name=name, flavor=flavor, volume=volume,
type=cdb_type, version=cdb_version) type=cdb_type, version=cdb_version)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
changed = True changed = True
@ -187,7 +187,7 @@ def delete_instance(module, name, wait, wait_timeout):
try: try:
instance.delete() instance.delete()
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
changed = True changed = True

@ -83,7 +83,7 @@ def save_database(module, cdb_id, name, character_set, collate):
try: try:
instance = cdb.get(cdb_id) instance = cdb.get(cdb_id)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
changed = False changed = False
@ -95,7 +95,7 @@ def save_database(module, cdb_id, name, character_set, collate):
database = instance.create_database(name=name, database = instance.create_database(name=name,
character_set=character_set, character_set=character_set,
collate=collate) collate=collate)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
changed = True changed = True
@ -109,7 +109,7 @@ def delete_database(module, cdb_id, name):
try: try:
instance = cdb.get(cdb_id) instance = cdb.get(cdb_id)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
changed = False changed = False
@ -119,7 +119,7 @@ def delete_database(module, cdb_id, name):
if database: if database:
try: try:
database.delete() database.delete()
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
changed = True changed = True

@ -98,7 +98,7 @@ def save_user(module, cdb_id, name, password, databases, host):
try: try:
instance = cdb.get(cdb_id) instance = cdb.get(cdb_id)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
changed = False changed = False
@ -112,7 +112,7 @@ def save_user(module, cdb_id, name, password, databases, host):
password=password, password=password,
database_names=databases, database_names=databases,
host=host) host=host)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
changed = True changed = True
@ -134,7 +134,7 @@ def save_user(module, cdb_id, name, password, databases, host):
new_dbs = [db for db in databases if db not in former_dbs] new_dbs = [db for db in databases if db not in former_dbs]
user.grant_user_access(db_names=new_dbs) user.grant_user_access(db_names=new_dbs)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
changed = True changed = True
@ -153,7 +153,7 @@ def delete_user(module, cdb_id, name):
try: try:
instance = cdb.get(cdb_id) instance = cdb.get(cdb_id)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
changed = False changed = False
@ -163,7 +163,7 @@ def delete_user(module, cdb_id, name):
if user: if user:
try: try:
user.delete() user.delete()
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
changed = True changed = True

@ -182,7 +182,7 @@ def cloud_load_balancer(module, state, name, meta, algorithm, port, protocol,
algorithm=algorithm, protocol=protocol, algorithm=algorithm, protocol=protocol,
timeout=timeout, virtual_ips=virtual_ips) timeout=timeout, virtual_ips=virtual_ips)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
balancer = balancers[0] balancer = balancers[0]
@ -240,7 +240,7 @@ def cloud_load_balancer(module, state, name, meta, algorithm, port, protocol,
try: try:
balancer.delete() balancer.delete()
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
instance = rax_to_dict(balancer, 'clb') instance = rax_to_dict(balancer, 'clb')

@ -192,7 +192,7 @@ def main():
if virtualenv: if virtualenv:
try: try:
_activate_virtualenv(virtualenv) _activate_virtualenv(virtualenv)
except IOError, e: except IOError as e:
module.fail_json(msg='Failed to activate virtualenv %s (%s)' % ( module.fail_json(msg='Failed to activate virtualenv %s (%s)' % (
virtualenv, e)) virtualenv, e))
@ -205,7 +205,7 @@ def main():
try: try:
lb = pyrax.cloud_loadbalancers.get(load_balancer_id) lb = pyrax.cloud_loadbalancers.get(load_balancer_id)
except pyrax.exc.PyraxException, e: except pyrax.exc.PyraxException as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
node = _get_node(lb, node_id, address, port) node = _get_node(lb, node_id, address, port)
@ -220,7 +220,7 @@ def main():
result = {} result = {}
except pyrax.exc.NotFound: except pyrax.exc.NotFound:
module.exit_json(changed=False, state=state) module.exit_json(changed=False, state=state)
except pyrax.exc.PyraxException, e: except pyrax.exc.PyraxException as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: # present else: # present
if not node: if not node:
@ -237,7 +237,7 @@ def main():
weight=weight, type=typ) weight=weight, type=typ)
resp, body = lb.add_nodes([node]) resp, body = lb.add_nodes([node])
result.update(body['nodes'][0]) result.update(body['nodes'][0])
except pyrax.exc.PyraxException, e: except pyrax.exc.PyraxException as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: # Updating an existing node else: # Updating an existing node
mutable = { mutable = {
@ -258,7 +258,7 @@ def main():
# type; this should probably be fixed in pyrax # type; this should probably be fixed in pyrax
lb.update_node(node, diff=mutable) lb.update_node(node, diff=mutable)
result.update(mutable) result.update(mutable)
except pyrax.exc.PyraxException, e: except pyrax.exc.PyraxException as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
if wait: if wait:

@ -89,14 +89,14 @@ def rax_dns(module, comment, email, name, state, ttl):
try: try:
domain = dns.find(name=name) domain = dns.find(name=name)
except pyrax.exceptions.NoUniqueMatch, e: except pyrax.exceptions.NoUniqueMatch as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
except pyrax.exceptions.NotFound: except pyrax.exceptions.NotFound:
try: try:
domain = dns.create(name=name, emailAddress=email, ttl=ttl, domain = dns.create(name=name, emailAddress=email, ttl=ttl,
comment=comment) comment=comment)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
update = {} update = {}
@ -112,7 +112,7 @@ def rax_dns(module, comment, email, name, state, ttl):
domain.update(**update) domain.update(**update)
changed = True changed = True
domain.get() domain.get()
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
elif state == 'absent': elif state == 'absent':
@ -121,14 +121,14 @@ def rax_dns(module, comment, email, name, state, ttl):
except pyrax.exceptions.NotFound: except pyrax.exceptions.NotFound:
domain = {} domain = {}
pass pass
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
if domain: if domain:
try: try:
domain.delete() domain.delete()
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
module.exit_json(changed=changed, domain=rax_to_dict(domain)) module.exit_json(changed=changed, domain=rax_to_dict(domain))

@ -152,7 +152,7 @@ def rax_dns_record_ptr(module, data=None, comment=None, loadbalancer=None,
try: try:
dns.update_ptr_record(item, record, name, data, ttl) dns.update_ptr_record(item, record, name, data, ttl)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
record.ttl = ttl record.ttl = ttl
record.name = name record.name = name
@ -168,7 +168,7 @@ def rax_dns_record_ptr(module, data=None, comment=None, loadbalancer=None,
try: try:
results = dns.add_ptr_records(item, [record]) results = dns.add_ptr_records(item, [record])
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
module.exit_json(changed=changed, records=results) module.exit_json(changed=changed, records=results)
@ -184,7 +184,7 @@ def rax_dns_record_ptr(module, data=None, comment=None, loadbalancer=None,
try: try:
dns.delete_ptr_records(item, data) dns.delete_ptr_records(item, data)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
module.exit_json(changed=changed, records=results) module.exit_json(changed=changed, records=results)
@ -210,7 +210,7 @@ def rax_dns_record(module, comment=None, data=None, domain=None, name=None,
try: try:
domain = dns.find(name=domain) domain = dns.find(name=domain)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
try: try:
@ -218,9 +218,9 @@ def rax_dns_record(module, comment=None, data=None, domain=None, name=None,
record = domain.find_record(record_type, name=name) record = domain.find_record(record_type, name=name)
else: else:
record = domain.find_record(record_type, name=name, data=data) record = domain.find_record(record_type, name=name, data=data)
except pyrax.exceptions.DomainRecordNotUnique, e: except pyrax.exceptions.DomainRecordNotUnique as e:
module.fail_json(msg='overwrite=true and there are multiple matching records') module.fail_json(msg='overwrite=true and there are multiple matching records')
except pyrax.exceptions.DomainRecordNotFound, e: except pyrax.exceptions.DomainRecordNotFound as e:
try: try:
record_data = { record_data = {
'type': record_type, 'type': record_type,
@ -235,7 +235,7 @@ def rax_dns_record(module, comment=None, data=None, domain=None, name=None,
record = domain.add_records([record_data])[0] record = domain.add_records([record_data])[0]
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
update = {} update = {}
@ -253,28 +253,28 @@ def rax_dns_record(module, comment=None, data=None, domain=None, name=None,
record.update(**update) record.update(**update)
changed = True changed = True
record.get() record.get()
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
elif state == 'absent': elif state == 'absent':
try: try:
domain = dns.find(name=domain) domain = dns.find(name=domain)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
try: try:
record = domain.find_record(record_type, name=name, data=data) record = domain.find_record(record_type, name=name, data=data)
except pyrax.exceptions.DomainRecordNotFound, e: except pyrax.exceptions.DomainRecordNotFound as e:
record = {} record = {}
pass pass
except pyrax.exceptions.DomainRecordNotUnique, e: except pyrax.exceptions.DomainRecordNotUnique as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
if record: if record:
try: try:
record.delete() record.delete()
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
module.exit_json(changed=changed, record=rax_to_dict(record)) module.exit_json(changed=changed, record=rax_to_dict(record))

@ -79,7 +79,7 @@ def rax_facts(module, address, name, server_id):
search_opts = dict(name='^%s$' % name) search_opts = dict(name='^%s$' % name)
try: try:
servers = cs.servers.list(search_opts=search_opts) servers = cs.servers.list(search_opts=search_opts)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
elif address: elif address:
servers = [] servers = []
@ -89,13 +89,13 @@ def rax_facts(module, address, name, server_id):
if address in addresses: if address in addresses:
servers.append(server) servers.append(server)
break break
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
elif server_id: elif server_id:
servers = [] servers = []
try: try:
servers.append(cs.servers.get(server_id)) servers.append(cs.servers.get(server_id))
except Exception, e: except Exception as e:
pass pass
servers[:] = [server for server in servers if server.status != "DELETED"] servers[:] = [server for server in servers if server.status != "DELETED"]

@ -142,7 +142,7 @@ EXAMPLES = '''
try: try:
import pyrax import pyrax
HAS_PYRAX = True HAS_PYRAX = True
except ImportError, e: except ImportError as e:
HAS_PYRAX = False HAS_PYRAX = False
EXIT_DICT = dict(success=True) EXIT_DICT = dict(success=True)
@ -152,7 +152,7 @@ META_PREFIX = 'x-container-meta-'
def _get_container(module, cf, container): def _get_container(module, cf, container):
try: try:
return cf.get_container(container) return cf.get_container(container)
except pyrax.exc.NoSuchContainer, e: except pyrax.exc.NoSuchContainer as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
@ -162,7 +162,7 @@ def _fetch_meta(module, container):
for k, v in container.get_metadata().items(): for k, v in container.get_metadata().items():
split_key = k.split(META_PREFIX)[-1] split_key = k.split(META_PREFIX)[-1]
EXIT_DICT['meta'][split_key] = v EXIT_DICT['meta'][split_key] = v
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
@ -172,7 +172,7 @@ def meta(cf, module, container_, state, meta_, clear_meta):
if meta_ and state == 'present': if meta_ and state == 'present':
try: try:
meta_set = c.set_metadata(meta_, clear=clear_meta) meta_set = c.set_metadata(meta_, clear=clear_meta)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
elif meta_ and state == 'absent': elif meta_ and state == 'absent':
remove_results = [] remove_results = []
@ -214,12 +214,12 @@ def container(cf, module, container_, state, meta_, clear_meta, ttl, public,
try: try:
c = cf.get_container(container_) c = cf.get_container(container_)
except pyrax.exc.NoSuchContainer, e: except pyrax.exc.NoSuchContainer as e:
# Make the container if state=present, otherwise bomb out # Make the container if state=present, otherwise bomb out
if state == 'present': if state == 'present':
try: try:
c = cf.create_container(container_) c = cf.create_container(container_)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
EXIT_DICT['changed'] = True EXIT_DICT['changed'] = True
@ -232,7 +232,7 @@ def container(cf, module, container_, state, meta_, clear_meta, ttl, public,
if state == 'absent': if state == 'absent':
try: try:
cont_deleted = c.delete() cont_deleted = c.delete()
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
EXIT_DICT['deleted'] = True EXIT_DICT['deleted'] = True
@ -240,7 +240,7 @@ def container(cf, module, container_, state, meta_, clear_meta, ttl, public,
if meta_: if meta_:
try: try:
meta_set = c.set_metadata(meta_, clear=clear_meta) meta_set = c.set_metadata(meta_, clear=clear_meta)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
finally: finally:
_fetch_meta(module, c) _fetch_meta(module, c)
@ -248,7 +248,7 @@ def container(cf, module, container_, state, meta_, clear_meta, ttl, public,
if ttl: if ttl:
try: try:
c.cdn_ttl = ttl c.cdn_ttl = ttl
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
EXIT_DICT['ttl'] = c.cdn_ttl EXIT_DICT['ttl'] = c.cdn_ttl
@ -256,7 +256,7 @@ def container(cf, module, container_, state, meta_, clear_meta, ttl, public,
if public: if public:
try: try:
cont_public = c.make_public() cont_public = c.make_public()
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
EXIT_DICT['container_urls'] = dict(url=c.cdn_uri, EXIT_DICT['container_urls'] = dict(url=c.cdn_uri,
@ -267,7 +267,7 @@ def container(cf, module, container_, state, meta_, clear_meta, ttl, public,
if private: if private:
try: try:
cont_private = c.make_private() cont_private = c.make_private()
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
EXIT_DICT['set_private'] = True EXIT_DICT['set_private'] = True
@ -275,7 +275,7 @@ def container(cf, module, container_, state, meta_, clear_meta, ttl, public,
if web_index: if web_index:
try: try:
cont_web_index = c.set_web_index_page(web_index) cont_web_index = c.set_web_index_page(web_index)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
EXIT_DICT['set_index'] = True EXIT_DICT['set_index'] = True
@ -285,7 +285,7 @@ def container(cf, module, container_, state, meta_, clear_meta, ttl, public,
if web_error: if web_error:
try: try:
cont_err_index = c.set_web_error_page(web_error) cont_err_index = c.set_web_error_page(web_error)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
EXIT_DICT['set_error'] = True EXIT_DICT['set_error'] = True

@ -196,7 +196,7 @@ META_PREFIX = 'x-object-meta-'
def _get_container(module, cf, container): def _get_container(module, cf, container):
try: try:
return cf.get_container(container) return cf.get_container(container)
except pyrax.exc.NoSuchContainer, e: except pyrax.exc.NoSuchContainer as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
@ -238,17 +238,17 @@ def upload(module, cf, container, src, dest, meta, expires):
if dest and not is_dir: if dest and not is_dir:
try: try:
cont_obj = c.upload_file(src, obj_name=dest, ttl=expires, headers=meta) cont_obj = c.upload_file(src, obj_name=dest, ttl=expires, headers=meta)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
elif is_dir: elif is_dir:
try: try:
total_bytes = _upload_folder(cf, src, c, ttl=expires, headers=meta) total_bytes = _upload_folder(cf, src, c, ttl=expires, headers=meta)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
try: try:
cont_obj = c.upload_file(src, ttl=expires, headers=meta) cont_obj = c.upload_file(src, ttl=expires, headers=meta)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
EXIT_DICT['success'] = True EXIT_DICT['success'] = True
@ -299,7 +299,7 @@ def download(module, cf, container, src, dest, structure):
for obj in objs: for obj in objs:
try: try:
c.download_object(obj, dest, structure=structure) c.download_object(obj, dest, structure=structure)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
results.append(obj) results.append(obj)
@ -348,7 +348,7 @@ def delete(module, cf, container, src, dest):
for obj in objs: for obj in objs:
try: try:
result = c.delete_object(obj) result = c.delete_object(obj)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
results.append(result) results.append(result)
@ -396,7 +396,7 @@ def get_meta(module, cf, container, src, dest):
for obj in objs: for obj in objs:
try: try:
meta = c.get_object(obj).get_metadata() meta = c.get_object(obj).get_metadata()
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
results[obj] = dict() results[obj] = dict()
@ -434,7 +434,7 @@ def put_meta(module, cf, container, src, dest, meta, clear_meta):
for obj in objs: for obj in objs:
try: try:
result = c.get_object(obj).set_metadata(meta, clear=clear_meta) result = c.get_object(obj).set_metadata(meta, clear=clear_meta)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
results.append(result) results.append(result)
@ -473,20 +473,20 @@ def delete_meta(module, cf, container, src, dest, meta):
for k, v in meta.items(): for k, v in meta.items():
try: try:
result = c.get_object(obj).remove_metadata_key(k) result = c.get_object(obj).remove_metadata_key(k)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
results.append(result) results.append(result)
else: else:
try: try:
o = c.get_object(obj) o = c.get_object(obj)
except pyrax.exc.NoSuchObject, e: except pyrax.exc.NoSuchObject as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
for k, v in o.get_metadata().items(): for k, v in o.get_metadata().items():
try: try:
result = o.remove_metadata_key(k) result = o.remove_metadata_key(k)
except Exception, e: except Exception as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
results.append(result) results.append(result)

@ -109,7 +109,7 @@ def rax_keypair(module, name, public_key, state):
f = open(public_key) f = open(public_key)
public_key = f.read() public_key = f.read()
f.close() f.close()
except Exception, e: except Exception as e:
module.fail_json(msg='Failed to load %s' % public_key) module.fail_json(msg='Failed to load %s' % public_key)
try: try:
@ -118,9 +118,9 @@ def rax_keypair(module, name, public_key, state):
try: try:
keypair = cs.keypairs.create(name, public_key) keypair = cs.keypairs.create(name, public_key)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
elif state == 'absent': elif state == 'absent':
@ -133,7 +133,7 @@ def rax_keypair(module, name, public_key, state):
try: try:
keypair.delete() keypair.delete()
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
module.exit_json(changed=changed, keypair=rax_to_dict(keypair)) module.exit_json(changed=changed, keypair=rax_to_dict(keypair))

@ -91,7 +91,7 @@ def rax_meta(module, address, name, server_id, meta):
search_opts = dict(name='^%s$' % name) search_opts = dict(name='^%s$' % name)
try: try:
servers = cs.servers.list(search_opts=search_opts) servers = cs.servers.list(search_opts=search_opts)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
elif address: elif address:
servers = [] servers = []
@ -101,13 +101,13 @@ def rax_meta(module, address, name, server_id, meta):
if address in addresses: if address in addresses:
servers.append(server) servers.append(server)
break break
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
elif server_id: elif server_id:
servers = [] servers = []
try: try:
servers.append(cs.servers.get(server_id)) servers.append(cs.servers.get(server_id))
except Exception, e: except Exception as e:
pass pass
if len(servers) > 1: if len(servers) > 1:

@ -86,9 +86,9 @@ def cloud_network(module, state, label, cidr):
try: try:
network = pyrax.cloud_networks.create(label, cidr=cidr) network = pyrax.cloud_networks.create(label, cidr=cidr)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
elif state == 'absent': elif state == 'absent':
@ -98,7 +98,7 @@ def cloud_network(module, state, label, cidr):
changed = True changed = True
except pyrax.exceptions.NetworkNotFound: except pyrax.exceptions.NetworkNotFound:
pass pass
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
if network: if network:

@ -93,7 +93,7 @@ def cloud_queue(module, state, name):
try: try:
queue = cq.create(name) queue = cq.create(name)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
queue = queues[0] queue = queues[0]
@ -108,7 +108,7 @@ def cloud_queue(module, state, name):
try: try:
queue.delete() queue.delete()
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
module.exit_json(changed=changed, queue=instance) module.exit_json(changed=changed, queue=instance)

@ -173,7 +173,7 @@ def rax_asg(module, cooldown=300, disk_config=None, files={}, flavor=None,
f = open(user_data) f = open(user_data)
user_data = f.read() user_data = f.read()
f.close() f.close()
except Exception, e: except Exception as e:
module.fail_json(msg='Failed to load %s' % user_data) module.fail_json(msg='Failed to load %s' % user_data)
if state == 'present': if state == 'present':
@ -215,7 +215,7 @@ def rax_asg(module, cooldown=300, disk_config=None, files={}, flavor=None,
'contents': f.read() 'contents': f.read()
}) })
f.close() f.close()
except Exception, e: except Exception as e:
module.fail_json(msg='Failed to load %s' % lpath) module.fail_json(msg='Failed to load %s' % lpath)
lbs = [] lbs = []
@ -237,7 +237,7 @@ def rax_asg(module, cooldown=300, disk_config=None, files={}, flavor=None,
try: try:
sg = au.find(name=name) sg = au.find(name=name)
except pyrax.exceptions.NoUniqueMatch, e: except pyrax.exceptions.NoUniqueMatch as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
except pyrax.exceptions.NotFound: except pyrax.exceptions.NotFound:
try: try:
@ -252,7 +252,7 @@ def rax_asg(module, cooldown=300, disk_config=None, files={}, flavor=None,
key_name=key_name, config_drive=config_drive, key_name=key_name, config_drive=config_drive,
user_data=user_data) user_data=user_data)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
if not changed: if not changed:
@ -344,9 +344,9 @@ def rax_asg(module, cooldown=300, disk_config=None, files={}, flavor=None,
sg = au.find(name=name) sg = au.find(name=name)
sg.delete() sg.delete()
changed = True changed = True
except pyrax.exceptions.NotFound, e: except pyrax.exceptions.NotFound as e:
sg = {} sg = {}
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
module.exit_json(changed=changed, autoscale_group=rax_to_dict(sg)) module.exit_json(changed=changed, autoscale_group=rax_to_dict(sg))

@ -141,12 +141,12 @@ def rax_asp(module, at=None, change=0, cron=None, cooldown=300,
except ValueError: except ValueError:
try: try:
sg = au.find(name=scaling_group) sg = au.find(name=scaling_group)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
try: try:
sg = au.get(scaling_group) sg = au.get(scaling_group)
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
if state == 'present': if state == 'present':
@ -168,7 +168,7 @@ def rax_asp(module, at=None, change=0, cron=None, cooldown=300,
desired_capacity=desired_capacity, desired_capacity=desired_capacity,
args=args) args=args)
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
@ -217,7 +217,7 @@ def rax_asp(module, at=None, change=0, cron=None, cooldown=300,
else: else:
policy.delete() policy.delete()
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
module.exit_json(changed=changed, autoscale_policy=rax_to_dict(policy)) module.exit_json(changed=changed, autoscale_policy=rax_to_dict(policy))

Loading…
Cancel
Save