blob: b274d5b131999c0942d99cff79f83face74639aa [file] [log] [blame]
Matteo Scandolo7781b5b2017-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 Williams63606562016-10-05 16:01:40 -070017from service import XOSService
Scott Baker7a327592016-06-20 17:34:06 -070018from core.models import ServiceAttribute
19from services.onos.models import ONOSService
20
Scott Baker7a327592016-06-20 17:34:06 -070021class XOSONOSService(XOSService):
22 provides = "tosca.nodes.ONOSService"
23 xos_model = ONOSService
24 copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "versionNumber", "rest_hostname", "rest_port", "no_container", "node_key"]
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_") and (k!="rest_hostname") and (k!="rest_port"):
48 self.set_service_attr(obj, k, v)
49