|
|
@ -313,9 +313,17 @@ class decort_osimage(DecortController):
|
|
|
|
amodule.fail_json(**self.result)
|
|
|
|
amodule.fail_json(**self.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['image_id'] != 0 and amodule.params['image_name']:
|
|
|
|
if amodule.params['virt_id'] != 0 and amodule.params['virt_name']:
|
|
|
|
self.validated_image_id = amodule.params['image_id']
|
|
|
|
self.validated_virt_image_id, image_facts =\
|
|
|
|
if amodule.params['image_name']:
|
|
|
|
self.decort_virt_image_find(amodule)
|
|
|
|
|
|
|
|
if (self.validated_virt_image_id and
|
|
|
|
|
|
|
|
amodule.params['virt_name'] != image_facts['name']):
|
|
|
|
|
|
|
|
self.decort_virt_image_rename(amodule)
|
|
|
|
|
|
|
|
self.result['msg'] = 'Virtual image renamed successfully'
|
|
|
|
|
|
|
|
elif amodule.params['image_id'] != 0 and amodule.params['image_name']:
|
|
|
|
|
|
|
|
self.validated_image_id, image_facts = self.decort_image_find(amodule)
|
|
|
|
|
|
|
|
if (self.validated_image_id and
|
|
|
|
|
|
|
|
amodule.params['image_name'] != image_facts['name']):
|
|
|
|
decort_osimage.decort_image_rename(self,amodule)
|
|
|
|
decort_osimage.decort_image_rename(self,amodule)
|
|
|
|
self.result['msg'] = ("Image renamed successfully")
|
|
|
|
self.result['msg'] = ("Image renamed successfully")
|
|
|
|
|
|
|
|
|
|
|
@ -350,7 +358,7 @@ class decort_osimage(DecortController):
|
|
|
|
hotresize=amodule.params['hotresize'],
|
|
|
|
hotresize=amodule.params['hotresize'],
|
|
|
|
username=amodule.params['image_username'],
|
|
|
|
username=amodule.params['image_username'],
|
|
|
|
password=amodule.params['image_password'],
|
|
|
|
password=amodule.params['image_password'],
|
|
|
|
account_Id=amodule.params['account_Id'],
|
|
|
|
account_Id=self.validated_account_id,
|
|
|
|
usernameDL=amodule.params['usernameDL'],
|
|
|
|
usernameDL=amodule.params['usernameDL'],
|
|
|
|
passwordDL=amodule.params['passwordDL'],
|
|
|
|
passwordDL=amodule.params['passwordDL'],
|
|
|
|
sepId=amodule.params['sepId'],
|
|
|
|
sepId=amodule.params['sepId'],
|
|
|
@ -389,6 +397,12 @@ class decort_osimage(DecortController):
|
|
|
|
image_id, image_facts = decort_osimage.decort_image_find(self, amodule)
|
|
|
|
image_id, image_facts = decort_osimage.decort_image_find(self, amodule)
|
|
|
|
return image_id, image_facts
|
|
|
|
return image_id, image_facts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def decort_virt_image_rename(self, amodule):
|
|
|
|
|
|
|
|
image_facts = self.image_rename(imageId=self.validated_virt_image_id,
|
|
|
|
|
|
|
|
name=amodule.params['virt_name'])
|
|
|
|
|
|
|
|
self.result['msg'] = ("Virtual image renamed successfully")
|
|
|
|
|
|
|
|
image_id, image_facts = self.decort_virt_image_find(amodule)
|
|
|
|
|
|
|
|
return image_id, image_facts
|
|
|
|
|
|
|
|
|
|
|
|
def decort_osimage_package_facts(arg_osimage_facts, arg_check_mode=False):
|
|
|
|
def decort_osimage_package_facts(arg_osimage_facts, arg_check_mode=False):
|
|
|
|
"""Package a dictionary of OS image according to the decort_osimage module specification. This
|
|
|
|
"""Package a dictionary of OS image according to the decort_osimage module specification. This
|
|
|
@ -507,38 +521,15 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
decon = decort_osimage(amodule)
|
|
|
|
decon = decort_osimage(amodule)
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['image_name'] or amodule.params['image_id']:
|
|
|
|
|
|
|
|
image_id, image_facts = decort_osimage.decort_image_find(decon, amodule)
|
|
|
|
|
|
|
|
decon.validated_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id']
|
|
|
|
|
|
|
|
if decort_osimage.decort_osimage_package_facts(image_facts)['id'] > 0:
|
|
|
|
|
|
|
|
decon.result['facts'] = decort_osimage.decort_osimage_package_facts(image_facts, amodule.check_mode)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['state'] == "present" and decon.validated_image_id == 0 and amodule.params['image_name'] and amodule.params['url']:
|
|
|
|
|
|
|
|
decort_osimage.decort_image_create(decon,amodule)
|
|
|
|
|
|
|
|
decon.result['changed'] = True
|
|
|
|
|
|
|
|
image_id, image_facts = decort_osimage.decort_image_find(decon, amodule)
|
|
|
|
|
|
|
|
decon.result['msg'] = ("OS image '{}' created").format(decort_osimage.decort_osimage_package_facts(image_facts)['id'])
|
|
|
|
|
|
|
|
decon.result['facts'] = decort_osimage.decort_osimage_package_facts(image_facts, amodule.check_mode)
|
|
|
|
|
|
|
|
decon.validated_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif amodule.params['state'] == "absent" and decon.validated_image_id:
|
|
|
|
|
|
|
|
if amodule.params['image_name'] or amodule.params['image_id'] and\
|
|
|
|
|
|
|
|
decort_osimage.decort_osimage_package_facts(image_facts)['accountId'] == amodule.params['account_Id']:
|
|
|
|
|
|
|
|
amodule.image_id_delete = decon.validated_image_id
|
|
|
|
|
|
|
|
decort_osimage.decort_image_delete(decon,amodule)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['virt_name'] or amodule.params['virt_id']:
|
|
|
|
if amodule.params['virt_name'] or amodule.params['virt_id']:
|
|
|
|
|
|
|
|
|
|
|
|
image_id, image_facts = decort_osimage.decort_virt_image_find(decon, amodule)
|
|
|
|
image_id, image_facts = decort_osimage.decort_virt_image_find(decon, amodule)
|
|
|
|
|
|
|
|
decon.validated_image_id, _ = decort_osimage.decort_image_find(decon, amodule)
|
|
|
|
if decort_osimage.decort_osimage_package_facts(image_facts)['id'] > 0:
|
|
|
|
if decort_osimage.decort_osimage_package_facts(image_facts)['id'] > 0:
|
|
|
|
decon.result['facts'] = decort_osimage.decort_osimage_package_facts(image_facts, amodule.check_mode)
|
|
|
|
decon.result['facts'] = decort_osimage.decort_osimage_package_facts(image_facts, amodule.check_mode)
|
|
|
|
decon.validated_virt_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id']
|
|
|
|
decon.validated_virt_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id']
|
|
|
|
decon.validated_virt_image_name = decort_osimage.decort_osimage_package_facts(image_facts)['name']
|
|
|
|
decon.validated_virt_image_name = decort_osimage.decort_osimage_package_facts(image_facts)['name']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if decort_osimage.decort_osimage_package_facts(image_facts)['id'] == 0 and amodule.params['state'] == "present" and decon.validated_image_id > 0:
|
|
|
|
if decort_osimage.decort_osimage_package_facts(image_facts)['id'] == 0 and amodule.params['state'] == "present" and decon.validated_image_id > 0:
|
|
|
|
image_id, image_facts = decort_osimage.decort_virt_image_create(decon,amodule)
|
|
|
|
image_id, image_facts = decort_osimage.decort_virt_image_create(decon,amodule)
|
|
|
|
decon.result['msg'] = ("Virtual image '{}' created").format(decort_osimage.decort_osimage_package_facts(image_facts)['id'])
|
|
|
|
decon.result['msg'] = ("Virtual image '{}' created").format(decort_osimage.decort_osimage_package_facts(image_facts)['id'])
|
|
|
@ -547,19 +538,36 @@ def main():
|
|
|
|
decon.result['msg'] = ("Cannot find OS image")
|
|
|
|
decon.result['msg'] = ("Cannot find OS image")
|
|
|
|
amodule.fail_json(**decon.result)
|
|
|
|
amodule.fail_json(**decon.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if decon.validated_virt_image_id:
|
|
|
|
if decon.validated_image_id:
|
|
|
|
|
|
|
|
if decort_osimage.decort_osimage_package_facts(image_facts)['linkto'] != decon.validated_image_id:
|
|
|
|
if decort_osimage.decort_osimage_package_facts(image_facts)['linkto'] != decon.validated_image_id:
|
|
|
|
decort_osimage.decort_virt_image_link(decon,amodule)
|
|
|
|
decort_osimage.decort_virt_image_link(decon,amodule)
|
|
|
|
decon.result['changed'] = True
|
|
|
|
decon.result['changed'] = True
|
|
|
|
amodule.exit_json(**decon.result)
|
|
|
|
amodule.exit_json(**decon.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if decon.validated_virt_image_id > 0 and amodule.params['state'] == "absent":
|
|
|
|
if decon.validated_virt_image_id > 0 and amodule.params['state'] == "absent":
|
|
|
|
decon.result['msg'] = ("Osimage module cannot delete virtual images.")
|
|
|
|
decon.result['msg'] = ("Osimage module cannot delete virtual images.")
|
|
|
|
decon.result['failed'] = True
|
|
|
|
decon.result['failed'] = True
|
|
|
|
amodule.exit_json(**decon.result)
|
|
|
|
amodule.exit_json(**decon.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif amodule.params['image_name'] or amodule.params['image_id']:
|
|
|
|
|
|
|
|
image_id, image_facts = decort_osimage.decort_image_find(decon, amodule)
|
|
|
|
|
|
|
|
decon.validated_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id']
|
|
|
|
|
|
|
|
if decort_osimage.decort_osimage_package_facts(image_facts)['id'] > 0:
|
|
|
|
|
|
|
|
decon.result['facts'] = decort_osimage.decort_osimage_package_facts(image_facts, amodule.check_mode)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['state'] == "present" and decon.validated_image_id == 0 and amodule.params['image_name'] and amodule.params['url']:
|
|
|
|
|
|
|
|
decort_osimage.decort_image_create(decon,amodule)
|
|
|
|
|
|
|
|
decon.result['changed'] = True
|
|
|
|
|
|
|
|
image_id, image_facts = decort_osimage.decort_image_find(decon, amodule)
|
|
|
|
|
|
|
|
decon.result['msg'] = ("OS image '{}' created").format(decort_osimage.decort_osimage_package_facts(image_facts)['id'])
|
|
|
|
|
|
|
|
decon.result['facts'] = decort_osimage.decort_osimage_package_facts(image_facts, amodule.check_mode)
|
|
|
|
|
|
|
|
decon.validated_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif amodule.params['state'] == "absent" and decon.validated_image_id:
|
|
|
|
|
|
|
|
if amodule.params['image_name'] or amodule.params['image_id'] and\
|
|
|
|
|
|
|
|
decort_osimage.decort_osimage_package_facts(image_facts)['accountId'] == amodule.params['account_Id']:
|
|
|
|
|
|
|
|
amodule.image_id_delete = decon.validated_image_id
|
|
|
|
|
|
|
|
decort_osimage.decort_image_delete(decon,amodule)
|
|
|
|
|
|
|
|
|
|
|
|
if decon.result['failed'] == True:
|
|
|
|
if decon.result['failed'] == True:
|
|
|
|
# we failed to find the specified image - fail the module
|
|
|
|
# we failed to find the specified image - fail the module
|
|
|
|