22
22
from heat.engine import properties
23
23
from heat.engine import resource
24
24
from heat.engine.resources import signal_responder
25
from heat.engine import support
25
26
from heat.scaling import cooldown
27
28
LOG = logging.getLogger(__name__)
39
40
AUTO_SCALING_GROUP_NAME, SCALING_ADJUSTMENT, ADJUSTMENT_TYPE,
41
COOLDOWN, MIN_ADJUSTMENT_STEP
42
43
'auto_scaling_group_id', 'scaling_adjustment', 'adjustment_type',
44
'cooldown', 'min_adjustment_step',
46
47
EXACT_CAPACITY, CHANGE_IN_CAPACITY, PERCENT_CHANGE_IN_CAPACITY = (
47
48
'exact_capacity', 'change_in_capacity', 'percent_change_in_capacity')
53
'alarm_url', 'signal_url'
55
56
properties_schema = {
81
82
_('Cooldown period, in seconds.'),
82
83
update_allowed=True
85
MIN_ADJUSTMENT_STEP: properties.Schema(
86
properties.Schema.INTEGER,
87
_('Minimum number of resources that are added or removed '
88
'when the AutoScaling group scales up or down. This can '
89
'be used only when specifying percent_change_in_capacity '
90
'for the adjustment_type property.'),
86
101
attributes_schema = {
87
102
ALARM_URL: attributes.Schema(
88
_("A signed url to handle the alarm.")
103
_("A signed url to handle the alarm."),
104
type=attributes.Schema.STRING
106
SIGNAL_URL: attributes.Schema(
107
_("A url to handle the alarm using native API."),
108
support_status=support.SupportStatus(version='5.0.0'),
109
type=attributes.Schema.STRING
115
Add validation for min_adjustment_step
117
super(AutoScalingPolicy, self).validate()
118
adjustment_type = self.properties.get(self.ADJUSTMENT_TYPE)
119
adjustment_step = self.properties.get(self.MIN_ADJUSTMENT_STEP)
120
if (adjustment_type != self.PERCENT_CHANGE_IN_CAPACITY
121
and adjustment_step is not None):
122
raise exception.ResourcePropertyValueDependency(
123
prop1=self.MIN_ADJUSTMENT_STEP,
124
prop2=self.ADJUSTMENT_TYPE,
125
value=self.PERCENT_CHANGE_IN_CAPACITY)
92
127
def handle_create(self):
93
128
super(AutoScalingPolicy, self).handle_create()
94
129
self.resource_id_set(self._get_user_id())
125
160
{'name': self.name, 'state': alarm_state})
127
162
if alarm_state != 'alarm':
163
raise resource.NoActionRequired()
129
164
if self._cooldown_inprogress():
130
165
LOG.info(_LI("%(name)s NOT performing scaling action, "
131
166
"cooldown %(cooldown)s"),
132
167
{'name': self.name,
133
168
'cooldown': self.properties[self.COOLDOWN]})
169
raise resource.NoActionRequired()
136
171
asgn_id = self.properties[self.AUTO_SCALING_GROUP_NAME]
137
172
group = self.stack.resource_by_refid(asgn_id)
146
181
{'name': self.name, 'group': group.name, 'asgn_id': asgn_id,
147
182
'filter': self.properties[self.SCALING_ADJUSTMENT]})
148
183
adjustment_type = self._get_adjustement_type()
149
group.adjust(self.properties[self.SCALING_ADJUSTMENT], adjustment_type)
184
group.adjust(self.properties[self.SCALING_ADJUSTMENT], adjustment_type,
185
self.properties[self.MIN_ADJUSTMENT_STEP])
151
187
self._cooldown_timestamp("%s : %s" %
152
188
(self.properties[self.ADJUSTMENT_TYPE],
153
189
self.properties[self.SCALING_ADJUSTMENT]))
155
191
def _resolve_attribute(self, name):
156
if name == self.ALARM_URL and self.resource_id is not None:
192
if name == self.ALARM_URL:
157
193
return six.text_type(self._get_signed_url())
194
elif name == self.SIGNAL_URL:
195
return six.text_type(self._get_signal_url())
159
197
def FnGetRefId(self):
160
198
return resource.Resource.FnGetRefId(self)