blob: e9f945c007ff5117d4d7aab2035f26d020943cb7 [file] [log] [blame]
Matteo Scandoloeb0d11c2017-08-08 13:05:26 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Zack Williams8af11362016-10-07 16:01:09 -070017from service import XOSService
Scott Baker31acc652016-06-23 15:47:56 -070018from core.models import ServiceAttribute
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +000019from services.monitoring.models import CeilometerService
Scott Baker31acc652016-06-23 15:47:56 -070020
Scott Baker31acc652016-06-23 15:47:56 -070021class XOSCeilometerService(XOSService):
22 provides = "tosca.nodes.CeilometerService"
23 xos_model = CeilometerService
Srikanth Vavilapalli71aa28d2017-01-31 00:43:13 +000024 copyin_props = ["view_url", "icon_url", "enabled", "published", "private_key_fn", "public_key", "versionNumber", "ceilometer_enable_pub_sub", "ceilometer_pub_sub_url"]
Scott Baker31acc652016-06-23 15:47:56 -070025
26 def set_service_attr(self, obj, prop_name, value):
27 value = self.try_intrinsic_function(value)
28 if value:
29 attrs = ServiceAttribute.objects.filter(service=obj, name=prop_name)
30 if attrs:
31 attr = attrs[0]
32 if attr.value != value:
33 self.info("updating attribute %s" % prop_name)
34 attr.value = value
35 attr.save()
36 else:
37 self.info("adding attribute %s" % prop_name)
38 ta = ServiceAttribute(service=obj, name=prop_name, value=value)
39 ta.save()
40
41 def postprocess(self, obj):
42 props = self.nodetemplate.get_properties()
43 for (k,d) in props.items():
44 v = d.value
45 if k.startswith("config_"):
46 self.set_service_attr(obj, k, v)
47 elif k.startswith("rest_"):
48 self.set_service_attr(obj, k, v)
49