Scott Baker | 8e6647a | 2016-06-20 17:16:20 -0700 | [diff] [blame] | 1 | from services.volt.models import AccessDevice, VOLTDevice |
| 2 | from xosresource import XOSResource |
| 3 | |
| 4 | class XOSAccessDevice(XOSResource): |
| 5 | provides = "tosca.nodes.AccessDevice" |
| 6 | xos_model = AccessDevice |
| 7 | copyin_props = ["uplink", "vlan"] |
| 8 | name_field = None |
| 9 | |
| 10 | def get_xos_args(self, throw_exception=True): |
| 11 | args = super(XOSAccessDevice, self).get_xos_args() |
| 12 | |
| 13 | volt_device_name = self.get_requirement("tosca.relationships.MemberOfDevice", throw_exception=throw_exception) |
| 14 | if volt_device_name: |
| 15 | args["volt_device"] = self.get_xos_object(VOLTDevice, throw_exception=throw_exception, name=volt_device_name) |
| 16 | |
| 17 | return args |
| 18 | |
| 19 | # AccessDevice has no name field, so we rely on matching the keys. We assume |
| 20 | # the for a given VOLTDevice, there is only one AccessDevice per (uplink, vlan) |
| 21 | # pair. |
| 22 | |
| 23 | def get_existing_objs(self): |
| 24 | args = self.get_xos_args(throw_exception=False) |
| 25 | volt_device = args.get("volt_device", None) |
| 26 | uplink = args.get("uplink", None) |
| 27 | vlan = args.get("vlan", None) |
| 28 | if (volt_device is not None) and (uplink is not None) and (vlan is not None): |
| 29 | existing_obj = self.get_xos_object(AccessDevice, volt_device=volt_device, uplink=uplink, vlan=vlan, throw_exception=False) |
| 30 | if existing_obj: |
| 31 | return [ existing_obj ] |
| 32 | return [] |
| 33 | |