Zack Williams | 8af1136 | 2016-10-07 16:01:09 -0700 | [diff] [blame] | 1 | from service import XOSService |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 2 | from core.models import ServiceAttribute |
Srikanth Vavilapalli | d84b7b7 | 2016-06-28 00:19:07 +0000 | [diff] [blame] | 3 | from services.monitoring.models import SFlowService |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 4 | |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 5 | class XOSSFlowService(XOSService): |
| 6 | provides = "tosca.nodes.SFlowService" |
| 7 | xos_model = SFlowService |
| 8 | copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "versionNumber", "sflow_port", "sflow_api_port"] |
| 9 | |
| 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 | |