Adds Stack Update
[snaps.git] / snaps / config / stack.py
1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 #                    and others.  All rights reserved.
3 #
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:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 STACK_DELETE_TIMEOUT = 1200
17 STACK_COMPLETE_TIMEOUT = 1200
18 STACK_UPDATE_TIMEOUT = 1200
19 POLL_INTERVAL = 3
20 STATUS_CREATE_FAILED = 'CREATE_FAILED'
21 STATUS_CREATE_COMPLETE = 'CREATE_COMPLETE'
22 STATUS_UPDATE_FAILED = 'UPDATE_FAILED'
23 STATUS_UPDATE_COMPLETE = 'UPDATE_COMPLETE'
24 STATUS_DELETE_COMPLETE = 'DELETE_COMPLETE'
25 STATUS_DELETE_FAILED = 'DELETE_FAILED'
26
27
28 class StackConfig(object):
29     """
30     Configuration for Heat stack
31     """
32
33     def __init__(self, **kwargs):
34         """
35         Constructor
36         :param name: the stack's name (required)
37         :param template: the heat template in dict() format (required if
38                          template_path attribute is None)
39         :param template_path: the location of the heat template file (required
40                               if template attribute is None)
41         :param resource_files: List of file paths to the resources referred to
42                                by the template
43         :param env_values: dict() of strings for substitution of template
44                            default values (optional)
45         """
46
47         self.name = kwargs.get('name')
48         self.template = kwargs.get('template')
49         self.template_path = kwargs.get('template_path')
50         self.resource_files = kwargs.get('resource_files')
51         self.env_values = kwargs.get('env_values')
52
53         if 'stack_create_timeout' in kwargs:
54             self.stack_create_timeout = kwargs['stack_create_timeout']
55         else:
56             self.stack_create_timeout = STACK_COMPLETE_TIMEOUT
57
58         if not self.name:
59             raise StackConfigError('name is required')
60
61         if not self.template and not self.template_path:
62             raise StackConfigError('A Heat template is required')
63
64         if self.resource_files and not isinstance(self.resource_files, list):
65             raise StackConfigError(
66                 'resource_files must be a list when not None')
67
68     def __eq__(self, other):
69         return (self.name == other.name and
70                 self.template == other.template and
71                 self.template_path == other.template_path and
72                 self.env_values == other.env_values and
73                 self.stack_create_timeout == other.stack_create_timeout)
74
75
76 class StackConfigError(Exception):
77     """
78     Exception to be thrown when an stack configuration are incorrect
79     """