Skip to content

Commit

Permalink
[CE-378] Updated code to handle k8s params from UI
Browse files Browse the repository at this point in the history
1. Added k8s_cerd_type in src/common/utils.py
2. Added code to handle "kubernetes" host type
   in src/resources/host_api.py

Change-Id: I7a0e96675957e42eb8aeb7714e5ed1f259de5db1
Signed-off-by: luke <jiahaochen1993@gmail.com>
  • Loading branch information
jiahaoc1993 committed Jun 7, 2018
1 parent 85b3974 commit 8fc89a1
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
NETWORK_STATUS_DELETING = 'deleting' # network is in deleting
NETWORK_STATUS_STOPPED = 'stopped' # network is stopped

K8S_CRED_TYPE = {
'account': '0',
'cert': '1',
'config': '2'
}

# Vcenter and VirtualMachine Confs
VIRTUAL_MACHINE = 'vm'
VCENTER = 'vc'
Expand Down
70 changes: 70 additions & 0 deletions src/resources/host_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
CODE_CREATED, \
request_debug

from common.utils import K8S_CRED_TYPE

from modules import host_handler
from modules.models import Cluster as ClusterModel
from modules.models import Host as HostModel
Expand Down Expand Up @@ -141,6 +143,28 @@ def host_create():
log_server=log_server,
host_type=host_type,
params=vsphere_param)

elif host_type == 'kubernetes':
worker_api = r.form['k8s_master_address']
k8s_param = create_k8s_host(name, capacity, log_type, r)
if len(k8s_param) == 0:
return make_fail_resp(error=error_msg, data=r.form)

logger.debug("name={}, capacity={},"
"fillup={}, schedulable={}, log={}/{}, k8s_param={}".
format(name, capacity, autofill, schedulable,
log_type, log_server, k8s_param))

result = host_handler.create(name=name, worker_api=worker_api,
capacity=int(capacity),
autofill=autofill,
schedulable=schedulable,
log_level=log_level,
log_type=log_type,
log_server=log_server,
host_type=host_type,
params=k8s_param)

else:
logger.debug("name={}, worker_api={}, capacity={}"
"fillup={}, schedulable={}, log={}/{}".
Expand Down Expand Up @@ -276,3 +300,49 @@ def host_actions():
error_msg = "unknown host action={}".format(action)
logger.warning(error_msg)
return make_fail_resp(error=error_msg, data=body)


def create_k8s_host(name, capacity, log_type, request):
k8s_param = {
'address': request.form['k8s_master_address'],
'credType': request.form['k8s_cred_type'],
'username': request.form['k8s_username'],
'password': request.form['k8s_password'],
'cert': request.form['k8s_cert'],
'key': request.form['k8s_key'],
'config': request.form['k8s_config'],
'nfsServer': request.form['k8s_nfs_server'],
'extra_params': request.form['k8s_extra_params']
}
if "k8s_ssl" in request.form and request.form["k8s_ssl"] == "on":
k8s_ssl = "true"
else:
k8s_ssl = "false"
k8s_param['use_ssl'] = k8s_ssl

k8s_must_have_params = {
'Name': name,
'Capacity': capacity,
'LoggingType': log_type,
'K8SAddress': request.form['k8s_master_address'],
'K8SCredType': request.form['k8s_cred_type'],
'K8SNfsServer': request.form['k8s_nfs_server'],
'K8SUseSsl': k8s_param['use_ssl']
}

if k8s_must_have_params['K8SCredType'] == K8S_CRED_TYPE['account']:
k8s_must_have_params['K8SUsername'] = request.form['k8s_username']
k8s_must_have_params['K8SPassword'] = request.form['k8s_password']
elif k8s_must_have_params['K8SCredType'] == K8S_CRED_TYPE['cert']:
k8s_must_have_params['K8SCert'] = request.form['k8s_cert']
k8s_must_have_params['K8SKey'] = request.form['k8s_key']
elif k8s_must_have_params['K8SCredType'] == K8S_CRED_TYPE['config']:
k8s_must_have_params['K8SConfig'] = request.form['k8s_config']

for key in k8s_must_have_params:
if k8s_must_have_params[key] == '':
error_msg = "host POST without {} data".format(key)
logger.warning(error_msg)
return []

return k8s_param

0 comments on commit 8fc89a1

Please sign in to comment.