Some impruvments and updates
This commit is contained in:
@@ -1,19 +1,68 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2021 Digital Energy Cloud Solutions LLC
|
||||
# Copyright: (c) 2018-2023 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
#
|
||||
# Author: Aleksandr Malyavin (aleksandr.malyavin@digitalenergy.online)
|
||||
#
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
---
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Create k8s cluster
|
||||
decort_k8s:
|
||||
verify_ssl: false
|
||||
authenticator: jwt
|
||||
jwt: "{{ run_jwt.jwt }}"
|
||||
controller_url: "{{CONTROLLER_URL}}"
|
||||
name: SOME_NAME
|
||||
rg_id: {{RG_ID}}
|
||||
k8ci_id: 10
|
||||
master_count: 3
|
||||
master_cpu: 2
|
||||
master_ram: 2048
|
||||
master_disk: 10
|
||||
state: present
|
||||
permanent: True
|
||||
started: True
|
||||
getConfig: True
|
||||
network_plugin: flannel
|
||||
workers:
|
||||
- name: wg1
|
||||
ram: 1024
|
||||
cpu: 2
|
||||
disk: 10
|
||||
num: 1
|
||||
labels:
|
||||
- disktype1=ssd1
|
||||
- disktype2=ssd2
|
||||
- disktype3=ssd3
|
||||
taints:
|
||||
- key1=value1:NoSchedule
|
||||
- key2=value2:NoSchedule
|
||||
- key3=value3:NoSchedule
|
||||
annotations:
|
||||
- node.deckhouse.io/group1=g1
|
||||
- node.deckhouse.io/group2=g2
|
||||
- node.deckhouse.io/group3=g3
|
||||
- name: wg2
|
||||
ram: 1024
|
||||
cpu: 2
|
||||
disk: 10
|
||||
num: 1
|
||||
labels:
|
||||
- apptype=main
|
||||
annotations:
|
||||
- node.mainapp.domen.local/group1=g1
|
||||
register: some_cluster
|
||||
'''
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
from ansible.module_utils.decort_utils import *
|
||||
@@ -21,11 +70,17 @@ from ansible.module_utils.decort_utils import *
|
||||
class decort_k8s(DecortController):
|
||||
def __init__(self,arg_amodule):
|
||||
super(decort_k8s, self).__init__(arg_amodule)
|
||||
|
||||
|
||||
validated_acc_id = 0
|
||||
validated_rg_id = 0
|
||||
validated_rg_facts = None
|
||||
validated_k8ci_id = 0
|
||||
self.k8s_should_exist = False
|
||||
if not arg_amodule.params['workers']:
|
||||
self.result['failed'] = True
|
||||
self.result['changed'] = False
|
||||
self.result['msg'] = "At least one worker group must be present"
|
||||
self.fail_json(**self.result)
|
||||
|
||||
if arg_amodule.params['name'] == "" and arg_amodule.params['id'] == 0:
|
||||
self.result['failed'] = True
|
||||
@@ -108,9 +163,11 @@ class decort_k8s(DecortController):
|
||||
ret_dict['techStatus'] = self.k8s_info['techStatus']
|
||||
ret_dict['state'] = self.k8s_info['status']
|
||||
ret_dict['rg_id'] = self.rg_id
|
||||
ret_dict['vins_id'] = self.k8s_vins_id
|
||||
ret_dict['account_id'] = self.acc_id
|
||||
if self.amodule.params['getConfig'] and self.k8s_info['techStatus'] == "STARTED":
|
||||
ret_dict['config'] = self.k8s_getConfig()
|
||||
|
||||
return ret_dict
|
||||
|
||||
def nop(self):
|
||||
@@ -149,10 +206,11 @@ class decort_k8s(DecortController):
|
||||
self.k8s_provision(self.amodule.params['name'],
|
||||
self.amodule.params['k8ci_id'],
|
||||
self.amodule.params['rg_id'],
|
||||
self.amodule.params['network_plugin'],
|
||||
self.amodule.params['master_count'],
|
||||
self.amodule.params['master_cpu'],
|
||||
self.amodule.params['master_ram_mb'],
|
||||
self.amodule.params['master_disk_gb'],
|
||||
self.amodule.params['master_ram'],
|
||||
self.amodule.params['master_disk'],
|
||||
self.amodule.params['workers'][0],
|
||||
self.amodule.params['extnet_id'],
|
||||
self.amodule.params['with_lb'],
|
||||
@@ -165,12 +223,12 @@ class decort_k8s(DecortController):
|
||||
|
||||
if self.k8s_id:
|
||||
self.k8s_should_exist = True
|
||||
if self.k8s_id and self.amodule.params['workers'][1]:
|
||||
if self.k8s_id and len(self.amodule.params['workers'])>1 :
|
||||
self.k8s_workers_modify(self.k8s_info,self.amodule.params['workers'])
|
||||
return
|
||||
|
||||
def destroy(self):
|
||||
self.k8s_delete(self.k8s_id)
|
||||
self.k8s_delete(self.k8s_id,self.amodule.params['permanent'])
|
||||
self.k8s_info['status'] = 'DELETED'
|
||||
self.k8s_should_exist = False
|
||||
return
|
||||
@@ -232,16 +290,17 @@ class decort_k8s(DecortController):
|
||||
rg_id=dict(type='int', default=0),
|
||||
rg_name=dict(type='str',default=""),
|
||||
k8ci_id=dict(type='int', required=True),
|
||||
network_plugin=dict(type='str',required=False,default="flannel"),
|
||||
wg_name=dict(type='str', required=False),
|
||||
master_count=dict(type='int', default=1),
|
||||
master_cpu=dict(type='int', default=2),
|
||||
master_ram_mb=dict(type='int', default=2048),
|
||||
master_disk_gb=dict(type='int', default=10),
|
||||
master_ram=dict(type='int', default=2048),
|
||||
master_disk=dict(type='int', default=10),
|
||||
worker_count=dict(type='int', default=1),
|
||||
worker_cpu=dict(type='int', default=1),
|
||||
worker_ram_mb=dict(type='int', default=1024),
|
||||
worker_disk_gb=dict(type='int', default=10),
|
||||
workers=dict(type='list'),
|
||||
workers=dict(type='list',required=True),
|
||||
extnet_id=dict(type='int', default=0),
|
||||
description=dict(type='str', default="Created by decort ansible module"),
|
||||
with_lb=dict(type='bool', default=True),
|
||||
|
||||
Reference in New Issue
Block a user