Fixing gce compile time errors irt exception handling for Python 3 (#3845)

This commit is contained in:
@ 2016-06-03 06:35:34 -07:00 committed by Matt Clay
parent 950931144f
commit 13bebda244
5 changed files with 29 additions and 29 deletions

View file

@ -141,7 +141,7 @@ def grant_check(module, gs, obj):
if not grant: if not grant:
obj.set_acl('authenticated-read') obj.set_acl('authenticated-read')
module.exit_json(changed=True, result="The objects permission as been set to 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)) module.fail_json(msg= str(e))
return True return True
@ -151,7 +151,7 @@ def key_check(module, gs, bucket, obj):
try: try:
bucket = gs.lookup(bucket) bucket = gs.lookup(bucket)
key_check = bucket.get_key(obj) 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)) module.fail_json(msg= str(e))
if key_check: if key_check:
grant_check(module, gs, key_check) grant_check(module, gs, key_check)
@ -173,7 +173,7 @@ def keysum(module, gs, bucket, obj):
def bucket_check(module, gs, bucket): def bucket_check(module, gs, bucket):
try: try:
result = gs.lookup(bucket) 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)) module.fail_json(msg= str(e))
if result: if result:
grant_check(module, gs, result) grant_check(module, gs, result)
@ -185,7 +185,7 @@ def create_bucket(module, gs, bucket):
try: try:
bucket = gs.create_bucket(bucket) bucket = gs.create_bucket(bucket)
bucket.set_acl(module.params.get('permission')) 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)) module.fail_json(msg= str(e))
if bucket: if bucket:
return True return True
@ -198,7 +198,7 @@ def delete_bucket(module, gs, bucket):
bucket.delete_key(key.name) bucket.delete_key(key.name)
bucket.delete() bucket.delete()
return True return True
except gs.provider.storage_response_error, e: except gs.provider.storage_response_error as e:
module.fail_json(msg= str(e)) module.fail_json(msg= str(e))
def delete_key(module, gs, bucket, obj): def delete_key(module, gs, bucket, obj):
@ -206,7 +206,7 @@ def delete_key(module, gs, bucket, obj):
bucket = gs.lookup(bucket) bucket = gs.lookup(bucket)
bucket.delete_key(obj) bucket.delete_key(obj)
module.exit_json(msg="Object deleted from bucket ", changed=True) 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)) module.fail_json(msg= str(e))
def create_dirkey(module, gs, bucket, obj): def create_dirkey(module, gs, bucket, obj):
@ -215,7 +215,7 @@ def create_dirkey(module, gs, bucket, obj):
key = bucket.new_key(obj) key = bucket.new_key(obj)
key.set_contents_from_string('') key.set_contents_from_string('')
module.exit_json(msg="Virtual directory %s created in bucket %s" % (obj, bucket.name), changed=True) 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)) module.fail_json(msg= str(e))
def path_check(path): def path_check(path):
@ -250,7 +250,7 @@ def upload_gsfile(module, gs, bucket, obj, src, expiry):
key.set_acl(module.params.get('permission')) key.set_acl(module.params.get('permission'))
url = key.generate_url(expiry) url = key.generate_url(expiry)
module.exit_json(msg="PUT operation complete", url=url, changed=True) 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)) module.fail_json(msg= str(e))
def download_gsfile(module, gs, bucket, obj, dest): def download_gsfile(module, gs, bucket, obj, dest):
@ -259,7 +259,7 @@ def download_gsfile(module, gs, bucket, obj, dest):
key = bucket.lookup(obj) key = bucket.lookup(obj)
key.get_contents_to_filename(dest) key.get_contents_to_filename(dest)
module.exit_json(msg="GET operation complete", changed=True) 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)) module.fail_json(msg= str(e))
def download_gsstr(module, gs, bucket, obj): def download_gsstr(module, gs, bucket, obj):
@ -268,7 +268,7 @@ def download_gsstr(module, gs, bucket, obj):
key = bucket.lookup(obj) key = bucket.lookup(obj)
contents = key.get_contents_as_string() contents = key.get_contents_as_string()
module.exit_json(msg="GET operation complete", contents=contents, changed=True) 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)) module.fail_json(msg= str(e))
def get_download_url(module, gs, bucket, obj, expiry): def get_download_url(module, gs, bucket, obj, expiry):
@ -277,7 +277,7 @@ def get_download_url(module, gs, bucket, obj, expiry):
key = bucket.lookup(obj) key = bucket.lookup(obj)
url = key.generate_url(expiry) url = key.generate_url(expiry)
module.exit_json(msg="Download url:", url=url, expiration=expiry, changed=True) 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)) module.fail_json(msg= str(e))
def handle_get(module, gs, bucket, obj, overwrite, dest): def handle_get(module, gs, bucket, obj, overwrite, dest):
@ -395,7 +395,7 @@ def main():
try: try:
gs = boto.connect_gs(gs_access_key, gs_secret_key) 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)) module.fail_json(msg = str(e))
if mode == 'get': if mode == 'get':

View file

@ -371,7 +371,7 @@ def create_instances(module, gce, instance_names):
instance_external_ip = gce.ex_get_address(instance_external_ip) instance_external_ip = gce.ex_get_address(instance_external_ip)
else: else:
instance_external_ip = 'ephemeral' 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)) module.fail_json(msg='Unexpected error attempting to get a static ip %s, error: %s' % (external_ip, e.value))
else: else:
instance_external_ip = external_ip instance_external_ip = external_ip

View file

@ -222,7 +222,7 @@ def main():
gcelb = get_driver_lb(Provider_lb.GCE)(gce_driver=gce) gcelb = get_driver_lb(Provider_lb.GCE)(gce_driver=gce)
gcelb.connection.user_agent_append("%s/%s" % ( gcelb.connection.user_agent_append("%s/%s" % (
USER_AGENT_PRODUCT, USER_AGENT_VERSION)) USER_AGENT_PRODUCT, USER_AGENT_VERSION))
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
changed = False changed = False
@ -248,7 +248,7 @@ def main():
changed = True changed = True
except ResourceExistsError: except ResourceExistsError:
hc = gce.ex_get_healthcheck(httphealthcheck_name) hc = gce.ex_get_healthcheck(httphealthcheck_name)
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
if hc is not None: if hc is not None:
@ -292,7 +292,7 @@ def main():
changed = True changed = True
except ResourceExistsError: except ResourceExistsError:
lb = gcelb.get_balancer(name) lb = gcelb.get_balancer(name)
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
if lb is not None: if lb is not None:
@ -318,7 +318,7 @@ def main():
changed = True changed = True
except ResourceNotFoundError: except ResourceNotFoundError:
pass pass
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
# destroy the health check if specified # destroy the health check if specified
@ -330,7 +330,7 @@ def main():
changed = True changed = True
except ResourceNotFoundError: except ResourceNotFoundError:
pass pass
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)

View file

@ -216,7 +216,7 @@ def main():
json_output['ipv4_range'] = network.cidr json_output['ipv4_range'] = network.cidr
except ResourceNotFoundError: except ResourceNotFoundError:
pass pass
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
# user wants to create a new network that doesn't yet exist # user wants to create a new network that doesn't yet exist
@ -230,7 +230,7 @@ def main():
json_output['name'] = name json_output['name'] = name
json_output['ipv4_range'] = ipv4_range json_output['ipv4_range'] = ipv4_range
changed = True changed = True
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
if fwname: if fwname:
@ -252,7 +252,7 @@ def main():
changed = True changed = True
except ResourceExistsError: except ResourceExistsError:
pass pass
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
json_output['fwname'] = fwname json_output['fwname'] = fwname
@ -269,7 +269,7 @@ def main():
fw = gce.ex_get_firewall(fwname) fw = gce.ex_get_firewall(fwname)
except ResourceNotFoundError: except ResourceNotFoundError:
pass pass
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
if fw: if fw:
gce.ex_destroy_firewall(fw) gce.ex_destroy_firewall(fw)
@ -283,7 +283,7 @@ def main():
except ResourceNotFoundError: except ResourceNotFoundError:
# json_output['d2'] = 'not found network name %s' % name # json_output['d2'] = 'not found network name %s' % name
pass pass
except Exception, e: except Exception as e:
# json_output['d3'] = 'error with %s' % name # json_output['d3'] = 'error with %s' % name
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
if network: if network:

View file

@ -218,7 +218,7 @@ def main():
json_output['size_gb'] = int(disk.size) json_output['size_gb'] = int(disk.size)
except ResourceNotFoundError: except ResourceNotFoundError:
pass pass
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
# user wants a disk to exist. If "instance_name" is supplied the user # user wants a disk to exist. If "instance_name" is supplied the user
@ -259,7 +259,7 @@ def main():
except QuotaExceededError: except QuotaExceededError:
module.fail_json(msg='Requested disk size exceeds quota', module.fail_json(msg='Requested disk size exceeds quota',
changed=False) changed=False)
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
json_output['size_gb'] = size_gb json_output['size_gb'] = size_gb
if image is not None: if image is not None:
@ -270,7 +270,7 @@ def main():
if inst and not is_attached: if inst and not is_attached:
try: try:
gce.attach_volume(inst, disk, device=name, ex_mode=mode) 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) module.fail_json(msg=unexpected_error_msg(e), changed=False)
json_output['attached_to_instance'] = inst.name json_output['attached_to_instance'] = inst.name
json_output['attached_mode'] = mode json_output['attached_mode'] = mode
@ -282,15 +282,15 @@ def main():
if inst and is_attached: if inst and is_attached:
try: try:
gce.detach_volume(disk, ex_node=inst) gce.detach_volume(disk, ex_node=inst)
except Exception, e: except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False) module.fail_json(msg=unexpected_error_msg(e), changed=False)
changed = True changed = True
if not detach_only: if not detach_only:
try: try:
gce.destroy_volume(disk) gce.destroy_volume(disk)
except ResourceInUseError, e: except ResourceInUseError as e:
module.fail_json(msg=str(e.value), changed=False) 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) module.fail_json(msg=unexpected_error_msg(e), changed=False)
changed = True changed = True