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
6
# http://www.apache.org/licenses/LICENSE-2.0
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
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
24
class AutoScalingResourceGroup(aws_asg.AutoScalingGroup):
25
"""An autoscaling group that can scale arbitrary resources."""
28
RESOURCE, MAX_SIZE, MIN_SIZE, COOLDOWN, DESIRED_CAPACITY,
31
'resource', 'max_size', 'min_size', 'cooldown', 'desired_capacity',
35
_ROLLING_UPDATES_SCHEMA = (
36
MIN_IN_SERVICE, MAX_BATCH_SIZE, PAUSE_TIME,
38
'min_in_service', 'max_batch_size', 'pause_time',
42
OUTPUTS, OUTPUTS_LIST, CURRENT_SIZE,
44
'outputs', 'outputs_list', 'current_size',
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 '
57
MAX_SIZE: properties.Schema(
58
properties.Schema.INTEGER,
59
_('Maximum number of resources in the group.'),
62
constraints=[constraints.Range(min=0)],
64
MIN_SIZE: properties.Schema(
65
properties.Schema.INTEGER,
66
_('Minimum number of resources in the group.'),
69
constraints=[constraints.Range(min=0)]
71
COOLDOWN: properties.Schema(
72
properties.Schema.INTEGER,
73
_('Cooldown period, in seconds.'),
76
DESIRED_CAPACITY: properties.Schema(
77
properties.Schema.INTEGER,
78
_('Desired initial number of resources.'),
81
ROLLING_UPDATES: properties.Schema(
82
properties.Schema.MAP,
83
_('Policy for rolling updates for this scaling group.'),
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)],
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)],
98
PAUSE_TIME: properties.Schema(
99
properties.Schema.NUMBER,
100
_('The number of seconds to wait between batches of '
102
constraints=[constraints.Range(min=0)],
108
attributes_schema = {
109
OUTPUTS: attributes.Schema(
110
_("A map of resource names to the specified attribute of each "
111
"individual resource.")
113
OUTPUTS_LIST: attributes.Schema(
114
_("A list of the specified attribute of each individual resource.")
116
CURRENT_SIZE: attributes.Schema(
117
_("The current size of AutoscalingResourceGroup.")
121
def _get_instance_definition(self):
122
rsrc = self.properties[self.RESOURCE]
123
return rsrc_defn.ResourceDefinition(
125
properties=rsrc.get('properties'),
126
metadata=rsrc.get('metadata'))
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.
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])
142
def _create_template(self, num_instances, num_replace=0,
143
template_version=('heat_template_version',
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)
150
def FnGetAtt(self, key, *path):
151
if key == self.CURRENT_SIZE:
152
return grouputils.get_size(self)
154
members = grouputils.get_members(self)
155
attrs = ((rsrc.name, rsrc.FnGetAtt(*path)) for rsrc in members)
156
if key == self.OUTPUTS:
158
if key == self.OUTPUTS_LIST:
159
return [value for name, value in attrs]
161
raise exception.InvalidTemplateAttribute(resource=self.name,
165
def resource_mapping():
167
'OS::Heat::AutoScalingGroup': AutoScalingResourceGroup,