blob: d9e8a5d457ef3801c31f250e74d11568597a42c3 [file] [log] [blame]
Sapan Bhatia46482ee2017-04-21 17:59:48 +02001sync_attributes = ("wan_container_ip", "wan_container_mac", "wan_container_netbits",
2 "wan_container_gateway_ip", "wan_container_gateway_mac",
3 "wan_vm_ip", "wan_vm_mac")
4
5def __init__(self, *args, **kwargs):
6 super(VSGTenant, self).__init__(*args, **kwargs)
7 self.cached_vrouter=None
8
9@property
10def vrouter(self):
11 vrouter = self.get_newest_subscribed_tenant(VRouterTenant)
12 if not vrouter:
13 return None
14
15 # always return the same object when possible
16 if (self.cached_vrouter) and (self.cached_vrouter.id == vrouter.id):
17 return self.cached_vrouter
18
19 vrouter.caller = self.creator
20 self.cached_vrouter = vrouter
21 return vrouter
22
23@vrouter.setter
24def vrouter(self, value):
25 raise XOSConfigurationError("VSGTenant.vrouter setter is not implemented")
26
27@property
28def volt(self):
29 from services.volt.models import VOLTTenant
30 if not self.subscriber_tenant:
31 return None
32 volts = VOLTTenant.objects.filter(id=self.subscriber_tenant.id)
33 if not volts:
34 return None
35 return volts[0]
36
37@volt.setter
38def volt(self, value):
39 raise XOSConfigurationError("VSGTenant.volt setter is not implemented")
40
41@property
42def ssh_command(self):
43 if self.instance:
44 return self.instance.get_ssh_command()
45 else:
46 return "no-instance"
47
48def get_vrouter_field(self, name, default=None):
49 if self.vrouter:
50 return getattr(self.vrouter, name, default)
51 else:
52 return default
53
54@property
55def wan_container_ip(self):
56 return self.get_vrouter_field("public_ip", None)
57
58@property
59def wan_container_mac(self):
60 return self.get_vrouter_field("public_mac", None)
61
62@property
63def wan_container_netbits(self):
64 return self.get_vrouter_field("netbits", None)
65
66@property
67def wan_container_gateway_ip(self):
68 return self.get_vrouter_field("gateway_ip", None)
69
70@property
71def wan_container_gateway_mac(self):
72 return self.get_vrouter_field("gateway_mac", None)
73
74@property
75def wan_vm_ip(self):
Scott Baker248ed752017-05-24 16:40:28 -070076 tags = Tag.objects.filter(content_type=self.instance.get_content_type_key(), object_id=self.instance.id, name="vm_vrouter_tenant")
Sapan Bhatia46482ee2017-04-21 17:59:48 +020077 if tags:
78 tenant = VRouterTenant.objects.get(id=tags[0].value)
79 return tenant.public_ip
80 else:
81 raise Exception("no vm_vrouter_tenant tag for instance %s" % o.instance)
82
83@property
84def wan_vm_mac(self):
Scott Baker248ed752017-05-24 16:40:28 -070085 tags = Tag.objects.filter(content_type=self.instance.get_content_type_key(), object_id=self.instance.id, name="vm_vrouter_tenant")
Sapan Bhatia46482ee2017-04-21 17:59:48 +020086 if tags:
87 tenant = VRouterTenant.objects.get(id=tags[0].value)
88 return tenant.public_mac
89 else:
90 raise Exception("no vm_vrouter_tenant tag for instance %s" % o.instance)
91
92@property
93def is_synced(self):
94 return (self.enacted is not None) and (self.enacted >= self.updated)
95
96@is_synced.setter
97def is_synced(self, value):
98 pass
99
Sapan Bhatia46482ee2017-04-21 17:59:48 +0200100def save(self, *args, **kwargs):
101 if not self.creator:
102 if not getattr(self, "caller", None):
103 # caller must be set when creating a vCPE since it creates a slice
104 raise XOSProgrammingError("VSGTenant's self.caller was not set")
105 self.creator = self.caller
106 if not self.creator:
107 raise XOSProgrammingError("VSGTenant's self.creator was not set")
108
109 super(VSGTenant, self).save(*args, **kwargs)
Sapan Bhatia46482ee2017-04-21 17:59:48 +0200110
111def delete(self, *args, **kwargs):
Sapan Bhatia46482ee2017-04-21 17:59:48 +0200112 super(VSGTenant, self).delete(*args, **kwargs)
113