Cloudify support for OOM
[oom.git] / cloudify-onap / plugins / onap-installation-plugin / k8s_installer / common / workarounds.py
1 ########
2 # Copyright (c) 2017 GigaSpaces Technologies Ltd. All rights reserved
3 #
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
7 #
8 #        http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 from cloudify import ctx
17 from cloudify.exceptions import NonRecoverableError
18
19 from fabric import api as fabric_api
20
21 def _retrieve_namespace():
22     namespace = ctx.node.properties.get(
23         'namespace',
24         ctx.node.properties
25             .get('options', {})
26             .get('namespace', None)
27     )
28
29     if not namespace:
30         raise NonRecoverableError(
31             'Namespace is not defined (node={})'.format(ctx.node.name)
32         )
33
34     return namespace
35
36
37 def configure_secret():
38     namespace = _retrieve_namespace()
39     ctx.logger.info(
40         'Configuring docker secrets for namespace: {0}'.format(namespace)
41     )
42
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)
50
51     ctx.logger.info('Command "{0}" will be executed'.format(command))
52
53     with fabric_api.settings(
54             **ctx.node.properties.get('ssh_credentials')):
55         fabric_api.run(command)
56
57     ctx.logger.info('Docker secrets configured successfully')
58
59
60 def _get_fabric_env():
61     result = dict()
62
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']
66
67     return result