fix bug where management network was being associated with vlan_id and VSG WAN addrs
add network_name to port APIs
Change-Id: I1b4d851019d5be3e61aee86bf0fc50219c8908ca
diff --git a/xos/api/service/vtn.py b/xos/api/service/vtn.py
index 193aaab..778c145 100644
--- a/xos/api/service/vtn.py
+++ b/xos/api/service/vtn.py
@@ -73,11 +73,12 @@
id = ReadOnlyField()
name = serializers.CharField(required=False)
network_id = serializers.CharField(required=False)
+ network_name = serializers.CharField(required=False)
mac_address = serializers.CharField(required=False)
ip_address = serializers.CharField(required=False)
class Meta:
- fields = ('id', 'name', 'network_id', 'mac_address', 'ip_address')
+ fields = ('id', 'name', 'network_id', 'network_name', 'mac_address', 'ip_address')
class FloatingAddressPairSerializer(serializers.Serializer):
ip_address = ReadOnlyField()
@@ -86,12 +87,13 @@
class VTNServicePortSerializer(serializers.Serializer):
id = ReadOnlyField()
vlan_id = serializers.IntegerField(required=False)
+ network_name = serializers.CharField(required=False)
# TODO: structure this better
floating_address_pairs = serializers.SerializerMethodField("getFloatingAddressPairs")
class Meta:
- fields = ('id', 'vlan_id')
+ fields = ('id', 'vlan_id', 'network_name')
def getFloatingAddressPairs(self, obj):
return obj.floating_address_pairs
diff --git a/xos/vtnnetport.py b/xos/vtnnetport.py
index 89d751d..3cbbf52 100644
--- a/xos/vtnnetport.py
+++ b/xos/vtnnetport.py
@@ -141,6 +141,10 @@
def vlan_id(self):
if not self.xos_port.instance:
return None
+ # Only some kinds of networks can have s-tags associated with them.
+ # Currently, only VSG access networks qualify.
+ if not self.xos_port.network.template.vtn_kind in ["VSG",]:
+ return None
tags = Tag.select_by_content_object(self.xos_port.instance).filter(name="s_tag")
if not tags:
return None
@@ -148,16 +152,22 @@
@property
def floating_address_pairs(self):
- address_pairs = []
- vsg = self.get_vsg_tenant()
- if vsg:
- if vsg.wan_container_ip and vsg.wan_container_mac:
- address_pairs.append({"ip_address": vsg.wan_container_ip,
- "mac_address": vsg.wan_container_mac})
+ # Floating_address_pairs is the set of WAN addresses that should be
+ # applied to this port.
- if vsg.wan_vm_ip and vsg.wan_vm_mac:
- address_pairs.append({"ip_address": vsg.wan_vm_ip,
- "mac_address": vsg.wan_vm_mac})
+ address_pairs = []
+
+ # only look apply the VSG addresses if the Network is of the VSG vtn_kind
+ if self.xos_port.network.template.vtn_kind in ["VSG", ]:
+ vsg = self.get_vsg_tenant()
+ if vsg:
+ if vsg.wan_container_ip and vsg.wan_container_mac:
+ address_pairs.append({"ip_address": vsg.wan_container_ip,
+ "mac_address": vsg.wan_container_mac})
+
+ if vsg.wan_vm_ip and vsg.wan_vm_mac:
+ address_pairs.append({"ip_address": vsg.wan_vm_ip,
+ "mac_address": vsg.wan_vm_mac})
return address_pairs
@@ -177,6 +187,10 @@
return cn.net_id
@property
+ def network_name(self):
+ return self.xos_port.network.name
+
+ @property
def mac_address(self):
return self.xos_port.mac