Compare commits
5 Commits
rc-5.2.4
...
rc-5.2.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9222fdd866 | ||
|
|
e94faef2ad | ||
|
|
66e72a3d3b | ||
|
|
740271b2f2 | ||
|
|
207c04bb77 |
@@ -9,4 +9,4 @@ Requirements:
|
||||
* PyJWT 2.0.0 Python module or higher
|
||||
* requests Python module
|
||||
* netaddr Python module
|
||||
* DECORT cloud platform version 3.8.6 or higher
|
||||
* DECORT cloud platform version 3.8.7 or higher
|
||||
|
||||
@@ -80,13 +80,13 @@ class decort_k8s(DecortController):
|
||||
self.result['failed'] = True
|
||||
self.result['changed'] = False
|
||||
self.result['msg'] = "At least one worker group must be present"
|
||||
self.fail_json(**self.result)
|
||||
self.amodule.fail_json(**self.result)
|
||||
|
||||
if arg_amodule.params['name'] == "" and arg_amodule.params['id'] == 0:
|
||||
self.result['failed'] = True
|
||||
self.result['changed'] = False
|
||||
self.result['msg'] = "Cannot manage k8s cluster when its ID is 0 and name is empty."
|
||||
self.fail_json(**self.result)
|
||||
self.amodule.fail_json(**self.result)
|
||||
|
||||
|
||||
if not arg_amodule.params['id']:
|
||||
@@ -99,17 +99,17 @@ class decort_k8s(DecortController):
|
||||
self.result['msg'] = ("Current user does not have access to the account ID {} / "
|
||||
"name '{}' or non-existent account specified.").format(arg_amodule.params['account_id'],
|
||||
arg_amodule.params['account_name'])
|
||||
self.fail_json(**self.result)
|
||||
self.amodule.fail_json(**self.result)
|
||||
# fail the module -> exit
|
||||
# now validate RG
|
||||
validated_rg_id, validated_rg_facts = self.rg_find(validated_acc_id,
|
||||
arg_amodule.params['rg_id'],)
|
||||
arg_amodule.params['rg_id'],)
|
||||
if not validated_rg_id:
|
||||
self.result['failed'] = True
|
||||
self.result['changed'] = False
|
||||
self.result['msg'] = "Cannot find RG ID {} / name '{}'.".format(arg_amodule.params['rg_id'],
|
||||
arg_amodule.params['rg_name'])
|
||||
self.fail_json(**self.result)
|
||||
self.amodule.fail_json(**self.result)
|
||||
# fail the module - exit
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ class decort_k8s(DecortController):
|
||||
self.result['failed'] = True
|
||||
self.result['changed'] = False
|
||||
self.result['msg'] = "Cannot find K8CI ID {}.".format(arg_amodule.params['k8ci_id'])
|
||||
self.fail_json(**self.result)
|
||||
self.amodule.fail_json(**self.result)
|
||||
|
||||
self.rg_id = validated_rg_id
|
||||
arg_amodule.params['rg_id'] = validated_rg_id
|
||||
@@ -203,7 +203,7 @@ class decort_k8s(DecortController):
|
||||
return
|
||||
|
||||
def create(self):
|
||||
self.k8s_provision(self.amodule.params['name'],
|
||||
k8s_id = self.k8s_provision(self.amodule.params['name'],
|
||||
self.amodule.params['k8ci_id'],
|
||||
self.amodule.params['rg_id'],
|
||||
self.amodule.params['network_plugin'],
|
||||
@@ -211,12 +211,18 @@ class decort_k8s(DecortController):
|
||||
self.amodule.params['master_cpu'],
|
||||
self.amodule.params['master_ram'],
|
||||
self.amodule.params['master_disk'],
|
||||
self.amodule.params['master_sepid'],
|
||||
self.amodule.params['master_pool'],
|
||||
self.amodule.params['workers'][0],
|
||||
self.amodule.params['extnet_id'],
|
||||
self.amodule.params['with_lb'],
|
||||
self.amodule.params['description'],)
|
||||
|
||||
self.k8s_id,self.k8s_info = self.k8s_find(k8s_id=self.amodule.params['id'],
|
||||
if not k8s_id:
|
||||
self.result['failed'] = True
|
||||
self.amodule.fail_json(**self.result)
|
||||
|
||||
self.k8s_id,self.k8s_info = self.k8s_find(k8s_id=k8s_id,
|
||||
k8s_name=self.amodule.params['name'],
|
||||
rg_id=self.rg_id,
|
||||
check_state=False)
|
||||
@@ -284,7 +290,7 @@ class decort_k8s(DecortController):
|
||||
user=dict(type='str',
|
||||
required=False,
|
||||
fallback=(env_fallback, ['DECORT_USER'])),
|
||||
name=dict(type='str', required=True),
|
||||
name=dict(type='str', required=False, default=""),
|
||||
id=dict(type='int', required=False, default=0),
|
||||
getConfig=dict(type='bool',required=False, default=False),
|
||||
rg_id=dict(type='int', default=0),
|
||||
@@ -296,6 +302,8 @@ class decort_k8s(DecortController):
|
||||
master_cpu=dict(type='int', default=2),
|
||||
master_ram=dict(type='int', default=2048),
|
||||
master_disk=dict(type='int', default=10),
|
||||
master_sepid=dict(type='int', required=False, default=None),
|
||||
master_pool=dict(type='str', required=False, default=None),
|
||||
worker_count=dict(type='int', default=1),
|
||||
worker_cpu=dict(type='int', default=1),
|
||||
worker_ram_mb=dict(type='int', default=1024),
|
||||
|
||||
@@ -541,7 +541,7 @@ class DecortController(object):
|
||||
|
||||
return
|
||||
|
||||
def compute_delete(self, comp_id, permanently=False):
|
||||
def compute_delete(self, comp_id, permanently=False,detach=True):
|
||||
"""Delete a Compute instance identified by its ID. It is assumed that the Compute with the specified
|
||||
ID exists.
|
||||
|
||||
@@ -559,7 +559,8 @@ class DecortController(object):
|
||||
return
|
||||
|
||||
api_params = dict(computeId=comp_id,
|
||||
permanently=permanently, )
|
||||
permanently=permanently,
|
||||
detachDisks=detach, )
|
||||
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/delete", api_params)
|
||||
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
||||
self.result['failed'] = False
|
||||
@@ -657,7 +658,7 @@ class DecortController(object):
|
||||
# if we have validated RG ID at this point, look up Compute by name in this RG
|
||||
# rg.vms list contains IDs of compute instances registered with this RG until compute is
|
||||
# destroyed. So we may see here computes in "active" and DELETED states.
|
||||
for runner in comp_list:
|
||||
for runner in comp_list['data']:
|
||||
if runner['name'] == comp_name and runner['rgId'] == rg_id:
|
||||
if not check_state or runner['status'] not in COMP_INVALID_STATES:
|
||||
ret_comp_id = runner['id']
|
||||
@@ -800,7 +801,7 @@ class DecortController(object):
|
||||
sepId=sep_id,
|
||||
pool=pool_name,
|
||||
start=start_on_create, # start_machine parameter requires DECORT API ver 3.3.1 or higher
|
||||
netType="NONE") # we create VM without any network connections
|
||||
interfaces='[]') # we create VM without any network connections
|
||||
if userdata:
|
||||
api_params['userdata'] = json.dumps(userdata) # we need to pass a string object as "userdata"
|
||||
|
||||
@@ -896,7 +897,7 @@ class DecortController(object):
|
||||
vins_iface_list.append(iface_data)
|
||||
elif iface['connType'] == 'VLAN':
|
||||
ip_addr = netaddr.IPAddress(iface['ipAddress'])
|
||||
for erunner in extnet_list:
|
||||
for erunner in extnet_list['data']:
|
||||
# match by IP address range
|
||||
# if iface['ipAddress'] <-> erunner['name']
|
||||
# enet_iface_list.append(erunner['id'])
|
||||
@@ -1366,7 +1367,7 @@ class DecortController(object):
|
||||
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/image/list", api_params)
|
||||
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
||||
images_list = json.loads(api_resp.content.decode('utf8'))
|
||||
for image_record in images_list:
|
||||
for image_record in images_list['data']:
|
||||
if image_record['name'] == image_name and image_record['status'] == "CREATED":
|
||||
if sepid == 0 and pool == "":
|
||||
# if no filtering by SEP ID or pool name is requested, return the first match
|
||||
@@ -1657,7 +1658,7 @@ class DecortController(object):
|
||||
if api_resp.status_code == 200:
|
||||
account_specs = json.loads(api_resp.content.decode('utf8'))
|
||||
#api_params.pop('accountId')
|
||||
for rg_item in account_specs:
|
||||
for rg_item in account_specs['data']:
|
||||
#
|
||||
if rg_item['name'] == arg_rg_name:
|
||||
# name matches
|
||||
@@ -1923,7 +1924,7 @@ class DecortController(object):
|
||||
# Parse response to see if a account matching arg_account_name is found in the output
|
||||
# If it is found, assign its ID to the return variable and copy dictionary with the facts
|
||||
accounts_list = json.loads(api_resp.content.decode('utf8'))
|
||||
for runner in accounts_list:
|
||||
for runner in accounts_list['data']:
|
||||
if runner['name'] == account_name:
|
||||
# get detailed information about the account from "accounts/get" call as
|
||||
# "accounts/list" does not return all necessary fields
|
||||
@@ -2028,7 +2029,7 @@ class DecortController(object):
|
||||
if api_resp.status_code == 200:
|
||||
ret_gpu_list = json.loads(api_resp.content.decode('utf8'))
|
||||
|
||||
return ret_gpu_list
|
||||
return ret_gpu_list['data']
|
||||
|
||||
###################################
|
||||
# Workflow callback stub methods - not fully implemented yet
|
||||
@@ -2084,9 +2085,9 @@ class DecortController(object):
|
||||
if api_resp.status_code == 200:
|
||||
locations = json.loads(api_resp.content.decode('utf8'))
|
||||
if location_code == "" and locations:
|
||||
ret_gid = locations[0]['gid']
|
||||
ret_gid = locations['data'][0]['gid']
|
||||
else:
|
||||
for runner in locations:
|
||||
for runner in locations['data']:
|
||||
if runner['locationCode'] == location_code:
|
||||
# location code matches
|
||||
ret_gid = runner['gid']
|
||||
@@ -2178,7 +2179,7 @@ class DecortController(object):
|
||||
"response {}.").format(rg_id, api_resp.status_code, api_resp.reason)
|
||||
return []
|
||||
|
||||
return ret_rg_vins_list
|
||||
return ret_rg_vins_list['data']
|
||||
|
||||
def vins_find(self, vins_id, vins_name="", account_id=0, rg_id=0, rg_facts="", check_state=True):
|
||||
"""Find specified ViNS.
|
||||
@@ -2626,7 +2627,8 @@ class DecortController(object):
|
||||
else:
|
||||
self.result['warning'] = ("get_all_account_vinses(): failed to get list VINS in Account ID {}. HTTP code {}, "
|
||||
"response {}.").format(acc_id, api_resp.status_code, api_resp.reason)
|
||||
return ret_listvins_dict
|
||||
return []
|
||||
return ret_listvins_dict['data']
|
||||
|
||||
def _vins_vnf_addmgmtaddr(self,dev_id,mgmtip):
|
||||
api_params = dict(devId=dev_id,ip=mgmtip)
|
||||
@@ -3035,7 +3037,7 @@ class DecortController(object):
|
||||
return all_rules
|
||||
|
||||
filtered_rules = []
|
||||
for runner in all_rules:
|
||||
for runner in all_rules['data']:
|
||||
if runner['vmId'] == comp_id:
|
||||
filtered_rules.append(runner)
|
||||
|
||||
@@ -3281,7 +3283,7 @@ class DecortController(object):
|
||||
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/k8s/list", api_params)
|
||||
if api_resp.status_code == 200:
|
||||
k8s_list = json.loads(api_resp.content.decode('utf8'))
|
||||
for k8s_item in k8s_list:
|
||||
for k8s_item in k8s_list['data']:
|
||||
if k8s_item['name'] == k8s_name and k8s_item['rgId'] == rg_id:
|
||||
if not check_state or k8s_item['status'] not in K8S_INVALID_STATES:
|
||||
# TODO: rework after k8s/get wilb be updated
|
||||
@@ -3412,10 +3414,18 @@ class DecortController(object):
|
||||
return
|
||||
|
||||
def k8s_provision(self, k8s_name,
|
||||
k8ci_id,rg_id,plugin,master_count,
|
||||
master_cpu, master_ram,
|
||||
master_disk, default_worker, extnet_id,
|
||||
with_lb, annotation, ):
|
||||
k8ci_id,rg_id,
|
||||
plugin,
|
||||
master_count,
|
||||
master_cpu,
|
||||
master_ram,
|
||||
master_disk,
|
||||
master_sepid,
|
||||
master_pool,
|
||||
default_worker,
|
||||
extnet_id,
|
||||
with_lb,
|
||||
annotation, ):
|
||||
|
||||
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "k8s_provision")
|
||||
|
||||
@@ -3429,6 +3439,8 @@ class DecortController(object):
|
||||
def_wg_cpu = default_worker['cpu']
|
||||
def_wg_ram = default_worker['ram']
|
||||
def_wg_disk = default_worker['disk']
|
||||
def_wg_sepid = default_worker['sep_id']
|
||||
def_wg_pool = default_worker['pool']
|
||||
def_wg_lab = default_worker['labels'] if "labels" in default_worker else None
|
||||
def_wg_taints = default_worker['taints'] if "taints" in default_worker else None
|
||||
def_wg_ann = default_worker['annotations'] if "annotations" in default_worker else None
|
||||
@@ -3443,10 +3455,14 @@ class DecortController(object):
|
||||
masterCpu=master_cpu,
|
||||
masterRam=master_ram,
|
||||
masterDisk=master_disk,
|
||||
masterSepId=master_sepid,
|
||||
masterSepPool=master_pool,
|
||||
workerNum=def_wg_count,
|
||||
workerCpu=def_wg_cpu,
|
||||
workerRam=def_wg_ram,
|
||||
workerDisk=def_wg_disk,
|
||||
workerSepId=def_wg_sepid,
|
||||
workerSepPool=def_wg_pool,
|
||||
labels=def_wg_lab,
|
||||
taints=def_wg_taints,
|
||||
annotations=def_wg_ann,
|
||||
@@ -3470,8 +3486,8 @@ class DecortController(object):
|
||||
self.result['failed'] = False
|
||||
time.sleep(30)
|
||||
elif ret_info['status'] == "ERROR":
|
||||
self.result['msg'] = ("k8s_provision(): Can't create cluster")
|
||||
self.result['failed'] = True
|
||||
self.result['msg'] = f"k8s_provision(): {ret_info['error']}"
|
||||
self.result['changed'] = False
|
||||
return
|
||||
elif ret_info['status'] == "OK":
|
||||
k8s_id = ret_info['result']
|
||||
@@ -3491,7 +3507,6 @@ class DecortController(object):
|
||||
self.result['failed'] = True
|
||||
|
||||
self.result['changed'] = False
|
||||
self.fail_json(**self.result)
|
||||
return
|
||||
|
||||
def k8s_workers_modify(self,arg_k8swg,arg_modwg):
|
||||
@@ -3544,6 +3559,8 @@ class DecortController(object):
|
||||
workerCpu=wg['cpu'],
|
||||
workerRam=wg['ram'],
|
||||
workerDisk=wg['disk'],
|
||||
workerSepId=wg['sep_id'] if "sep_id" in wg else None,
|
||||
workerSepPool=wg['pool'] if "pool" in wg else None,
|
||||
labels=wg['labels'] if "labels" in wg else None,
|
||||
taints=wg['taints'] if "taints" in wg else None,
|
||||
annotations=wg['annotations'] if "annotations" in wg else None,
|
||||
@@ -3576,7 +3593,7 @@ class DecortController(object):
|
||||
k8ci_id_present = False
|
||||
if api_resp.status_code == 200:
|
||||
ret_k8ci_list = json.loads(api_resp.content.decode('utf8'))
|
||||
for k8ci_item in ret_k8ci_list:
|
||||
for k8ci_item in ret_k8ci_list['data']:
|
||||
if k8ci_item['id'] == arg_k8ci_id:
|
||||
k8ci_id_present = True
|
||||
break
|
||||
@@ -3636,7 +3653,8 @@ class DecortController(object):
|
||||
else:
|
||||
self.result['warning'] = ("bservice_rg_list(): failed to get B-service list. HTTP code {}, "
|
||||
"response {}.").format(api_resp.status_code, api_resp.reason)
|
||||
return ret_bs_dict
|
||||
return []
|
||||
return ret_bs_dict['data']
|
||||
|
||||
def bservice_find(self,account_id,rg_id,bservice_name="",bservice_id = 0,check_state=True):
|
||||
|
||||
@@ -3992,7 +4010,7 @@ class DecortController(object):
|
||||
"response {}.").format(rg_id, api_resp.status_code, api_resp.reason)
|
||||
return []
|
||||
|
||||
return ret_rg_vins_list
|
||||
return ret_rg_vins_list['data']
|
||||
def lb_find(self,lb_id=0,lb_name="",rg_id=0):
|
||||
"""Find specified LB.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user