Provide a signal URL attribute for alarms
This patch adds a new attribute to scaling policies allowing it to be called by the ceilometer service user using trusts on alarming. Implements: blueprint trust-alarm-urls Change-Id: Ic039d9aaf3804ab09e3d546d3ae55a18b528d585
This commit is contained in:
parent
321c705a9a
commit
6b573daa96
|
@ -22,6 +22,7 @@ from heat.engine import constraints
|
|||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources import signal_responder
|
||||
from heat.engine import support
|
||||
from heat.scaling import cooldown
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -47,9 +48,9 @@ class AutoScalingPolicy(signal_responder.SignalResponder,
|
|||
'exact_capacity', 'change_in_capacity', 'percent_change_in_capacity')
|
||||
|
||||
ATTRIBUTES = (
|
||||
ALARM_URL,
|
||||
ALARM_URL, SIGNAL_URL
|
||||
) = (
|
||||
'alarm_url',
|
||||
'alarm_url', 'signal_url'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
|
@ -101,6 +102,11 @@ class AutoScalingPolicy(signal_responder.SignalResponder,
|
|||
ALARM_URL: attributes.Schema(
|
||||
_("A signed url to handle the alarm.")
|
||||
),
|
||||
SIGNAL_URL: attributes.Schema(
|
||||
_("A url to handle the alarm using native API."),
|
||||
support_status=support.SupportStatus(version='2015.2'),
|
||||
type=attributes.Schema.STRING
|
||||
),
|
||||
}
|
||||
|
||||
def validate(self):
|
||||
|
@ -182,8 +188,10 @@ class AutoScalingPolicy(signal_responder.SignalResponder,
|
|||
self.properties[self.SCALING_ADJUSTMENT]))
|
||||
|
||||
def _resolve_attribute(self, name):
|
||||
if name == self.ALARM_URL and self.resource_id is not None:
|
||||
if name == self.ALARM_URL:
|
||||
return six.text_type(self._get_signed_url())
|
||||
elif name == self.SIGNAL_URL:
|
||||
return six.text_type(self._get_signal_url())
|
||||
|
||||
def FnGetRefId(self):
|
||||
return resource.Resource.FnGetRefId(self)
|
||||
|
|
|
@ -104,3 +104,18 @@ class SignalResponder(stack_user.StackUser):
|
|||
|
||||
self.data_set('ec2_signed_url', url)
|
||||
return url
|
||||
|
||||
def _get_signal_url(self):
|
||||
stored = self.data().get('signal_url')
|
||||
if stored is not None:
|
||||
return stored
|
||||
|
||||
url = self.client_plugin('heat').get_heat_url()
|
||||
host_url = urlparse.urlparse(url)
|
||||
path = self.identifier().url_path()
|
||||
|
||||
url = urlparse.urlunsplit(
|
||||
(host_url.scheme, host_url.netloc, 'v1/%s/signal' % path, '', ''))
|
||||
|
||||
self.data_set('signal_url', url)
|
||||
return url
|
||||
|
|
|
@ -237,3 +237,16 @@ class ScalingPolicyAttrTest(common.HeatTestCase):
|
|||
self.assertEqual('SignatureVersion', args[3].split('=')[0])
|
||||
self.assertEqual('Signature', args[4].split('=')[0])
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_signal_attribute(self):
|
||||
self.m.StubOutWithMock(self.stack.clients.client_plugin('heat'),
|
||||
'get_heat_url')
|
||||
self.stack.clients.client_plugin('heat').get_heat_url().AndReturn(
|
||||
'http://server.test:8000/v1')
|
||||
self.m.ReplayAll()
|
||||
self.assertEqual(
|
||||
'http://server.test:8000/v1/test_tenant_id/stacks/'
|
||||
'%s/%s/resources/my-policy/signal' % (
|
||||
self.stack.name, self.stack.id),
|
||||
self.policy.FnGetAtt('signal_url'))
|
||||
self.m.VerifyAll()
|
||||
|
|
Loading…
Reference in New Issue