blob: 9c2eaddffeead212646c6e58b39b555a47307b9f [file] [log] [blame]
Zack Williams8af11362016-10-07 16:01:09 -07001from service import XOSService
Scott Baker31acc652016-06-23 15:47:56 -07002from core.models import ServiceAttribute
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +00003from services.monitoring.models import CeilometerService
Scott Baker31acc652016-06-23 15:47:56 -07004
Scott Baker31acc652016-06-23 15:47:56 -07005class XOSCeilometerService(XOSService):
6 provides = "tosca.nodes.CeilometerService"
7 xos_model = CeilometerService
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +00008 copyin_props = ["view_url", "icon_url", "enabled", "published", "private_key_fn", "public_key", "versionNumber", "ceilometer_pub_sub_url"]
Scott Baker31acc652016-06-23 15:47:56 -07009
10 def set_service_attr(self, obj, prop_name, value):
11 value = self.try_intrinsic_function(value)
12 if value:
13 attrs = ServiceAttribute.objects.filter(service=obj, name=prop_name)
14 if attrs:
15 attr = attrs[0]
16 if attr.value != value:
17 self.info("updating attribute %s" % prop_name)
18 attr.value = value
19 attr.save()
20 else:
21 self.info("adding attribute %s" % prop_name)
22 ta = ServiceAttribute(service=obj, name=prop_name, value=value)
23 ta.save()
24
25 def postprocess(self, obj):
26 props = self.nodetemplate.get_properties()
27 for (k,d) in props.items():
28 v = d.value
29 if k.startswith("config_"):
30 self.set_service_attr(obj, k, v)
31 elif k.startswith("rest_"):
32 self.set_service_attr(obj, k, v)
33