6.0.0
This commit is contained in:
@@ -217,31 +217,44 @@ class decort_rg(DecortController):
|
||||
self.validated_rg_id = 0
|
||||
self.validated_rg_facts = None
|
||||
|
||||
if self.amodule.params['account_id']:
|
||||
self.validated_acc_id, _ = self.account_find("", amodule.params['account_id'])
|
||||
elif amodule.params['account_name']:
|
||||
self.validated_acc_id, _ = self.account_find(amodule.params['account_name'])
|
||||
if not self.validated_acc_id:
|
||||
# we failed to locate account by either name or ID - abort with an error
|
||||
self.result['failed'] = True
|
||||
self.result['msg'] = ("Current user does not have access to the requested account "
|
||||
"or non-existent account specified.")
|
||||
self.amodule.fail_json(**self.result)
|
||||
|
||||
if amodule.params['rg_id'] > 0:
|
||||
self.validated_rg_id = amodule.params['rg_id']
|
||||
if amodule.params['rg_id'] is None:
|
||||
if self.amodule.params['account_id']:
|
||||
self.validated_acc_id, _ = self.account_find("", amodule.params['account_id'])
|
||||
elif amodule.params['account_name']:
|
||||
self.validated_acc_id, _ = self.account_find(amodule.params['account_name'])
|
||||
if not self.validated_acc_id:
|
||||
# we failed to locate account by either name or ID - abort with an error
|
||||
self.result['failed'] = True
|
||||
self.result['msg'] = ("Current user does not have access to the requested account "
|
||||
"or non-existent account specified.")
|
||||
self.amodule.fail_json(**self.result)
|
||||
|
||||
# Check if the RG with the specified parameters already exists
|
||||
self.validated_rg_id, self.rg_facts = self.rg_find(self.validated_acc_id,
|
||||
arg_rg_id = self.validated_rg_id,
|
||||
arg_rg_name=amodule.params['rg_name'],
|
||||
arg_check_state=False)
|
||||
self.get_info()
|
||||
|
||||
if amodule.params['state'] != "absent":
|
||||
self.rg_should_exist = True
|
||||
else:
|
||||
self.rg_should_exist = False
|
||||
|
||||
def get_info(self):
|
||||
# If this is the first getting info
|
||||
if not self.validated_rg_id:
|
||||
self.validated_rg_id, self.rg_facts = self.rg_find(
|
||||
arg_account_id=self.validated_acc_id,
|
||||
arg_rg_id=self.aparams['rg_id'],
|
||||
arg_rg_name=self.aparams['rg_name'],
|
||||
arg_check_state=False,
|
||||
)
|
||||
# If this is a repeated getting info
|
||||
else:
|
||||
# If check mode is enabled, there is no needed to
|
||||
# request info again
|
||||
if self.amodule.check_mode:
|
||||
return
|
||||
|
||||
_, self.rg_facts = self.rg_find(arg_rg_id=self.validated_rg_id)
|
||||
|
||||
def access(self):
|
||||
should_change_access = False
|
||||
acc_granted = False
|
||||
@@ -296,17 +309,37 @@ class decort_rg(DecortController):
|
||||
self.result['msg'] = ("Cannot limit less than already reserved'{}'").format(incorrect_quota)
|
||||
self.result['failed'] = True
|
||||
|
||||
if self.result['failed'] != True:
|
||||
self.rg_update(self.rg_facts, self.amodule.params['quotas'],
|
||||
self.amodule.params['resType'], self.amodule.params['rename'])
|
||||
if not self.result['failed']:
|
||||
self.rg_update(
|
||||
arg_rg_dict=self.rg_facts,
|
||||
arg_quotas=self.amodule.params['quotas'],
|
||||
arg_res_types=self.amodule.params['resType'],
|
||||
arg_newname=self.amodule.params['rename'],
|
||||
arg_sep_pools=self.amodule.params['sep_pools'],
|
||||
)
|
||||
self.rg_should_exist = True
|
||||
return
|
||||
|
||||
def setDefNet(self):
|
||||
if self.amodule.params['def_netId'] != self.rg_facts['def_net_id']:
|
||||
self.rg_setDefNet(self.validated_rg_id,
|
||||
self.amodule.params['def_netType'],
|
||||
self.amodule.params['def_netId'])
|
||||
rg_def_net_type = self.rg_facts['def_net_type']
|
||||
rg_def_net_id = self.rg_facts['def_net_id']
|
||||
aparam_def_net_type = self.aparams['def_netType']
|
||||
aparam_def_net_id = self.aparams['def_netId']
|
||||
|
||||
need_to_reset = (aparam_def_net_type == 'NONE'
|
||||
and rg_def_net_type != aparam_def_net_type)
|
||||
|
||||
need_to_change = False
|
||||
if aparam_def_net_id is not None:
|
||||
need_to_change = (aparam_def_net_id != rg_def_net_id
|
||||
or aparam_def_net_type != rg_def_net_type)
|
||||
|
||||
if need_to_reset or need_to_change:
|
||||
self.rg_setDefNet(
|
||||
arg_rg_id=self.validated_rg_id,
|
||||
arg_net_type=aparam_def_net_type,
|
||||
arg_net_id=aparam_def_net_id,
|
||||
)
|
||||
self.rg_should_exist = True
|
||||
return
|
||||
|
||||
@@ -351,8 +384,11 @@ class decort_rg(DecortController):
|
||||
return
|
||||
|
||||
def destroy(self):
|
||||
|
||||
self.rg_delete(self.validated_rg_id, self.amodule.params['permanently'])
|
||||
self.rg_delete(
|
||||
rg_id=self.validated_rg_id,
|
||||
permanently=self.amodule.params['permanently'],
|
||||
recursively=self.aparams['recursive_deletion'],
|
||||
)
|
||||
if self.amodule.params['permanently'] == True:
|
||||
self.rg_facts['status'] = 'DESTROYED'
|
||||
else:
|
||||
@@ -393,6 +429,7 @@ class decort_rg(DecortController):
|
||||
ret_dict['defNetType'] = self.rg_facts['def_net_type']
|
||||
ret_dict['ViNS'] = self.rg_facts['vins']
|
||||
ret_dict['computes'] = self.rg_facts['vms']
|
||||
ret_dict['uniqPools'] = self.rg_facts['uniqPools']
|
||||
|
||||
return ret_dict
|
||||
|
||||
@@ -418,7 +455,7 @@ class decort_rg(DecortController):
|
||||
controller_url=dict(type='str', required=True),
|
||||
# datacenter=dict(type='str', required=False, default=''),
|
||||
def_netType=dict(type='str', choices=['PRIVATE','PUBLIC', 'NONE'], default='PRIVATE'),
|
||||
def_netId=dict(type='int', default=0),
|
||||
def_netId=dict(type='int'),
|
||||
extNetId=dict(type='int', default=0),
|
||||
extNetIp=dict(type='str', default=""),
|
||||
owner=dict(type='str', default=""),
|
||||
@@ -446,10 +483,29 @@ class decort_rg(DecortController):
|
||||
required=False,
|
||||
fallback=(env_fallback, ['DECORT_USER'])),
|
||||
rg_name=dict(type='str', required=False,),
|
||||
rg_id=dict(type='int', required=False, default=0),
|
||||
rg_id=dict(type='int', required=False),
|
||||
verify_ssl=dict(type='bool', required=False, default=True),
|
||||
workflow_callback=dict(type='str', required=False),
|
||||
workflow_context=dict(type='str', required=False),
|
||||
sep_pools=dict(
|
||||
type='list',
|
||||
elements='dict',
|
||||
options=dict(
|
||||
sep_id=dict(
|
||||
type='int',
|
||||
required=True,
|
||||
),
|
||||
pool_names=dict(
|
||||
type='list',
|
||||
required=True,
|
||||
elements='str',
|
||||
),
|
||||
),
|
||||
),
|
||||
recursive_deletion=dict(
|
||||
type='bool',
|
||||
default=False,
|
||||
)
|
||||
)
|
||||
|
||||
# Workflow digest:
|
||||
@@ -486,11 +542,16 @@ def main():
|
||||
elif amodule.params['state'] == "disabled":
|
||||
decon.enable()
|
||||
if amodule.params['state'] in ['present', 'enabled']:
|
||||
if amodule.params['quotas'] or amodule.params['resType'] or amodule.params['rename'] != "":
|
||||
if (
|
||||
amodule.params['quotas']
|
||||
or amodule.params['resType']
|
||||
or amodule.params['rename'] != ""
|
||||
or amodule.params['sep_pools'] is not None
|
||||
):
|
||||
decon.update()
|
||||
if amodule.params['access']:
|
||||
decon.access()
|
||||
if amodule.params['def_netId'] > 0:
|
||||
if amodule.params['def_netType'] is not None:
|
||||
decon.setDefNet()
|
||||
|
||||
elif decon.rg_facts['status'] == "DELETED":
|
||||
@@ -528,6 +589,8 @@ def main():
|
||||
amodule.fail_json(**decon.result)
|
||||
else:
|
||||
if decon.rg_should_exist:
|
||||
if decon.result['changed']:
|
||||
decon.get_info()
|
||||
decon.result['facts'] = decon.package_facts(amodule.check_mode)
|
||||
amodule.exit_json(**decon.result)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user