blob: 47c7f1dca8f8d8c90dc473e6b861dc021fabbada [file] [log] [blame]
Zack Williams63606562016-10-05 16:01:40 -07001from service import XOSService
Scott Baker7a327592016-06-20 17:34:06 -07002from core.models import ServiceAttribute
3from services.onos.models import ONOSService
4
Scott Baker7a327592016-06-20 17:34:06 -07005class XOSONOSService(XOSService):
6 provides = "tosca.nodes.ONOSService"
7 xos_model = ONOSService
8 copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "versionNumber", "rest_hostname", "rest_port", "no_container", "node_key"]
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_") and (k!="rest_hostname") and (k!="rest_port"):
32 self.set_service_attr(obj, k, v)
33