2 # Copyright (c) 2017 GigaSpaces Technologies Ltd. All rights reserved
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # * See the License for the specific language governing permissions and
14 # * limitations under the License.
16 from cloudify import ctx
17 from cloudify.exceptions import NonRecoverableError
19 from fabric import api as fabric_api
21 def _retrieve_namespace():
22 namespace = ctx.node.properties.get(
26 .get('namespace', None)
30 raise NonRecoverableError(
31 'Namespace is not defined (node={})'.format(ctx.node.name)
37 def configure_secret():
38 namespace = _retrieve_namespace()
40 'Configuring docker secrets for namespace: {0}'.format(namespace)
43 command = 'kubectl create secret ' \
44 'docker-registry onap-docker-registry-key ' \
45 '--docker-server=nexus3.onap.org:10001 ' \
46 '--docker-username=docker ' \
47 '--docker-password=docker ' \
48 '--docker-email=email@email.com ' \
49 '--namespace={0}'.format(namespace)
51 ctx.logger.info('Command "{0}" will be executed'.format(command))
53 with fabric_api.settings(
54 **ctx.node.properties.get('ssh_credentials')):
55 fabric_api.run(command)
57 ctx.logger.info('Docker secrets configured successfully')
60 def _get_fabric_env():
63 result['host_string'] = ctx.node.properties.get('ssh_credentials')['host_string']
64 result['user'] = ctx.node.properties.get('ssh_credentials')['user']
65 result['key'] = ctx.node.properties.get('ssh_credentials')['key']