Matteo Scandolo | 7781b5b | 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 | 6360656 | 2016-10-05 16:01:40 -0700 | [diff] [blame] | 17 | from service import XOSService |
Scott Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 18 | from core.models import ServiceAttribute |
| 19 | from services.onos.models import ONOSService |
| 20 | |
Scott Baker | 7a32759 | 2016-06-20 17:34:06 -0700 | [diff] [blame] | 21 | class 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 | |