diff options
author | 2017-10-03 14:55:19 +0200 | |
---|---|---|
committer | 2017-10-03 15:27:26 +0200 | |
commit | 63f2cc936ed6e6790f287195694f6d067decdd89 (patch) | |
tree | e79b62b7fc3e099708b6707454b4c52ee3e581da /cloudify/scripts/onap/delete_resources_services.py | |
parent | b9644b17f8545dedd3ede40f778b33f9b4ecf480 (diff) |
Cloudify support for OOM
Issue-ID: OOM-106
Change-Id: Ie0a37ef378fd1907825da181c81502c6fbe9134c
Signed-off-by: Marek Wolczanski <marek.wolczanski@cloudify.co>
Diffstat (limited to 'cloudify/scripts/onap/delete_resources_services.py')
-rw-r--r-- | cloudify/scripts/onap/delete_resources_services.py | 132 |
1 files changed, 0 insertions, 132 deletions
diff --git a/cloudify/scripts/onap/delete_resources_services.py b/cloudify/scripts/onap/delete_resources_services.py deleted file mode 100644 index 305a7484bd..0000000000 --- a/cloudify/scripts/onap/delete_resources_services.py +++ /dev/null @@ -1,132 +0,0 @@ -import pip - -from cloudify import ctx -from cloudify.exceptions import NonRecoverableError - - -SERVICES_FILE_PARTS_SEPARATOR = '---' - - -def _import_or_install(): - try: - import yaml - except ImportError: - pip.main(["install", "pyaml"]) - - try: - import cloudify_kubernetes.tasks as kubernetes_plugin - except ImportError: - pip.main([ - "install", - "https://github.com/cloudify-incubator/cloudify-kubernetes-plugin/archive/1.2.1rc1.zip" - ]) - - try: - import jinja2 - except ImportError: - pip.main(["install", "jinja2"]) - - import yaml - import jinja2 - import cloudify_kubernetes.tasks as kubernetes_plugin - - return yaml, kubernetes_plugin, jinja2 - - -def _init_jinja(jinja2): - return jinja2.Environment( - loader=jinja2.BaseLoader() - ) - - -def _render_template(jinja_env, template_content, values): - template_content = template_content.replace('.Values', 'Values') - - template = jinja_env.from_string(template_content) - rendered_template = template.render(Values=values) - return rendered_template - - -def _retrieve_resources_paths(): - return ctx.node.properties.get('resources', []) - - -def _retrieve_services_paths(): - return ctx.node.properties.get('services', None) - - -def _retrieve_values(yaml): - values_file_path = ctx.node.properties.get('values', None) - - if values_file_path: - return yaml.load(ctx.get_resource(values_file_path)) - - ctx.logger.warn('Values file not found') - - -def _set_deployment_result(key): - result = ctx.instance.runtime_properties.pop(key) - ctx.instance.runtime_properties['kubernetes'] = result - - -def _do_delete_resources(kubernetes_plugin, yaml, jinja_env, values): - for path in _retrieve_resources_paths(): - ctx.logger.info('Deleting resource defined in: {0}'.format(path)) - - template_content = ctx.get_resource(path) - yaml_content = _render_template( - jinja_env, - template_content, - values - ) - content = yaml.load(yaml_content) - - _set_deployment_result( - 'resource_{0}'.format(content['metadata']['name']) - ) - kubernetes_plugin.resource_delete(definition=content) - - ctx.logger.info('Resources deleted successfully') - - -def _do_delete_services(kubernetes_plugin, yaml, jinja_env, values): - ctx.logger.info('Deleting services') - services_file_path = _retrieve_services_paths() - - if not services_file_path: - ctx.logger.warn( - 'Service file is not defined. Skipping services provisioning !' - ) - - return - - template_content = ctx.get_resource(services_file_path) - yaml_content = _render_template( - jinja_env, - template_content, - values - ) - - yaml_content_parts = \ - yaml_content.split(SERVICES_FILE_PARTS_SEPARATOR) - - for yaml_content_part in yaml_content_parts: - content = yaml.load(yaml_content_part) - - _set_deployment_result( - 'service_{0}'.format(content['metadata']['name']) - ) - kubernetes_plugin.resource_delete(definition=content) - - ctx.logger.info('Services deleted successfully') - - -if __name__ == '__main__': - yaml, kubernetes_plugin, jinja2 = _import_or_install() - jinja_env = _init_jinja(jinja2) - values = _retrieve_values(yaml) - - _do_delete_services(kubernetes_plugin, yaml, jinja_env, values) - _do_delete_resources(kubernetes_plugin, yaml, jinja_env, values) - - |