diff options
author | Marek Wolczanski <marek.wolczanski@cloudify.co> | 2017-10-03 14:55:19 +0200 |
---|---|---|
committer | Marek Wolczanski <marek.wolczanski@cloudify.co> | 2017-10-03 15:27:26 +0200 |
commit | 63f2cc936ed6e6790f287195694f6d067decdd89 (patch) | |
tree | e79b62b7fc3e099708b6707454b4c52ee3e581da /cloudify | |
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')
-rw-r--r-- | cloudify/inputs/message-router-blueprint.yaml.example | 25 | ||||
-rw-r--r-- | cloudify/scripts/configure_node.py | 49 | ||||
-rw-r--r-- | cloudify/scripts/create.py | 72 | ||||
-rw-r--r-- | cloudify/scripts/onap/configure_docker_secret_workaround.py | 40 | ||||
-rw-r--r-- | cloudify/scripts/onap/create_init_pod.py | 65 | ||||
-rw-r--r-- | cloudify/scripts/onap/create_namespace.py | 101 | ||||
-rw-r--r-- | cloudify/scripts/onap/create_resources_services.py | 131 | ||||
-rw-r--r-- | cloudify/scripts/onap/delete_init_pod.py | 64 | ||||
-rw-r--r-- | cloudify/scripts/onap/delete_namespace.py | 101 | ||||
-rw-r--r-- | cloudify/scripts/onap/delete_resources_services.py | 132 | ||||
-rw-r--r-- | cloudify/scripts/tasks.py | 24 | ||||
-rw-r--r-- | cloudify/types/kubernetes.yaml | 91 | ||||
-rw-r--r-- | cloudify/types/onap.yaml | 89 |
13 files changed, 0 insertions, 984 deletions
diff --git a/cloudify/inputs/message-router-blueprint.yaml.example b/cloudify/inputs/message-router-blueprint.yaml.example deleted file mode 100644 index ecab0eca2c..0000000000 --- a/cloudify/inputs/message-router-blueprint.yaml.example +++ /dev/null @@ -1,25 +0,0 @@ -join_command: kubeadm join --token f66aad.cb001cc90bd69b38 192.168.120.6:6443 -kubernetes_master_ip: 192.168.120.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G90dlZSekVtN0dmWllMUUs2cW9Wczk4TTRjS3RhdjVlL3VVcXFGckY2NVYzUE1QV3M1NGp2Q1U5CklFTDJ0ZmQ1TzFrMGlEcXFtdWdBVjgxblNOdHlnK0FZN3o5SVdXRFhKcTNUQ1RHQnZLQmxCdzNWSDVBbnQxblEKSFNrSmJ0ZGhpaFA0KzU0emlKZEhPNFcxekFGam4zUVpIZVZDNU8rSkdSOWNZWW5aTHc4ZC92YmxZeXRpTWZPVwoyN3VzcW1RbmtPZDliNXozaTlvRDBvUUYyY1RObk85NzJkeTBuTmhiK0VMclpGNEpKUS9XVjB0Z083ST0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= - server: https://192.168.120.6:6443 - name: kubernetes - contexts: - - context: - cluster: kubernetes - user: kubernetes-admin - name: kubernetes-admin@kubernetes - current-context: kubernetes-admin@kubernetes - kind: Config - preferences: {} - users: - - name: kubernetes-admin - user: - client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akNDQWRxZ0F3SUJBZ0lJSm9EQWNpYWVkSVF3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB4TnpBNE1ETXdOek15TXpkYUZ3MHhPREE0TURNd056TXlNemxhTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQW1xd3duNlU0TFVFQkphMWUKQzIrUjM0K0oyZ3BBYTJ0aDVOZXdnS2NhUWQwaE5BODNjNE1IMDFVUjU3b3ByNUNFczFQVmVwMkZtczlpaFRITwo0SUpINjkxUVQvTUVJZE5iWTl0RXdDV21ia1lMbFBjc09yclErYTl5VGdxYm5IWjBONnJOdUZ4dDB2alRPSUR1CmRDMnB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_node.py deleted file mode 100644 index 9cfa206b54..0000000000 --- a/cloudify/scripts/configure_node.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python - -import subprocess -from cloudify import ctx -from cloudify.state import ctx_parameters as inputs - - -def execute_command(_command): - - ctx.logger.debug('_command {0}.'.format(_command)) - - subprocess_args = { - 'args': _command.split(), - 'stdout': subprocess.PIPE, - 'stderr': subprocess.PIPE - } - - ctx.logger.debug('subprocess_args {0}.'.format(subprocess_args)) - - process = subprocess.Popen(**subprocess_args) - output, error = process.communicate() - - ctx.logger.debug('command: {0} '.format(_command)) - ctx.logger.debug('output: {0} '.format(output)) - ctx.logger.debug('error: {0} '.format(error)) - ctx.logger.debug('process.returncode: {0} '.format(process.returncode)) - - if process.returncode: - ctx.logger.error('Running `{0}` returns error.'.format(_command)) - return False - - return output - - -if __name__ == '__main__': - - join_command = inputs['join_command'] - join_command = 'sudo {0} --skip-preflight-checks'.format(join_command) - execute_command(join_command) - - # Install weave-related utils - execute_command('sudo curl -L git.io/weave -o /usr/local/bin/weave') - execute_command('sudo chmod a+x /usr/local/bin/weave') - execute_command('sudo curl -L git.io/scope -o /usr/local/bin/scope') - execute_command('sudo chmod a+x /usr/local/bin/scope') - execute_command('/usr/local/bin/scope launch') - - hostname = execute_command('hostname') - ctx.instance.runtime_properties['hostname'] = hostname.rstrip('\n') diff --git a/cloudify/scripts/create.py b/cloudify/scripts/create.py deleted file mode 100644 index eb362a4558..0000000000 --- a/cloudify/scripts/create.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python - -import subprocess -from cloudify import ctx -from cloudify.exceptions import OperationRetry - - -def check_command(command): - - try: - process = subprocess.Popen( - command.split() - ) - except OSError: - return False - - output, error = process.communicate() - - ctx.logger.debug('command: {0} '.format(command)) - ctx.logger.debug('output: {0} '.format(output)) - ctx.logger.debug('error: {0} '.format(error)) - ctx.logger.debug('process.returncode: {0} '.format(process.returncode)) - - if process.returncode: - ctx.logger.error('Running `{0}` returns error.'.format(command)) - return False - - return True - - -def execute_command(_command): - - ctx.logger.debug('_command {0}.'.format(_command)) - - subprocess_args = { - 'args': _command.split(), - 'stdout': subprocess.PIPE, - 'stderr': subprocess.PIPE - } - - ctx.logger.debug('subprocess_args {0}.'.format(subprocess_args)) - - process = subprocess.Popen(**subprocess_args) - output, error = process.communicate() - - ctx.logger.debug('command: {0} '.format(_command)) - ctx.logger.debug('output: {0} '.format(output)) - ctx.logger.debug('error: {0} '.format(error)) - ctx.logger.debug('process.returncode: {0} '.format(process.returncode)) - - if process.returncode: - ctx.logger.error('Running `{0}` returns error.'.format(_command)) - return False - - return output - - -if __name__ == '__main__': - - docker_command = 'docker ps' - - if not check_command(docker_command): - raise OperationRetry('Waiting for docker to be installed.') - - finished = False - ps = execute_command('ps -ef') - for line in ps.split('\n'): - if '/usr/bin/python /usr/bin/cloud-init modules' in line: - ctx.logger.error('in line') - raise OperationRetry('Waiting for Cloud Init to finish.') - - ctx.logger.info('Docker is ready and Cloud Init finished.') diff --git a/cloudify/scripts/onap/configure_docker_secret_workaround.py b/cloudify/scripts/onap/configure_docker_secret_workaround.py deleted file mode 100644 index 6e9deff059..0000000000 --- a/cloudify/scripts/onap/configure_docker_secret_workaround.py +++ /dev/null @@ -1,40 +0,0 @@ -from fabric.api import run - -from cloudify import ctx -from cloudify.exceptions import NonRecoverableError - - -def _retrieve_namespace(): - namespace = ctx.node.properties.get( - 'namespace', - ctx.node.properties - .get('options', {}) - .get('namespace', None) - ) - - if not namespace: - raise NonRecoverableError( - 'Namespace is not defined (node={})'.format(ctx.node.name) - ) - - return namespace - - -def configure_secret(): - namespace = _retrieve_namespace() - ctx.logger.info( - 'Configuring docker secrets for namespace: {0}'.format(namespace) - ) - - command = 'kubectl create secret ' \ - 'docker-registry onap-docker-registry-key ' \ - '--docker-server=nexus3.onap.org:10001 ' \ - '--docker-username=docker ' \ - '--docker-password=docker ' \ - '--docker-email=email@email.com ' \ - '--namespace={0}'.format(namespace) - - ctx.logger.info('Command "{0}" will be executed'.format(command)) - run(command) - - ctx.logger.info('Docker secrets configured successfully') diff --git a/cloudify/scripts/onap/create_init_pod.py b/cloudify/scripts/onap/create_init_pod.py deleted file mode 100644 index c82172d15f..0000000000 --- a/cloudify/scripts/onap/create_init_pod.py +++ /dev/null @@ -1,65 +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" - ]) - - import yaml - import cloudify_kubernetes.tasks as kubernetes_plugin - - return yaml, kubernetes_plugin - - -def _retrieve_path(): - return ctx.node.properties.get('init_pod', None) - - -def _save_deployment_result(key): - result = ctx.instance.runtime_properties['kubernetes'] - ctx.instance.runtime_properties[key] = result - ctx.instance.runtime_properties['kubernetes'] = {} - - -def _do_create_init_pod(kubernetes_plugin, yaml): - ctx.logger.info('Creating init pod') - init_pod_file_path = _retrieve_path() - - if not init_pod_file_path: - raise NonRecoverableError('Init pod file is not defined.') - - temp_file_path = ctx.download_resource_and_render( - init_pod_file_path - ) - - with open(temp_file_path) as temp_file: - init_pod_file_content = temp_file.read() - init_pod_yaml_content = yaml.load(init_pod_file_content) - - kubernetes_plugin.resource_create(definition=init_pod_yaml_content) - _save_deployment_result('init_pod') - - ctx.logger.info('Init pod created successfully') - - -if __name__ == '__main__': - yaml, kubernetes_plugin = _import_or_install() - - _do_create_init_pod(kubernetes_plugin, yaml) - diff --git a/cloudify/scripts/onap/create_namespace.py b/cloudify/scripts/onap/create_namespace.py deleted file mode 100644 index c0f1f19680..0000000000 --- a/cloudify/scripts/onap/create_namespace.py +++ /dev/null @@ -1,101 +0,0 @@ -import pip - -from cloudify import ctx -from cloudify.exceptions import NonRecoverableError - - -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" - ]) - - import yaml - import cloudify_kubernetes.tasks as kubernetes_plugin - - return yaml, kubernetes_plugin - - -def _retrieve_namespace(): - namespace = ctx.node.properties.get( - 'namespace', - ctx.node.properties - .get('options', {}) - .get('namespace', None) - ) - - if not namespace: - raise NonRecoverableError( - 'Namespace is not defined (node={})'.format(ctx.node.name) - ) - - return namespace - - -def _prepare_namespace_resource_template(name): - return { - 'definition': { - 'apiVersion': 'v1', - 'kind': 'Namespace', - 'metadata': { - 'name': name, - 'labels': { - 'name': name - }, - }, - }, - 'api_mapping': { - 'create': { - 'api': 'CoreV1Api', - 'method': 'create_namespace', - 'payload': 'V1Namespace' - }, - 'read': { - 'api': 'CoreV1Api', - 'method': 'read_namespace', - }, - 'delete': { - 'api': 'CoreV1Api', - 'method': 'delete_namespace', - 'payload': 'V1DeleteOptions' - } - } - } - - -def _save_deployment_result(key): - result = ctx.instance.runtime_properties['kubernetes'] - ctx.instance.runtime_properties[key] = result - ctx.instance.runtime_properties['kubernetes'] = {} - - -def _do_create_namespace(kubernetes_plugin): - namespace = _retrieve_namespace() - ctx.logger.info('Creating namespace: {0}'.format(namespace)) - - namespace_resource_template = _prepare_namespace_resource_template( - namespace - ) - - ctx.logger.debug( - 'Kubernetes object which will be deployed: {0}' - .format(namespace_resource_template) - ) - - kubernetes_plugin.custom_resource_create(**namespace_resource_template) - _save_deployment_result('namespace') - ctx.logger.info('Namespace created successfully') - - -if __name__ == '__main__': - _, kubernetes_plugin = _import_or_install() - - _do_create_namespace(kubernetes_plugin) diff --git a/cloudify/scripts/onap/create_resources_services.py b/cloudify/scripts/onap/create_resources_services.py deleted file mode 100644 index 8548e29b70..0000000000 --- a/cloudify/scripts/onap/create_resources_services.py +++ /dev/null @@ -1,131 +0,0 @@ -import pip - -from cloudify import ctx - - -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 _save_deployment_result(key): - result = ctx.instance.runtime_properties['kubernetes'] - ctx.instance.runtime_properties[key] = result - ctx.instance.runtime_properties['kubernetes'] = {} - - -def _do_create_resources(kubernetes_plugin, yaml, jinja_env, values): - for path in _retrieve_resources_paths(): - ctx.logger.info('Creating 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) - - kubernetes_plugin.resource_create(definition=content) - _save_deployment_result( - 'resource_{0}'.format(content['metadata']['name']) - ) - - ctx.logger.info('Resources created successfully') - - -def _do_create_services(kubernetes_plugin, yaml, jinja_env, values): - ctx.logger.info('Creating 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) - - kubernetes_plugin.resource_create(definition=content) - _save_deployment_result( - 'service_{0}'.format(content['metadata']['name']) - ) - - ctx.logger.info('Services created successfully') - - -if __name__ == '__main__': - yaml, kubernetes_plugin, jinja2 = _import_or_install() - jinja_env = _init_jinja(jinja2) - values = _retrieve_values(yaml) - - _do_create_resources(kubernetes_plugin, yaml, jinja_env, values) - _do_create_services(kubernetes_plugin, yaml, jinja_env, values) - diff --git a/cloudify/scripts/onap/delete_init_pod.py b/cloudify/scripts/onap/delete_init_pod.py deleted file mode 100644 index 1da805b959..0000000000 --- a/cloudify/scripts/onap/delete_init_pod.py +++ /dev/null @@ -1,64 +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" - ]) - - import yaml - import cloudify_kubernetes.tasks as kubernetes_plugin - - return yaml, kubernetes_plugin - - -def _retrieve_path(): - return ctx.node.properties.get('init_pod', None) - - -def _set_deployment_result(key): - result = ctx.instance.runtime_properties.pop(key) - ctx.instance.runtime_properties['kubernetes'] = result - - -def _do_delete_init_pod(kubernetes_plugin, yaml): - ctx.logger.info('Deleting init pod') - init_pod_file_path = _retrieve_path() - - if not init_pod_file_path: - raise NonRecoverableError('Init pod file is not defined.') - - temp_file_path = ctx.download_resource_and_render( - init_pod_file_path - ) - - with open(temp_file_path) as temp_file: - init_pod_file_content = temp_file.read() - init_pod_yaml_content = yaml.load(init_pod_file_content) - - _set_deployment_result('init_pod') - kubernetes_plugin.resource_delete(definition=init_pod_yaml_content) - - ctx.logger.info('Init pod deleted successfully') - - -if __name__ == '__main__': - yaml, kubernetes_plugin = _import_or_install() - - _do_delete_init_pod(kubernetes_plugin, yaml) - diff --git a/cloudify/scripts/onap/delete_namespace.py b/cloudify/scripts/onap/delete_namespace.py deleted file mode 100644 index 6973e59944..0000000000 --- a/cloudify/scripts/onap/delete_namespace.py +++ /dev/null @@ -1,101 +0,0 @@ -import pip - -from cloudify import ctx -from cloudify.exceptions import NonRecoverableError - - -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" - ]) - - import yaml - import cloudify_kubernetes.tasks as kubernetes_plugin - - return yaml, kubernetes_plugin - - -def _retrieve_namespace(): - namespace = ctx.node.properties.get( - 'namespace', - ctx.node.properties - .get('options', {}) - .get('namespace', None) - ) - - if not namespace: - raise NonRecoverableError( - 'Namespace is not defined (node={})'.format(ctx.node.name) - ) - - return namespace - - -def _prepare_namespace_resource_template(name): - return { - 'definition': { - 'apiVersion': 'v1', - 'kind': 'Namespace', - 'metadata': { - 'name': name, - 'labels': { - 'name': name - }, - }, - }, - 'api_mapping': { - 'create': { - 'api': 'CoreV1Api', - 'method': 'create_namespace', - 'payload': 'V1Namespace' - }, - 'read': { - 'api': 'CoreV1Api', - 'method': 'read_namespace', - }, - 'delete': { - 'api': 'CoreV1Api', - 'method': 'delete_namespace', - 'payload': 'V1DeleteOptions' - } - } - } - - -def _set_deployment_result(key): - result = ctx.instance.runtime_properties.pop(key) - ctx.instance.runtime_properties['kubernetes'] = result - - -def _do_delete_namespace(kubernetes_plugin): - namespace = _retrieve_namespace() - ctx.logger.info('Deleting namespace: {0}'.format(namespace)) - - namespace_resource_template = _prepare_namespace_resource_template( - namespace - ) - - ctx.logger.debug( - 'Kubernetes object which will be deleted: {0}' - .format(namespace_resource_template) - ) - - _set_deployment_result('namespace') - kubernetes_plugin.custom_resource_delete(**namespace_resource_template) - ctx.logger.info('Namespace deleted successfully') - - -if __name__ == '__main__': - _, kubernetes_plugin = _import_or_install() - - _do_delete_namespace(kubernetes_plugin) - 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) - - diff --git a/cloudify/scripts/tasks.py b/cloudify/scripts/tasks.py deleted file mode 100644 index 035a780cb3..0000000000 --- a/cloudify/scripts/tasks.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python - -from fabric.api import run - - -def label_node(labels, hostname): - if labels: - label_list = [] - for key, value in labels.items(): - label_pair_string = '%s=%s' % (key, value) - label_list.append(label_pair_string) - label_string = ' '.join(label_list) - command = 'kubectl label nodes %s %s' % (hostname, label_string) - run(command) - - -def stop_node(hostname): - command = 'kubectl drain %s' % (hostname) - run(command) - - -def delete_node(hostname): - command = 'kubectl delete no %s' % (hostname) - run(command) diff --git a/cloudify/types/kubernetes.yaml b/cloudify/types/kubernetes.yaml deleted file mode 100644 index 1698aa210e..0000000000 --- a/cloudify/types/kubernetes.yaml +++ /dev/null @@ -1,91 +0,0 @@ -inputs: - - join_command: - type: string - - labels: - default: - app: { get_input: app_name } - - kubernetes_master_ip: - type: string - - kubernetes_master_agent_user: - default: { get_input: agent_user } - -node_types: - - cloudify.nodes.Kubernetes.Node: - derived_from: cloudify.nodes.Root - interfaces: - cloudify.interfaces.lifecycle: - create: - implementation: cloudify/scripts/create.py - configure: - implementation: cloudify/scripts/configure_node.py - inputs: - join_command: - default: { get_input: join_command } - start: - implementation: fabric.fabric_plugin.tasks.run_task - inputs: - tasks_file: - default: cloudify/scripts/tasks.py - task_name: - default: label_node - task_properties: - default: - hostname: { get_attribute: [ SELF, hostname ] } - labels: { get_input: labels } - fabric_env: - default: - host_string: { get_input: kubernetes_master_ip } - user: { get_input: kubernetes_master_agent_user } - key: { get_secret: agent_key_private } -# stop: -# implementation: fabric.fabric_plugin.tasks.run_task -# inputs: -# tasks_file: -# default: cloudify/scripts/tasks.py -# task_name: -# default: stop_node -# task_properties: -# default: -# hostname: { get_attribute: [ SELF, hostname ] } -# fabric_env: -# default: -# host_string: { get_input: kubernetes_master_ip } -# user: { get_input: kubernetes_master_agent_user } -# key: { get_secret: agent_key_private } - delete: - implementation: fabric.fabric_plugin.tasks.run_task - inputs: - tasks_file: - default: cloudify/scripts/tasks.py - task_name: - default: delete_node - task_properties: - default: - hostname: { get_attribute: [ SELF, hostname ] } - fabric_env: - default: - host_string: { get_input: kubernetes_master_ip } - user: { get_input: kubernetes_master_agent_user } - key: { get_secret: agent_key_private } - - cloudify.kubernetes.resources.Namespace: - derived_from: cloudify.kubernetes.resources.Main - properties: - _api_mapping: - default: - create: - api: CoreV1Api - method: create_namespace - payload: V1Namespace - read: - api: CoreV1Api - method: read_namespace - delete: - api: CoreV1Api - method: delete_namespace - payload: V1DeleteOptions diff --git a/cloudify/types/onap.yaml b/cloudify/types/onap.yaml deleted file mode 100644 index 7e9b83425e..0000000000 --- a/cloudify/types/onap.yaml +++ /dev/null @@ -1,89 +0,0 @@ -node_types: - cloudify.onap.kubernetes.Environment: - derived_from: cloudify.nodes.Root - properties: - namespace: - type: string - init_pod: - type: string - description: > - Path to init pod YAML file - options: - description: > - For compatibility with kubernetes plugin. - To be removed in the future. - default: {} - interfaces: - cloudify.interfaces.lifecycle: - create: - implementation: cloudify/scripts/onap/create_namespace.py - executor: central_deployment_agent - start: - implementation: cloudify/scripts/onap/create_init_pod.py - executor: central_deployment_agent - stop: - implementation: cloudify/scripts/onap/delete_init_pod.py - executor: central_deployment_agent - delete: - implementation: cloudify/scripts/onap/delete_namespace.py - executor: central_deployment_agent - - cloudify.onap.kubernetes.App: - derived_from: cloudify.nodes.Root - properties: - name: - type: string - description: > - Name of ONAP app - values: - type: string - description: > - Paths (relative, blueprint prespective) to values.yaml file - required: false - resources: - description: > - List of paths (relative, blueprint prespective) - to all kubernetes resources YAML files definition - default: [] - services: - type: string - description: > - Path (relative, blueprint prespective) - to kubernetes app services YAML file definition - default: [] - inputs: - description: > - Parameters required to create kubernetes resources for each app - default: {} - options: - description: > - For compatibility with kubernetes plugin. - To be removed in the future. - default: {} - interfaces: - cloudify.interfaces.lifecycle: - create: - implementation: cloudify/scripts/onap/create_namespace.py - executor: central_deployment_agent - configure: - implementation: fabric.fabric_plugin.tasks.run_task - executor: central_deployment_agent - inputs: - tasks_file: - default: cloudify/scripts/onap/configure_docker_secret_workaround.py - task_name: - default: configure_secret - fabric_env: - default: - host_string: { get_secret: kubernetes_master_ip } - user: { get_secret: agent_user } - key: { get_secret: agent_key_private } - start: - implementation: cloudify/scripts/onap/create_resources_services.py - executor: central_deployment_agent - stop: - implementation: cloudify/scripts/onap/delete_resources_services.py - executor: central_deployment_agent - delete: - implementation: cloudify/scripts/onap/delete_namespace.py - executor: central_deployment_agent |