[CORD-2938] Moving convenience methods in the synchronizer containers

Change-Id: I229d139a684044a838865c68502c93761c68c845
diff --git a/xos/synchronizer/models/convenience/vsgserviceinstance.py b/xos/synchronizer/models/convenience/vsgserviceinstance.py
new file mode 100644
index 0000000..800ad53
--- /dev/null
+++ b/xos/synchronizer/models/convenience/vsgserviceinstance.py
@@ -0,0 +1,108 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from xosapi.orm import ORMWrapper, register_convenience_wrapper
+
+class ORMWrapperVSGServiceInstance(ORMWrapper):
+    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")
+
+    @property
+    def ingress_service_instance(self):
+        links = self.provided_links.all()
+        for link in links:
+            subscriber_service_instance = link.subscriber_service_instance.leaf_model
+            # Look for something that has an s_tag attribute
+            if (hasattr(subscriber_service_instance, "s_tag")):
+                return subscriber_service_instance
+        return None
+
+    @property
+    def volt(self):
+        return self.ingress_service_instance
+
+    def is_address_manager_service_instance(self, si):
+        # TODO: hardcoded dependency
+        # TODO: VRouterTenant is deprecated
+        return si.leaf_model_name in ["AddressManagerServiceInstance", "VRouterTenant"]
+
+    # DEPRECATED
+    @property
+    def vrouter(self):
+        return self.address_service_instance
+
+    @property
+    def address_service_instance(self):
+        links = self.subscribed_links.all()
+        for link in links:
+            if not self.is_address_manager_service_instance(link.provider_service_instance):
+                continue
+            # cast from ServiceInstance to AddressManagerServiceInstance or similar
+            return link.provider_service_instance.leaf_model
+        return None
+
+    def get_address_service_instance_field(self, name, default=None):
+        if self.address_service_instance:
+            return getattr(self.address_service_instance, name, default)
+        else:
+            return default
+
+    @property
+    def wan_container_ip(self):
+        return self.get_address_service_instance_field("public_ip", None)
+
+    @property
+    def wan_container_mac(self):
+        return self.get_address_service_instance_field("public_mac", None)
+
+    @property
+    def wan_container_netbits(self):
+        return self.get_address_service_instance_field("netbits", None)
+
+    @property
+    def wan_container_gateway_ip(self):
+        return self.get_address_service_instance_field("gateway_ip", None)
+
+    @property
+    def wan_container_gateway_mac(self):
+        return self.get_address_service_instance_field("gateway_mac", None)
+
+    @property
+    def wan_vm_ip(self):
+        tags = self.stub.Tag.objects.filter(name="vm_vrouter_tenant", object_id=self.instance.id, content_type=self.instance.self_content_type_id)
+        if tags:
+            service_instances = self.stub.ServiceInstance.objects.filter(id=int(tags[0].value))
+            if not service_instances:
+                raise Exception("ServiceInstance %d linked to vsg %s does not exist" % (int(tags[0].value), self))
+            return service_instances[0].leaf_model.public_ip
+        else:
+            raise Exception("no vm_vrouter_tenant tag for instance %s" % self.instance)
+
+    @property
+    def wan_vm_mac(self):
+        tags = self.stub.Tag.objects.filter(name="vm_vrouter_tenant", object_id=self.instance.id, content_type=self.instance.self_content_type_id)
+        if tags:
+            service_instances = self.stub.ServiceInstance.objects.filter(id=int(tags[0].value))
+            if not service_instances:
+                raise Exception("ServiceInstance %d linked to vsg %s does not exist" % (int(tags[0].value), self))
+            return service_instances[0].leaf_model.public_mac
+        else:
+            raise Exception("no vm_vrouter_tenant tag for instance %s" % self.instance)
+
+
+register_convenience_wrapper("VSGTenant", ORMWrapperVSGServiceInstance)   # DEPRECATED
+register_convenience_wrapper("VSGServiceInstance", ORMWrapperVSGServiceInstance)
diff --git a/xos/tosca/resources/vsgservice.py b/xos/tosca/resources/vsgservice.py
deleted file mode 100644
index d00b7d6..0000000
--- a/xos/tosca/resources/vsgservice.py
+++ /dev/null
@@ -1,26 +0,0 @@
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-from services.vsg.models import VSGService
-from service import XOSService
-
-class XOSVsgService(XOSService):
-    provides = "tosca.nodes.VSGService"
-    xos_model = VSGService
-    copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key",
-                    "private_key_fn", "versionNumber",
-                    "dns_servers", "node_label", "docker_image_name", "docker_insecure_registry"]
-