mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Update bare exceptions to specify Exception.
This will keep us from accidentally catching program-exiting exceptions like KeyboardInterupt and SystemExit.
This commit is contained in:
@@ -228,7 +228,7 @@ def conn(url, user, password):
|
||||
api = API(url=url, username=user, password=password, insecure=True)
|
||||
try:
|
||||
value = api.test()
|
||||
except:
|
||||
except Exception:
|
||||
raise Exception("error connecting to the oVirt API")
|
||||
return api
|
||||
|
||||
@@ -262,16 +262,16 @@ def create_vm(conn, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork,
|
||||
|
||||
try:
|
||||
conn.vms.add(vmparams)
|
||||
except:
|
||||
except Exception:
|
||||
raise Exception("Error creating VM with specified parameters")
|
||||
vm = conn.vms.get(name=vmname)
|
||||
try:
|
||||
vm.disks.add(vmdisk)
|
||||
except:
|
||||
except Exception:
|
||||
raise Exception("Error attaching disk")
|
||||
try:
|
||||
vm.nics.add(nic_net1)
|
||||
except:
|
||||
except Exception:
|
||||
raise Exception("Error adding nic")
|
||||
|
||||
|
||||
@@ -280,7 +280,7 @@ def create_vm_template(conn, vmname, image, zone):
|
||||
vmparams = params.VM(name=vmname, cluster=conn.clusters.get(name=zone), template=conn.templates.get(name=image), disks=params.Disks(clone=True))
|
||||
try:
|
||||
conn.vms.add(vmparams)
|
||||
except:
|
||||
except Exception:
|
||||
raise Exception('error adding template %s' % image)
|
||||
|
||||
|
||||
|
||||
@@ -339,7 +339,7 @@ class RHEVConn(object):
|
||||
api = API(url=url, username=user, password=password, insecure=str(insecure_api))
|
||||
api.test()
|
||||
self.conn = api
|
||||
except:
|
||||
except Exception:
|
||||
raise Exception("Failed to connect to RHEV-M.")
|
||||
|
||||
def __del__(self):
|
||||
|
||||
@@ -354,7 +354,7 @@ class Virt(object):
|
||||
results.append(x.name())
|
||||
else:
|
||||
results.append(x.name())
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
return results
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ class LibvirtConnection(object):
|
||||
else:
|
||||
try:
|
||||
state = self.find_entry(entryid).isActive()
|
||||
except:
|
||||
except Exception:
|
||||
return self.module.exit_json(changed=True)
|
||||
if not state:
|
||||
return self.module.exit_json(changed=True)
|
||||
@@ -302,7 +302,7 @@ class LibvirtConnection(object):
|
||||
try:
|
||||
state = self.find_entry(entryid).isActive()
|
||||
return ENTRY_STATE_ACTIVE_MAP.get(state, "unknown")
|
||||
except:
|
||||
except Exception:
|
||||
return ENTRY_STATE_ACTIVE_MAP.get("inactive", "unknown")
|
||||
|
||||
def get_uuid(self, entryid):
|
||||
@@ -315,7 +315,7 @@ class LibvirtConnection(object):
|
||||
xml = etree.fromstring(self.find_entry(entryid).XMLDesc(0))
|
||||
try:
|
||||
result = xml.xpath('/network/forward')[0].get('mode')
|
||||
except:
|
||||
except Exception:
|
||||
raise ValueError('Forward mode not specified')
|
||||
return result
|
||||
|
||||
@@ -323,7 +323,7 @@ class LibvirtConnection(object):
|
||||
xml = etree.fromstring(self.find_entry(entryid).XMLDesc(0))
|
||||
try:
|
||||
result = xml.xpath('/network/domain')[0].get('name')
|
||||
except:
|
||||
except Exception:
|
||||
raise ValueError('Domain not specified')
|
||||
return result
|
||||
|
||||
@@ -331,7 +331,7 @@ class LibvirtConnection(object):
|
||||
xml = etree.fromstring(self.find_entry(entryid).XMLDesc(0))
|
||||
try:
|
||||
result = xml.xpath('/network/mac')[0].get('address')
|
||||
except:
|
||||
except Exception:
|
||||
raise ValueError('MAC address not specified')
|
||||
return result
|
||||
|
||||
@@ -345,7 +345,7 @@ class LibvirtConnection(object):
|
||||
else:
|
||||
try:
|
||||
return self.find_entry(entryid).autostart()
|
||||
except:
|
||||
except Exception:
|
||||
return self.module.exit_json(changed=True)
|
||||
|
||||
def set_autostart(self, entryid, val):
|
||||
@@ -354,7 +354,7 @@ class LibvirtConnection(object):
|
||||
else:
|
||||
try:
|
||||
state = self.find_entry(entryid).autostart()
|
||||
except:
|
||||
except Exception:
|
||||
return self.module.exit_json(changed=True)
|
||||
if bool(state) != val:
|
||||
return self.module.exit_json(changed=True)
|
||||
@@ -376,7 +376,7 @@ class LibvirtConnection(object):
|
||||
else:
|
||||
try:
|
||||
self.find_entry(entryid)
|
||||
except:
|
||||
except Exception:
|
||||
return self.module.exit_json(changed=True)
|
||||
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ class LibvirtConnection(object):
|
||||
else:
|
||||
try:
|
||||
state = self.find_entry(entryid).isActive()
|
||||
except:
|
||||
except Exception:
|
||||
return self.module.exit_json(changed=True)
|
||||
if not state:
|
||||
return self.module.exit_json(changed=True)
|
||||
@@ -293,7 +293,7 @@ class LibvirtConnection(object):
|
||||
try:
|
||||
state = self.find_entry(entryid).isActive()
|
||||
return ENTRY_STATE_ACTIVE_MAP.get(state, "unknown")
|
||||
except:
|
||||
except Exception:
|
||||
return ENTRY_STATE_ACTIVE_MAP.get("inactive", "unknown")
|
||||
|
||||
def get_uuid(self, entryid):
|
||||
@@ -319,14 +319,14 @@ class LibvirtConnection(object):
|
||||
result.append(device.get('path'))
|
||||
try:
|
||||
return result
|
||||
except:
|
||||
except Exception:
|
||||
raise ValueError('No devices specified')
|
||||
|
||||
def get_format(self, entryid):
|
||||
xml = etree.fromstring(self.find_entry(entryid).XMLDesc(0))
|
||||
try:
|
||||
result = xml.xpath('/pool/source/format')[0].get('type')
|
||||
except:
|
||||
except Exception:
|
||||
raise ValueError('Format not specified')
|
||||
return result
|
||||
|
||||
@@ -334,7 +334,7 @@ class LibvirtConnection(object):
|
||||
xml = etree.fromstring(self.find_entry(entryid).XMLDesc(0))
|
||||
try:
|
||||
result = xml.xpath('/pool/source/host')[0].get('name')
|
||||
except:
|
||||
except Exception:
|
||||
raise ValueError('Host not specified')
|
||||
return result
|
||||
|
||||
@@ -342,7 +342,7 @@ class LibvirtConnection(object):
|
||||
xml = etree.fromstring(self.find_entry(entryid).XMLDesc(0))
|
||||
try:
|
||||
result = xml.xpath('/pool/source/dir')[0].get('path')
|
||||
except:
|
||||
except Exception:
|
||||
raise ValueError('Source path not specified')
|
||||
return result
|
||||
|
||||
@@ -360,7 +360,7 @@ class LibvirtConnection(object):
|
||||
else:
|
||||
try:
|
||||
state = self.find_entry(entryid)
|
||||
except:
|
||||
except Exception:
|
||||
return self.module.exit_json(changed=True)
|
||||
if not state:
|
||||
return self.module.exit_json(changed=True)
|
||||
@@ -371,7 +371,7 @@ class LibvirtConnection(object):
|
||||
else:
|
||||
try:
|
||||
state = self.find_entry(entryid)
|
||||
except:
|
||||
except Exception:
|
||||
return self.module.exit_json(changed=True)
|
||||
if state:
|
||||
return self.module.exit_json(changed=True)
|
||||
@@ -386,7 +386,7 @@ class LibvirtConnection(object):
|
||||
else:
|
||||
try:
|
||||
return self.find_entry(entryid).autostart()
|
||||
except:
|
||||
except Exception:
|
||||
return self.module.exit_json(changed=True)
|
||||
|
||||
def set_autostart(self, entryid, val):
|
||||
@@ -395,7 +395,7 @@ class LibvirtConnection(object):
|
||||
else:
|
||||
try:
|
||||
state = self.find_entry(entryid).autostart()
|
||||
except:
|
||||
except Exception:
|
||||
return self.module.exit_json(changed=True)
|
||||
if bool(state) != val:
|
||||
return self.module.exit_json(changed=True)
|
||||
@@ -413,7 +413,7 @@ class LibvirtConnection(object):
|
||||
else:
|
||||
try:
|
||||
self.find_entry(entryid)
|
||||
except:
|
||||
except Exception:
|
||||
return self.module.exit_json(changed=True)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user