Matteo Scandolo | eb0d11c | 2017-08-08 13:05:26 -0700 | [diff] [blame] | 1 | |
| 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 Williams | 8af1136 | 2016-10-07 16:01:09 -0700 | [diff] [blame] | 17 | from service import XOSService |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 18 | from core.models import ServiceAttribute |
Srikanth Vavilapalli | d84b7b7 | 2016-06-28 00:19:07 +0000 | [diff] [blame] | 19 | from services.monitoring.models import CeilometerService |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 20 | |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 21 | class XOSCeilometerService(XOSService): |
| 22 | provides = "tosca.nodes.CeilometerService" |
| 23 | xos_model = CeilometerService |
Srikanth Vavilapalli | 71aa28d | 2017-01-31 00:43:13 +0000 | [diff] [blame] | 24 | copyin_props = ["view_url", "icon_url", "enabled", "published", "private_key_fn", "public_key", "versionNumber", "ceilometer_enable_pub_sub", "ceilometer_pub_sub_url"] |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 25 | |
| 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 | |