Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 1 | import os |
| 2 | import pdb |
| 3 | import sys |
| 4 | import tempfile |
| 5 | sys.path.append("/opt/tosca") |
| 6 | from translator.toscalib.tosca_template import ToscaTemplate |
| 7 | |
| 8 | from core.models import ServiceAttribute |
Srikanth Vavilapalli | d84b7b7 | 2016-06-28 00:19:07 +0000 | [diff] [blame] | 9 | from services.monitoring.models import CeilometerService |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 10 | |
| 11 | from service import XOSService |
| 12 | |
| 13 | class XOSCeilometerService(XOSService): |
| 14 | provides = "tosca.nodes.CeilometerService" |
| 15 | xos_model = CeilometerService |
Srikanth Vavilapalli | d84b7b7 | 2016-06-28 00:19:07 +0000 | [diff] [blame] | 16 | copyin_props = ["view_url", "icon_url", "enabled", "published", "private_key_fn", "public_key", "versionNumber", "ceilometer_pub_sub_url"] |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 17 | |
| 18 | def set_service_attr(self, obj, prop_name, value): |
| 19 | value = self.try_intrinsic_function(value) |
| 20 | if value: |
| 21 | attrs = ServiceAttribute.objects.filter(service=obj, name=prop_name) |
| 22 | if attrs: |
| 23 | attr = attrs[0] |
| 24 | if attr.value != value: |
| 25 | self.info("updating attribute %s" % prop_name) |
| 26 | attr.value = value |
| 27 | attr.save() |
| 28 | else: |
| 29 | self.info("adding attribute %s" % prop_name) |
| 30 | ta = ServiceAttribute(service=obj, name=prop_name, value=value) |
| 31 | ta.save() |
| 32 | |
| 33 | def postprocess(self, obj): |
| 34 | props = self.nodetemplate.get_properties() |
| 35 | for (k,d) in props.items(): |
| 36 | v = d.value |
| 37 | if k.startswith("config_"): |
| 38 | self.set_service_attr(obj, k, v) |
| 39 | elif k.startswith("rest_"): |
| 40 | self.set_service_attr(obj, k, v) |
| 41 | |