1 # ============LICENSE_START==========================================
2 # ===================================================================
3 # Copyright (c) 2018 AT&T
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #============LICENSE_END============================================
18 from tempfile import NamedTemporaryFile
19 from fabric.api import get, sudo, run
20 from cloudify import ctx
21 from cloudify.exceptions import NonRecoverableError, RecoverableError
23 CONFIG_PATH = '/etc/cloudify/config.yaml'
26 def install_rpm(_rpm):
28 sudo("rpm -i {0}".format(_rpm))
29 except Exception as e:
30 raise NonRecoverableError(str(e))
34 def install_requirements():
36 sudo("sudo yum install -y python-backports-ssl_match_hostname "
37 "python-setuptools python-backports")
38 except Exception as e:
39 raise NonRecoverableError(str(e))
43 def update_config(private, public, _config_path):
44 SED = "sed -i 's|{0}|{1}|g' {2}"
46 old_private_ip = " private_ip: \\x27\\x27"
47 new_private_ip = " private_ip: \\x27{0}\\x27".format(private)
50 sudo(SED.format(old_private_ip, new_private_ip, _config_path))
51 except Exception as e:
52 raise NonRecoverableError(str(e))
54 old_public_ip = " public_ip: \\x27\\x27"
55 new_public_ip = " public_ip: \\x27{0}\\x27".format(public)
58 sudo(SED.format(old_public_ip, new_public_ip, _config_path))
59 except Exception as e:
60 raise NonRecoverableError(str(e))
62 old_networks = " networks: {}"
63 new_networks = " networks: {{ \\x27default\\x27: \\x27{0}\\x27, \\x27external\\x27: \\x27{1}\\x27 }}".format(
67 sudo(SED.format(old_networks, new_networks, _config_path))
68 sudo("chmod 775 {0}".format(_config_path))
69 except Exception as e:
70 raise NonRecoverableError(str(e))
74 def cfy_install(password, old=False):
75 sudo("chmod 777 {0}".format(CONFIG_PATH))
77 install_string = 'cfy_manager install'
81 install_string + ' ' + '--admin-password {0}'.format(
84 install_string = install_string + ' --clean-db'
87 sudo("sudo yum install -y openssl-1.0.2k")
88 except Exception as e:
89 raise NonRecoverableError(str(e))
93 except Exception as e:
94 ctx.logger.error(str(e))
97 sudo("chmod 775 {0}".format(CONFIG_PATH))
102 def plugins_upload():
104 run("cfy plugins bundle-upload")
105 except Exception as e:
106 raise NonRecoverableError(str(e))
111 def secrets_create(secret_key, secret_value):
113 run("cfy secrets create {0} -s \"{1}\"".format(
114 secret_key, secret_value))
115 except Exception as e:
116 raise NonRecoverableError(str(e))
121 def blueprints_upload(file, name, url):
123 run("cfy blueprints upload -n {0} -b {1} {2}".format(file, name, url))
124 except Exception as e:
125 raise NonRecoverableError(str(e))
130 def create(private_ip,
135 config_path=CONFIG_PATH,
138 ctx.logger.info("Installing Cloudify Manager components.")
142 except Exception as e:
143 raise RecoverableError(str(e))
145 if not ctx.instance.runtime_properties.get('installed_rpm'):
146 install_requirements()
147 ctx.instance.runtime_properties['installed_rpm'] = install_rpm(rpm)
149 if not ctx.instance.runtime_properties.get('updated_config'):
150 ctx.instance.runtime_properties['updated_config'] = \
151 update_config(private_ip, public_ip, config_path)
153 if 'cfy_installed' not in ctx.instance.runtime_properties:
154 cfy_install_output = cfy_install(password)
156 cfy_install_output = cfy_install(password, old=True)
158 ctx.instance.runtime_properties['cfy_installed'] = cfy_install_output
159 if not cfy_install_output:
160 raise RecoverableError('cfy install failed.')
162 if not ctx.instance.runtime_properties.get('plugins_uploaded'):
165 "cfy plugins upload https://nexus.onap.org/content/sites/raw/org.onap.ccsdk.platform.plugins/plugins/helm-3.0.0-py27-none-linux_x86_64.wgn -y https://nexus.onap.org/content/sites/raw/org.onap.ccsdk.platform.plugins/type_files/helm/1.1.0/helm-type.yaml")
166 except Exception as e:
167 raise NonRecoverableError(str(e))
168 ctx.instance.runtime_properties['plugins_uploaded'] = plugins_upload()
171 {'key': 'cfy_user', 'value': 'admin'},
172 {'key': 'kubernetes_master_port', 'value': 'kubernetes_master_port'},
173 {'key': 'kubernetes-admin_client_certificate_data',
174 'value': 'kubernetes-admin_client_certificate_data'},
175 {'key': 'kubernetes_master_ip', 'value': 'kubernetes_master_ip'},
176 {'key': 'kubernetes_certificate_authority_data',
177 'value': 'kubernetes_certificate_authority_data'},
178 {'key': 'kubernetes-admin_client_key_data',
179 'value': 'kubernetes-admin_client_key_data'},
180 {'key': 'cfy_password', 'value': password or 'cfy_password'},
181 {'key': 'cfy_tenant', 'value': 'default_tenant'},
182 {'key': 'kubernetes_token', 'value': 'kubernetes_token'}
184 for ms in more_secrets:
187 for secret in secrets:
192 for blueprint in blueprints:
194 blueprint.get('file'),
195 blueprint.get('name'),
196 blueprint.get('url'))
199 "Initialize your CLI profile: "
201 "{0} -u admin -p {1} -t default_tenant`".format(public_ip,
205 "Since you did not provide a password, scroll up though "
206 "the execution log and search for \"Manager password is\".")