CORD-879 eliminate proxy models in vRouter

Change-Id: I3587ba971b63c0498c6f7c7b915f291d30ba5d5b
diff --git a/xos/admin.py b/xos/admin.py
index a6ce270..45c8238 100644
--- a/xos/admin.py
+++ b/xos/admin.py
@@ -107,12 +107,9 @@
 
 
 class VRouterTenantForm(forms.ModelForm):
-    public_ip = forms.CharField(required=True)
-    public_mac = forms.CharField(required=True)
     gateway_ip = forms.CharField(required=False)
     gateway_mac = forms.CharField(required=False)
     cidr = forms.CharField(required=False)
-    address_pool = forms.ModelChoiceField(queryset=AddressPool.objects.all(),required=False)
 
     def __init__(self,*args,**kwargs):
         super (VRouterTenantForm,self ).__init__(*args,**kwargs)
@@ -120,22 +117,16 @@
         self.fields['provider_service'].queryset = VRouterService.get_service_objects().all()
         if self.instance:
             # fields for the attributes
-            self.fields['address_pool'].initial = self.instance.address_pool
-            self.fields['public_ip'].initial = self.instance.public_ip
-            self.fields['public_mac'].initial = self.instance.public_mac
             self.fields['gateway_ip'].initial = self.instance.gateway_ip
             self.fields['gateway_mac'].initial = self.instance.gateway_mac
             self.fields['cidr'].initial = self.instance.cidr
         if (not self.instance) or (not self.instance.pk):
             # default fields for an 'add' form
             self.fields['kind'].initial = VROUTER_KIND
-            if VRouterService.get_service_objects().exists():
-               self.fields["provider_service"].initial = VRouterService.get_service_objects().all()[0]
+            if VRouterService.objects.exists():
+               self.fields["provider_service"].initial = VRouterService.objects.first()
 
     def save(self, commit=True):
-        self.instance.public_ip = self.cleaned_data.get("public_ip")
-        self.instance.public_mac = self.cleaned_data.get("public_mac")
-        self.instance.address_pool = self.cleaned_data.get("address_pool")
         return super(VRouterTenantForm, self).save(commit=commit)
 
     class Meta:
diff --git a/xos/models.py b/xos/models.py
index 8396d3e..016cb3d 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -32,46 +32,14 @@
     class Meta:
         app_label = APP_LABEL
         verbose_name = "vRouter Service"
-        proxy = True
 
-    default_attributes = {
-        "rest_hostname": "",
-        "rest_port": "8181",
-        "rest_user": "onos",
-        "rest_pass": "rocks"
-    }
+    # Are rest_hostname and rest_port redundant with ONOS service?
+    # Should ONOSService be augmented with rest_user and rest_pass?
 
-    @property
-    def rest_hostname(self):
-        return self.get_attribute("rest_hostname", self.default_attributes["rest_hostname"])
-
-    @rest_hostname.setter
-    def rest_hostname(self, value):
-        self.set_attribute("rest_hostname", value)
-
-    @property
-    def rest_port(self):
-        return self.get_attribute("rest_port", self.default_attributes["rest_port"])
-
-    @rest_port.setter
-    def rest_port(self, value):
-        self.set_attribute("rest_port", value)
-
-    @property
-    def rest_user(self):
-        return self.get_attribute("rest_user", self.default_attributes["rest_user"])
-
-    @rest_user.setter
-    def rest_user(self, value):
-        self.set_attribute("rest_user", value)
-
-    @property
-    def rest_pass(self):
-        return self.get_attribute("rest_pass", self.default_attributes["rest_pass"])
-
-    @rest_pass.setter
-    def rest_pass(self, value):
-        self.set_attribute("rest_pass", value)
+    rest_hostname = StrippedCharField(max_length=255, null=True, blank=True)
+    rest_port = models.IntegerField(default=8181)
+    rest_user = StrippedCharField(max_length=255, default="onos")
+    rest_pass = StrippedCharField(max_length=255, default="rocks")
 
     def ip_to_mac(self, ip):
         (a, b, c, d) = ip.split('.')
@@ -112,16 +80,13 @@
 
 class VRouterTenant(Tenant):
     class Meta:
-        proxy = True
         verbose_name = "vRouter Tenant"
 
     KIND = VROUTER_KIND
 
-    simple_attributes = (
-        ("public_ip", None),
-        ("public_mac", None),
-        ("address_pool_id", None),
-    )
+    public_ip = StrippedCharField(max_length = 30, null=True, blank=True)
+    public_mac = StrippedCharField(max_length = 30, null=True, blank=True)
+    address_pool = models.ForeignKey(AddressPool, related_name='vrouter_tenants', blank=True, null=True)
 
     @property
     def gateway_ip(self):
@@ -150,30 +115,9 @@
                 return int(parts[1].strip())
         return None
 
-    @property
-    def address_pool(self):
-        if getattr(self, "cached_address_pool", None):
-            return self.cached_address_pool
-        if not self.address_pool_id:
-            return None
-        aps = AddressPool.objects.filter(id=self.address_pool_id)
-        if not aps:
-            return None
-        ap = aps[0]
-        self.cached_address_pool = ap
-        return ap
-
-    @address_pool.setter
-    def address_pool(self, value):
-        if value:
-            value = value.id
-        if (value != self.get_attribute("address_pool_id", None)):
-            self.cached_address_pool = None
-        self.set_attribute("address_pool_id", value)
-
     def cleanup_addresspool(self):
-        if self.address_pool_id:
-            ap = AddressPool.objects.filter(id=self.address_pool_id)
+        if self.address_pool:
+            ap = self.address_pool
             if ap:
                 ap[0].put_address(self.public_ip)
                 self.public_ip = None
@@ -182,8 +126,6 @@
         self.cleanup_addresspool()
         super(VRouterTenant, self).delete(*args, **kwargs)
 
-VRouterTenant.setup_simple_attributes()
-
 
 # DEVICES
 class VRouterDevice(PlCoreBase):