CORD-755 Fix VTNNetPort only returning address pairs for one vSG

Change-Id: Ib156ddb8270c005ea1924073781eec77a509f882
diff --git a/xos/vtnnetport.py b/xos/vtnnetport.py
index 3f8fac0..ba71199 100644
--- a/xos/vtnnetport.py
+++ b/xos/vtnnetport.py
@@ -121,81 +121,81 @@
         return self.to_dict() == other.to_dict()
 
 class VTNPort(object):
-    def __init__(self, xos_port=None):

-        self.xos_port = xos_port

-

-    def get_controller_network(self):

-        for cn in self.xos_port.network.controllernetworks.all():

-            # TODO: find the right one

-            return cn

-        return None

-

-    def get_vsg_tenant(self):

-        from services.vsg.models import VSGTenant

-        for tenant in VSGTenant.get_tenant_objects().all():

-            if tenant.instance == self.xos_port.instance:

-                return tenant

-        return None

-

-    @property

-    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

-        return tags[0].value

-

-    @property

-    def floating_address_pairs(self):

-        # Floating_address_pairs is the set of WAN addresses that should be

-        # applied to this port.

-

-        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

-

-    @property

-    def id(self):

-        return self.xos_port.port_id

-

-    @property

-    def name(self):

-        return "port-%s" % self.xos_port.id

-

-    @property

-    def network_id(self):

-        cn = self.get_controller_network()

-        if not cn:

-            return None

-        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

-

-    @property

-    def ip_address(self):

+    def __init__(self, xos_port=None):
+        self.xos_port = xos_port
+
+    def get_controller_network(self):
+        for cn in self.xos_port.network.controllernetworks.all():
+            # TODO: find the right one
+            return cn
+        return None
+
+    def get_vsg_tenants(self):
+        from services.vsg.models import VSGTenant
+        vsg_tenants=[]
+        for tenant in VSGTenant.get_tenant_objects().all():
+            if tenant.instance == self.xos_port.instance:
+                vsg_tenants.append(tenant)
+        return vsg_tenants
+
+    @property
+    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
+        return tags[0].value
+
+    @property
+    def floating_address_pairs(self):
+        # Floating_address_pairs is the set of WAN addresses that should be
+        # applied to this port.
+
+        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", ]:
+            for vsg in self.get_vsg_tenants():
+                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
+
+    @property
+    def id(self):
+        return self.xos_port.port_id
+
+    @property
+    def name(self):
+        return "port-%s" % self.xos_port.id
+
+    @property
+    def network_id(self):
+        cn = self.get_controller_network()
+        if not cn:
+            return None
+        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
+
+    @property
+    def ip_address(self):
         return self.xos_port.ip
 
     def to_dict(self):