Andy Bavier | 03df22b | 2017-08-30 14:46:02 -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 | |
| 17 | from services.volt.models import AccessDevice, VOLTDevice |
| 18 | from xosresource import XOSResource |
| 19 | |
| 20 | class XOSAccessDevice(XOSResource): |
| 21 | provides = "tosca.nodes.AccessDevice" |
| 22 | xos_model = AccessDevice |
| 23 | copyin_props = ["uplink", "vlan"] |
| 24 | name_field = None |
| 25 | |
| 26 | def get_xos_args(self, throw_exception=True): |
| 27 | args = super(XOSAccessDevice, self).get_xos_args() |
| 28 | |
| 29 | volt_device_name = self.get_requirement("tosca.relationships.MemberOfDevice", throw_exception=throw_exception) |
| 30 | if volt_device_name: |
| 31 | args["volt_device"] = self.get_xos_object(VOLTDevice, throw_exception=throw_exception, name=volt_device_name) |
| 32 | |
| 33 | return args |
| 34 | |
| 35 | # AccessDevice has no name field, so we rely on matching the keys. We assume |
| 36 | # the for a given VOLTDevice, there is only one AccessDevice per (uplink, vlan) |
| 37 | # pair. |
| 38 | |
| 39 | def get_existing_objs(self): |
| 40 | args = self.get_xos_args(throw_exception=False) |
| 41 | volt_device = args.get("volt_device", None) |
| 42 | uplink = args.get("uplink", None) |
| 43 | vlan = args.get("vlan", None) |
| 44 | if (volt_device is not None) and (uplink is not None) and (vlan is not None): |
| 45 | existing_obj = self.get_xos_object(AccessDevice, volt_device=volt_device, uplink=uplink, vlan=vlan, throw_exception=False) |
| 46 | if existing_obj: |
| 47 | return [ existing_obj ] |
| 48 | return [] |
| 49 | |