Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2e9b550bb | ||
|
|
a8f50bfb6b | ||
|
|
9222fdd866 | ||
|
|
e94faef2ad | ||
|
|
66e72a3d3b | ||
|
|
740271b2f2 | ||
|
|
207c04bb77 |
@@ -9,4 +9,4 @@ Requirements:
|
|||||||
* PyJWT 2.0.0 Python module or higher
|
* PyJWT 2.0.0 Python module or higher
|
||||||
* requests Python module
|
* requests Python module
|
||||||
* netaddr Python module
|
* netaddr Python module
|
||||||
* DECORT cloud platform version 3.8.6 or higher
|
* DECORT cloud platform version 3.8.7 or higher
|
||||||
|
|||||||
BIN
decort-ansible.tar
Normal file
BIN
decort-ansible.tar
Normal file
Binary file not shown.
@@ -1,38 +0,0 @@
|
|||||||
#
|
|
||||||
# DECORT kvmvm module example
|
|
||||||
#
|
|
||||||
- hosts: ansible_master
|
|
||||||
tasks:
|
|
||||||
- name: create a VM named cloud-init_example
|
|
||||||
decort_kvmvm:
|
|
||||||
annotation: "VM managed by decort_kvmvm module"
|
|
||||||
authenticator: oauth2
|
|
||||||
app_id: "" # Application id from SSO Digital Energy
|
|
||||||
app_secret: "" # API key from SSO Digital Energy
|
|
||||||
controller_url: "" #"https://mr4.digitalenergy.online"
|
|
||||||
name: cloud-init_example
|
|
||||||
cpu: 2
|
|
||||||
ram: 2048
|
|
||||||
boot_disk: 10
|
|
||||||
image_name: "DECS Ubuntu 18.04 v1.2.3" #Name of OS image
|
|
||||||
networks:
|
|
||||||
- type: VINS
|
|
||||||
id: #VINS id
|
|
||||||
tags: "Ansible cloud init example"
|
|
||||||
state: present
|
|
||||||
rg_id: #Resource group id
|
|
||||||
ci_user_data:
|
|
||||||
- packages:
|
|
||||||
- apache2
|
|
||||||
- write_files:
|
|
||||||
- content: |
|
|
||||||
<div>
|
|
||||||
Hello World!
|
|
||||||
</div>
|
|
||||||
owner: user:user
|
|
||||||
path: /var/www/html/index.html
|
|
||||||
- hostname: test-apache
|
|
||||||
- ssh_keys:
|
|
||||||
- rsa_public: ssh-rsa AAAAOasDmLxnD= user@pc
|
|
||||||
delegate_to: localhost
|
|
||||||
register: simple_vm
|
|
||||||
@@ -22,17 +22,17 @@
|
|||||||
state: present
|
state: present
|
||||||
rg_id: #Resource group id
|
rg_id: #Resource group id
|
||||||
ci_user_data:
|
ci_user_data:
|
||||||
- packages:
|
packages:
|
||||||
- apache2
|
- apache2
|
||||||
- write_files:
|
write_files:
|
||||||
- content: |
|
- content: |
|
||||||
<div>
|
<div>
|
||||||
Hello World!
|
Hello World!
|
||||||
</div>
|
</div>
|
||||||
owner: user:user
|
owner: user:user
|
||||||
path: /var/www/html/index.html
|
path: /var/www/html/index.html
|
||||||
- hostname: test-apache
|
hostname: test-apache
|
||||||
- ssh_keys:
|
ssh_keys:
|
||||||
- rsa_public: ssh-rsa AAAAOasDmLxnD= user@pc
|
- rsa_public: ssh-rsa AAAAOasDmLxnD= user@pc
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
register: simple_vm
|
register: simple_vm
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class decort_group(DecortController):
|
|||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['changed'] = False
|
self.result['changed'] = False
|
||||||
self.result['msg'] = ("Cannot find B-service ID {}.").format(arg_amodule.params['bservice_id'])
|
self.result['msg'] = ("Cannot find B-service ID {}.").format(arg_amodule.params['bservice_id'])
|
||||||
self.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
#find group
|
#find group
|
||||||
self.bservice_id = validated_bservice_id
|
self.bservice_id = validated_bservice_id
|
||||||
self.bservice_info = bservice_info
|
self.bservice_info = bservice_info
|
||||||
|
|||||||
@@ -80,13 +80,13 @@ class decort_k8s(DecortController):
|
|||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['changed'] = False
|
self.result['changed'] = False
|
||||||
self.result['msg'] = "At least one worker group must be present"
|
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:
|
if arg_amodule.params['name'] == "" and arg_amodule.params['id'] == 0:
|
||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['changed'] = False
|
self.result['changed'] = False
|
||||||
self.result['msg'] = "Cannot manage k8s cluster when its ID is 0 and name is empty."
|
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']:
|
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 {} / "
|
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'],
|
"name '{}' or non-existent account specified.").format(arg_amodule.params['account_id'],
|
||||||
arg_amodule.params['account_name'])
|
arg_amodule.params['account_name'])
|
||||||
self.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
# fail the module -> exit
|
# fail the module -> exit
|
||||||
# now validate RG
|
# now validate RG
|
||||||
validated_rg_id, validated_rg_facts = self.rg_find(validated_acc_id,
|
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:
|
if not validated_rg_id:
|
||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['changed'] = False
|
self.result['changed'] = False
|
||||||
self.result['msg'] = "Cannot find RG ID {} / name '{}'.".format(arg_amodule.params['rg_id'],
|
self.result['msg'] = "Cannot find RG ID {} / name '{}'.".format(arg_amodule.params['rg_id'],
|
||||||
arg_amodule.params['rg_name'])
|
arg_amodule.params['rg_name'])
|
||||||
self.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
# fail the module - exit
|
# fail the module - exit
|
||||||
|
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ class decort_k8s(DecortController):
|
|||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['changed'] = False
|
self.result['changed'] = False
|
||||||
self.result['msg'] = "Cannot find K8CI ID {}.".format(arg_amodule.params['k8ci_id'])
|
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
|
self.rg_id = validated_rg_id
|
||||||
arg_amodule.params['rg_id'] = validated_rg_id
|
arg_amodule.params['rg_id'] = validated_rg_id
|
||||||
@@ -132,6 +132,7 @@ class decort_k8s(DecortController):
|
|||||||
k8s_name=arg_amodule.params['name'],
|
k8s_name=arg_amodule.params['name'],
|
||||||
rg_id=validated_rg_id,
|
rg_id=validated_rg_id,
|
||||||
check_state=False)
|
check_state=False)
|
||||||
|
|
||||||
if self.k8s_id:
|
if self.k8s_id:
|
||||||
self.k8s_should_exist = True
|
self.k8s_should_exist = True
|
||||||
self.acc_id = self.k8s_info['accountId']
|
self.acc_id = self.k8s_info['accountId']
|
||||||
@@ -165,6 +166,9 @@ class decort_k8s(DecortController):
|
|||||||
ret_dict['rg_id'] = self.rg_id
|
ret_dict['rg_id'] = self.rg_id
|
||||||
ret_dict['vins_id'] = self.k8s_vins_id
|
ret_dict['vins_id'] = self.k8s_vins_id
|
||||||
ret_dict['account_id'] = self.acc_id
|
ret_dict['account_id'] = self.acc_id
|
||||||
|
ret_dict['k8s_Masters'] = self.k8s_info['k8sGroups']['masters']
|
||||||
|
ret_dict['k8s_Workers'] = self.k8s_info['k8sGroups']['workers']
|
||||||
|
|
||||||
if self.amodule.params['getConfig'] and self.k8s_info['techStatus'] == "STARTED":
|
if self.amodule.params['getConfig'] and self.k8s_info['techStatus'] == "STARTED":
|
||||||
ret_dict['config'] = self.k8s_getConfig()
|
ret_dict['config'] = self.k8s_getConfig()
|
||||||
|
|
||||||
@@ -203,20 +207,37 @@ class decort_k8s(DecortController):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def create(self):
|
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['k8ci_id'],
|
||||||
self.amodule.params['rg_id'],
|
self.amodule.params['rg_id'],
|
||||||
|
self.amodule.params['vins_id'],
|
||||||
self.amodule.params['network_plugin'],
|
self.amodule.params['network_plugin'],
|
||||||
self.amodule.params['master_count'],
|
self.amodule.params['master_count'],
|
||||||
self.amodule.params['master_cpu'],
|
self.amodule.params['master_cpu'],
|
||||||
self.amodule.params['master_ram'],
|
self.amodule.params['master_ram'],
|
||||||
self.amodule.params['master_disk'],
|
self.amodule.params['master_disk'],
|
||||||
|
self.amodule.params['master_sepid'],
|
||||||
|
self.amodule.params['master_pool'],
|
||||||
self.amodule.params['workers'][0],
|
self.amodule.params['workers'][0],
|
||||||
self.amodule.params['extnet_id'],
|
self.amodule.params['extnet_id'],
|
||||||
self.amodule.params['with_lb'],
|
self.amodule.params['with_lb'],
|
||||||
self.amodule.params['description'],)
|
self.amodule.params['ha_lb'],
|
||||||
|
self.amodule.params['additionalSANs'],
|
||||||
|
self.amodule.params['init_conf'],
|
||||||
|
self.amodule.params['cluster_conf'],
|
||||||
|
self.amodule.params['kublet_conf'],
|
||||||
|
self.amodule.params['kubeproxy_conf'],
|
||||||
|
self.amodule.params['join_conf'],
|
||||||
|
self.amodule.params['oidc_cert'],
|
||||||
|
self.amodule.params['description'],
|
||||||
|
self.amodule.params['extnet_only'],
|
||||||
|
)
|
||||||
|
|
||||||
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'],
|
k8s_name=self.amodule.params['name'],
|
||||||
rg_id=self.rg_id,
|
rg_id=self.rg_id,
|
||||||
check_state=False)
|
check_state=False)
|
||||||
@@ -235,7 +256,8 @@ class decort_k8s(DecortController):
|
|||||||
|
|
||||||
def action(self,disared_state,started=True):
|
def action(self,disared_state,started=True):
|
||||||
|
|
||||||
self.k8s_state(self.k8s_info, disared_state,started)
|
#k8s state
|
||||||
|
self.k8s_state(self.k8s_info, disared_state, started)
|
||||||
self.k8s_id,self.k8s_info = self.k8s_find(k8s_id=self.amodule.params['id'],
|
self.k8s_id,self.k8s_info = self.k8s_find(k8s_id=self.amodule.params['id'],
|
||||||
k8s_name=self.amodule.params['name'],
|
k8s_name=self.amodule.params['name'],
|
||||||
rg_id=self.rg_id,
|
rg_id=self.rg_id,
|
||||||
@@ -243,7 +265,11 @@ class decort_k8s(DecortController):
|
|||||||
if started == True and self.k8s_info['techStatus'] == "STOPPED":
|
if started == True and self.k8s_info['techStatus'] == "STOPPED":
|
||||||
self.k8s_state(self.k8s_info, disared_state,started)
|
self.k8s_state(self.k8s_info, disared_state,started)
|
||||||
self.k8s_info['techStatus'] == "STARTED"
|
self.k8s_info['techStatus'] == "STARTED"
|
||||||
|
#check groups and modify if needed
|
||||||
self.k8s_workers_modify(self.k8s_info,self.amodule.params['workers'])
|
self.k8s_workers_modify(self.k8s_info,self.amodule.params['workers'])
|
||||||
|
if self.result['changed'] == True:
|
||||||
|
self.k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||||
|
#TODO check workers metadata and modify if needed
|
||||||
|
|
||||||
return
|
return
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -284,26 +310,34 @@ class decort_k8s(DecortController):
|
|||||||
user=dict(type='str',
|
user=dict(type='str',
|
||||||
required=False,
|
required=False,
|
||||||
fallback=(env_fallback, ['DECORT_USER'])),
|
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),
|
id=dict(type='int', required=False, default=0),
|
||||||
getConfig=dict(type='bool',required=False, default=False),
|
getConfig=dict(type='bool',required=False, default=False),
|
||||||
rg_id=dict(type='int', default=0),
|
rg_id=dict(type='int', default=0),
|
||||||
rg_name=dict(type='str',default=""),
|
rg_name=dict(type='str',default=""),
|
||||||
|
vins_id=dict(type='int', required=False,default=None),
|
||||||
k8ci_id=dict(type='int', required=True),
|
k8ci_id=dict(type='int', required=True),
|
||||||
network_plugin=dict(type='str',required=False,default="flannel"),
|
network_plugin=dict(type='str',required=False,default="flannel"),
|
||||||
wg_name=dict(type='str', required=False),
|
|
||||||
master_count=dict(type='int', default=1),
|
master_count=dict(type='int', default=1),
|
||||||
master_cpu=dict(type='int', default=2),
|
master_cpu=dict(type='int', default=2),
|
||||||
master_ram=dict(type='int', default=2048),
|
master_ram=dict(type='int', default=2048),
|
||||||
master_disk=dict(type='int', default=10),
|
master_disk=dict(type='int', default=10),
|
||||||
worker_count=dict(type='int', default=1),
|
master_sepid=dict(type='int', required=False, default=None),
|
||||||
worker_cpu=dict(type='int', default=1),
|
master_pool=dict(type='str', required=False, default=None),
|
||||||
worker_ram_mb=dict(type='int', default=1024),
|
|
||||||
worker_disk_gb=dict(type='int', default=10),
|
|
||||||
workers=dict(type='list',required=True),
|
workers=dict(type='list',required=True),
|
||||||
|
workers_metadata=dict(type='bool',required=False,default=False),
|
||||||
extnet_id=dict(type='int', default=0),
|
extnet_id=dict(type='int', default=0),
|
||||||
description=dict(type='str', default="Created by decort ansible module"),
|
description=dict(type='str', default="Created by decort ansible module"),
|
||||||
with_lb=dict(type='bool', default=True),
|
with_lb=dict(type='bool', default=True),
|
||||||
|
ha_lb=dict(type='bool', default=False),
|
||||||
|
extnet_only=dict(type='bool', default=False),
|
||||||
|
additionalSANs=dict(type='list',required=False, default=None),
|
||||||
|
init_conf=dict(type='dict', required=False, default=None),
|
||||||
|
cluster_conf=dict(type='str', required=False, default=None),
|
||||||
|
kublet_conf=dict(type='str', required=False, default=None),
|
||||||
|
kubeproxy_conf=dict(type='str', required=False, default=None),
|
||||||
|
join_conf=dict(type='str', required=False, default=None),
|
||||||
|
oidc_cert=dict(type='raw',required=False,default=None),
|
||||||
verify_ssl=dict(type='bool', required=False, default=True),
|
verify_ssl=dict(type='bool', required=False, default=True),
|
||||||
workflow_callback=dict(type='str', required=False),
|
workflow_callback=dict(type='str', required=False),
|
||||||
workflow_context=dict(type='str', required=False),)
|
workflow_context=dict(type='str', required=False),)
|
||||||
|
|||||||
@@ -531,9 +531,7 @@ class decort_kvmvm(DecortController):
|
|||||||
"shell": '/bin/bash'}
|
"shell": '/bin/bash'}
|
||||||
]}
|
]}
|
||||||
elif self.amodule.params['ci_user_data']:
|
elif self.amodule.params['ci_user_data']:
|
||||||
cloud_init_params = {}
|
cloud_init_params = self.amodule.params['ci_user_data']
|
||||||
for ci_param in self.amodule.params['ci_user_data']:
|
|
||||||
cloud_init_params.update(ci_param)
|
|
||||||
else:
|
else:
|
||||||
cloud_init_params = None
|
cloud_init_params = None
|
||||||
# if we get through here, all parameters required to create new Compute instance should be at hand
|
# if we get through here, all parameters required to create new Compute instance should be at hand
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ EXAMPLES = '''
|
|||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.basic import env_fallback
|
from ansible.module_utils.basic import env_fallback
|
||||||
|
|
||||||
from ansible.module_utils.decort_utils import *
|
from ansible.module_utils.decort_utils import *
|
||||||
|
|
||||||
class decort_lb(DecortController):
|
class decort_lb(DecortController):
|
||||||
@@ -65,28 +64,28 @@ class decort_lb(DecortController):
|
|||||||
if not self.rg_id:
|
if not self.rg_id:
|
||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['msg'] = "Specified RG ID {} not found.".format(arg_amodule.params['vins_id'])
|
self.result['msg'] = "Specified RG ID {} not found.".format(arg_amodule.params['vins_id'])
|
||||||
self.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
|
|
||||||
if arg_amodule.params['vins_id']:
|
if arg_amodule.params['vins_id']:
|
||||||
self.vins_id, self.vins_facts = self.vins_find(arg_amodule.params['vins_id'])
|
self.vins_id, self.vins_facts = self.vins_find(arg_amodule.params['vins_id'])
|
||||||
if not self.vins_id:
|
if not self.vins_id:
|
||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['msg'] = "Specified ViNS ID {} not found.".format(arg_amodule.params['vins_id'])
|
self.result['msg'] = "Specified ViNS ID {} not found.".format(arg_amodule.params['vins_id'])
|
||||||
self.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
|
|
||||||
elif arg_amodule.params['account_id'] or arg_amodule.params['account_name'] != "":
|
elif arg_amodule.params['account_id'] or arg_amodule.params['account_name'] != "":
|
||||||
|
|
||||||
if arg_amodule.params['rg_name']:
|
if arg_amodule.params['rg_name']:
|
||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['msg'] = ("RG name must be specified with account present")
|
self.result['msg'] = ("RG name must be specified with account present")
|
||||||
self.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
self.acc_id, self.acc_facts = self.account_find(arg_amodule.params['account_name'],
|
self.acc_id, self.acc_facts = self.account_find(arg_amodule.params['account_name'],
|
||||||
arg_amodule.params['account_id'])
|
arg_amodule.params['account_id'])
|
||||||
if not self.acc_id:
|
if not self.acc_id:
|
||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['msg'] = ("Current user does not have access to the requested account "
|
self.result['msg'] = ("Current user does not have access to the requested account "
|
||||||
"or non-existent account specified.")
|
"or non-existent account specified.")
|
||||||
self.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
self.rg_id, self.rg_facts = self.rg_find(self._acc_id,0, arg_rg_name=arg_amodule.params['rg_name'])
|
self.rg_id, self.rg_facts = self.rg_find(self._acc_id,0, arg_rg_name=arg_amodule.params['rg_name'])
|
||||||
|
|
||||||
if self.rg_id and self.vins_id:
|
if self.rg_id and self.vins_id:
|
||||||
@@ -97,10 +96,14 @@ class decort_lb(DecortController):
|
|||||||
self.lb_id = self.lb_provision(self.amodule.params['lb_name'],
|
self.lb_id = self.lb_provision(self.amodule.params['lb_name'],
|
||||||
self.rg_id,self.vins_id,
|
self.rg_id,self.vins_id,
|
||||||
self.amodule.params['ext_net_id'],
|
self.amodule.params['ext_net_id'],
|
||||||
|
self.amodule.params['ha_lb'],
|
||||||
self.amodule.params['annotation'])
|
self.amodule.params['annotation'])
|
||||||
if self.amodule.params['backends'] or self.amodule.params['frontends']:
|
if self.amodule.params['backends'] or self.amodule.params['frontends']:
|
||||||
self.lb_id, self.lb_facts = self.lb_find(0,self.amodule.params['lb_name'],self.rg_id)
|
self.lb_id, self.lb_facts = self.lb_find(0,self.amodule.params['lb_name'],self.rg_id)
|
||||||
self.lb_update(
|
self.lb_update(
|
||||||
|
self.lb_facts['primaryNode'],
|
||||||
|
self.lb_facts['frontendHAIP'],
|
||||||
|
self.lb_facts['backendHAIP'],
|
||||||
self.lb_facts['backends'],
|
self.lb_facts['backends'],
|
||||||
self.lb_facts['frontends'],
|
self.lb_facts['frontends'],
|
||||||
self.amodule.params['backends'],
|
self.amodule.params['backends'],
|
||||||
@@ -117,11 +120,14 @@ class decort_lb(DecortController):
|
|||||||
self.lb_facts['techStatus'] = "STARTED"
|
self.lb_facts['techStatus'] = "STARTED"
|
||||||
|
|
||||||
self.lb_update(
|
self.lb_update(
|
||||||
|
self.lb_facts['primaryNode'],
|
||||||
|
self.lb_facts['frontendHAIP'],
|
||||||
|
self.lb_facts['backendHAIP'],
|
||||||
self.lb_facts['backends'],
|
self.lb_facts['backends'],
|
||||||
self.lb_facts['frontends'],
|
self.lb_facts['frontends'],
|
||||||
self.amodule.params['backends'],
|
self.amodule.params['backends'],
|
||||||
self.amodule.params['servers'],
|
self.amodule.params['servers'],
|
||||||
self.amodule.params['frontends']
|
self.amodule.params['frontends'],
|
||||||
)
|
)
|
||||||
|
|
||||||
if d_state != '':
|
if d_state != '':
|
||||||
@@ -243,6 +249,7 @@ class decort_lb(DecortController):
|
|||||||
verify_ssl=dict(type='bool', required=False, default=True),
|
verify_ssl=dict(type='bool', required=False, default=True),
|
||||||
lb_id=dict(type='int', required=False, default=0),
|
lb_id=dict(type='int', required=False, default=0),
|
||||||
lb_name=dict(type='str', required=True),
|
lb_name=dict(type='str', required=True),
|
||||||
|
ha_lb=dict(type='bool', required=False, default=False),
|
||||||
backends=dict(type='list',required=False,default=[]),
|
backends=dict(type='list',required=False,default=[]),
|
||||||
frontends=dict(type='list',required=False,default=[]),
|
frontends=dict(type='list',required=False,default=[]),
|
||||||
servers=dict(type='list',required=False,default=[]),
|
servers=dict(type='list',required=False,default=[]),
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ class decort_vins(DecortController):
|
|||||||
if self.vins_id == 0:
|
if self.vins_id == 0:
|
||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['msg'] = "Specified ViNS ID {} not found.".format(arg_amodule.params['vins_id'])
|
self.result['msg'] = "Specified ViNS ID {} not found.".format(arg_amodule.params['vins_id'])
|
||||||
self.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
self.vins_level = "ID"
|
self.vins_level = "ID"
|
||||||
#raise Exception(self.vins_facts)
|
#raise Exception(self.vins_facts)
|
||||||
validated_acc_id = self.vins_facts['accountId']
|
validated_acc_id = self.vins_facts['accountId']
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ class DecortController(object):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def decort_api_call(self, arg_req_function, arg_api_name, arg_params):
|
def decort_api_call(self, arg_req_function, arg_api_name, arg_params, arg_files=None):
|
||||||
"""Wrapper around DECORT API calls. It uses authorization mode and credentials validated at the class
|
"""Wrapper around DECORT API calls. It uses authorization mode and credentials validated at the class
|
||||||
instance creation to properly format API call and send it to the DECORT controller URL.
|
instance creation to properly format API call and send it to the DECORT controller URL.
|
||||||
If connection errors are detected, it aborts execution of the script and relay error messages to upstream
|
If connection errors are detected, it aborts execution of the script and relay error messages to upstream
|
||||||
@@ -366,7 +366,12 @@ class DecortController(object):
|
|||||||
|
|
||||||
while retry_counter > 0:
|
while retry_counter > 0:
|
||||||
try:
|
try:
|
||||||
api_resp = arg_req_function(req_url, params=arg_params, headers=http_headers, verify=self.verify_ssl)
|
api_resp = arg_req_function(
|
||||||
|
req_url,
|
||||||
|
files=arg_files,
|
||||||
|
params=arg_params,
|
||||||
|
headers=http_headers,
|
||||||
|
verify=self.verify_ssl)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['msg'] = "Failed to connect to '{}' when calling DECORT API.".format(api_resp.url)
|
self.result['msg'] = "Failed to connect to '{}' when calling DECORT API.".format(api_resp.url)
|
||||||
@@ -541,7 +546,7 @@ class DecortController(object):
|
|||||||
|
|
||||||
return
|
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
|
"""Delete a Compute instance identified by its ID. It is assumed that the Compute with the specified
|
||||||
ID exists.
|
ID exists.
|
||||||
|
|
||||||
@@ -559,7 +564,8 @@ class DecortController(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
api_params = dict(computeId=comp_id,
|
api_params = dict(computeId=comp_id,
|
||||||
permanently=permanently, )
|
permanently=permanently,
|
||||||
|
detachDisks=detach, )
|
||||||
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/delete", api_params)
|
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.
|
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
||||||
self.result['failed'] = False
|
self.result['failed'] = False
|
||||||
@@ -657,7 +663,7 @@ class DecortController(object):
|
|||||||
# if we have validated RG ID at this point, look up Compute by name in this RG
|
# 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
|
# 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.
|
# 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 runner['name'] == comp_name and runner['rgId'] == rg_id:
|
||||||
if not check_state or runner['status'] not in COMP_INVALID_STATES:
|
if not check_state or runner['status'] not in COMP_INVALID_STATES:
|
||||||
ret_comp_id = runner['id']
|
ret_comp_id = runner['id']
|
||||||
@@ -800,7 +806,8 @@ class DecortController(object):
|
|||||||
sepId=sep_id,
|
sepId=sep_id,
|
||||||
pool=pool_name,
|
pool=pool_name,
|
||||||
start=start_on_create, # start_machine parameter requires DECORT API ver 3.3.1 or higher
|
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:
|
if userdata:
|
||||||
api_params['userdata'] = json.dumps(userdata) # we need to pass a string object as "userdata"
|
api_params['userdata'] = json.dumps(userdata) # we need to pass a string object as "userdata"
|
||||||
|
|
||||||
@@ -896,7 +903,7 @@ class DecortController(object):
|
|||||||
vins_iface_list.append(iface_data)
|
vins_iface_list.append(iface_data)
|
||||||
elif iface['connType'] == 'VLAN':
|
elif iface['connType'] == 'VLAN':
|
||||||
ip_addr = netaddr.IPAddress(iface['ipAddress'])
|
ip_addr = netaddr.IPAddress(iface['ipAddress'])
|
||||||
for erunner in extnet_list:
|
for erunner in extnet_list['data']:
|
||||||
# match by IP address range
|
# match by IP address range
|
||||||
# if iface['ipAddress'] <-> erunner['name']
|
# if iface['ipAddress'] <-> erunner['name']
|
||||||
# enet_iface_list.append(erunner['id'])
|
# enet_iface_list.append(erunner['id'])
|
||||||
@@ -1366,7 +1373,7 @@ class DecortController(object):
|
|||||||
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/image/list", api_params)
|
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.
|
# 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'))
|
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 image_record['name'] == image_name and image_record['status'] == "CREATED":
|
||||||
if sepid == 0 and pool == "":
|
if sepid == 0 and pool == "":
|
||||||
# if no filtering by SEP ID or pool name is requested, return the first match
|
# if no filtering by SEP ID or pool name is requested, return the first match
|
||||||
@@ -1657,7 +1664,7 @@ class DecortController(object):
|
|||||||
if api_resp.status_code == 200:
|
if api_resp.status_code == 200:
|
||||||
account_specs = json.loads(api_resp.content.decode('utf8'))
|
account_specs = json.loads(api_resp.content.decode('utf8'))
|
||||||
#api_params.pop('accountId')
|
#api_params.pop('accountId')
|
||||||
for rg_item in account_specs:
|
for rg_item in account_specs['data']:
|
||||||
#
|
#
|
||||||
if rg_item['name'] == arg_rg_name:
|
if rg_item['name'] == arg_rg_name:
|
||||||
# name matches
|
# name matches
|
||||||
@@ -1923,7 +1930,7 @@ class DecortController(object):
|
|||||||
# Parse response to see if a account matching arg_account_name is found in the output
|
# 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
|
# 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'))
|
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:
|
if runner['name'] == account_name:
|
||||||
# get detailed information about the account from "accounts/get" call as
|
# get detailed information about the account from "accounts/get" call as
|
||||||
# "accounts/list" does not return all necessary fields
|
# "accounts/list" does not return all necessary fields
|
||||||
@@ -2028,7 +2035,7 @@ class DecortController(object):
|
|||||||
if api_resp.status_code == 200:
|
if api_resp.status_code == 200:
|
||||||
ret_gpu_list = json.loads(api_resp.content.decode('utf8'))
|
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
|
# Workflow callback stub methods - not fully implemented yet
|
||||||
@@ -2084,9 +2091,9 @@ class DecortController(object):
|
|||||||
if api_resp.status_code == 200:
|
if api_resp.status_code == 200:
|
||||||
locations = json.loads(api_resp.content.decode('utf8'))
|
locations = json.loads(api_resp.content.decode('utf8'))
|
||||||
if location_code == "" and locations:
|
if location_code == "" and locations:
|
||||||
ret_gid = locations[0]['gid']
|
ret_gid = locations['data'][0]['gid']
|
||||||
else:
|
else:
|
||||||
for runner in locations:
|
for runner in locations['data']:
|
||||||
if runner['locationCode'] == location_code:
|
if runner['locationCode'] == location_code:
|
||||||
# location code matches
|
# location code matches
|
||||||
ret_gid = runner['gid']
|
ret_gid = runner['gid']
|
||||||
@@ -2178,7 +2185,7 @@ class DecortController(object):
|
|||||||
"response {}.").format(rg_id, api_resp.status_code, api_resp.reason)
|
"response {}.").format(rg_id, api_resp.status_code, api_resp.reason)
|
||||||
return []
|
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):
|
def vins_find(self, vins_id, vins_name="", account_id=0, rg_id=0, rg_facts="", check_state=True):
|
||||||
"""Find specified ViNS.
|
"""Find specified ViNS.
|
||||||
@@ -2626,7 +2633,8 @@ class DecortController(object):
|
|||||||
else:
|
else:
|
||||||
self.result['warning'] = ("get_all_account_vinses(): failed to get list VINS in Account ID {}. HTTP code {}, "
|
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)
|
"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):
|
def _vins_vnf_addmgmtaddr(self,dev_id,mgmtip):
|
||||||
api_params = dict(devId=dev_id,ip=mgmtip)
|
api_params = dict(devId=dev_id,ip=mgmtip)
|
||||||
@@ -3035,7 +3043,7 @@ class DecortController(object):
|
|||||||
return all_rules
|
return all_rules
|
||||||
|
|
||||||
filtered_rules = []
|
filtered_rules = []
|
||||||
for runner in all_rules:
|
for runner in all_rules['data']:
|
||||||
if runner['vmId'] == comp_id:
|
if runner['vmId'] == comp_id:
|
||||||
filtered_rules.append(runner)
|
filtered_rules.append(runner)
|
||||||
|
|
||||||
@@ -3207,8 +3215,12 @@ class DecortController(object):
|
|||||||
|
|
||||||
ret_rules = self._pfw_get(comp_facts['id'], vins_facts['id'])
|
ret_rules = self._pfw_get(comp_facts['id'], vins_facts['id'])
|
||||||
return ret_rules
|
return ret_rules
|
||||||
|
##############################
|
||||||
def _k8s_get_by_id(self, k8s_id):
|
#
|
||||||
|
# K8s management
|
||||||
|
#
|
||||||
|
##############################
|
||||||
|
def k8s_get_by_id(self, k8s_id):
|
||||||
"""Helper function that locates k8s by ID and returns k8s facts.
|
"""Helper function that locates k8s by ID and returns k8s facts.
|
||||||
|
|
||||||
@param (int) k8s_id: ID of the k8s to find and return facts for.
|
@param (int) k8s_id: ID of the k8s to find and return facts for.
|
||||||
@@ -3228,19 +3240,13 @@ class DecortController(object):
|
|||||||
api_params = dict(k8sId=k8s_id, )
|
api_params = dict(k8sId=k8s_id, )
|
||||||
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/k8s/get", api_params)
|
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/k8s/get", api_params)
|
||||||
if api_resp.status_code == 200:
|
if api_resp.status_code == 200:
|
||||||
ret_k8s_id = k8s_id
|
|
||||||
ret_k8s_dict = json.loads(api_resp.content.decode('utf8'))
|
ret_k8s_dict = json.loads(api_resp.content.decode('utf8'))
|
||||||
else:
|
else:
|
||||||
self.result['warning'] = ("k8s_get_by_id(): failed to get k8s by ID {}. HTTP code {}, "
|
self.result['warning'] = ("k8s_get_by_id(): failed to get k8s by ID {}. HTTP code {}, "
|
||||||
"response {}.").format(k8s_id, api_resp.status_code, api_resp.reason)
|
"response {}.").format(k8s_id, api_resp.status_code, api_resp.reason)
|
||||||
|
|
||||||
return ret_k8s_id, ret_k8s_dict
|
return ret_k8s_dict
|
||||||
|
|
||||||
##############################
|
|
||||||
#
|
|
||||||
# K8s management
|
|
||||||
#
|
|
||||||
##############################
|
|
||||||
def k8s_find(self, k8s_id, k8s_name="",rg_id=0,check_state=True):
|
def k8s_find(self, k8s_id, k8s_name="",rg_id=0,check_state=True):
|
||||||
"""Returns non zero k8s ID and a dictionary with k8s details on success, 0 and empty dictionary otherwise.
|
"""Returns non zero k8s ID and a dictionary with k8s details on success, 0 and empty dictionary otherwise.
|
||||||
This method does not fail the run if k8s cannot be located by its name (arg_k8s_name), because this could be
|
This method does not fail the run if k8s cannot be located by its name (arg_k8s_name), because this could be
|
||||||
@@ -3257,41 +3263,30 @@ class DecortController(object):
|
|||||||
@return: dictionary with k8s facts if k8s is present. Empty dictionary otherwise. None on error.
|
@return: dictionary with k8s facts if k8s is present. Empty dictionary otherwise. None on error.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Resource group can be in one of the following states:
|
|
||||||
# MODELED, CREATED, DISABLING, DISABLED, ENABLING, DELETING, DELETED, DESTROYED, DESTROYED
|
|
||||||
#
|
|
||||||
# Transient state (ending with ING) are invalid from k8s manipulation viewpoint
|
|
||||||
#
|
|
||||||
|
|
||||||
K8S_INVALID_STATES = ["MODELED","DESTROYED","DESTROYING"]
|
K8S_INVALID_STATES = ["MODELED","DESTROYED","DESTROYING"]
|
||||||
|
|
||||||
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "k8s_find")
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "k8s_find")
|
||||||
|
|
||||||
ret_k8s_id = 0
|
ret_k8s_id = 0
|
||||||
api_params = dict(includedeleted=True)
|
api_params = dict(includedeleted=True,name=k8s_name,rgId=rg_id)
|
||||||
ret_k8s_dict = None
|
ret_k8s_dict = None
|
||||||
|
|
||||||
if k8s_id:
|
|
||||||
ret_k8s_id, ret_k8s_dict = self._k8s_get_by_id(k8s_id)
|
|
||||||
if not ret_k8s_id:
|
|
||||||
self.result['failed'] = True
|
|
||||||
self.result['msg'] = "k8s_find(): cannot find k8s cluster by ID {}.".format(k8s_id)
|
|
||||||
self.amodule.fail_json(**self.result)
|
|
||||||
else:
|
|
||||||
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:
|
|
||||||
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
|
|
||||||
self.k8s_vins_id = None
|
|
||||||
self.k8s_vins_id = k8s_item['vinsId']
|
|
||||||
#
|
|
||||||
ret_k8s_id = k8s_item['id']
|
|
||||||
_, ret_k8s_dict = self._k8s_get_by_id(ret_k8s_id)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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'))
|
||||||
|
|
||||||
|
if k8s_list['entryCount'] == 0:
|
||||||
|
return None,None
|
||||||
|
|
||||||
|
for k8s_item in k8s_list['data']:
|
||||||
|
if not check_state or k8s_item['status'] not in K8S_INVALID_STATES:
|
||||||
|
ret_k8s_id = k8s_item['id']
|
||||||
|
ret_k8s_dict = self.k8s_get_by_id(ret_k8s_id)
|
||||||
|
self.k8s_vins_id = k8s_item['vinsId']
|
||||||
|
|
||||||
return ret_k8s_id, ret_k8s_dict
|
return ret_k8s_id, ret_k8s_dict
|
||||||
|
|
||||||
def k8s_state(self, arg_k8s_dict, arg_desired_state, arg_started=False):
|
def k8s_state(self, arg_k8s_dict, arg_desired_state, arg_started=False):
|
||||||
@@ -3412,10 +3407,30 @@ class DecortController(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def k8s_provision(self, k8s_name,
|
def k8s_provision(self, k8s_name,
|
||||||
k8ci_id,rg_id,plugin,master_count,
|
k8ci_id,
|
||||||
master_cpu, master_ram,
|
rg_id,
|
||||||
master_disk, default_worker, extnet_id,
|
vins_id,
|
||||||
with_lb, annotation, ):
|
plugin,
|
||||||
|
master_count,
|
||||||
|
master_cpu,
|
||||||
|
master_ram,
|
||||||
|
master_disk,
|
||||||
|
master_sepid,
|
||||||
|
master_pool,
|
||||||
|
default_worker,
|
||||||
|
extnet_id,
|
||||||
|
with_lb,
|
||||||
|
ha_lb,
|
||||||
|
sans,
|
||||||
|
init_conf,
|
||||||
|
cluster_conf,
|
||||||
|
kublet_conf,
|
||||||
|
kubeproxy_conf,
|
||||||
|
join_conf,
|
||||||
|
oidc_cert,
|
||||||
|
annotation,
|
||||||
|
extnet_only,
|
||||||
|
):
|
||||||
|
|
||||||
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "k8s_provision")
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "k8s_provision")
|
||||||
|
|
||||||
@@ -3429,32 +3444,54 @@ class DecortController(object):
|
|||||||
def_wg_cpu = default_worker['cpu']
|
def_wg_cpu = default_worker['cpu']
|
||||||
def_wg_ram = default_worker['ram']
|
def_wg_ram = default_worker['ram']
|
||||||
def_wg_disk = default_worker['disk']
|
def_wg_disk = default_worker['disk']
|
||||||
|
def_wg_sepid = default_worker['sep_id']
|
||||||
|
def_wg_pool = default_worker['pool']
|
||||||
|
def_wg_ud = json.dumps(default_worker['ci_user_data']) if \
|
||||||
|
"ci_user_data" in default_worker else None
|
||||||
def_wg_lab = default_worker['labels'] if "labels" in default_worker else None
|
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_taints = default_worker['taints'] if "taints" in default_worker else None
|
||||||
def_wg_ann = default_worker['annotations'] if "annotations" in default_worker else None
|
def_wg_ann = default_worker['annotations'] if "annotations" in default_worker else None
|
||||||
|
|
||||||
api_url = "/restmachine/cloudapi/k8s/create"
|
api_url = "/restmachine/cloudapi/k8s/create"
|
||||||
api_params = dict(name=k8s_name,
|
api_params = dict(name=k8s_name,
|
||||||
rgId=rg_id,
|
rgId=rg_id,
|
||||||
k8ciId=k8ci_id,
|
k8ciId=k8ci_id,
|
||||||
|
vins_Id=vins_id,
|
||||||
workerGroupName=def_wg_name,
|
workerGroupName=def_wg_name,
|
||||||
networkPlugin=plugin,
|
networkPlugin=plugin,
|
||||||
masterNum=master_count,
|
masterNum=master_count,
|
||||||
masterCpu=master_cpu,
|
masterCpu=master_cpu,
|
||||||
masterRam=master_ram,
|
masterRam=master_ram,
|
||||||
masterDisk=master_disk,
|
masterDisk=master_disk,
|
||||||
|
masterSepId=master_sepid,
|
||||||
|
masterSepPool=master_pool,
|
||||||
workerNum=def_wg_count,
|
workerNum=def_wg_count,
|
||||||
workerCpu=def_wg_cpu,
|
workerCpu=def_wg_cpu,
|
||||||
workerRam=def_wg_ram,
|
workerRam=def_wg_ram,
|
||||||
workerDisk=def_wg_disk,
|
workerDisk=def_wg_disk,
|
||||||
|
workerSepId=def_wg_sepid,
|
||||||
|
workerSepPool=def_wg_pool,
|
||||||
labels=def_wg_lab,
|
labels=def_wg_lab,
|
||||||
taints=def_wg_taints,
|
taints=def_wg_taints,
|
||||||
annotations=def_wg_ann,
|
annotations=def_wg_ann,
|
||||||
extnetId=extnet_id,
|
extnetId=extnet_id,
|
||||||
withLB=with_lb,
|
withLB=with_lb,
|
||||||
|
highlyAvailableLB=ha_lb,
|
||||||
|
additionalSANs=sans,
|
||||||
|
initConfiguration=json.dumps(init_conf) if init_conf else None,
|
||||||
|
clusterConfiguration=json.dumps(cluster_conf) if cluster_conf else None,
|
||||||
|
kubeletConfiguration=json.dumps(kublet_conf) if kublet_conf else None,
|
||||||
|
kubeProxyConfiguration=json.dumps(kubeproxy_conf)if kubeproxy_conf else None,
|
||||||
|
joinConfiguration=json.dumps(join_conf)if join_conf else None,
|
||||||
desc=annotation,
|
desc=annotation,
|
||||||
|
userData=def_wg_ud,
|
||||||
|
extnetOnly=extnet_only,
|
||||||
)
|
)
|
||||||
api_resp = self.decort_api_call(requests.post, api_url, api_params)
|
|
||||||
|
if oidc_cert:
|
||||||
|
upload_files = {'oidcCertificate': ('cert.pem', str(oidc_cert),'application/x-x509-ca-cert')}
|
||||||
|
|
||||||
|
api_resp = self.decort_api_call(requests.post, api_url, api_params, upload_files)
|
||||||
k8s_id = ""
|
k8s_id = ""
|
||||||
if api_resp.status_code == 200:
|
if api_resp.status_code == 200:
|
||||||
for i in range(300):
|
for i in range(300):
|
||||||
@@ -3470,11 +3507,11 @@ class DecortController(object):
|
|||||||
self.result['failed'] = False
|
self.result['failed'] = False
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
elif ret_info['status'] == "ERROR":
|
elif ret_info['status'] == "ERROR":
|
||||||
self.result['msg'] = ("k8s_provision(): Can't create cluster")
|
self.result['msg'] = f"k8s_provision(): {ret_info['error']}"
|
||||||
self.result['failed'] = True
|
self.result['changed'] = False
|
||||||
return
|
return
|
||||||
elif ret_info['status'] == "OK":
|
elif ret_info['status'] == "OK":
|
||||||
k8s_id = ret_info['result']
|
k8s_id = ret_info['result'][0]
|
||||||
self.result['msg'] = f"k8s_provision(): K8s cluster {k8s_name} created successful"
|
self.result['msg'] = f"k8s_provision(): K8s cluster {k8s_name} created successful"
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
return k8s_id
|
return k8s_id
|
||||||
@@ -3491,7 +3528,6 @@ class DecortController(object):
|
|||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
|
|
||||||
self.result['changed'] = False
|
self.result['changed'] = False
|
||||||
self.fail_json(**self.result)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def k8s_workers_modify(self,arg_k8swg,arg_modwg):
|
def k8s_workers_modify(self,arg_k8swg,arg_modwg):
|
||||||
@@ -3544,9 +3580,12 @@ class DecortController(object):
|
|||||||
workerCpu=wg['cpu'],
|
workerCpu=wg['cpu'],
|
||||||
workerRam=wg['ram'],
|
workerRam=wg['ram'],
|
||||||
workerDisk=wg['disk'],
|
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,
|
labels=wg['labels'] if "labels" in wg else None,
|
||||||
taints=wg['taints'] if "taints" in wg else None,
|
taints=wg['taints'] if "taints" in wg else None,
|
||||||
annotations=wg['annotations'] if "annotations" in wg else None,
|
annotations=wg['annotations'] if "annotations" in wg else None,
|
||||||
|
userData=json.dumps(wg['ci_user_data']) if 'ci_user_data' in wg else None
|
||||||
)
|
)
|
||||||
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/k8s/workersGroupAdd", api_params)
|
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/k8s/workersGroupAdd", api_params)
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
@@ -3576,7 +3615,7 @@ class DecortController(object):
|
|||||||
k8ci_id_present = False
|
k8ci_id_present = False
|
||||||
if api_resp.status_code == 200:
|
if api_resp.status_code == 200:
|
||||||
ret_k8ci_list = json.loads(api_resp.content.decode('utf8'))
|
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:
|
if k8ci_item['id'] == arg_k8ci_id:
|
||||||
k8ci_id_present = True
|
k8ci_id_present = True
|
||||||
break
|
break
|
||||||
@@ -3636,7 +3675,8 @@ class DecortController(object):
|
|||||||
else:
|
else:
|
||||||
self.result['warning'] = ("bservice_rg_list(): failed to get B-service list. HTTP code {}, "
|
self.result['warning'] = ("bservice_rg_list(): failed to get B-service list. HTTP code {}, "
|
||||||
"response {}.").format(api_resp.status_code, api_resp.reason)
|
"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):
|
def bservice_find(self,account_id,rg_id,bservice_name="",bservice_id = 0,check_state=True):
|
||||||
|
|
||||||
@@ -3992,7 +4032,7 @@ class DecortController(object):
|
|||||||
"response {}.").format(rg_id, api_resp.status_code, api_resp.reason)
|
"response {}.").format(rg_id, api_resp.status_code, api_resp.reason)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
return ret_rg_vins_list
|
return ret_rg_vins_list['data']
|
||||||
def lb_find(self,lb_id=0,lb_name="",rg_id=0):
|
def lb_find(self,lb_id=0,lb_name="",rg_id=0):
|
||||||
"""Find specified LB.
|
"""Find specified LB.
|
||||||
|
|
||||||
@@ -4036,7 +4076,7 @@ class DecortController(object):
|
|||||||
self.amodule.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
|
|
||||||
return 0, None
|
return 0, None
|
||||||
def lb_provision(self,lb_name,rg_id,vins_id,ext_net_id,annotation,start=True):
|
def lb_provision(self,lb_name,rg_id,vins_id,ext_net_id,ha_status,annotation,start=True):
|
||||||
"""Provision LB according to the specified arguments.
|
"""Provision LB according to the specified arguments.
|
||||||
If critical error occurs the embedded call to API function will abort further execution of
|
If critical error occurs the embedded call to API function will abort further execution of
|
||||||
the script and relay error to Ansible.
|
the script and relay error to Ansible.
|
||||||
@@ -4063,6 +4103,7 @@ class DecortController(object):
|
|||||||
rgId=rg_id,
|
rgId=rg_id,
|
||||||
extnetId=ext_net_id,
|
extnetId=ext_net_id,
|
||||||
vinsId=vins_id,
|
vinsId=vins_id,
|
||||||
|
highlyAvailable=ha_status,
|
||||||
start=start,
|
start=start,
|
||||||
decs=annotation
|
decs=annotation
|
||||||
)
|
)
|
||||||
@@ -4374,6 +4415,9 @@ class DecortController(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def _lb_bind_frontend(self,front_name,bind_name,bind_addr=None,bind_port=None,update=False):
|
def _lb_bind_frontend(self,front_name,bind_name,bind_addr=None,bind_port=None,update=False):
|
||||||
|
|
||||||
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "lb_bind_frontend")
|
||||||
|
|
||||||
api_params = dict(
|
api_params = dict(
|
||||||
lbId=self.lb_id,
|
lbId=self.lb_id,
|
||||||
frontendName=front_name,
|
frontendName=front_name,
|
||||||
@@ -4388,7 +4432,9 @@ class DecortController(object):
|
|||||||
api_resp = self.decort_api_call(requests.post, api_url, api_params)
|
api_resp = self.decort_api_call(requests.post, api_url, api_params)
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
|
|
||||||
def lb_update(self,lb_backends=[],lb_frontends=[],mod_backends=[],mod_servers=[],mod_frontends=[]):
|
def lb_update(self,prime,front_ha_ip,back_ha_ip,lb_backends=[],lb_frontends=[],mod_backends=[],mod_servers=[],mod_frontends=[]):
|
||||||
|
|
||||||
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "lb_update")
|
||||||
#lists from module and cloud
|
#lists from module and cloud
|
||||||
mod_backs_list = [back['name'] for back in mod_backends]
|
mod_backs_list = [back['name'] for back in mod_backends]
|
||||||
lb_backs_list = [back['name'] for back in lb_backends]
|
lb_backs_list = [back['name'] for back in lb_backends]
|
||||||
@@ -4431,16 +4477,30 @@ class DecortController(object):
|
|||||||
if del_list_fronts:
|
if del_list_fronts:
|
||||||
self._lb_delete_fronts(del_list_fronts)
|
self._lb_delete_fronts(del_list_fronts)
|
||||||
|
|
||||||
|
#set bind_ip
|
||||||
|
if front_ha_ip != "":
|
||||||
|
bind_ip = front_ha_ip
|
||||||
|
|
||||||
|
if front_ha_ip == "" and back_ha_ip != "":
|
||||||
|
bind_ip = back_ha_ip
|
||||||
|
|
||||||
|
if front_ha_ip == "" and back_ha_ip == "":
|
||||||
|
if prime["frontendIp"] != "":
|
||||||
|
bind_ip = prime["frontendIp"]
|
||||||
|
else:
|
||||||
|
bind_ip = prime["backendIp"]
|
||||||
|
|
||||||
if add_list_fronts:
|
if add_list_fronts:
|
||||||
self._lb_add_fronts(add_list_fronts,mod_frontends)
|
self._lb_add_fronts(add_list_fronts,mod_frontends,bind_ip)
|
||||||
if upd_front_list:
|
if upd_front_list:
|
||||||
self._lb_update_fronts(upd_front_list,lb_frontends,mod_frontends)
|
self._lb_update_fronts(upd_front_list,lb_frontends,mod_frontends,bind_ip)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _lb_delete_backends(self,back_list,lb_fronts):
|
def _lb_delete_backends(self,back_list,lb_fronts):
|
||||||
|
|
||||||
#delete frontends with that backend
|
#delete frontends with that backend
|
||||||
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "lb_delete_backends")
|
||||||
for back in back_list:
|
for back in back_list:
|
||||||
fronts = list(filter(lambda i: i['backend'] == back,lb_fronts))
|
fronts = list(filter(lambda i: i['backend'] == back,lb_fronts))
|
||||||
if fronts:
|
if fronts:
|
||||||
@@ -4453,6 +4513,9 @@ class DecortController(object):
|
|||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
return
|
return
|
||||||
def _lb_delete_fronts(self,d_fronts):
|
def _lb_delete_fronts(self,d_fronts):
|
||||||
|
|
||||||
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "lb_delete_fronts")
|
||||||
|
|
||||||
for front in d_fronts:
|
for front in d_fronts:
|
||||||
api_params = dict(
|
api_params = dict(
|
||||||
lbId=self.lb_id,
|
lbId=self.lb_id,
|
||||||
@@ -4465,7 +4528,10 @@ class DecortController(object):
|
|||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
|
|
||||||
return
|
return
|
||||||
def _lb_add_fronts(self,front_list,mod_fronts):
|
def _lb_add_fronts(self,front_list,mod_fronts,bind_ip):
|
||||||
|
|
||||||
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "lb_add_fronts")
|
||||||
|
|
||||||
for front in front_list:
|
for front in front_list:
|
||||||
add_front, = list(filter(lambda i: i['name'] == front,mod_fronts))
|
add_front, = list(filter(lambda i: i['name'] == front,mod_fronts))
|
||||||
api_params = dict(
|
api_params = dict(
|
||||||
@@ -4478,14 +4544,17 @@ class DecortController(object):
|
|||||||
self._lb_bind_frontend(
|
self._lb_bind_frontend(
|
||||||
add_front['name'],
|
add_front['name'],
|
||||||
bind['name'],
|
bind['name'],
|
||||||
bind['address']if "address" in bind else None,
|
bind['address']if "address" in bind else bind_ip,
|
||||||
bind['port'] if "port" in bind else None,
|
bind['port'],
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
def _lb_create_backends(self,back_list,mod_backs,mod_serv):
|
def _lb_create_backends(self,back_list,mod_backs,mod_serv):
|
||||||
'''
|
'''
|
||||||
Create backends and add servers to them
|
Create backends and add servers to them
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "lb_create_backends")
|
||||||
|
|
||||||
for back in back_list:
|
for back in back_list:
|
||||||
backend, = list(filter(lambda i: i['name'] == back,mod_backs))
|
backend, = list(filter(lambda i: i['name'] == back,mod_backs))
|
||||||
api_params = dict(
|
api_params = dict(
|
||||||
@@ -4518,15 +4587,14 @@ class DecortController(object):
|
|||||||
|
|
||||||
def _lb_update_backends(self,back_list,lb_backs,mod_backs,mod_serv):
|
def _lb_update_backends(self,back_list,lb_backs,mod_backs,mod_serv):
|
||||||
|
|
||||||
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "lb_update_backends")
|
||||||
|
|
||||||
lb_backs = list(filter(lambda i: i['name'] in back_list,lb_backs))
|
lb_backs = list(filter(lambda i: i['name'] in back_list,lb_backs))
|
||||||
#mod_back = list(filter(lambda i: i['name'] in back_list,mod_backs))
|
|
||||||
|
|
||||||
for back in lb_backs:
|
for back in lb_backs:
|
||||||
|
|
||||||
del back['serverDefaultSettings']['guid']
|
del back['serverDefaultSettings']['guid']
|
||||||
mod_back, = list(filter(lambda i: i['name']==back['name'],mod_backs))
|
mod_back, = list(filter(lambda i: i['name']==back['name'],mod_backs))
|
||||||
#mod_servers = list(filter(lambda i: i['name']==back['name'],mod_serv))
|
|
||||||
#raise Exception(mod_servers)
|
|
||||||
if "default_settings" not in mod_back:
|
if "default_settings" not in mod_back:
|
||||||
mod_back["default_settings"] = self.default_settings
|
mod_back["default_settings"] = self.default_settings
|
||||||
else:
|
else:
|
||||||
@@ -4601,7 +4669,9 @@ class DecortController(object):
|
|||||||
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/lb/backendServerDelete", api_params)
|
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/lb/backendServerDelete", api_params)
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
return
|
return
|
||||||
def _lb_update_fronts(self,upd_front_list,lb_frontends,mod_frontends):
|
def _lb_update_fronts(self,upd_front_list,lb_frontends,mod_frontends,bind_ip):
|
||||||
|
|
||||||
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "lb_update_fronts")
|
||||||
|
|
||||||
for front in upd_front_list:
|
for front in upd_front_list:
|
||||||
mod_front, = list(filter(lambda i: i['name'] == front,mod_frontends))
|
mod_front, = list(filter(lambda i: i['name'] == front,mod_frontends))
|
||||||
@@ -4613,8 +4683,8 @@ class DecortController(object):
|
|||||||
self._lb_bind_frontend(
|
self._lb_bind_frontend(
|
||||||
front,
|
front,
|
||||||
bind['name'],
|
bind['name'],
|
||||||
bind['address']if "address" in bind else None,
|
bind['address']if "address" in bind else bind_ip,
|
||||||
bind['port'] if "port" in bind else None,
|
bind['port'],
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
lb_bind, = list(filter(lambda i: i['name'] == bind['name'],lb_front['bindings']))
|
lb_bind, = list(filter(lambda i: i['name'] == bind['name'],lb_front['bindings']))
|
||||||
@@ -4624,8 +4694,8 @@ class DecortController(object):
|
|||||||
self._lb_bind_frontend(
|
self._lb_bind_frontend(
|
||||||
front,
|
front,
|
||||||
bind['name'],
|
bind['name'],
|
||||||
bind['address']if "address" in bind else None,
|
bind['address'] if "address" in bind else bind_ip,
|
||||||
bind['port'] if "port" in bind else None,
|
bind['port'],
|
||||||
update=True,
|
update=True,
|
||||||
)
|
)
|
||||||
lb_binds_list.remove(bind['name'])
|
lb_binds_list.remove(bind['name'])
|
||||||
|
|||||||
Reference in New Issue
Block a user