eliminate gateway settings in vSG; start removing non-VTN vSG code
diff --git a/xos/configurations/cord-pod/cord-vtn-vsg.yaml b/xos/configurations/cord-pod/cord-vtn-vsg.yaml
index c8c6ceb..7de536a 100644
--- a/xos/configurations/cord-pod/cord-vtn-vsg.yaml
+++ b/xos/configurations/cord-pod/cord-vtn-vsg.yaml
@@ -49,9 +49,6 @@
           backend_network_label: hpc_client
           public_key: { get_artifact: [ SELF, pubkey, LOCAL_FILE] }
           private_key_fn: /opt/xos/synchronizers/vcpe/vcpe_private_key
-          wan_container_gateway_ip: 10.168.0.1
-          wan_container_gateway_mac: 02:42:0a:a8:00:01
-          wan_container_netbits: 24
 #          node_label: label_vsg
       artifacts:
           pubkey: /opt/xos/synchronizers/vcpe/vcpe_public_key
diff --git a/xos/services/cord/admin.py b/xos/services/cord/admin.py
index 3cccc6c..e7704d3 100644
--- a/xos/services/cord/admin.py
+++ b/xos/services/cord/admin.py
@@ -104,9 +104,6 @@
     bbs_server = forms.CharField(required=False)
     backend_network_label = forms.CharField(required=False)
     bbs_slice = forms.ModelChoiceField(queryset=Slice.objects.all(), required=False)
-    wan_container_gateway_ip = forms.CharField(required=False)
-    wan_container_gateway_mac = forms.CharField(required=False)
-    wan_container_netbits = forms.CharField(required=False)
     dns_servers = forms.CharField(required=False)
     url_filter_kind = forms.ChoiceField(choices=VSGService.URL_FILTER_KIND_CHOICES, required=False)
     node_label = forms.CharField(required=False)
@@ -119,9 +116,6 @@
             self.fields['bbs_server'].initial = self.instance.bbs_server
             self.fields['backend_network_label'].initial = self.instance.backend_network_label
             self.fields['bbs_slice'].initial = self.instance.bbs_slice
-            self.fields['wan_container_gateway_ip'].initial = self.instance.wan_container_gateway_ip
-            self.fields['wan_container_gateway_mac'].initial = self.instance.wan_container_gateway_mac
-            self.fields['wan_container_netbits'].initial = self.instance.wan_container_netbits
             self.fields['dns_servers'].initial = self.instance.dns_servers
             self.fields['url_filter_kind']. initial = self.instance.url_filter_kind
             self.fields['node_label'].initial = self.instance.node_label
@@ -132,9 +126,6 @@
         self.instance.bbs_server = self.cleaned_data.get("bbs_server")
         self.instance.backend_network_label = self.cleaned_data.get("backend_network_label")
         self.instance.bbs_slice = self.cleaned_data.get("bbs_slice")
-        self.instance.wan_container_gateway_ip = self.cleaned_data.get("wan_container_gateway_ip")
-        self.instance.wan_container_gateway_mac = self.cleaned_data.get("wan_container_gateway_mac")
-        self.instance.wan_container_netbits = self.cleaned_data.get("wan_container_netbits")
         self.instance.dns_servers = self.cleaned_data.get("dns_servers")
         self.instance.url_filter_kind = self.cleaned_data.get("url_filter_kind")
         self.instance.node_label = self.cleaned_data.get("node_label")
@@ -153,7 +144,7 @@
                                      'classes':['suit-tab suit-tab-general']}),
                  ("backend config", {'fields': [ "backend_network_label", "url_filter_kind", "bbs_api_hostname", "bbs_api_port", "bbs_server", "bbs_slice"],
                                      'classes':['suit-tab suit-tab-backend']}),
-                 ("vSG config", {'fields': [ "wan_container_gateway_ip", "wan_container_gateway_mac", "wan_container_netbits", "dns_servers"],
+                 ("vSG config", {'fields': ["dns_servers"],
                                      'classes':['suit-tab suit-tab-vsg']}) ]
     readonly_fields = ('backend_status_text', "service_specific_attribute")
     inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
diff --git a/xos/services/cord/models.py b/xos/services/cord/models.py
index 0da4809..c57d9fb 100644
--- a/xos/services/cord/models.py
+++ b/xos/services/cord/models.py
@@ -372,9 +372,6 @@
                           ("bbs_api_port", None),
                           ("bbs_server", None),
                           ("backend_network_label", "hpc_client"),
-                          ("wan_container_gateway_ip", ""),
-                          ("wan_container_gateway_mac", ""),
-                          ("wan_container_netbits", "24"),
                           ("dns_servers", "8.8.8.8"),
                           ("url_filter_kind", None),
                           ("node_label", None) )
@@ -419,25 +416,15 @@
 
 VSGService.setup_simple_attributes()
 
-#class STagBlock(PlCoreBase):
-#    instance = models.ForeignKey(Instance, related_name="s_tags")
-#    s_tag = models.CharField(null=false, blank=false, unique=true, max_length=10)
-#    #c_tags = models.TextField(null=true, blank=true)
-#
-#    def __unicode__(self): return u'%s' % (self.s_tag)
-
 class VSGTenant(TenantWithContainer):
     class Meta:
         proxy = True
 
     KIND = VCPE_KIND
 
-    sync_attributes = ("nat_ip", "nat_mac",
-                       "lan_ip", "lan_mac",
-                       "wan_ip", "wan_mac",
-                       "wan_container_ip", "wan_container_mac",
-                       "private_ip", "private_mac",
-                       "hpc_client_ip", "hpc_client_mac")
+    sync_attributes = ("wan_container_ip", "wan_container_mac", "wan_container_netbits",
+                       "wan_container_gateway_ip", "wan_container_gateway_mac",
+                       "wan_vm_ip", "wan_vm_mac")
 
     default_attributes = {"instance_id": None,
                           "container_id": None,
@@ -448,22 +435,12 @@
 
     def __init__(self, *args, **kwargs):
         super(VSGTenant, self).__init__(*args, **kwargs)
-        self.cached_vbng=None
         self.cached_vrouter=None
 
     @property
     def vbng(self):
-        vbng = self.get_newest_subscribed_tenant(VBNGTenant)
-        if not vbng:
-            return None
-
-        # always return the same object when possible
-        if (self.cached_vbng) and (self.cached_vbng.id == vbng.id):
-            return self.cached_vbng
-
-        vbng.caller = self.creator
-        self.cached_vbng = vbng
-        return vbng
+        # not supported
+        return None
 
     @vbng.setter
     def vbng(self, value):
@@ -523,92 +500,31 @@
     def ssh_command(self, value):
         pass
 
-    @property
-    def addresses(self):
-        if self.instance:
-            ports = self.instance.ports.all()
-        elif self.container:
-            ports = self.container.ports.all()
+    def get_vrouter_field(self, name, default=None):
+        if self.vrouter:
+            return getattr(self.vrouter, name, default)
         else:
-            return {}
-
-        addresses = {}
-        for ns in ports:
-            if "lan" in ns.network.name.lower():
-                addresses["lan"] = (ns.ip, ns.mac)
-            elif "wan" in ns.network.name.lower():
-                addresses["wan"] = (ns.ip, ns.mac)
-            elif "private" in ns.network.name.lower():
-                addresses["private"] = (ns.ip, ns.mac)
-            elif "nat" in ns.network.name.lower():
-                addresses["nat"] = (ns.ip, ns.mac)
-            elif "hpc_client" in ns.network.name.lower():
-                addresses["hpc_client"] = (ns.ip, ns.mac)
-        return addresses
-
-    # ------------------------------------------------------------------------
-    # The following IP addresses all come from the VM
-    # Note: They might not be useful for the VTN-vSG
-
-    @property
-    def nat_ip(self):
-        return self.addresses.get("nat", (None,None) )[0]
-
-    @property
-    def nat_mac(self):
-        return self.addresses.get("nat", (None,None) )[1]
-
-    @property
-    def lan_ip(self):
-        return self.addresses.get("lan", (None, None) )[0]
-
-    @property
-    def lan_mac(self):
-        return self.addresses.get("lan", (None, None) )[1]
-
-    @property
-    def wan_ip(self):
-        return self.addresses.get("wan", (None, None) )[0]
-
-    @property
-    def wan_mac(self):
-        return self.addresses.get("wan", (None, None) )[1]
-
-    # end of VM IP address stubs
-    # ------------------------------------------------------------------------
+            return default
 
     @property
     def wan_container_ip(self):
-        if self.vrouter:
-            return self.vrouter.public_ip
-        else:
-            if  (CORD_USE_VTN):
-                # Should this be an error?
-                return None
-            else:
-                # When not using VTN, wan_container_ip is the same as wan_ip.
-                # XXX Is this broken for multiple-containers-per-VM?
-                return self.wan_ip
+        return self.get_vrouter_field("public_ip", None)
 
-    @wan_container_ip.setter
-    def wan_container_ip(self, value):
-        raise Exception("wan_container_ip is not settable")
-
-    def ip_to_mac(self, ip):
-        (a, b, c, d) = ip.split('.')
-        return "02:42:%02x:%02x:%02x:%02x" % (int(a), int(b), int(c), int(d))
-
-    # Generate the MAC for the container interface connected to WAN
     @property
     def wan_container_mac(self):
-        if self.vrouter:
-            return self.vrouter.public_mac
-        else:
-            if (CORD_USE_VTN):
-                # Should this be an error?
-                return None
-            else:
-                return self.ip_to_mac(self.wan_container_ip)
+        return self.get_vrouter_field("public_mac", None)
+
+    @property
+    def wan_container_netbits(self):
+        return self.get_vrouter_field("netbits", None)
+
+    @property
+    def wan_container_gateway_ip(self):
+        return self.get_vrouter_field("gateway_ip", None)
+
+    @property
+    def wan_container_gateway_mac(self):
+        return self.get_vrouter_field("gateway_mac", None)
 
     @property
     def wan_vm_ip(self):
@@ -617,10 +533,7 @@
             tenant = VRouterTenant.objects.get(id=tags[0].value)
             return tenant.public_ip
         else:
-            if CORD_USE_VTN:
-                raise Exception("no vm_vrouter_tenant tag for instance %s" % o.instance)
-            else:
-                return ""
+            raise Exception("no vm_vrouter_tenant tag for instance %s" % o.instance)
 
     @property
     def wan_vm_mac(self):
@@ -629,26 +542,7 @@
             tenant = VRouterTenant.objects.get(id=tags[0].value)
             return tenant.public_mac
         else:
-            if CORD_USE_VTN:
-                raise Exception("no vm_vrouter_tenant tag for instance %s" % o.instance)
-            else:
-                return ""
-
-    @property
-    def private_ip(self):
-        return self.addresses.get("private", (None, None) )[0]
-
-    @property
-    def private_mac(self):
-        return self.addresses.get("private", (None, None) )[1]
-
-    @property
-    def hpc_client_ip(self):
-        return self.addresses.get("hpc_client", (None, None) )[0]
-
-    @property
-    def hpc_client_mac(self):
-        return self.addresses.get("hpc_client", (None, None) )[1]
+            raise Exception("no vm_vrouter_tenant tag for instance %s" % o.instance)
 
     @property
     def is_synced(self):
@@ -658,27 +552,6 @@
     def is_synced(self, value):
         pass
 
-    def manage_vbng(self):
-        # Each vCPE object owns exactly one vBNG object
-
-        if self.deleted:
-            return
-
-        if self.vbng is None:
-            vbngServices = VBNGService.get_service_objects().all()
-            if not vbngServices:
-                raise XOSConfigurationError("No VBNG Services available")
-
-            vbng = VBNGTenant(provider_service = vbngServices[0],
-                              subscriber_tenant = self)
-            vbng.caller = self.creator
-            vbng.save()
-
-    def cleanup_vbng(self):
-        if self.vbng:
-            # print "XXX cleanup vnbg", self.vbng
-            self.vbng.delete()
-
     def get_vrouter_service(self):
         vrouterServices = VRouterService.get_service_objects().all()
         if not vrouterServices:
@@ -702,13 +575,6 @@
             self.vrouter.delete()
 
     def cleanup_orphans(self):
-        # ensure vCPE only has one vBNG
-        cur_vbng = self.vbng
-        for vbng in list(self.get_subscribed_tenants(VBNGTenant)):
-            if (not cur_vbng) or (vbng.id != cur_vbng.id):
-                # print "XXX clean up orphaned vbng", vbng
-                vbng.delete()
-
         # ensure vCPE only has one vRouter
         cur_vrouter = self.vrouter
         for vrouter in list(self.get_subscribed_tenants(VRouterTenant)):
@@ -900,7 +766,6 @@
         model_policy_vcpe(self.pk)
 
     def delete(self, *args, **kwargs):
-        self.cleanup_vbng()
         self.cleanup_vrouter()
         self.cleanup_container()
         super(VSGTenant, self).delete(*args, **kwargs)
@@ -914,7 +779,6 @@
         vcpe = vcpe[0]
         vcpe.manage_container()
         vcpe.manage_vrouter()
-        #vcpe.manage_vbng()
         vcpe.manage_bbs_account()
         vcpe.cleanup_orphans()
 
diff --git a/xos/services/vrouter/models.py b/xos/services/vrouter/models.py
index 5dba838..05b57e2 100644
--- a/xos/services/vrouter/models.py
+++ b/xos/services/vrouter/models.py
@@ -95,6 +95,15 @@
         return self.address_pool.cidr
 
     @property
+    def netbits(self):
+        # return number of bits in the network portion of the cidr
+        if self.cidr:
+            parts = self.cidr.split("/")
+            if len(parts)==2:
+                return int(parts[1].strip())
+        return None
+
+    @property
     def address_pool(self):
         if getattr(self, "cached_address_pool", None):
             return self.cached_address_pool
diff --git a/xos/synchronizers/vcpe/steps/sync_vcpetenant.py b/xos/synchronizers/vcpe/steps/sync_vcpetenant.py
index c28b3c1..9e3dfac 100644
--- a/xos/synchronizers/vcpe/steps/sync_vcpetenant.py
+++ b/xos/synchronizers/vcpe/steps/sync_vcpetenant.py
@@ -153,9 +153,6 @@
                         if mac:
                             safe_macs.append(mac)
 
-        wan_vm_ip=o.wan_vm_ip
-        wan_vm_mac=o.wan_vm_mac
-
         fields = {"vlan_ids": vlan_ids,   # XXX remove this
                 "s_tags": s_tags,
                 "c_tags": c_tags,
@@ -164,11 +161,6 @@
                 "bbs_addrs": bbs_addrs,
                 "full_setup": full_setup,
                 "isolation": o.instance.isolation,
-                "wan_container_gateway_mac": vcpe_service.wan_container_gateway_mac,
-                "wan_container_gateway_ip": vcpe_service.wan_container_gateway_ip,
-                "wan_container_netbits": vcpe_service.wan_container_netbits,
-                "wan_vm_mac": wan_vm_mac,
-                "wan_vm_ip": wan_vm_ip,
                 "safe_browsing_macs": safe_macs,
                 "container_name": "vcpe-%s-%s" % (s_tags[0], c_tags[0]),
                 "dns_servers": [x.strip() for x in vcpe_service.dns_servers.split(",")],
diff --git a/xos/synchronizers/vtr/steps/sync_vtrtenant.py b/xos/synchronizers/vtr/steps/sync_vtrtenant.py
index d2ec209..8debadf 100644
--- a/xos/synchronizers/vtr/steps/sync_vtrtenant.py
+++ b/xos/synchronizers/vtr/steps/sync_vtrtenant.py
@@ -84,35 +84,22 @@
             s_tags.append(o.target.volt.s_tag)
             c_tags.append(o.target.volt.c_tag)
 
-        wan_vm_ip=""
-        wan_vm_mac=""
-        tags = Tag.select_by_content_object(instance).filter(name="vm_wan_addr")
-        if tags:
-            parts=tags[0].value.split(",")
-            if len(parts)!=3:
-                raise Exception("vm_wan_addr tag is malformed: %s" % value)
-            wan_vm_ip = parts[1]
-            wan_vm_mac = parts[2]
-        else:
-            if CORD_USE_VTN:
-                raise Exception("no vm_wan_addr tag for instance %s" % instance)
-
         fields = {"s_tags": s_tags,
                 "c_tags": c_tags,
                 "isolation": instance.isolation,
-                "wan_container_gateway_mac": vcpe_service.wan_container_gateway_mac,
-                "wan_container_gateway_ip": vcpe_service.wan_container_gateway_ip,
-                "wan_container_netbits": vcpe_service.wan_container_netbits,
-                "wan_vm_mac": wan_vm_mac,
-                "wan_vm_ip": wan_vm_ip,
                 "container_name": "vcpe-%s-%s" % (s_tags[0], c_tags[0]),
                 "dns_servers": [x.strip() for x in vcpe_service.dns_servers.split(",")],
 
                 "result_fn": "%s-vcpe-%s-%s" % (o.test, s_tags[0], c_tags[0]),
                 "resultcode_fn": "code-%s-vcpe-%s-%s" % (o.test, s_tags[0], c_tags[0]) }
 
-        # add in the sync_attributes that come from the SubscriberRoot object
+        # add in the sync_attributes that come from the vSG object
+        # this will be wan_ip, wan_mac, wan_container_ip, wan_container_mac, ...
+        if o.target and o.target.volt and o.target.volt.vsg:
+            for attribute_name in o.target.volt.vsg.sync_attributes:
+                fields[attribute_name] = getattr(o.target.volt.vsg, attribute_name)
 
+        # add in the sync_attributes that come from the SubscriberRoot object
         if o.target and hasattr(o.target, "sync_attributes"):
             for attribute_name in o.target.sync_attributes:
                 fields[attribute_name] = getattr(o.target, attribute_name)
diff --git a/xos/tosca/custom_types/xos.m4 b/xos/tosca/custom_types/xos.m4
index fd4f8ec..b8e8581 100644
--- a/xos/tosca/custom_types/xos.m4
+++ b/xos/tosca/custom_types/xos.m4
@@ -221,15 +221,6 @@
                 type: string
                 required: false
                 description: Label that matches network used to connect HPC and BBS services.
-            wan_container_gateway_ip:
-                type: string
-                required: false
-            wan_container_gateway_mac:
-                type: string
-                required: false
-            wan_container_netbits:
-                type: string
-                required: false
             dns_servers:
                 type: string
                 required: false
diff --git a/xos/tosca/custom_types/xos.yaml b/xos/tosca/custom_types/xos.yaml
index 9bdcfc3..d887e7f 100644
--- a/xos/tosca/custom_types/xos.yaml
+++ b/xos/tosca/custom_types/xos.yaml
@@ -323,15 +323,6 @@
                 type: string
                 required: false
                 description: Label that matches network used to connect HPC and BBS services.
-            wan_container_gateway_ip:
-                type: string
-                required: false
-            wan_container_gateway_mac:
-                type: string
-                required: false
-            wan_container_netbits:
-                type: string
-                required: false
             dns_servers:
                 type: string
                 required: false
diff --git a/xos/tosca/resources/vcpeservice.py b/xos/tosca/resources/vcpeservice.py
index 2a6a56d..972c13c 100644
--- a/xos/tosca/resources/vcpeservice.py
+++ b/xos/tosca/resources/vcpeservice.py
@@ -14,6 +14,5 @@
     xos_model = VSGService
     copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key",
                     "private_key_fn", "versionNumber", "backend_network_label",
-                    "wan_container_gateway_ip", "wan_container_gateway_mac",
-                    "wan_container_netbits", "dns_servers", "node_label"]
+                    "dns_servers", "node_label"]