Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-magnumclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kubernetes
python-magnumclient
Commits
37e602d1
Commit
37e602d1
authored
Feb 28, 2019
by
Zuul
Committed by
Gerrit Code Review
Feb 28, 2019
Browse files
Options
Downloads
Plain Diff
Merge "Keystone auth support"
parents
5deb5389
81b84804
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
magnumclient/common/utils.py
+61
-27
61 additions, 27 deletions
magnumclient/common/utils.py
magnumclient/osc/v1/clusters.py
+21
-5
21 additions, 5 deletions
magnumclient/osc/v1/clusters.py
with
82 additions
and
32 deletions
magnumclient/common/utils.py
+
61
−
27
View file @
37e602d1
...
@@ -160,11 +160,11 @@ def handle_json_from_file(json_arg):
...
@@ -160,11 +160,11 @@ def handle_json_from_file(json_arg):
def
config_cluster
(
cluster
,
cluster_template
,
cfg_dir
,
force
=
False
,
def
config_cluster
(
cluster
,
cluster_template
,
cfg_dir
,
force
=
False
,
certs
=
None
):
certs
=
None
,
use_keystone
=
False
):
"""
Return and write configuration for the given cluster.
"""
"""
Return and write configuration for the given cluster.
"""
if
cluster_template
.
coe
==
'
kubernetes
'
:
if
cluster_template
.
coe
==
'
kubernetes
'
:
return
_config_cluster_kubernetes
(
cluster
,
cluster_template
,
cfg_dir
,
return
_config_cluster_kubernetes
(
cluster
,
cluster_template
,
cfg_dir
,
force
,
certs
)
force
,
certs
,
use_keystone
)
elif
(
cluster_template
.
coe
==
'
swarm
'
elif
(
cluster_template
.
coe
==
'
swarm
'
or
cluster_template
.
coe
==
'
swarm-mode
'
):
or
cluster_template
.
coe
==
'
swarm-mode
'
):
return
_config_cluster_swarm
(
cluster
,
cluster_template
,
cfg_dir
,
return
_config_cluster_swarm
(
cluster
,
cluster_template
,
cfg_dir
,
...
@@ -172,7 +172,7 @@ def config_cluster(cluster, cluster_template, cfg_dir, force=False,
...
@@ -172,7 +172,7 @@ def config_cluster(cluster, cluster_template, cfg_dir, force=False,
def
_config_cluster_kubernetes
(
cluster
,
cluster_template
,
cfg_dir
,
def
_config_cluster_kubernetes
(
cluster
,
cluster_template
,
cfg_dir
,
force
=
False
,
certs
=
None
):
force
=
False
,
certs
=
None
,
use_keystone
=
False
):
"""
Return and write configuration for the given kubernetes cluster.
"""
"""
Return and write configuration for the given kubernetes cluster.
"""
cfg_file
=
"
%s/config
"
%
cfg_dir
cfg_file
=
"
%s/config
"
%
cfg_dir
if
cluster_template
.
tls_disabled
or
certs
is
None
:
if
cluster_template
.
tls_disabled
or
certs
is
None
:
...
@@ -193,6 +193,7 @@ def _config_cluster_kubernetes(cluster, cluster_template, cfg_dir,
...
@@ -193,6 +193,7 @@ def _config_cluster_kubernetes(cluster, cluster_template, cfg_dir,
"
- name: %(name)s
'
\n
"
"
- name: %(name)s
'
\n
"
%
{
'
name
'
:
cluster
.
name
,
'
api_address
'
:
cluster
.
api_address
})
%
{
'
name
'
:
cluster
.
name
,
'
api_address
'
:
cluster
.
api_address
})
else
:
else
:
if
not
use_keystone
:
cfg
=
(
"
apiVersion: v1
\n
"
cfg
=
(
"
apiVersion: v1
\n
"
"
clusters:
\n
"
"
clusters:
\n
"
"
- cluster:
\n
"
"
- cluster:
\n
"
...
@@ -217,6 +218,39 @@ def _config_cluster_kubernetes(cluster, cluster_template, cfg_dir,
...
@@ -217,6 +218,39 @@ def _config_cluster_kubernetes(cluster, cluster_template, cfg_dir,
'
key
'
:
base64
.
b64encode
(
certs
[
'
key
'
]),
'
key
'
:
base64
.
b64encode
(
certs
[
'
key
'
]),
'
cert
'
:
base64
.
b64encode
(
certs
[
'
cert
'
]),
'
cert
'
:
base64
.
b64encode
(
certs
[
'
cert
'
]),
'
ca
'
:
base64
.
b64encode
(
certs
[
'
ca
'
])})
'
ca
'
:
base64
.
b64encode
(
certs
[
'
ca
'
])})
else
:
cfg
=
(
"
apiVersion: v1
\n
"
"
clusters:
\n
"
"
- cluster:
\n
"
"
certificate-authority-data: %(ca)s
\n
"
"
server: %(api_address)s
\n
"
"
name: %(name)s
\n
"
"
contexts:
\n
"
"
- context:
\n
"
"
cluster: %(name)s
\n
"
"
user: openstackuser
\n
"
"
name: openstackuser@kubernetes
\n
"
"
current-context: openstackuser@kubernetes
\n
"
"
kind: Config
\n
"
"
preferences: {}
\n
"
"
users:
\n
"
"
- name: openstackuser
\n
"
"
user:
\n
"
"
exec:
\n
"
"
command: /bin/bash
\n
"
"
apiVersion: client.authentication.k8s.io/v1alpha1
\n
"
"
args:
\n
"
"
- -c
\n
"
"
- >
\n
"
"
if [ -z ${OS_TOKEN} ]; then
\n
"
"
echo
'
Error: Missing OpenStack credential from environment variable $OS_TOKEN
'
> /dev/stderr
\n
"
# noqa
"
exit 1
\n
"
"
else
\n
"
"
echo
'
{
\"
apiVersion
\"
:
\"
client.authentication.k8s.io/v1alpha1
\"
,
\"
kind
\"
:
\"
ExecCredential
\"
,
\"
status
\"
: {
\"
token
\"
:
\"
'
\"
${OS_TOKEN}
\"
'
\"
}}
'
\n
"
# noqa
"
fi
\n
"
%
{
'
name
'
:
cluster
.
name
,
'
api_address
'
:
cluster
.
api_address
,
'
ca
'
:
base64
.
b64encode
(
certs
[
'
ca
'
])})
if
os
.
path
.
exists
(
cfg_file
)
and
not
force
:
if
os
.
path
.
exists
(
cfg_file
)
and
not
force
:
raise
exc
.
CommandError
(
"
File %s exists, aborting.
"
%
cfg_file
)
raise
exc
.
CommandError
(
"
File %s exists, aborting.
"
%
cfg_file
)
...
...
...
...
This diff is collapsed.
Click to expand it.
magnumclient/osc/v1/clusters.py
+
21
−
5
View file @
37e602d1
...
@@ -305,6 +305,18 @@ class ConfigCluster(command.Command):
...
@@ -305,6 +305,18 @@ class ConfigCluster(command.Command):
dest
=
'
output_certs
'
,
dest
=
'
output_certs
'
,
default
=
False
,
default
=
False
,
help
=
_
(
'
Output certificates in separate files.
'
))
help
=
_
(
'
Output certificates in separate files.
'
))
parser
.
add_argument
(
'
--use-certificate
'
,
action
=
'
store_true
'
,
dest
=
'
use_certificate
'
,
default
=
True
,
help
=
_
(
'
Use certificate in config files.
'
))
parser
.
add_argument
(
'
--use-keystone
'
,
action
=
'
store_true
'
,
dest
=
'
use_keystone
'
,
default
=
False
,
help
=
_
(
'
Use Keystone token in config files.
'
))
return
parser
return
parser
...
@@ -315,6 +327,11 @@ class ConfigCluster(command.Command):
...
@@ -315,6 +327,11 @@ class ConfigCluster(command.Command):
the corresponding COE configured to access the cluster.
the corresponding COE configured to access the cluster.
"""
"""
if
parsed_args
.
use_keystone
:
parsed_args
.
use_certificate
=
False
if
not
parsed_args
.
use_certificate
:
parsed_args
.
use_keystone
=
True
self
.
log
.
debug
(
"
take_action(%s)
"
,
parsed_args
)
self
.
log
.
debug
(
"
take_action(%s)
"
,
parsed_args
)
mag_client
=
self
.
app
.
client_manager
.
container_infra
mag_client
=
self
.
app
.
client_manager
.
container_infra
...
@@ -346,8 +363,7 @@ class ConfigCluster(command.Command):
...
@@ -346,8 +363,7 @@ class ConfigCluster(command.Command):
with
open
(
fname
,
"
w
"
)
as
f
:
with
open
(
fname
,
"
w
"
)
as
f
:
f
.
write
(
tls
[
k
])
f
.
write
(
tls
[
k
])
print
(
magnum_utils
.
config_cluster
(
cluster
,
print
(
magnum_utils
.
config_cluster
(
cluster_template
,
cluster
,
cluster_template
,
parsed_args
.
dir
,
parsed_args
.
dir
,
force
=
parsed_args
.
force
,
certs
=
tls
,
force
=
parsed_args
.
force
,
use_keystone
=
parsed_args
.
use_keystone
))
certs
=
tls
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment