Skip to content

Commit

Permalink
[CE-385] Using cert/key to create kubernetes host
Browse files Browse the repository at this point in the history
1. Added a textbox for input key.
2. Modified the module layer to accept "worker_api" rather
than "kubernetes_master_address" while creating k8s host.

Change-Id: I05645f8d05ae0ce83eb6fd39fd946e63ef4a5c62
Signed-off-by: luke <jiahaochen1993@gmail.com>
  • Loading branch information
jiahaoc1993 committed Jun 19, 2018
1 parent b42e272 commit 64cf1b6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 42 deletions.
45 changes: 17 additions & 28 deletions src/resources/host_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ def host_create():
params=vsphere_param)

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

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

result = host_handler.create(name=name, worker_api=worker_api,
capacity=int(capacity),
Expand Down Expand Up @@ -303,46 +303,35 @@ def host_actions():


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":
if "k8s_ssl" in request and request["k8s_ssl"] == "on":
k8s_ssl = "true"
else:
k8s_ssl = "false"
k8s_param['use_ssl'] = k8s_ssl
request['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']
'K8SAddress': request['worker_api'],
'K8SCredType': request['k8s_cred_type'],
'K8SNfsServer': request['k8s_nfs_server'],
'K8SUseSsl': request['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']
k8s_must_have_params['K8SUsername'] = request['k8s_username']
k8s_must_have_params['K8SPassword'] = request['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']
k8s_must_have_params['K8SCert'] = request['k8s_cert']
k8s_must_have_params['K8SKey'] = request['k8s_key']
elif k8s_must_have_params['K8SCredType'] == K8S_CRED_TYPE['config']:
k8s_must_have_params['K8SConfig'] = request.form['k8s_config']
k8s_must_have_params['K8SConfig'] = request['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
return k8s_must_have_params
1 change: 1 addition & 0 deletions src/static/dashboard/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"Host.Create.Validate.Required.LogType": "Please select a log type.",
"Host.Create.Validate.Required.CredentialType": "Please select a credential type.",
"Host.Create.Validate.Required.CertificateContent": "Please input certificate content.",
"Host.Create.Validate.Required.CertificateKey": "Please input certificate key.",
"Host.Create.Validate.Required.ConfigurationContent": "Please input configuration content.",
"Host.Create.Validate.Required.Username": "Please input username.",
"Host.Create.Validate.Required.Password": "Please input password.",
Expand Down
1 change: 1 addition & 0 deletions src/static/dashboard/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"Host.Create.Validate.Required.LogType": "请选择一个日志类型。",
"Host.Create.Validate.Required.CredentialType": "请选择一个凭证类型。",
"Host.Create.Validate.Required.CertificateContent": "请输入证书内容。",
"Host.Create.Validate.Required.CertificateKey": "请输入密钥内容。",
"Host.Create.Validate.Required.ConfigurationContent": "请输入配置内容。",
"Host.Create.Validate.Required.Username": "请输入用户名。",
"Host.Create.Validate.Required.Password": "请输入密码。",
Expand Down
53 changes: 39 additions & 14 deletions src/static/dashboard/src/routes/Host/CreateHost/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const messages = defineMessages({
id: 'Host.Create.Validate.Label.CertificateContent',
defaultMessage: 'Certificate Content',
},
certificateKey: {
id: 'Host.Create.Validate.Label.CertificateKey',
defaultMessage: 'Certificate Key',
},
configurationContent: {
id: 'Host.Create.Validate.Label.ConfigurationContent',
defaultMessage: 'Configuration Content',
Expand Down Expand Up @@ -149,6 +153,10 @@ const messages = defineMessages({
id: 'Host.Create.Validate.Required.CertificateContent',
defaultMessage: 'Please input certificate content.',
},
certificateKey: {
id: 'Host.Create.Validate.Required.CertificateKey',
defaultMessage: 'Please input certificate key.',
},
configurationContent: {
id: 'Host.Create.Validate.Required.ConfigurationContent',
defaultMessage: 'Please input configuration content.',
Expand Down Expand Up @@ -193,16 +201,16 @@ class CreateHost extends PureComponent {
const hostTypeValues = ['docker', 'swarm', 'kubernetes', 'vsphere'];
const k8sCredTypes = [
{
id: 'cert_key',
name: 'cert/key',
id: '1',
name: 'cert_key',
},
{
id: 'config',
id: '2',
name: 'config',
},
{
id: 'username_password',
name: 'username/password',
id: '0',
name: 'username_password',
},
];
this.state = {
Expand Down Expand Up @@ -372,16 +380,16 @@ class CreateHost extends PureComponent {
));
const k8sCredTypes = [
{
id: 'cert_key',
name: 'cert/key',
id: '1',
name: 'cert_key',
},
{
id: 'config',
id: '2',
name: 'config',
},
{
id: 'username_password',
name: 'username/password',
id: '0',
name: 'username_password',
},
];
const k8sCredTypeOptions = k8sCredTypes.map(item => (
Expand Down Expand Up @@ -488,7 +496,8 @@ class CreateHost extends PureComponent {
</Select>
)}
</FormItem>
{k8sCredType === 'cert_key' && (
{k8sCredType === '1' && (
<div>
<FormItem
{...formItemLayout}
label={intl.formatMessage(messages.label.certificateContent)}
Expand All @@ -502,10 +511,26 @@ class CreateHost extends PureComponent {
),
},
],
})(<TextArea rows={4} />)}
})(<TextArea rows={4} placeholder={intl.formatMessage(messages.label.certificateContent)} />)}
</FormItem>
<FormItem
{...formItemLayout}
label={intl.formatMessage(messages.label.certificateKey)}
>
{getFieldDecorator('k8s_key', {
rules: [
{
required: true,
message: intl.formatMessage(
messages.validate.required.certificateKey
),
},
],
})(<TextArea rows={4} placeholder={intl.formatMessage(messages.label.certificateKey)} />)}
</FormItem>
</div>
)}
{k8sCredType === 'config' && (
{k8sCredType === '2' && (
<FormItem
{...formItemLayout}
label={intl.formatMessage(messages.label.configurationContent)}
Expand All @@ -522,7 +547,7 @@ class CreateHost extends PureComponent {
})(<TextArea rows={4} />)}
</FormItem>
)}
{k8sCredType === 'username_password' && (
{k8sCredType === '0' && (
<div>
<FormItem
{...formItemLayout}
Expand Down

0 comments on commit 64cf1b6

Please sign in to comment.