blob: 54d18069d5859d7bd445fc4b0bfdb81a79ab735a [file] [log] [blame]
Scott Baker3b8ceca2017-10-12 11:38:50 -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
17from xosapi.orm import ORMWrapper, register_convenience_wrapper
18
19class ORMWrapperVEGTenant(ORMWrapper):
20 sync_attributes = ("wan_container_ip", "wan_container_mac", "wan_container_netbits",
21 "wan_container_gateway_ip", "wan_container_gateway_mac",
22 "wan_vm_ip", "wan_vm_mac")
23
24 @property
25 def vee(self):
26 links = self.provided_links.all()
27 for link in links:
28 subscriber_service_instance = link.subscriber_service_instance.leaf_model
29 # Look for something that has an s_tag attribute
30 if (hasattr(subscriber_service_instance, "s_tag")):
31 return subscriber_service_instance
32 return None
33
34 # DEPRECATED
35 @property
36 def volt(self):
37 return self.vee
38
39 def is_address_manager_service_instance(self, si):
40 # TODO: hardcoded dependency
41 # TODO: VRouterTenant is deprecated
42 return si.leaf_model_name in ["AddressManagerServiceInstance", "VRouterTenant"]
43
44 # DEPRECATED
45 @property
46 def vrouter(self):
47 return self.address_service_instance
48
49 @property
50 def address_service_instance(self):
51 links = self.subscribed_links.all()
52 for link in links:
53 if not self.is_address_manager_service_instance(link.provider_service_instance):
54 continue
55 # cast from ServiceInstance to AddressManagerServiceInstance or similar
56 return link.provider_service_instance.leaf_model
57 return None
58
59 def get_address_service_instance_field(self, name, default=None):
60 if self.address_service_instance:
61 return getattr(self.address_service_instance, name, default)
62 else:
63 return default
64
65 @property
66 def wan_container_ip(self):
67 return self.get_address_service_instance_field("public_ip", None)
68
69 @property
70 def wan_container_mac(self):
71 return self.get_address_service_instance_field("public_mac", None)
72
73 @property
74 def wan_container_netbits(self):
75 return self.get_address_service_instance_field("netbits", None)
76
77 @property
78 def wan_container_gateway_ip(self):
79 return self.get_address_service_instance_field("gateway_ip", None)
80
81 @property
82 def wan_container_gateway_mac(self):
83 return self.get_address_service_instance_field("gateway_mac", None)
84
85 @property
86 def wan_vm_ip(self):
87 tags = self.stub.Tag.objects.filter(name="vm_vrouter_tenant", object_id=self.instance.id, content_type=self.instance.self_content_type_id)
88 if tags:
89 service_instances = self.stub.ServiceInstance.objects.filter(id=int(tags[0].value))
90 if not service_instances:
91 raise Exception("ServiceInstance %d linked to vsg %s does not exist" % (int(tags[0].value), self))
92 return service_instances[0].leaf_model.public_ip
93 else:
94 raise Exception("no vm_vrouter_tenant tag for instance %s" % self.instance)
95
96 @property
97 def wan_vm_mac(self):
98 tags = self.stub.Tag.objects.filter(name="vm_vrouter_tenant", object_id=self.instance.id, content_type=self.instance.self_content_type_id)
99 if tags:
100 service_instances = self.stub.ServiceInstance.objects.filter(id=int(tags[0].value))
101 if not service_instances:
102 raise Exception("ServiceInstance %d linked to vsg %s does not exist" % (int(tags[0].value), self))
103 return service_instances[0].leaf_model.public_mac
104 else:
105 raise Exception("no vm_vrouter_tenant tag for instance %s" % self.instance)
106
107
108register_convenience_wrapper("VEGTenant", ORMWrapperVEGTenant)