CORD-879 eliminate proxy models in onos-service

Change-Id: I9d6bb02d003eb3ddd355210dcd82c3a19cf4f615
diff --git a/xos/admin.py b/xos/admin.py
index d33a3eb..5ab2f1c 100644
--- a/xos/admin.py
+++ b/xos/admin.py
@@ -18,35 +18,6 @@
 from django.core.urlresolvers import reverse
 from django.contrib.admin.utils import quote
 
-class ONOSServiceForm(forms.ModelForm):
-    rest_hostname = forms.CharField(required=False)
-    rest_port = forms.CharField(required=False)
-    no_container = forms.BooleanField(required=False)
-#    external_hostname = forms.CharField(required=False)
-#    external_container = forms.CharField(required=False)
-
-    def __init__(self,*args,**kwargs):
-        super (ONOSServiceForm,self ).__init__(*args,**kwargs)
-        if self.instance:
-            # fields for the attributes
-            self.fields['rest_hostname'].initial = self.instance.rest_hostname
-            self.fields['rest_port'].initial = self.instance.rest_port
-            self.fields['no_container'].initial = self.instance.no_container
-#            self.fields['external_hostname'].initial = self.instance.external_hostname
-#            self.fields['external_container'].initial = self.instance.external_hostname
-
-    def save(self, commit=True):
-        self.instance.rest_hostname = self.cleaned_data.get("rest_hostname")
-        self.instance.rest_port = self.cleaned_data.get("rest_port")
-        self.instance.no_container = self.cleaned_data.get("no_container")
-#        self.instance.external_hostname = self.cleaned_data.get("external_hostname")
-#        self.instance.external_container = self.cleaned_data.get("external_container")
-        return super(ONOSServiceForm, self).save(commit=commit)
-
-    class Meta:
-        model = ONOSService
-        fields = '__all__'
-
 class ONOSServiceAdmin(ReadOnlyAwareAdmin):
     model = ONOSService
     verbose_name = "ONOS Service"
@@ -56,7 +27,6 @@
     fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description',"view_url","icon_url", "rest_hostname", "rest_port", "no_container" ], 'classes':['suit-tab suit-tab-general']})]
     readonly_fields = ('backend_status_text', )
     inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
-    form = ONOSServiceForm
 
     extracontext_registered_admins = True
 
@@ -76,30 +46,18 @@
         return ONOSService.get_service_objects_by_user(request.user)
 
 class ONOSAppForm(forms.ModelForm):
-    creator = forms.ModelChoiceField(queryset=User.objects.all())
-    name = forms.CharField()
-    dependencies = forms.CharField(required=False)
-
     def __init__(self,*args,**kwargs):
         super (ONOSAppForm,self ).__init__(*args,**kwargs)
         self.fields['kind'].widget.attrs['readonly'] = True
-        self.fields['provider_service'].queryset = ONOSService.get_service_objects().all()
-        if self.instance:
-            # fields for the attributes
-            self.fields['creator'].initial = self.instance.creator
-            self.fields['name'].initial = self.instance.name
-            self.fields['dependencies'].initial = self.instance.dependencies
+        self.fields['provider_service'].queryset = ONOSService.objects.all()
         if (not self.instance) or (not self.instance.pk):
             # default fields for an 'add' form
             self.fields['kind'].initial = ONOS_KIND
             self.fields['creator'].initial = get_request().user
-            if ONOSService.get_service_objects().exists():
+            if ONOSService.objects.exists():
                self.fields["provider_service"].initial = ONOSService.get_service_objects().all()[0]
 
     def save(self, commit=True):
-        self.instance.creator = self.cleaned_data.get("creator")
-        self.instance.name = self.cleaned_data.get("name")
-        self.instance.dependencies = self.cleaned_data.get("dependencies")
         return super(ONOSAppForm, self).save(commit=commit)
 
     class Meta:
diff --git a/xos/models.py b/xos/models.py
index 20fa73f..9f5409e 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -19,108 +19,31 @@
     class Meta:
         app_label = "onos"
         verbose_name = "ONOS Service"
-        proxy = True
 
-    default_attributes = {"rest_hostname": "",
-                          "rest_port": "8181",
-                          "no_container": False,
-                          "node_key": ""}
-
-    @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 no_container(self):
-        return self.get_attribute("no_container", self.default_attributes["no_container"])
-
-    @no_container.setter
-    def no_container(self, value):
-        self.set_attribute("no_container", value)
-
-    @property
-    def node_key(self):
-        return self.get_attribute("node_key", self.default_attributes["node_key"])
-
-    @node_key.setter
-    def node_key(self, value):
-        self.set_attribute("node_key", value)
-
+    rest_hostname = StrippedCharField(max_length=255, null=True, blank=True)
+    rest_port = models.IntegerField(default=8181)
+    no_container = models.BooleanField(default=False)
+    node_key = StrippedCharField(max_length=1024, null=True, blank=True)
 
 class ONOSApp(Tenant):   # aka 'ONOSTenant'
     class Meta:
-        proxy = True
+        app_label = "onos"
 
     KIND = ONOS_KIND
 
-    default_attributes = {"name": "",
-                          "install_dependencies": "",
-                          "dependencies": ""}
+    name = StrippedCharField(max_length=255, null=True, blank=True)
+    install_dependencies = models.TextField(null=True, blank=True)
+    dependencies = models.TextField(null=True, blank=True)
+
+    # why is this necessary?
+    creator = models.ForeignKey(User, related_name='onos_apps', blank=True, null=True)
+
     def __init__(self, *args, **kwargs):
         onos_services = ONOSService.get_service_objects().all()
         if onos_services:
             self._meta.get_field("provider_service").default = onos_services[0].id
         super(ONOSApp, self).__init__(*args, **kwargs)
 
-    @property
-    def creator(self):
-        from core.models import User
-        if getattr(self, "cached_creator", None):
-            return self.cached_creator
-        creator_id=self.get_attribute("creator_id")
-        if not creator_id:
-            return None
-        users=User.objects.filter(id=creator_id)
-        if not users:
-            return None
-        user=users[0]
-        self.cached_creator = users[0]
-        return user
-
-    @creator.setter
-    def creator(self, value):
-        if value:
-            value = value.id
-        if (value != self.get_attribute("creator_id", None)):
-            self.cached_creator=None
-        self.set_attribute("creator_id", value)
-
-    @property
-    def name(self):
-        return self.get_attribute("name", self.default_attributes["name"])
-
-    @name.setter
-    def name(self, value):
-        self.set_attribute("name", value)
-
-    @property
-    def dependencies(self):
-        return self.get_attribute("dependencies", self.default_attributes["dependencies"])
-
-    @dependencies.setter
-    def dependencies(self, value):
-        self.set_attribute("dependencies", value)
-
-    @property
-    def install_dependencies(self):
-        return self.get_attribute("install_dependencies", self.default_attributes["install_dependencies"])
-
-    @install_dependencies.setter
-    def install_dependencies(self, value):
-        self.set_attribute("install_dependencies", value)
-
     def save(self, *args, **kwargs):
         if not self.creator:
             if not getattr(self, "caller", None):
@@ -131,16 +54,7 @@
                 raise XOSProgrammingError("ONOSApp's self.creator was not set")
 
         super(ONOSApp, self).save(*args, **kwargs)
-        model_policy_onos_app(self.pk)
 
-# TODO: Probably don't need this...
-def model_policy_onos_app(pk):
-    # TODO: this should be made in to a real model_policy
-    with transaction.atomic():
-        oa = ONOSApp.objects.select_for_update().filter(pk=pk)
-        if not oa:
-            return
-        oa = oa[0]
-        #oa.manage_container()
+