Merge pull request #1059 from sivel/sys-exit-removal

sys.exit removal from various modules
reviewable/pr18780/r1
Brian Coca 9 years ago
commit 6336838354

@ -201,7 +201,6 @@ def main():
changed = delete_image(gce, name, module)
module.exit_json(changed=changed, name=name)
sys.exit(0)
# import module snippets
from ansible.module_utils.basic import *

@ -219,7 +219,6 @@ def main():
changed, tags_changed = remove_tags(gce, module, instance_name, tags)
module.exit_json(changed=changed, instance_name=instance_name, tags=tags_changed, zone=zone)
sys.exit(0)
# import module snippets
from ansible.module_utils.basic import *

@ -207,14 +207,13 @@ action: ovirt >
'''
import sys
try:
from ovirtsdk.api import API
from ovirtsdk.xml import params
HAS_OVIRTSDK = True
except ImportError:
print "failed=True msg='ovirtsdk required for this module'"
sys.exit(1)
HAS_OVIRTSDK = False
# ------------------------------------------------------------------- #
# create connection with API
@ -224,8 +223,7 @@ def conn(url, user, password):
try:
value = api.test()
except:
print "error connecting to the oVirt API"
sys.exit(1)
raise Exception("error connecting to the oVirt API")
return api
# ------------------------------------------------------------------- #
@ -253,17 +251,16 @@ def create_vm(conn, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork,
try:
conn.vms.add(vmparams)
except:
print "Error creating VM with specified parameters"
sys.exit(1)
raise Exception("Error creating VM with specified parameters")
vm = conn.vms.get(name=vmname)
try:
vm.disks.add(vmdisk)
except:
print "Error attaching disk"
raise Exception("Error attaching disk")
try:
vm.nics.add(nic_net1)
except:
print "Error adding nic"
raise Exception("Error adding nic")
# create an instance from a template
@ -272,8 +269,7 @@ def create_vm_template(conn, vmname, image, zone):
try:
conn.vms.add(vmparams)
except:
print 'error adding template %s' % image
sys.exit(1)
raise Exception('error adding template %s' % image)
# start instance
@ -356,6 +352,9 @@ def main():
)
)
if not HAS_OVIRTSDK:
module.fail_json(msg='ovirtsdk required for this module')
state = module.params['state']
user = module.params['user']
url = module.params['url']
@ -377,16 +376,25 @@ def main():
sdomain = module.params['sdomain'] # storage domain to store disk on
region = module.params['region'] # oVirt Datacenter
#initialize connection
try:
c = conn(url+"/api", user, password)
except Exception, e:
module.fail_json(msg='%s' % e)
if state == 'present':
if get_vm(c, vmname) == "empty":
if resource_type == 'template':
try:
create_vm_template(c, vmname, image, zone)
except Exception, e:
module.fail_json(msg='%s' % e)
module.exit_json(changed=True, msg="deployed VM %s from template %s" % (vmname,image))
elif resource_type == 'new':
# FIXME: refactor, use keyword args.
try:
create_vm(c, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork, vmmem, vmdisk_alloc, sdomain, vmcores, vmos, vmdisk_int)
except Exception, e:
module.fail_json(msg='%s' % e)
module.exit_json(changed=True, msg="deployed VM %s from scratch" % vmname)
else:
module.exit_json(changed=False, msg="You did not specify a resource type")

@ -28,7 +28,6 @@ author:
'''
import platform
import sys
import XenAPI
EXAMPLES = '''
@ -75,12 +74,9 @@ class XenServerFacts:
def get_xenapi_session():
try:
session = XenAPI.xapi_local()
session.xenapi.login_with_password('', '')
return session
except XenAPI.Failure:
sys.exit(1)
def get_networks(session):
@ -163,8 +159,10 @@ def main():
module = AnsibleModule({})
obj = XenServerFacts()
try:
session = get_xenapi_session()
except XenAPI.Failure, e:
module.fail_json(msg='%s' % e)
data = {
'xenserver_version': obj.version,

@ -285,7 +285,6 @@ def main():
msg.attach(part)
except Exception, e:
module.fail_json(rc=1, msg="Failed to send mail: can't attach file %s: %s" % (file, e))
sys.exit()
composed = msg.as_string()

@ -180,7 +180,6 @@ def main():
CapabilitiesModule(module)
sys.exit(0)
# import module snippets
from ansible.module_utils.basic import *

Loading…
Cancel
Save