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
20 import resources_services
22 SERVICES_FILE_PARTS_SEPARATOR = '---'
25 def do_create_init_pod():
26 ctx.logger.info('Creating init pod')
28 yaml_config = resources_services.render_chart(
29 ctx.node.properties["init_pod"],
30 _retrieve_root_path(),
31 _retrieve_helm_cli_path()
33 yaml_content_part = yaml_config.split(SERVICES_FILE_PARTS_SEPARATOR)[2]
34 enhanced_yaml = _add_openstack_envs(yaml_content_part)
36 resources_services.create_resource(enhanced_yaml)
38 ctx.logger.info('Init pod created successfully')
41 def do_delete_init_pod():
42 ctx.logger.info('Deleting init pod')
44 ctx.logger.info('Init pod deleted successfully')
46 def _add_openstack_envs(yaml_content):
47 input_dict = yaml.load(yaml_content)
49 container_dict = input_dict['spec']['containers'][0]
50 container_dict.pop('envFrom')
52 openstack_envs = ctx.node.properties["openstack_envs"]
53 for item in openstack_envs.items():
54 ctx.logger.debug("adding item = {}".format(item))
55 container_dict['env'].append(item)
59 def _retrieve_root_path():
60 return ctx.instance.runtime_properties.get(constants.RT_APPS_ROOT_PATH, None)
62 def _retrieve_helm_cli_path():
63 return ctx.instance.runtime_properties.get(constants.RT_HELM_CLI_PATH, None)