|
|
@ -252,161 +252,127 @@ from ansible.module_utils.basic import env_fallback
|
|
|
|
from ansible.module_utils.decort_utils import *
|
|
|
|
from ansible.module_utils.decort_utils import *
|
|
|
|
|
|
|
|
|
|
|
|
class decort_disk(DecortController):
|
|
|
|
class decort_disk(DecortController):
|
|
|
|
def __init__(self,amodule):
|
|
|
|
def __init__(self,arg_amodule):
|
|
|
|
super(decort_disk, self).__init__(amodule)
|
|
|
|
super(decort_disk, self).__init__(arg_amodule)
|
|
|
|
|
|
|
|
|
|
|
|
self.validated_account_id = 0
|
|
|
|
validated_acc_id = 0
|
|
|
|
self.validated_disk_id = 0
|
|
|
|
validated_acc_info = None
|
|
|
|
self.disk_facts = None # will hold Disk facts
|
|
|
|
validated_disk_id = 0
|
|
|
|
self.acc_facts = None # will hold Account facts
|
|
|
|
self.disk_id = 0
|
|
|
|
|
|
|
|
self.account_id = 0
|
|
|
|
|
|
|
|
validated_disk_facts = None
|
|
|
|
# limitIO check for exclusive parameters
|
|
|
|
# limitIO check for exclusive parameters
|
|
|
|
if amodule.params['limitIO']:
|
|
|
|
|
|
|
|
limit = amodule.params['limitIO']
|
|
|
|
|
|
|
|
if limit['total_bytes_sec'] > 0 and limit['read_bytes_sec'] > 0 or \
|
|
|
|
|
|
|
|
limit['total_bytes_sec'] > 0 and limit['write_bytes_sec'] > 0:
|
|
|
|
|
|
|
|
self.result['failed'] = True
|
|
|
|
|
|
|
|
self.result['msg'] = ("total and read/write of bytes_sec cannot be set at the same time.")
|
|
|
|
|
|
|
|
amodule.fail_json(**self.result)
|
|
|
|
|
|
|
|
elif limit['total_iops_sec'] > 0 and limit['read_iops_sec'] > 0 or \
|
|
|
|
|
|
|
|
limit['total_iops_sec'] > 0 and limit['write_iops_sec'] > 0:
|
|
|
|
|
|
|
|
self.result['failed'] = True
|
|
|
|
|
|
|
|
self.result['msg'] = ("total and read/write of iops_sec cannot be set at the same time.")
|
|
|
|
|
|
|
|
amodule.fail_json(**self.result)
|
|
|
|
|
|
|
|
elif limit['total_bytes_sec_max'] > 0 and limit['read_bytes_sec_max'] > 0 or \
|
|
|
|
|
|
|
|
limit['total_bytes_sec_max'] > 0 and limit['write_bytes_sec_max'] > 0:
|
|
|
|
|
|
|
|
self.result['failed'] = True
|
|
|
|
|
|
|
|
self.result['msg'] = ("total and read/write of bytes_sec_max cannot be set at the same time.")
|
|
|
|
|
|
|
|
amodule.fail_json(**self.result)
|
|
|
|
|
|
|
|
elif limit['total_iops_sec_max'] > 0 and limit['read_iops_sec_max'] > 0 or \
|
|
|
|
|
|
|
|
limit['total_iops_sec_max'] > 0 and limit['write_iops_sec_max'] > 0:
|
|
|
|
|
|
|
|
self.result['failed'] = True
|
|
|
|
|
|
|
|
self.result['msg'] = ("total and read/write of iops_sec_max cannot be set at the same time.")
|
|
|
|
|
|
|
|
amodule.fail_json(**self.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['account_id']:
|
|
|
|
|
|
|
|
self.validated_account_id = amodule.params['account_id']
|
|
|
|
|
|
|
|
elif amodule.params['account_name']:
|
|
|
|
|
|
|
|
self.validated_account_id, _ = self.account_find(amodule.params['account_name'])
|
|
|
|
|
|
|
|
elif not amodule.params['id'] and not amodule.params['account_name']:
|
|
|
|
|
|
|
|
self.result['failed'] = True
|
|
|
|
|
|
|
|
self.result['msg'] = ("Cannot found disk without account id or name.")
|
|
|
|
|
|
|
|
amodule.fail_json(**self.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.validated_account_id == 0 and not amodule.params['id']:
|
|
|
|
|
|
|
|
# we failed either to find or access the specified account - fail the module
|
|
|
|
|
|
|
|
self.result['failed'] = True
|
|
|
|
|
|
|
|
self.result['msg'] = ("Cannot find account '{}'").format(amodule.params['account_name'])
|
|
|
|
|
|
|
|
amodule.fail_json(**self.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['id'] or amodule.params['name']:
|
|
|
|
|
|
|
|
self.validated_disk_id, self.disk_facts = self.decort_disk_find(amodule)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.result['failed'] = True
|
|
|
|
|
|
|
|
self.result['msg'] = ("Cannot find or create disk without disk name or disk id")
|
|
|
|
|
|
|
|
amodule.fail_json(**self.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['place_with'] > 0:
|
|
|
|
if arg_amodule.params['limitIO']:
|
|
|
|
image_id, image_facts = self.image_find(amodule.params['place_with'], "", 0)
|
|
|
|
self.disk_check_iotune_arg(arg_amodule.params['limitIO'])
|
|
|
|
amodule.params['sep_id']= image_facts['sepId']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def decort_disk_create(self, amodule):
|
|
|
|
if arg_amodule.params['id'] or arg_amodule.params['name']:
|
|
|
|
if not self.disk_facts:
|
|
|
|
if arg_amodule.params['account_id'] or arg_amodule.params['account_name'] :
|
|
|
|
self.disk_id = self.disk_create(accountId=self.validated_account_id, gid=amodule.params['gid'],
|
|
|
|
validated_acc_id,validated_acc_info = self.account_find(arg_amodule.params['account_name'],arg_amodule.params['account_id'])
|
|
|
|
name=amodule.params['name'], description=amodule.params['description'],
|
|
|
|
if not validated_acc_id:
|
|
|
|
size=amodule.params['size'], type=amodule.params['type'],
|
|
|
|
self.result['failed'] = True
|
|
|
|
iops=amodule.params['iops'],
|
|
|
|
self.result['changed'] = False
|
|
|
|
sep_id=amodule.params['sep_id'], pool=amodule.params['pool'])
|
|
|
|
self.result['msg'] = ("Current user does not have access to the account ID {} / "
|
|
|
|
self.result['msg'] = ("Disk with id '{}' successfully created.").format(self.disk_id)
|
|
|
|
"name '{}' or non-existent account specified.").format(arg_amodule.params['account_id'],
|
|
|
|
|
|
|
|
arg_amodule.params['account_name'])
|
|
|
|
elif self.disk_facts['status'] in ["DESTROYED", "PURGED"]:
|
|
|
|
self.fail_json(**self.result)
|
|
|
|
if not amodule.params['limitIO']:
|
|
|
|
|
|
|
|
amodule.params['limitIO'] = self.disk_facts['iotune']
|
|
|
|
|
|
|
|
if amodule.params['sep_id'] == 0:
|
|
|
|
|
|
|
|
validated_sep_id = self.disk_facts['sepId']
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
validated_sep_id = amodule.params['sep_id']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['pool'] == 0:
|
|
|
|
|
|
|
|
validated_pool = self.disk_facts['pool']
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
validated_pool = amodule.params['pool']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['size'] == 0:
|
|
|
|
|
|
|
|
validated_size = self.disk_facts['sizeMax']
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
validated_size = amodule.params['size']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['gid'] == 0:
|
|
|
|
|
|
|
|
validated_gid = self.disk_facts['gid']
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
validated_gid = amodule.params['gid']
|
|
|
|
self.acc_id = validated_acc_id
|
|
|
|
|
|
|
|
self.acc_info = validated_acc_info
|
|
|
|
|
|
|
|
validated_disk_id,validated_disk_facts = self.disk_find(
|
|
|
|
|
|
|
|
disk_id=arg_amodule.params['id'],
|
|
|
|
|
|
|
|
name=arg_amodule.params['name'] if "name" in arg_amodule.params else "",
|
|
|
|
|
|
|
|
account_id=self.acc_id,
|
|
|
|
|
|
|
|
check_state=False,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.result['failed'] = True
|
|
|
|
|
|
|
|
self.result['msg'] = ("Cannot manage Disk when its ID is 0 and name is empty")
|
|
|
|
|
|
|
|
self.fail_json(**self.result)
|
|
|
|
|
|
|
|
|
|
|
|
self.disk_id = self.disk_create(accountId=self.validated_account_id, gid=validated_gid,
|
|
|
|
if arg_amodule.params['place_with']:
|
|
|
|
name=self.disk_facts['name'], description=amodule.params['description'],
|
|
|
|
image_id, image_facts = self.image_find(arg_amodule.params['place_with'], "", 0)
|
|
|
|
size=validated_size, type=self.disk_facts['type'],
|
|
|
|
arg_amodule.params['sep_id'] = image_facts['sepId']
|
|
|
|
iops=self.disk_facts['iotune']['total_iops_sec'],
|
|
|
|
|
|
|
|
sep_id=validated_sep_id, pool=validated_pool)
|
|
|
|
|
|
|
|
if not amodule.params['limitIO']:
|
|
|
|
|
|
|
|
amodule.params['limitIO'] = self.disk_facts['iotune']
|
|
|
|
|
|
|
|
self.result['msg'] = ("Disk with id '{}' successfully recreated.").format(self.disk_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.result['failed'] = False
|
|
|
|
self.disk_id = validated_disk_id
|
|
|
|
self.result['changed'] = True
|
|
|
|
self.disk_info = validated_disk_facts
|
|
|
|
return self.disk_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def decort_disk_delete(self, amodule):
|
|
|
|
def create(self):
|
|
|
|
self.disk_id = self.disk_delete(disk_id=self.validated_disk_id,
|
|
|
|
|
|
|
|
detach=amodule.params['force_detach'],
|
|
|
|
self.disk_id = self.disk_create(accountId=self.acc_id,
|
|
|
|
permanently=amodule.params['permanently'],
|
|
|
|
name = self.amodule.params['name'],
|
|
|
|
reason=amodule.params['reason'])
|
|
|
|
description=self.amodule.params['annotation'],
|
|
|
|
|
|
|
|
size=self.amodule.params['size'],
|
|
|
|
|
|
|
|
type=self.amodule.params['type'],
|
|
|
|
|
|
|
|
iops=self.amodule.params['iops'],
|
|
|
|
|
|
|
|
sep_id=self.amodule.params['sep_id'],
|
|
|
|
|
|
|
|
pool=self.amodule.params['pool'],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
#IO tune
|
|
|
|
|
|
|
|
if self.amodule.params['limitIO']:
|
|
|
|
|
|
|
|
self.disk_limitIO(self.amodule.params['limitIO'],self.disk_id)
|
|
|
|
|
|
|
|
#set share status
|
|
|
|
|
|
|
|
if self.amodule.params['shareable'] and self.amodule.params['type'] == "D":
|
|
|
|
|
|
|
|
self.dick_share(self.disk_id,self.amodule.params['shareable'])
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def action(self,restore=False):
|
|
|
|
def decort_disk_find(self, amodule):
|
|
|
|
|
|
|
|
if amodule.params['name'] and not amodule.params['id']:
|
|
|
|
#restore never be done
|
|
|
|
self.disk_id, self.disk_facts = self.disk_find(disk_id=self.validated_disk_id,
|
|
|
|
if restore:
|
|
|
|
name=amodule.params['name'],
|
|
|
|
self.disk_restore(self.disk_id)
|
|
|
|
account_id=self.validated_account_id)
|
|
|
|
#rename if id present
|
|
|
|
elif self.validated_disk_id > 0:
|
|
|
|
if self.amodule.params['name'] != self.disk_info['name']:
|
|
|
|
self.disk_id, self.disk_facts = self.disk_find(disk_id=self.validated_disk_id,
|
|
|
|
self.disk_rename(diskId=self.disk_id,
|
|
|
|
name=self.disk_facts['name'],
|
|
|
|
name=self.amodule.params['name'])
|
|
|
|
account_id=0)
|
|
|
|
self.disk_info['name'] = self.amodule.params['name']
|
|
|
|
elif amodule.params['id']:
|
|
|
|
#resize
|
|
|
|
self.disk_id, self.disk_facts = self.disk_find(disk_id=amodule.params['id'],
|
|
|
|
if self.amodule.params['size'] != self.disk_info['sizeMax']:
|
|
|
|
name=amodule.params['name'],
|
|
|
|
self.disk_resize(self.disk_info,self.amodule.params['size'])
|
|
|
|
account_id=0)
|
|
|
|
#IO TUNE
|
|
|
|
|
|
|
|
if self.amodule.params['limitIO']:
|
|
|
|
if not self.disk_id and not amodule.params['name']:
|
|
|
|
clean_io = [param for param in self.amodule.params['limitIO'] \
|
|
|
|
self.result['failed'] = True
|
|
|
|
if self.amodule.params['limitIO'][param] == None]
|
|
|
|
self.result['msg'] = "Specified Disk ID {} not found.".format(amodule.params['id'])
|
|
|
|
for key in clean_io: del self.amodule.params['limitIO'][key]
|
|
|
|
amodule.fail_json(**self.result)
|
|
|
|
if self.amodule.params['limitIO'] != self.disk_info['iotune']:
|
|
|
|
self.result['facts'] = decort_disk.decort_disk_package_facts(self.disk_facts)
|
|
|
|
self.disk_limitIO(self.disk_id,self.amodule.params['limitIO'])
|
|
|
|
return self.disk_id, self.disk_facts
|
|
|
|
#share check/update
|
|
|
|
|
|
|
|
#raise Exception(self.amodule.params['shareable'])
|
|
|
|
def decort_disk_limitIO(self, amodule):
|
|
|
|
if self.amodule.params['shareable'] != self.disk_info['shareable'] and \
|
|
|
|
self.limits = amodule.params['limitIO']
|
|
|
|
self.amodule.params['type'] == "D":
|
|
|
|
|
|
|
|
self.disk_share(self.disk_id,self.amodule.params['shareable'])
|
|
|
|
self.disk_limitIO(limits = self.limits,
|
|
|
|
return
|
|
|
|
diskId = self.validated_disk_id)
|
|
|
|
|
|
|
|
self.disk_facts['iotune'] = amodule.params['limitIO']
|
|
|
|
def delete(self):
|
|
|
|
self.result['facts'] = decort_disk.decort_disk_package_facts(self.disk_facts)
|
|
|
|
self.disk_id = self.disk_delete(disk_id=self.disk_id,
|
|
|
|
|
|
|
|
detach=self.amodule.params['force_detach'],
|
|
|
|
|
|
|
|
permanently=self.amodule.params['permanently'],
|
|
|
|
|
|
|
|
reason=self.amodule.params['reason'])
|
|
|
|
|
|
|
|
self.disk_info['status'] = "DELETED"
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def decort_disk_rename(self, amodule):
|
|
|
|
def rename(self):
|
|
|
|
self.disk_rename(diskId = self.validated_disk_id,
|
|
|
|
|
|
|
|
name = amodule.params['name'])
|
|
|
|
|
|
|
|
self.disk_facts['name'] = amodule.params['name']
|
|
|
|
self.disk_rename(diskId = self.disk_id,
|
|
|
|
self.result['facts'] = decort_disk.decort_disk_package_facts(self.disk_facts)
|
|
|
|
name = self.amodule.params['name'])
|
|
|
|
self.result['msg'] = ("Disk with id '{}',successfully renamed to '{}'.").format(self.validated_disk_id, amodule.params['name'])
|
|
|
|
self.disk_info['name'] = self.amodule.params['name']
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def decort_disk_package_facts(disk_facts, check_mode=False):
|
|
|
|
def nop(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.result['failed'] = False
|
|
|
|
|
|
|
|
self.result['changed'] = False
|
|
|
|
|
|
|
|
if self.disk_id:
|
|
|
|
|
|
|
|
self.result['msg'] = ("No state change required for Disk ID {} because of its "
|
|
|
|
|
|
|
|
"current status '{}'.").format(self.disk_id, self.disk_info['status'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.result['msg'] = ("No state change to '{}' can be done for "
|
|
|
|
|
|
|
|
"non-existent Disk.").format(self.amodule.params['state'])
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def package_facts(self, check_mode=False):
|
|
|
|
ret_dict = dict(id=0,
|
|
|
|
ret_dict = dict(id=0,
|
|
|
|
name="none",
|
|
|
|
name="none",
|
|
|
|
state="CHECK_MODE",
|
|
|
|
state="CHECK_MODE",
|
|
|
@ -418,29 +384,27 @@ class decort_disk(DecortController):
|
|
|
|
gid=0
|
|
|
|
gid=0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if check_mode:
|
|
|
|
if check_mode or self.disk_info is None:
|
|
|
|
# in check mode return immediately with the default values
|
|
|
|
|
|
|
|
return ret_dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if disk_facts is None:
|
|
|
|
|
|
|
|
# if void facts provided - change state value to ABSENT and return
|
|
|
|
|
|
|
|
ret_dict['state'] = "ABSENT"
|
|
|
|
|
|
|
|
return ret_dict
|
|
|
|
return ret_dict
|
|
|
|
|
|
|
|
|
|
|
|
ret_dict['id'] = disk_facts['id']
|
|
|
|
# remove io param with zero value
|
|
|
|
ret_dict['name'] = disk_facts['name']
|
|
|
|
clean_io = [param for param in self.disk_info['iotune'] if self.disk_info['iotune'][param] == 0]
|
|
|
|
ret_dict['size'] = disk_facts['sizeMax']
|
|
|
|
for key in clean_io: del self.disk_info['iotune'][key]
|
|
|
|
ret_dict['state'] = disk_facts['status']
|
|
|
|
|
|
|
|
ret_dict['account_id'] = disk_facts['accountId']
|
|
|
|
ret_dict['id'] = self.disk_info['id']
|
|
|
|
ret_dict['sep_id'] = disk_facts['sepId']
|
|
|
|
ret_dict['name'] = self.disk_info['name']
|
|
|
|
ret_dict['pool'] = disk_facts['pool']
|
|
|
|
ret_dict['size'] = self.disk_info['sizeMax']
|
|
|
|
ret_dict['attached_to'] = disk_facts['vmid']
|
|
|
|
ret_dict['state'] = self.disk_info['status']
|
|
|
|
ret_dict['gid'] = disk_facts['gid']
|
|
|
|
ret_dict['account_id'] = self.disk_info['accountId']
|
|
|
|
ret_dict['iotune'] = disk_facts['iotune']
|
|
|
|
ret_dict['sep_id'] = self.disk_info['sepId']
|
|
|
|
|
|
|
|
ret_dict['pool'] = self.disk_info['pool']
|
|
|
|
|
|
|
|
ret_dict['attached_to'] = self.disk_info['vmid']
|
|
|
|
|
|
|
|
ret_dict['gid'] = self.disk_info['gid']
|
|
|
|
|
|
|
|
ret_dict['iotune'] = self.disk_info['iotune']
|
|
|
|
|
|
|
|
|
|
|
|
return ret_dict
|
|
|
|
return ret_dict
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def decort_disk_parameters():
|
|
|
|
def build_parameters():
|
|
|
|
"""Build and return a dictionary of parameters expected by decort_disk module in a form accepted
|
|
|
|
"""Build and return a dictionary of parameters expected by decort_disk module in a form accepted
|
|
|
|
by AnsibleModule utility class."""
|
|
|
|
by AnsibleModule utility class."""
|
|
|
|
|
|
|
|
|
|
|
@ -476,32 +440,30 @@ class decort_disk(DecortController):
|
|
|
|
place_with=dict(type='int', default=0),
|
|
|
|
place_with=dict(type='int', default=0),
|
|
|
|
pool=dict(type='str', default=''),
|
|
|
|
pool=dict(type='str', default=''),
|
|
|
|
sep_id=dict(type='int', default=0),
|
|
|
|
sep_id=dict(type='int', default=0),
|
|
|
|
gid=dict(type='int', default=0),
|
|
|
|
|
|
|
|
size=dict(type='int', default=0),
|
|
|
|
size=dict(type='int', default=0),
|
|
|
|
type=dict(type='str',
|
|
|
|
type=dict(type='str',
|
|
|
|
required=False,
|
|
|
|
required=False,
|
|
|
|
default="D",
|
|
|
|
default="D",
|
|
|
|
choices=['B', 'D', 'T']),
|
|
|
|
choices=['B', 'D', 'T']),
|
|
|
|
iops=dict(type='int', default=2000),
|
|
|
|
iops=dict(type='int',required=False,default=2000),
|
|
|
|
limitIO=dict(type='dict',
|
|
|
|
limitIO=dict(type='dict',
|
|
|
|
options=dict(
|
|
|
|
options=dict(
|
|
|
|
total_bytes_sec=dict(default=0,type='int'),
|
|
|
|
total_bytes_sec=dict(required=False,type='int'),
|
|
|
|
read_bytes_sec=dict(default=0,type='int'),
|
|
|
|
read_bytes_sec=dict(required=False,type='int'),
|
|
|
|
write_bytes_sec=dict(default=0,type='int'),
|
|
|
|
write_bytes_sec=dict(required=False,type='int'),
|
|
|
|
total_iops_sec=dict(default=0,type='int'),
|
|
|
|
total_iops_sec=dict(required=False,type='int'),
|
|
|
|
read_iops_sec=dict(default=0,type='int'),
|
|
|
|
read_iops_sec=dict(required=False,type='int'),
|
|
|
|
write_iops_sec=dict(default=0,type='int'),
|
|
|
|
write_iops_sec=dict(required=False,type='int'),
|
|
|
|
total_bytes_sec_max=dict(default=0,type='int'),
|
|
|
|
total_bytes_sec_max=dict(required=False,type='int'),
|
|
|
|
read_bytes_sec_max=dict(default=0,type='int'),
|
|
|
|
read_bytes_sec_max=dict(required=False,type='int'),
|
|
|
|
write_bytes_sec_max=dict(default=0,type='int'),
|
|
|
|
write_bytes_sec_max=dict(required=False,type='int'),
|
|
|
|
total_iops_sec_max=dict(default=0,type='int'),
|
|
|
|
total_iops_sec_max=dict(required=False,type='int'),
|
|
|
|
read_iops_sec_max=dict(default=0,type='int'),
|
|
|
|
read_iops_sec_max=dict(required=False,type='int'),
|
|
|
|
write_iops_sec_max=dict(default=0,type='int'),
|
|
|
|
write_iops_sec_max=dict(required=False,type='int'),
|
|
|
|
size_iops_sec=dict(default=0,type='int'),)),
|
|
|
|
size_iops_sec=dict(required=False,type='int'),)),
|
|
|
|
permanently=dict(type='bool', required=False, default=False),
|
|
|
|
permanently=dict(type='bool', required=False, default=False),
|
|
|
|
reason=dict(type='int', required=False),
|
|
|
|
shareable=dict(type='bool', required=False, default=False),
|
|
|
|
description=dict(type='str', required=False,
|
|
|
|
reason=dict(type='str', required=False,default='Managed by Ansible decort_disk'),
|
|
|
|
default="Disk created with Ansible Decort_disk module."),
|
|
|
|
|
|
|
|
state=dict(type='str',
|
|
|
|
state=dict(type='str',
|
|
|
|
default='present',
|
|
|
|
default='present',
|
|
|
|
choices=['absent', 'present']),
|
|
|
|
choices=['absent', 'present']),
|
|
|
@ -514,7 +476,7 @@ class decort_disk(DecortController):
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
module_parameters = decort_disk.decort_disk_parameters()
|
|
|
|
module_parameters = decort_disk.build_parameters()
|
|
|
|
|
|
|
|
|
|
|
|
amodule = AnsibleModule(argument_spec=module_parameters,
|
|
|
|
amodule = AnsibleModule(argument_spec=module_parameters,
|
|
|
|
supports_check_mode=True,
|
|
|
|
supports_check_mode=True,
|
|
|
@ -530,105 +492,51 @@ def main():
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
decon = decort_disk(amodule)
|
|
|
|
decon = decort_disk(amodule)
|
|
|
|
|
|
|
|
#
|
|
|
|
if decon.validated_disk_id == 0 and amodule.params['state'] == 'present':
|
|
|
|
#Full range of Disk status is as follows:
|
|
|
|
# if sep_id or place_with not specified, then exit with error
|
|
|
|
#
|
|
|
|
if amodule.params['sep_id'] == 0 and amodule.params['place_with'] == 0:
|
|
|
|
# "ASSIGNED","MODELED", "CREATING","CREATED","DELETED", "DESTROYED","PURGED",
|
|
|
|
decon.result['msg'] = ("To create a disk, you must specify sep_id or place_with.")\
|
|
|
|
#
|
|
|
|
.format(decon.validated_disk_id)
|
|
|
|
if decon.disk_id:
|
|
|
|
amodule.fail_json(**decon.result)
|
|
|
|
#disk exist
|
|
|
|
# if id cannot cannot be found and have a state 'present', then create a new disk
|
|
|
|
if decon.disk_info['status'] in ["MODELED", "CREATING"]:
|
|
|
|
decon.validated_disk_id = decon.decort_disk_create(amodule)
|
|
|
|
decon.result['failed'] = True
|
|
|
|
_, decon.disk_facts = decon.decort_disk_find(amodule)
|
|
|
|
decon.result['changed'] = False
|
|
|
|
decon.result['changed'] = True
|
|
|
|
decon.result['msg'] = ("No change can be done for existing Disk ID {} because of its current "
|
|
|
|
decon.result['msg'] = ("Disk with id '{}' successfully created.").format(decon.validated_disk_id)
|
|
|
|
"status '{}'").format(decon.disk_id, decon.disk_info['status'])
|
|
|
|
|
|
|
|
# "ASSIGNED","CREATED","DELETED","PURGED", "DESTROYED"
|
|
|
|
elif decon.validated_disk_id == 0 and amodule.params['state'] == 'absent' and amodule.params['name']:
|
|
|
|
elif decon.disk_info['status'] in ["ASSIGNED","CREATED"]:
|
|
|
|
# if disk with specified name cannot be found and have a state 'absent', then nothing to do,
|
|
|
|
if amodule.params['state'] == 'absent':
|
|
|
|
# specified disk already deleted
|
|
|
|
decon.delete()
|
|
|
|
decon.result['msg'] = ("Disk with name '{}' has already been deleted or your account does not have"
|
|
|
|
elif amodule.params['state'] == 'present':
|
|
|
|
" access to it.")\
|
|
|
|
decon.action()
|
|
|
|
.format(amodule.params['name'])
|
|
|
|
elif decon.disk_info['status'] in ["PURGED", "DESTROYED"]:
|
|
|
|
amodule.exit_json(**decon.result)
|
|
|
|
#re-provision disk
|
|
|
|
|
|
|
|
if amodule.params['state'] in ('present'):
|
|
|
|
elif decon.validated_disk_id == 0 and amodule.params['state'] == 'absent' and amodule.params['id']:
|
|
|
|
decon.create()
|
|
|
|
# if disk with specified id cannot be found and have a state 'absent', then nothing to do,
|
|
|
|
else:
|
|
|
|
# specified disk already deleted
|
|
|
|
decon.nop()
|
|
|
|
decon.result['msg'] = ("Disk with name '{}' has already been deleted or your account does not have"
|
|
|
|
elif decon.disk_info['status'] == "DELETED":
|
|
|
|
" access to it.")\
|
|
|
|
if amodule.params['state'] in ('present'):
|
|
|
|
.format(decon.validated_disk_id)
|
|
|
|
decon.action(restore=True)
|
|
|
|
amodule.exit_json(**decon.result)
|
|
|
|
else:
|
|
|
|
|
|
|
|
decon.nop()
|
|
|
|
elif decon.disk_facts['status'] == "CREATED":
|
|
|
|
else:
|
|
|
|
if amodule.params['state'] == 'present':
|
|
|
|
# preexisting Disk was not found
|
|
|
|
# if disk status in condition "CREATED" and state "present", nothing to do,
|
|
|
|
|
|
|
|
# specified disk already created
|
|
|
|
|
|
|
|
decon.result['msg'] = "Specified Disk ID {} already created.".format(decon.validated_disk_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['state'] == 'absent':
|
|
|
|
if amodule.params['state'] == 'absent':
|
|
|
|
# if disk status in condition "CREATED" and state "absent", delete the disk
|
|
|
|
decon.nop()
|
|
|
|
decon.validated_disk_id = decon.decort_disk_delete(amodule)
|
|
|
|
else:
|
|
|
|
decon.disk_facts['status'] = "DESTROYED"
|
|
|
|
decon.create()
|
|
|
|
decon.result['msg'] = ("Disk with id '{}' successfully deleted.").format(decon.disk_facts['id'])
|
|
|
|
|
|
|
|
decon.result['facts'] = decon.decort_disk_package_facts(decon.disk_facts)
|
|
|
|
|
|
|
|
amodule.exit_json(**decon.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif decon.disk_facts['status'] in ["MODELED", "CREATING" ]:
|
|
|
|
|
|
|
|
# if disk in status "MODELED" or "CREATING",
|
|
|
|
|
|
|
|
# then we cannot do anything, while disk in this status
|
|
|
|
|
|
|
|
decon.result['changed'] = False
|
|
|
|
|
|
|
|
decon.result['msg'] = ("Cannot do anything with disk id '{}',please wait until disk will be created.")\
|
|
|
|
|
|
|
|
.format(decon.validated_disk_id)
|
|
|
|
|
|
|
|
amodule.fail_json(**decon.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif decon.disk_facts['status'] == "DELETED":
|
|
|
|
|
|
|
|
if amodule.params['state'] == 'present':
|
|
|
|
|
|
|
|
# if disk in "DELETED" status and "present" state, restore
|
|
|
|
|
|
|
|
decon.disk_restore(decon.validated_disk_id)
|
|
|
|
|
|
|
|
_, decon.disk_facts = decon.decort_disk_find(amodule)
|
|
|
|
|
|
|
|
decon.result['changed'] = True
|
|
|
|
|
|
|
|
decon.result['msg'] = ("Disk with id '{}',restored successfully.").format(decon.validated_disk_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif amodule.params['state'] == 'absent':
|
|
|
|
|
|
|
|
# if disk in "DELETED" status and "absent" state, nothing to do
|
|
|
|
|
|
|
|
decon.result['msg'] = "Specified Disk ID {} already destroyed.".format(decon.validated_disk_id)
|
|
|
|
|
|
|
|
amodule.exit_json(**decon.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif decon.disk_facts['status'] in ["DESTROYED", "PURGED"]:
|
|
|
|
|
|
|
|
if amodule.params['state'] == 'present':
|
|
|
|
|
|
|
|
decon.validated_disk_id = decon.decort_disk_create(amodule)
|
|
|
|
|
|
|
|
_, decon.disk_facts = decon.decort_disk_find(amodule)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif amodule.params['state'] == 'absent':
|
|
|
|
|
|
|
|
decon.result['msg'] = "Specified Disk ID {} already destroyed.".format(decon.validated_disk_id)
|
|
|
|
|
|
|
|
amodule.exit_json(**decon.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['state'] == "present":
|
|
|
|
|
|
|
|
if decon.disk_facts['sizeMax'] != amodule.params['size']:
|
|
|
|
|
|
|
|
if decon.disk_facts['sizeMax'] > amodule.params['size'] and amodule.params['size'] != 0:
|
|
|
|
|
|
|
|
decon.result['failed'] = True
|
|
|
|
|
|
|
|
decon.result['msg'] = ("Disk id '{}', cannot reduce disk size.").format(decon.validated_disk_id)
|
|
|
|
|
|
|
|
amodule.fail_json(**decon.result)
|
|
|
|
|
|
|
|
elif decon.disk_facts['sizeMax'] < amodule.params['size']:
|
|
|
|
|
|
|
|
decon.disk_resize(disk_facts=decon.disk_facts,
|
|
|
|
|
|
|
|
new_size=amodule.params['size'])
|
|
|
|
|
|
|
|
decon.result['changed'] = True
|
|
|
|
|
|
|
|
decon.disk_facts['size'] = amodule.params['size']
|
|
|
|
|
|
|
|
decon.result['msg'] = ("Disk with id '{}',resized successfully.").format(decon.validated_disk_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['limitIO'] and amodule.params['limitIO'] != decon.disk_facts['iotune']:
|
|
|
|
|
|
|
|
decon.decort_disk_limitIO(amodule)
|
|
|
|
|
|
|
|
decon.result['changed'] = True
|
|
|
|
|
|
|
|
decon.result['msg'] = ("Disk with id '{}',limited successfully.").format(decon.validated_disk_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if amodule.params['name'] and amodule.params['id']:
|
|
|
|
if decon.result['failed']:
|
|
|
|
if amodule.params['name'] != decon.disk_facts['name']:
|
|
|
|
amodule.fail_json(**decon.result)
|
|
|
|
decon.decort_disk_rename(amodule)
|
|
|
|
else:
|
|
|
|
decon.result['changed'] = True
|
|
|
|
if decon.result['changed'] and amodule.params['state'] in ('present'):
|
|
|
|
decon.result['msg'] = ("Disk with id '{}',renamed successfully from '{}' to '{}'.")\
|
|
|
|
_, decon.disk_info = decon.disk_find(decon.disk_id)
|
|
|
|
.format(decon.validated_disk_id, decon.disk_facts['name'], amodule.params['name'])
|
|
|
|
decon.result['facts'] = decon.package_facts(amodule.check_mode)
|
|
|
|
|
|
|
|
amodule.exit_json(**decon.result)
|
|
|
|
amodule.exit_json(**decon.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#SHARE
|