Fixing gce compile time errors irt exception handling for Python 3 (#3845)
This commit is contained in:
parent
100cc644a3
commit
d0a955452a
5 changed files with 29 additions and 29 deletions
|
@ -134,7 +134,7 @@ def grant_check(module, gs, obj):
|
|||
if not grant:
|
||||
obj.set_acl('authenticated-read')
|
||||
module.exit_json(changed=True, result="The objects permission as been set to authenticated-read")
|
||||
except gs.provider.storage_response_error, e:
|
||||
except gs.provider.storage_response_error as e:
|
||||
module.fail_json(msg= str(e))
|
||||
return True
|
||||
|
||||
|
@ -144,7 +144,7 @@ def key_check(module, gs, bucket, obj):
|
|||
try:
|
||||
bucket = gs.lookup(bucket)
|
||||
key_check = bucket.get_key(obj)
|
||||
except gs.provider.storage_response_error, e:
|
||||
except gs.provider.storage_response_error as e:
|
||||
module.fail_json(msg= str(e))
|
||||
if key_check:
|
||||
grant_check(module, gs, key_check)
|
||||
|
@ -166,7 +166,7 @@ def keysum(module, gs, bucket, obj):
|
|||
def bucket_check(module, gs, bucket):
|
||||
try:
|
||||
result = gs.lookup(bucket)
|
||||
except gs.provider.storage_response_error, e:
|
||||
except gs.provider.storage_response_error as e:
|
||||
module.fail_json(msg= str(e))
|
||||
if result:
|
||||
grant_check(module, gs, result)
|
||||
|
@ -178,7 +178,7 @@ def create_bucket(module, gs, bucket):
|
|||
try:
|
||||
bucket = gs.create_bucket(bucket)
|
||||
bucket.set_acl(module.params.get('permission'))
|
||||
except gs.provider.storage_response_error, e:
|
||||
except gs.provider.storage_response_error as e:
|
||||
module.fail_json(msg= str(e))
|
||||
if bucket:
|
||||
return True
|
||||
|
@ -191,7 +191,7 @@ def delete_bucket(module, gs, bucket):
|
|||
bucket.delete_key(key.name)
|
||||
bucket.delete()
|
||||
return True
|
||||
except gs.provider.storage_response_error, e:
|
||||
except gs.provider.storage_response_error as e:
|
||||
module.fail_json(msg= str(e))
|
||||
|
||||
def delete_key(module, gs, bucket, obj):
|
||||
|
@ -199,7 +199,7 @@ def delete_key(module, gs, bucket, obj):
|
|||
bucket = gs.lookup(bucket)
|
||||
bucket.delete_key(obj)
|
||||
module.exit_json(msg="Object deleted from bucket ", changed=True)
|
||||
except gs.provider.storage_response_error, e:
|
||||
except gs.provider.storage_response_error as e:
|
||||
module.fail_json(msg= str(e))
|
||||
|
||||
def create_dirkey(module, gs, bucket, obj):
|
||||
|
@ -208,7 +208,7 @@ def create_dirkey(module, gs, bucket, obj):
|
|||
key = bucket.new_key(obj)
|
||||
key.set_contents_from_string('')
|
||||
module.exit_json(msg="Virtual directory %s created in bucket %s" % (obj, bucket.name), changed=True)
|
||||
except gs.provider.storage_response_error, e:
|
||||
except gs.provider.storage_response_error as e:
|
||||
module.fail_json(msg= str(e))
|
||||
|
||||
def path_check(path):
|
||||
|
@ -243,7 +243,7 @@ def upload_gsfile(module, gs, bucket, obj, src, expiry):
|
|||
key.set_acl(module.params.get('permission'))
|
||||
url = key.generate_url(expiry)
|
||||
module.exit_json(msg="PUT operation complete", url=url, changed=True)
|
||||
except gs.provider.storage_copy_error, e:
|
||||
except gs.provider.storage_copy_error as e:
|
||||
module.fail_json(msg= str(e))
|
||||
|
||||
def download_gsfile(module, gs, bucket, obj, dest):
|
||||
|
@ -252,7 +252,7 @@ def download_gsfile(module, gs, bucket, obj, dest):
|
|||
key = bucket.lookup(obj)
|
||||
key.get_contents_to_filename(dest)
|
||||
module.exit_json(msg="GET operation complete", changed=True)
|
||||
except gs.provider.storage_copy_error, e:
|
||||
except gs.provider.storage_copy_error as e:
|
||||
module.fail_json(msg= str(e))
|
||||
|
||||
def download_gsstr(module, gs, bucket, obj):
|
||||
|
@ -261,7 +261,7 @@ def download_gsstr(module, gs, bucket, obj):
|
|||
key = bucket.lookup(obj)
|
||||
contents = key.get_contents_as_string()
|
||||
module.exit_json(msg="GET operation complete", contents=contents, changed=True)
|
||||
except gs.provider.storage_copy_error, e:
|
||||
except gs.provider.storage_copy_error as e:
|
||||
module.fail_json(msg= str(e))
|
||||
|
||||
def get_download_url(module, gs, bucket, obj, expiry):
|
||||
|
@ -270,7 +270,7 @@ def get_download_url(module, gs, bucket, obj, expiry):
|
|||
key = bucket.lookup(obj)
|
||||
url = key.generate_url(expiry)
|
||||
module.exit_json(msg="Download url:", url=url, expiration=expiry, changed=True)
|
||||
except gs.provider.storage_response_error, e:
|
||||
except gs.provider.storage_response_error as e:
|
||||
module.fail_json(msg= str(e))
|
||||
|
||||
def handle_get(module, gs, bucket, obj, overwrite, dest):
|
||||
|
@ -388,7 +388,7 @@ def main():
|
|||
|
||||
try:
|
||||
gs = boto.connect_gs(gs_access_key, gs_secret_key)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
module.fail_json(msg = str(e))
|
||||
|
||||
if mode == 'get':
|
||||
|
|
|
@ -356,7 +356,7 @@ def create_instances(module, gce, instance_names):
|
|||
instance_external_ip = gce.ex_get_address(instance_external_ip)
|
||||
else:
|
||||
instance_external_ip = 'ephemeral'
|
||||
except GoogleBaseError, e:
|
||||
except GoogleBaseError as e:
|
||||
module.fail_json(msg='Unexpected error attempting to get a static ip %s, error: %s' % (external_ip, e.value))
|
||||
else:
|
||||
instance_external_ip = external_ip
|
||||
|
|
|
@ -222,7 +222,7 @@ def main():
|
|||
gcelb = get_driver_lb(Provider_lb.GCE)(gce_driver=gce)
|
||||
gcelb.connection.user_agent_append("%s/%s" % (
|
||||
USER_AGENT_PRODUCT, USER_AGENT_VERSION))
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
|
||||
changed = False
|
||||
|
@ -248,7 +248,7 @@ def main():
|
|||
changed = True
|
||||
except ResourceExistsError:
|
||||
hc = gce.ex_get_healthcheck(httphealthcheck_name)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
|
||||
if hc is not None:
|
||||
|
@ -292,7 +292,7 @@ def main():
|
|||
changed = True
|
||||
except ResourceExistsError:
|
||||
lb = gcelb.get_balancer(name)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
|
||||
if lb is not None:
|
||||
|
@ -318,7 +318,7 @@ def main():
|
|||
changed = True
|
||||
except ResourceNotFoundError:
|
||||
pass
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
|
||||
# destroy the health check if specified
|
||||
|
@ -330,7 +330,7 @@ def main():
|
|||
changed = True
|
||||
except ResourceNotFoundError:
|
||||
pass
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ def main():
|
|||
json_output['ipv4_range'] = network.cidr
|
||||
except ResourceNotFoundError:
|
||||
pass
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
|
||||
# user wants to create a new network that doesn't yet exist
|
||||
|
@ -230,7 +230,7 @@ def main():
|
|||
json_output['name'] = name
|
||||
json_output['ipv4_range'] = ipv4_range
|
||||
changed = True
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
|
||||
if fwname:
|
||||
|
@ -252,7 +252,7 @@ def main():
|
|||
changed = True
|
||||
except ResourceExistsError:
|
||||
pass
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
|
||||
json_output['fwname'] = fwname
|
||||
|
@ -269,7 +269,7 @@ def main():
|
|||
fw = gce.ex_get_firewall(fwname)
|
||||
except ResourceNotFoundError:
|
||||
pass
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
if fw:
|
||||
gce.ex_destroy_firewall(fw)
|
||||
|
@ -283,7 +283,7 @@ def main():
|
|||
except ResourceNotFoundError:
|
||||
# json_output['d2'] = 'not found network name %s' % name
|
||||
pass
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
# json_output['d3'] = 'error with %s' % name
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
if network:
|
||||
|
|
|
@ -218,7 +218,7 @@ def main():
|
|||
json_output['size_gb'] = int(disk.size)
|
||||
except ResourceNotFoundError:
|
||||
pass
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
|
||||
# user wants a disk to exist. If "instance_name" is supplied the user
|
||||
|
@ -259,7 +259,7 @@ def main():
|
|||
except QuotaExceededError:
|
||||
module.fail_json(msg='Requested disk size exceeds quota',
|
||||
changed=False)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
json_output['size_gb'] = size_gb
|
||||
if image is not None:
|
||||
|
@ -270,7 +270,7 @@ def main():
|
|||
if inst and not is_attached:
|
||||
try:
|
||||
gce.attach_volume(inst, disk, device=name, ex_mode=mode)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
json_output['attached_to_instance'] = inst.name
|
||||
json_output['attached_mode'] = mode
|
||||
|
@ -282,15 +282,15 @@ def main():
|
|||
if inst and is_attached:
|
||||
try:
|
||||
gce.detach_volume(disk, ex_node=inst)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
changed = True
|
||||
if not detach_only:
|
||||
try:
|
||||
gce.destroy_volume(disk)
|
||||
except ResourceInUseError, e:
|
||||
except ResourceInUseError as e:
|
||||
module.fail_json(msg=str(e.value), changed=False)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||
changed = True
|
||||
|
||||
|
|
Loading…
Reference in a new issue