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):
