~ubuntu-branches/ubuntu/wily/heat/wily-proposed

« back to all changes in this revision

Viewing changes to heat/engine/resources/openstack/autoscaling_group.py

  • Committer: Package Import Robot
  • Author(s): James Page, Corey Bryant, James Page
  • Date: 2015-03-30 11:11:18 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20150330111118-2qpycylx6swu4yhj
Tags: 2015.1~b3-0ubuntu1
[ Corey Bryant ]
* New upstream milestone release for OpenStack kilo:
  - d/control: Align with upstream dependencies.
  - d/p/sudoers_patch.patch: Rebased.
  - d/p/fix-requirements.patch: Rebased.

[ James Page ]
* d/p/fixup-assert-regex.patch: Tweak test to use assertRegexpMatches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
3
 
#    not use this file except in compliance with the License. You may obtain
4
 
#    a copy of the License at
5
 
#
6
 
#         http://www.apache.org/licenses/LICENSE-2.0
7
 
#
8
 
#    Unless required by applicable law or agreed to in writing, software
9
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
 
#    License for the specific language governing permissions and limitations
12
 
#    under the License.
13
 
 
14
 
from heat.common import exception
15
 
from heat.common import grouputils
16
 
from heat.common.i18n import _
17
 
from heat.engine import attributes
18
 
from heat.engine import constraints
19
 
from heat.engine import properties
20
 
from heat.engine.resources.aws import autoscaling_group as aws_asg
21
 
from heat.engine import rsrc_defn
22
 
 
23
 
 
24
 
class AutoScalingResourceGroup(aws_asg.AutoScalingGroup):
25
 
    """An autoscaling group that can scale arbitrary resources."""
26
 
 
27
 
    PROPERTIES = (
28
 
        RESOURCE, MAX_SIZE, MIN_SIZE, COOLDOWN, DESIRED_CAPACITY,
29
 
        ROLLING_UPDATES,
30
 
    ) = (
31
 
        'resource', 'max_size', 'min_size', 'cooldown', 'desired_capacity',
32
 
        'rolling_updates',
33
 
    )
34
 
 
35
 
    _ROLLING_UPDATES_SCHEMA = (
36
 
        MIN_IN_SERVICE, MAX_BATCH_SIZE, PAUSE_TIME,
37
 
    ) = (
38
 
        'min_in_service', 'max_batch_size', 'pause_time',
39
 
    )
40
 
 
41
 
    ATTRIBUTES = (
42
 
        OUTPUTS, OUTPUTS_LIST, CURRENT_SIZE,
43
 
    ) = (
44
 
        'outputs', 'outputs_list', 'current_size',
45
 
    )
46
 
 
47
 
    properties_schema = {
48
 
        RESOURCE: properties.Schema(
49
 
            properties.Schema.MAP,
50
 
            _('Resource definition for the resources in the group, in HOT '
51
 
              'format. The value of this property is the definition of a '
52
 
              'resource just as if it had been declared in the template '
53
 
              'itself.'),
54
 
            required=True,
55
 
            update_allowed=True,
56
 
        ),
57
 
        MAX_SIZE: properties.Schema(
58
 
            properties.Schema.INTEGER,
59
 
            _('Maximum number of resources in the group.'),
60
 
            required=True,
61
 
            update_allowed=True,
62
 
            constraints=[constraints.Range(min=0)],
63
 
        ),
64
 
        MIN_SIZE: properties.Schema(
65
 
            properties.Schema.INTEGER,
66
 
            _('Minimum number of resources in the group.'),
67
 
            required=True,
68
 
            update_allowed=True,
69
 
            constraints=[constraints.Range(min=0)]
70
 
        ),
71
 
        COOLDOWN: properties.Schema(
72
 
            properties.Schema.INTEGER,
73
 
            _('Cooldown period, in seconds.'),
74
 
            update_allowed=True
75
 
        ),
76
 
        DESIRED_CAPACITY: properties.Schema(
77
 
            properties.Schema.INTEGER,
78
 
            _('Desired initial number of resources.'),
79
 
            update_allowed=True
80
 
        ),
81
 
        ROLLING_UPDATES: properties.Schema(
82
 
            properties.Schema.MAP,
83
 
            _('Policy for rolling updates for this scaling group.'),
84
 
            required=False,
85
 
            update_allowed=True,
86
 
            schema={
87
 
                MIN_IN_SERVICE: properties.Schema(
88
 
                    properties.Schema.NUMBER,
89
 
                    _('The minimum number of resources in service while '
90
 
                      'rolling updates are being executed.'),
91
 
                    constraints=[constraints.Range(min=0)],
92
 
                    default=0),
93
 
                MAX_BATCH_SIZE: properties.Schema(
94
 
                    properties.Schema.NUMBER,
95
 
                    _('The maximum number of resources to replace at once.'),
96
 
                    constraints=[constraints.Range(min=0)],
97
 
                    default=1),
98
 
                PAUSE_TIME: properties.Schema(
99
 
                    properties.Schema.NUMBER,
100
 
                    _('The number of seconds to wait between batches of '
101
 
                      'updates.'),
102
 
                    constraints=[constraints.Range(min=0)],
103
 
                    default=0),
104
 
            },
105
 
        ),
106
 
    }
107
 
 
108
 
    attributes_schema = {
109
 
        OUTPUTS: attributes.Schema(
110
 
            _("A map of resource names to the specified attribute of each "
111
 
              "individual resource.")
112
 
        ),
113
 
        OUTPUTS_LIST: attributes.Schema(
114
 
            _("A list of the specified attribute of each individual resource.")
115
 
        ),
116
 
        CURRENT_SIZE: attributes.Schema(
117
 
            _("The current size of AutoscalingResourceGroup.")
118
 
        ),
119
 
    }
120
 
 
121
 
    def _get_instance_definition(self):
122
 
        rsrc = self.properties[self.RESOURCE]
123
 
        return rsrc_defn.ResourceDefinition(
124
 
            None, rsrc['type'],
125
 
            properties=rsrc.get('properties'),
126
 
            metadata=rsrc.get('metadata'))
127
 
 
128
 
    def _lb_reload(self, exclude=None):
129
 
        """AutoScalingResourceGroup does not maintain load balancer
130
 
        connections, so we just ignore calls to update the LB.
131
 
        """
132
 
        pass
133
 
 
134
 
    def _try_rolling_update(self, prop_diff):
135
 
        if (self.properties[self.ROLLING_UPDATES] and
136
 
                self.RESOURCE in prop_diff):
137
 
            policy = self.properties[self.ROLLING_UPDATES]
138
 
            self._replace(policy[self.MIN_IN_SERVICE],
139
 
                          policy[self.MAX_BATCH_SIZE],
140
 
                          policy[self.PAUSE_TIME])
141
 
 
142
 
    def _create_template(self, num_instances, num_replace=0,
143
 
                         template_version=('heat_template_version',
144
 
                                           '2013-05-23')):
145
 
        """Create a template in the HOT format for the nested stack."""
146
 
        return super(AutoScalingResourceGroup,
147
 
                     self)._create_template(num_instances, num_replace,
148
 
                                            template_version=template_version)
149
 
 
150
 
    def FnGetAtt(self, key, *path):
151
 
        if key == self.CURRENT_SIZE:
152
 
            return grouputils.get_size(self)
153
 
        if path:
154
 
            members = grouputils.get_members(self)
155
 
            attrs = ((rsrc.name, rsrc.FnGetAtt(*path)) for rsrc in members)
156
 
            if key == self.OUTPUTS:
157
 
                return dict(attrs)
158
 
            if key == self.OUTPUTS_LIST:
159
 
                return [value for name, value in attrs]
160
 
 
161
 
        raise exception.InvalidTemplateAttribute(resource=self.name,
162
 
                                                 key=key)
163
 
 
164
 
 
165
 
def resource_mapping():
166
 
    return {
167
 
        'OS::Heat::AutoScalingGroup': AutoScalingResourceGroup,
168
 
    }