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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Corey Bryant, Corey Bryant, James Page
  • Date: 2015-07-07 17:06:19 UTC
  • mfrom: (1.1.26) (45.1.1 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20150707170619-hra2dbjpfofpou4s
Tags: 1:5.0.0~b1-0ubuntu1
[ Corey Bryant ]
* New upstream milestone for OpenStack Liberty:
  - d/control: Align (build-)depends with upstream.
  - d/p/fix-requirements.patch: Rebased.
  - d/p/sudoers_patch.patch: Rebased.

[ James Page ]
* d/s/options: Ignore any removal of egg-info data during package clean.
* d/control: Drop MySQL and PostgreSQL related BD's, not required for unit
  testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
26
27
 
27
28
LOG = logging.getLogger(__name__)
37
38
    """
38
39
    PROPERTIES = (
39
40
        AUTO_SCALING_GROUP_NAME, SCALING_ADJUSTMENT, ADJUSTMENT_TYPE,
40
 
        COOLDOWN,
 
41
        COOLDOWN, MIN_ADJUSTMENT_STEP
41
42
    ) = (
42
43
        'auto_scaling_group_id', 'scaling_adjustment', 'adjustment_type',
43
 
        'cooldown',
 
44
        'cooldown', 'min_adjustment_step',
44
45
    )
45
46
 
46
47
    EXACT_CAPACITY, CHANGE_IN_CAPACITY, PERCENT_CHANGE_IN_CAPACITY = (
47
48
        'exact_capacity', 'change_in_capacity', 'percent_change_in_capacity')
48
49
 
49
50
    ATTRIBUTES = (
50
 
        ALARM_URL,
 
51
        ALARM_URL, SIGNAL_URL
51
52
    ) = (
52
 
        'alarm_url',
 
53
        'alarm_url', 'signal_url'
53
54
    )
54
55
 
55
56
    properties_schema = {
81
82
            _('Cooldown period, in seconds.'),
82
83
            update_allowed=True
83
84
        ),
 
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.'),
 
91
            constraints=[
 
92
                constraints.Range(
 
93
                    min=0,
 
94
                ),
 
95
            ],
 
96
            update_allowed=True
 
97
        ),
 
98
 
84
99
    }
85
100
 
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
 
105
        ),
 
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
89
110
        ),
90
111
    }
91
112
 
 
113
    def validate(self):
 
114
        """
 
115
        Add validation for min_adjustment_step
 
116
        """
 
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)
 
126
 
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})
126
161
 
127
162
        if alarm_state != 'alarm':
128
 
            return
 
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]})
134
 
            return
 
169
            raise resource.NoActionRequired()
135
170
 
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])
150
186
 
151
187
        self._cooldown_timestamp("%s : %s" %
152
188
                                 (self.properties[self.ADJUSTMENT_TYPE],
153
189
                                  self.properties[self.SCALING_ADJUSTMENT]))
154
190
 
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())
158
196
 
159
197
    def FnGetRefId(self):
160
198
        return resource.Resource.FnGetRefId(self)