Skip to content

Commit 64cf1b6

Browse files
committed
[CE-385] Using cert/key to create kubernetes host
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>
1 parent b42e272 commit 64cf1b6

File tree

4 files changed

+58
-42
lines changed

4 files changed

+58
-42
lines changed

src/resources/host_api.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ def host_create():
145145
params=vsphere_param)
146146

147147
elif host_type == 'kubernetes':
148-
worker_api = r.form['k8s_master_address']
149-
k8s_param = create_k8s_host(name, capacity, log_type, r)
148+
worker_api = body['worker_api']
149+
k8s_param = create_k8s_host(name, capacity, log_type, body)
150150
if len(k8s_param) == 0:
151151
return make_fail_resp(error=error_msg, data=r.form)
152152

153-
logger.debug("name={}, capacity={},"
153+
logger.debug("name={}, worker_api={}, capacity={},"
154154
"fillup={}, schedulable={}, log={}/{}, k8s_param={}".
155-
format(name, capacity, autofill, schedulable,
156-
log_type, log_server, k8s_param))
155+
format(name, worker_api, capacity, autofill,
156+
schedulable, log_type, log_server, k8s_param))
157157

158158
result = host_handler.create(name=name, worker_api=worker_api,
159159
capacity=int(capacity),
@@ -303,46 +303,35 @@ def host_actions():
303303

304304

305305
def create_k8s_host(name, capacity, log_type, request):
306-
k8s_param = {
307-
'address': request.form['k8s_master_address'],
308-
'credType': request.form['k8s_cred_type'],
309-
'username': request.form['k8s_username'],
310-
'password': request.form['k8s_password'],
311-
'cert': request.form['k8s_cert'],
312-
'key': request.form['k8s_key'],
313-
'config': request.form['k8s_config'],
314-
'nfsServer': request.form['k8s_nfs_server'],
315-
'extra_params': request.form['k8s_extra_params']
316-
}
317-
if "k8s_ssl" in request.form and request.form["k8s_ssl"] == "on":
306+
if "k8s_ssl" in request and request["k8s_ssl"] == "on":
318307
k8s_ssl = "true"
319308
else:
320309
k8s_ssl = "false"
321-
k8s_param['use_ssl'] = k8s_ssl
310+
request['use_ssl'] = k8s_ssl
322311

323312
k8s_must_have_params = {
324313
'Name': name,
325314
'Capacity': capacity,
326315
'LoggingType': log_type,
327-
'K8SAddress': request.form['k8s_master_address'],
328-
'K8SCredType': request.form['k8s_cred_type'],
329-
'K8SNfsServer': request.form['k8s_nfs_server'],
330-
'K8SUseSsl': k8s_param['use_ssl']
316+
'K8SAddress': request['worker_api'],
317+
'K8SCredType': request['k8s_cred_type'],
318+
'K8SNfsServer': request['k8s_nfs_server'],
319+
'K8SUseSsl': request['use_ssl']
331320
}
332321

333322
if k8s_must_have_params['K8SCredType'] == K8S_CRED_TYPE['account']:
334-
k8s_must_have_params['K8SUsername'] = request.form['k8s_username']
335-
k8s_must_have_params['K8SPassword'] = request.form['k8s_password']
323+
k8s_must_have_params['K8SUsername'] = request['k8s_username']
324+
k8s_must_have_params['K8SPassword'] = request['k8s_password']
336325
elif k8s_must_have_params['K8SCredType'] == K8S_CRED_TYPE['cert']:
337-
k8s_must_have_params['K8SCert'] = request.form['k8s_cert']
338-
k8s_must_have_params['K8SKey'] = request.form['k8s_key']
326+
k8s_must_have_params['K8SCert'] = request['k8s_cert']
327+
k8s_must_have_params['K8SKey'] = request['k8s_key']
339328
elif k8s_must_have_params['K8SCredType'] == K8S_CRED_TYPE['config']:
340-
k8s_must_have_params['K8SConfig'] = request.form['k8s_config']
329+
k8s_must_have_params['K8SConfig'] = request['k8s_config']
341330

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

348-
return k8s_param
337+
return k8s_must_have_params

src/static/dashboard/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"Host.Create.Validate.Required.LogType": "Please select a log type.",
5555
"Host.Create.Validate.Required.CredentialType": "Please select a credential type.",
5656
"Host.Create.Validate.Required.CertificateContent": "Please input certificate content.",
57+
"Host.Create.Validate.Required.CertificateKey": "Please input certificate key.",
5758
"Host.Create.Validate.Required.ConfigurationContent": "Please input configuration content.",
5859
"Host.Create.Validate.Required.Username": "Please input username.",
5960
"Host.Create.Validate.Required.Password": "Please input password.",

src/static/dashboard/src/locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"Host.Create.Validate.Required.LogType": "请选择一个日志类型。",
5555
"Host.Create.Validate.Required.CredentialType": "请选择一个凭证类型。",
5656
"Host.Create.Validate.Required.CertificateContent": "请输入证书内容。",
57+
"Host.Create.Validate.Required.CertificateKey": "请输入密钥内容。",
5758
"Host.Create.Validate.Required.ConfigurationContent": "请输入配置内容。",
5859
"Host.Create.Validate.Required.Username": "请输入用户名。",
5960
"Host.Create.Validate.Required.Password": "请输入密码。",

src/static/dashboard/src/routes/Host/CreateHost/index.js

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ const messages = defineMessages({
7070
id: 'Host.Create.Validate.Label.CertificateContent',
7171
defaultMessage: 'Certificate Content',
7272
},
73+
certificateKey: {
74+
id: 'Host.Create.Validate.Label.CertificateKey',
75+
defaultMessage: 'Certificate Key',
76+
},
7377
configurationContent: {
7478
id: 'Host.Create.Validate.Label.ConfigurationContent',
7579
defaultMessage: 'Configuration Content',
@@ -149,6 +153,10 @@ const messages = defineMessages({
149153
id: 'Host.Create.Validate.Required.CertificateContent',
150154
defaultMessage: 'Please input certificate content.',
151155
},
156+
certificateKey: {
157+
id: 'Host.Create.Validate.Required.CertificateKey',
158+
defaultMessage: 'Please input certificate key.',
159+
},
152160
configurationContent: {
153161
id: 'Host.Create.Validate.Required.ConfigurationContent',
154162
defaultMessage: 'Please input configuration content.',
@@ -193,16 +201,16 @@ class CreateHost extends PureComponent {
193201
const hostTypeValues = ['docker', 'swarm', 'kubernetes', 'vsphere'];
194202
const k8sCredTypes = [
195203
{
196-
id: 'cert_key',
197-
name: 'cert/key',
204+
id: '1',
205+
name: 'cert_key',
198206
},
199207
{
200-
id: 'config',
208+
id: '2',
201209
name: 'config',
202210
},
203211
{
204-
id: 'username_password',
205-
name: 'username/password',
212+
id: '0',
213+
name: 'username_password',
206214
},
207215
];
208216
this.state = {
@@ -372,16 +380,16 @@ class CreateHost extends PureComponent {
372380
));
373381
const k8sCredTypes = [
374382
{
375-
id: 'cert_key',
376-
name: 'cert/key',
383+
id: '1',
384+
name: 'cert_key',
377385
},
378386
{
379-
id: 'config',
387+
id: '2',
380388
name: 'config',
381389
},
382390
{
383-
id: 'username_password',
384-
name: 'username/password',
391+
id: '0',
392+
name: 'username_password',
385393
},
386394
];
387395
const k8sCredTypeOptions = k8sCredTypes.map(item => (
@@ -488,7 +496,8 @@ class CreateHost extends PureComponent {
488496
</Select>
489497
)}
490498
</FormItem>
491-
{k8sCredType === 'cert_key' && (
499+
{k8sCredType === '1' && (
500+
<div>
492501
<FormItem
493502
{...formItemLayout}
494503
label={intl.formatMessage(messages.label.certificateContent)}
@@ -502,10 +511,26 @@ class CreateHost extends PureComponent {
502511
),
503512
},
504513
],
505-
})(<TextArea rows={4} />)}
514+
})(<TextArea rows={4} placeholder={intl.formatMessage(messages.label.certificateContent)} />)}
515+
</FormItem>
516+
<FormItem
517+
{...formItemLayout}
518+
label={intl.formatMessage(messages.label.certificateKey)}
519+
>
520+
{getFieldDecorator('k8s_key', {
521+
rules: [
522+
{
523+
required: true,
524+
message: intl.formatMessage(
525+
messages.validate.required.certificateKey
526+
),
527+
},
528+
],
529+
})(<TextArea rows={4} placeholder={intl.formatMessage(messages.label.certificateKey)} />)}
506530
</FormItem>
531+
</div>
507532
)}
508-
{k8sCredType === 'config' && (
533+
{k8sCredType === '2' && (
509534
<FormItem
510535
{...formItemLayout}
511536
label={intl.formatMessage(messages.label.configurationContent)}
@@ -522,7 +547,7 @@ class CreateHost extends PureComponent {
522547
})(<TextArea rows={4} />)}
523548
</FormItem>
524549
)}
525-
{k8sCredType === 'username_password' && (
550+
{k8sCredType === '0' && (
526551
<div>
527552
<FormItem
528553
{...formItemLayout}

0 commit comments

Comments
 (0)