3 from cloudify import ctx
4 from cloudify.exceptions import NonRecoverableError
7 SERVICES_FILE_PARTS_SEPARATOR = '---'
10 def _import_or_install():
14 pip.main(["install", "pyaml"])
17 import cloudify_kubernetes.tasks as kubernetes_plugin
21 "https://github.com/cloudify-incubator/cloudify-kubernetes-plugin/archive/1.2.1rc1.zip"
25 import cloudify_kubernetes.tasks as kubernetes_plugin
27 return yaml, kubernetes_plugin
31 return ctx.node.properties.get('init_pod', None)
34 def _save_deployment_result(key):
35 result = ctx.instance.runtime_properties['kubernetes']
36 ctx.instance.runtime_properties[key] = result
37 ctx.instance.runtime_properties['kubernetes'] = {}
40 def _do_create_init_pod(kubernetes_plugin, yaml):
41 ctx.logger.info('Creating init pod')
42 init_pod_file_path = _retrieve_path()
44 if not init_pod_file_path:
45 raise NonRecoverableError('Init pod file is not defined.')
47 temp_file_path = ctx.download_resource_and_render(
51 with open(temp_file_path) as temp_file:
52 init_pod_file_content = temp_file.read()
53 init_pod_yaml_content = yaml.load(init_pod_file_content)
55 kubernetes_plugin.resource_create(definition=init_pod_yaml_content)
56 _save_deployment_result('init_pod')
58 ctx.logger.info('Init pod created successfully')
61 if __name__ == '__main__':
62 yaml, kubernetes_plugin = _import_or_install()
64 _do_create_init_pod(kubernetes_plugin, yaml)