Use 'except ... as' syntax in contrib/ and test/ too
This commit is contained in:
parent
eb99aa8c68
commit
9ae66a7f5c
14 changed files with 25 additions and 25 deletions
|
@ -76,7 +76,7 @@ def save_cache(data, config):
|
|||
cache = open('/'.join([dpath,'inventory']), 'w')
|
||||
cache.write(json.dumps(data))
|
||||
cache.close()
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
pass # not really sure what to do here
|
||||
|
||||
|
||||
|
@ -88,7 +88,7 @@ def get_cache(cache_item, config):
|
|||
cache = open('/'.join([dpath,'inventory']), 'r')
|
||||
inv = cache.read()
|
||||
cache.close()
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
pass # not really sure what to do here
|
||||
|
||||
return inv
|
||||
|
@ -172,7 +172,7 @@ def generate_inv_from_api(enterprise_entity,config):
|
|||
else:
|
||||
vm_metadata = metadata['metadata']['metadata']
|
||||
inventory['_meta']['hostvars'][vm_nic] = vm_metadata
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
inventory[vm_vapp]['children'].append(vmcollection['name'])
|
||||
|
@ -183,7 +183,7 @@ def generate_inv_from_api(enterprise_entity,config):
|
|||
inventory[vmcollection['name']].append(vm_nic)
|
||||
|
||||
return inventory
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
# Return empty hosts output
|
||||
return { 'all': {'hosts': []}, '_meta': { 'hostvars': {} } }
|
||||
|
||||
|
@ -214,7 +214,7 @@ if __name__ == '__main__':
|
|||
try:
|
||||
login = api_get(None,config)
|
||||
enterprise = next(link for link in (login['links']) if (link['rel']=='enterprise'))
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
enterprise = None
|
||||
|
||||
if cache_available(config):
|
||||
|
|
|
@ -98,7 +98,7 @@ class CloudStackInventory(object):
|
|||
options = parser.parse_args()
|
||||
try:
|
||||
self.cs = CloudStack(**read_config())
|
||||
except CloudStackException, e:
|
||||
except CloudStackException as e:
|
||||
print >> sys.stderr, "Error: Could not connect to CloudStack API"
|
||||
|
||||
project_id = ''
|
||||
|
|
|
@ -136,7 +136,7 @@ except ImportError:
|
|||
|
||||
try:
|
||||
import consul
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
print """failed=True msg='python-consul required for this module. see
|
||||
http://python-consul.readthedocs.org/en/latest/#installation'"""
|
||||
sys.exit(1)
|
||||
|
|
|
@ -145,7 +145,7 @@ except ImportError:
|
|||
|
||||
try:
|
||||
from dopy.manager import DoError, DoManager
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
print "failed=True msg='`dopy` library required for this script'"
|
||||
sys.exit(1)
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ class GceInventory(object):
|
|||
'''Gets details about a specific instance '''
|
||||
try:
|
||||
return self.driver.ex_get_node(instance_name)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
return None
|
||||
|
||||
def group_instances(self):
|
||||
|
|
|
@ -101,7 +101,7 @@ except:
|
|||
from chube.linode_obj import Linode
|
||||
|
||||
sys.path = old_path
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
raise Exception("could not import chube")
|
||||
|
||||
load_chube_config()
|
||||
|
@ -184,7 +184,7 @@ class LinodeInventory(object):
|
|||
try:
|
||||
for node in Linode.search(status=Linode.STATUS_RUNNING):
|
||||
self.add_node(node)
|
||||
except chube_api.linode_api.ApiError, e:
|
||||
except chube_api.linode_api.ApiError as e:
|
||||
print "Looks like Linode's API is down:"
|
||||
print
|
||||
print e
|
||||
|
@ -194,7 +194,7 @@ class LinodeInventory(object):
|
|||
"""Gets details about a specific node."""
|
||||
try:
|
||||
return Linode.find(api_id=linode_id)
|
||||
except chube_api.linode_api.ApiError, e:
|
||||
except chube_api.linode_api.ApiError as e:
|
||||
print "Looks like Linode's API is down:"
|
||||
print
|
||||
print e
|
||||
|
|
|
@ -412,7 +412,7 @@ def setup():
|
|||
pyrax.keyring_auth(keyring_username, region=region)
|
||||
else:
|
||||
pyrax.set_credential_file(creds_file, region=region)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
sys.stderr.write("%s: %s\n" % (e, e.message))
|
||||
sys.exit(1)
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ try:
|
|||
for group in spacewalk_report('system-groups'):
|
||||
org_groups[group['spacewalk_group_id']] = group['spacewalk_org_id']
|
||||
|
||||
except (OSError), e:
|
||||
except (OSError) as e:
|
||||
print >> sys.stderr, 'Problem executing the command "%s system-groups": %s' % \
|
||||
(SW_REPORT, str(e))
|
||||
sys.exit(2)
|
||||
|
@ -148,7 +148,7 @@ if options.list:
|
|||
for item in spacewalk_report('inventory'):
|
||||
host_vars[ item['spacewalk_profile_name'] ] = dict( ( key, ( value.split(';') if ';' in value else value) ) for key, value in item.items() )
|
||||
|
||||
except (OSError), e:
|
||||
except (OSError) as e:
|
||||
print >> sys.stderr, 'Problem executing the command "%s inventory": %s' % \
|
||||
(SW_REPORT, str(e))
|
||||
sys.exit(2)
|
||||
|
@ -185,7 +185,7 @@ if options.list:
|
|||
if system['spacewalk_server_name'] in host_vars and not system['spacewalk_server_name'] in meta[ "hostvars" ]:
|
||||
meta[ "hostvars" ][ system['spacewalk_server_name'] ] = host_vars[ system['spacewalk_server_name'] ]
|
||||
|
||||
except (OSError), e:
|
||||
except (OSError) as e:
|
||||
print >> sys.stderr, 'Problem executing the command "%s system-groups-systems": %s' % \
|
||||
(SW_REPORT, str(e))
|
||||
sys.exit(2)
|
||||
|
@ -212,7 +212,7 @@ elif options.host:
|
|||
host_details = system
|
||||
break
|
||||
|
||||
except (OSError), e:
|
||||
except (OSError) as e:
|
||||
print >> sys.stderr, 'Problem executing the command "%s inventory": %s' % \
|
||||
(SW_REPORT, str(e))
|
||||
sys.exit(2)
|
||||
|
|
|
@ -164,7 +164,7 @@ class VMwareInventory(object):
|
|||
obj_info = self._get_obj_info(val, depth - 1, seen)
|
||||
if obj_info != ():
|
||||
d[attr] = obj_info
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
pass
|
||||
return d
|
||||
elif isinstance(obj, SudsObject):
|
||||
|
@ -207,7 +207,7 @@ class VMwareInventory(object):
|
|||
host_info[k] = v
|
||||
try:
|
||||
host_info['ipAddress'] = host.config.network.vnic[0].spec.ip.ipAddress
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
print >> sys.stderr, e
|
||||
host_info = self._flatten_dict(host_info, prefix)
|
||||
if ('%s_ipAddress' % prefix) in host_info:
|
||||
|
|
|
@ -109,7 +109,7 @@ class ZabbixInventory(object):
|
|||
try:
|
||||
api = ZabbixAPI(server=self.zabbix_server)
|
||||
api.login(user=self.zabbix_username, password=self.zabbix_password)
|
||||
except BaseException, e:
|
||||
except BaseException as e:
|
||||
print >> sys.stderr, "Error: Could not login to Zabbix server. Check your zabbix.ini."
|
||||
sys.exit(1)
|
||||
|
||||
|
|
|
@ -175,5 +175,5 @@ if __name__ == '__main__':
|
|||
filters = {"tag:Name":opts.match_re.replace('^',''), "instance-state-name": ['running', 'pending', 'stopped' ]}
|
||||
delete_aws_instances(aws.get_all_instances(filters=filters), opts)
|
||||
|
||||
except KeyboardInterrupt, e:
|
||||
except KeyboardInterrupt as e:
|
||||
print "\nExiting on user command."
|
||||
|
|
|
@ -73,5 +73,5 @@ if __name__ == '__main__':
|
|||
delete_gce_resources(get_snapshots, 'name', opts)
|
||||
# Delete matching disks
|
||||
delete_gce_resources(gce.list_volumes, 'name', opts)
|
||||
except KeyboardInterrupt, e:
|
||||
except KeyboardInterrupt as e:
|
||||
print "\nExiting on user command."
|
||||
|
|
|
@ -20,7 +20,7 @@ else:
|
|||
def createDaemon():
|
||||
try:
|
||||
pid = os.fork()
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
raise Exception, "%s [%d]" % (e.strerror, e.errno)
|
||||
|
||||
if (pid == 0):
|
||||
|
@ -28,7 +28,7 @@ def createDaemon():
|
|||
|
||||
try:
|
||||
pid = os.fork()
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
raise Exception, "%s [%d]" % (e.strerror, e.errno)
|
||||
|
||||
if (pid == 0):
|
||||
|
|
|
@ -38,5 +38,5 @@ if __name__ == '__main__':
|
|||
gce.create_volume_snapshot(base_volume, name=prefix+'-snapshot')
|
||||
gce.create_volume(
|
||||
size=10, name=prefix+'-extra', location='us-central1-a')
|
||||
except KeyboardInterrupt, e:
|
||||
except KeyboardInterrupt as e:
|
||||
print "\nExiting on user command."
|
||||
|
|
Loading…
Reference in a new issue