blob: a9fd9992afda90520ecc780c75b1f652d2791c2b [file] [log] [blame]
Matteo Scandolo5e293c92017-08-08 13:05:23 -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
Scott Baker8e6647a2016-06-20 17:16:20 -070017from services.volt.models import AccessDevice, VOLTDevice
18from xosresource import XOSResource
19
20class 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