blob: f31b37a7ff4e354148bc080cc1ff6ca0f6671264 [file] [log] [blame]
Scott Baker8e6647a2016-06-20 17:16:20 -07001import os
2import pdb
3import sys
4import tempfile
5sys.path.append("/opt/tosca")
6from translator.toscalib.tosca_template import ToscaTemplate
7
8from services.volt.models import AccessDevice, VOLTDevice
9from xosresource import XOSResource
10
11class XOSAccessDevice(XOSResource):
12 provides = "tosca.nodes.AccessDevice"
13 xos_model = AccessDevice
14 copyin_props = ["uplink", "vlan"]
15 name_field = None
16
17 def get_xos_args(self, throw_exception=True):
18 args = super(XOSAccessDevice, self).get_xos_args()
19
20 volt_device_name = self.get_requirement("tosca.relationships.MemberOfDevice", throw_exception=throw_exception)
21 if volt_device_name:
22 args["volt_device"] = self.get_xos_object(VOLTDevice, throw_exception=throw_exception, name=volt_device_name)
23
24 return args
25
26 # AccessDevice has no name field, so we rely on matching the keys. We assume
27 # the for a given VOLTDevice, there is only one AccessDevice per (uplink, vlan)
28 # pair.
29
30 def get_existing_objs(self):
31 args = self.get_xos_args(throw_exception=False)
32 volt_device = args.get("volt_device", None)
33 uplink = args.get("uplink", None)
34 vlan = args.get("vlan", None)
35 if (volt_device is not None) and (uplink is not None) and (vlan is not None):
36 existing_obj = self.get_xos_object(AccessDevice, volt_device=volt_device, uplink=uplink, vlan=vlan, throw_exception=False)
37 if existing_obj:
38 return [ existing_obj ]
39 return []
40