move plugins from from ccsdk to dcaegen2
[dcaegen2/platform/plugins.git] / helm / plugin / workflows.py
1 # ============LICENSE_START==========================================
2 # ===================================================================
3 # Copyright (c) 2018-2020 AT&T
4 # Copyright (c) 2020 Pantheon.tech. All rights reserved.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #         http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END============================================
18
19 from cloudify.decorators import workflow
20 from cloudify.workflows import ctx
21 from cloudify.exceptions import NonRecoverableError
22 import json
23 import yaml
24 import base64
25
26
27 @workflow
28 def upgrade(node_instance_id, config_set, config, config_url, config_format,
29             chart_version, chart_repo_url, repo_user, repo_user_password, **kwargs):
30     node_instance = ctx.get_node_instance(node_instance_id)
31
32     if not node_instance_id:
33         raise NonRecoverableError(
34             'No such node_instance_id in deployment: {0}.'.format(
35                 node_instance_id))
36
37     kwargs = {}
38     kwargs['config'] = ''
39     kwargs['chart_version'] = str(chart_version)
40     kwargs['chart_repo'] = str(chart_repo_url)
41     kwargs['config_set'] = str(config_set)
42     kwargs['config_json'] = str(config)
43     kwargs['config_url'] = str(config_url)
44     kwargs['config_format'] = str(config_format)
45     kwargs['repo_user'] = str(repo_user)
46     kwargs['repo_user_passwd'] = str(repo_user_password)
47     operation_args = {'operation': 'upgrade', }
48     operation_args['kwargs'] = kwargs
49     node_instance.execute_operation(**operation_args)
50
51
52 @workflow
53 def rollback(node_instance_id, revision, **kwargs):
54     node_instance = ctx.get_node_instance(node_instance_id)
55
56     if not node_instance_id:
57         raise NonRecoverableError(
58             'No such node_instance_id in deployment: {0}.'.format(
59                 node_instance_id))
60
61     kwargs = {}
62     kwargs['revision'] = str(revision)
63     operation_args = {'operation': 'rollback', }
64     operation_args['kwargs'] = kwargs
65     node_instance.execute_operation(**operation_args)
66
67 @workflow
68 def status(**kwargs):
69
70     for node in ctx.nodes:
71         for node_instance in node.instances:
72             kwargs = {}
73             operation_args = {'operation': 'status', }
74             operation_args['kwargs'] = kwargs
75             node_instance.execute_operation(**operation_args)