CORD-2510 Migrate vEG to dynamic load

Change-Id: I390345541c35d57c0eade808ddc7af79dddf2f82
diff --git a/xos/header.py b/xos/header.py
deleted file mode 120000
index 721b5c0..0000000
--- a/xos/header.py
+++ /dev/null
@@ -1 +0,0 @@
-attic/header.py
\ No newline at end of file
diff --git a/xos/macros.m4 b/xos/macros.m4
deleted file mode 100644
index 391aafd..0000000
--- a/xos/macros.m4
+++ /dev/null
@@ -1,100 +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.
-
-
-# Note: Tosca derived_from isn't working the way I think it should, it's not
-#    inheriting from the parent template. Until we get that figured out, use
-#    m4 macros do our inheritance
-
-define(xos_base_props,
-            no-delete:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to delete this object
-            no-create:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to create this object
-            no-update:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to update this object
-            replaces:
-                type: string
-                required: false
-                descrption: Replaces/renames this object)
-# Service
-define(xos_base_service_caps,
-            scalable:
-                type: tosca.capabilities.Scalable
-            service:
-                type: tosca.capabilities.xos.Service)
-define(xos_base_service_props,
-            kind:
-                type: string
-                default: generic
-                description: Type of service.
-            view_url:
-                type: string
-                required: false
-                description: URL to follow when icon is clicked in the Service Directory.
-            icon_url:
-                type: string
-                required: false
-                description: ICON to display in the Service Directory.
-            enabled:
-                type: boolean
-                default: true
-            published:
-                type: boolean
-                default: true
-                description: If True then display this Service in the Service Directory.
-            public_key:
-                type: string
-                required: false
-                description: Public key to install into Instances to allows Services to SSH into them.
-            private_key_fn:
-                type: string
-                required: false
-                description: Location of private key file
-            versionNumber:
-                type: string
-                required: false
-                description: Version number of Service.)
-# Subscriber
-define(xos_base_subscriber_caps,
-            subscriber:
-                type: tosca.capabilities.xos.Subscriber)
-define(xos_base_subscriber_props,
-            kind:
-                type: string
-                default: generic
-                description: Kind of subscriber
-            service_specific_id:
-                type: string
-                required: false
-                description: Service specific ID opaque to XOS but meaningful to service)
-define(xos_base_tenant_props,
-            kind:
-                type: string
-                default: generic
-                description: Kind of tenant
-            service_specific_id:
-                type: string
-                required: false
-                description: Service specific ID opaque to XOS but meaningful to service)
-
-# end m4 macros
-
diff --git a/xos/synchronizer/model_policies/test_model_policy_vegtenant.py b/xos/synchronizer/model_policies/test_model_policy_vegtenant.py
index 34c94ac..2761846 100644
--- a/xos/synchronizer/model_policies/test_model_policy_vegtenant.py
+++ b/xos/synchronizer/model_policies/test_model_policy_vegtenant.py
@@ -27,9 +27,17 @@
     xos_dir=os.path.join(test_path, "../../../../../../orchestration/xos/xos")
     services_dir=os.path.join(xos_dir, "../../xos_services")
 
-# ---------------------------------------------------------------------------------------------------------------------
-# End Model Policy Testing Framework
-# ---------------------------------------------------------------------------------------------------------------------
+# While transitioning from static to dynamic load, the path to find neighboring xproto files has changed. So check
+# both possible locations...
+def get_models_fn(service_name, xproto_name):
+    name = os.path.join(service_name, "xos", xproto_name)
+    if os.path.exists(os.path.join(services_dir, name)):
+        return name
+    else:
+        name = os.path.join(service_name, "xos", "synchronizer", "models", xproto_name)
+        if os.path.exists(os.path.join(services_dir, name)):
+            return name
+    raise Exception("Unable to find service=%s xproto=%s" % (service_name, xproto_name))
 
 class TestModelPolicyVsgTenant(unittest.TestCase):
     def setUp(self):
@@ -45,7 +53,8 @@
         Config.init(config, 'synchronizer-config-schema.yaml')
 
         from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
-        build_mock_modelaccessor(xos_dir, services_dir, ["vEG/xos/veg.xproto", "addressmanager/xos/addressmanager.xproto"])
+        build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("vEG", "veg.xproto"),
+                                                         get_models_fn("addressmanager", "addressmanager.xproto")])
 
         import synchronizers.new_base.modelaccessor
         import synchronizers.new_base.model_policies.model_policy_tenantwithcontainer
diff --git a/xos/attic/header.py b/xos/synchronizer/models/attic/header.py
similarity index 100%
rename from xos/attic/header.py
rename to xos/synchronizer/models/attic/header.py
diff --git a/xos/attic/vegtenant_bottom.py b/xos/synchronizer/models/attic/vegtenant_bottom.py
similarity index 100%
rename from xos/attic/vegtenant_bottom.py
rename to xos/synchronizer/models/attic/vegtenant_bottom.py
diff --git a/xos/attic/vegtenant_model.py b/xos/synchronizer/models/attic/vegtenant_model.py
similarity index 100%
rename from xos/attic/vegtenant_model.py
rename to xos/synchronizer/models/attic/vegtenant_model.py
diff --git a/xos/veg.xproto b/xos/synchronizer/models/veg.xproto
similarity index 100%
rename from xos/veg.xproto
rename to xos/synchronizer/models/veg.xproto
diff --git a/xos/synchronizer/steps/test_sync_vegtenant.py b/xos/synchronizer/steps/test_sync_vegtenant.py
index 05d83f6..aca3d97 100644
--- a/xos/synchronizer/steps/test_sync_vegtenant.py
+++ b/xos/synchronizer/steps/test_sync_vegtenant.py
@@ -27,6 +27,18 @@
     xos_dir=os.path.join(test_path, "../../../../../../orchestration/xos/xos")
     services_dir=os.path.join(xos_dir, "../../xos_services")
 
+# While transitioning from static to dynamic load, the path to find neighboring xproto files has changed. So check
+# both possible locations...
+def get_models_fn(service_name, xproto_name):
+    name = os.path.join(service_name, "xos", xproto_name)
+    if os.path.exists(os.path.join(services_dir, name)):
+        return name
+    else:
+        name = os.path.join(service_name, "xos", "synchronizer", "models", xproto_name)
+        if os.path.exists(os.path.join(services_dir, name)):
+            return name
+    raise Exception("Unable to find service=%s xproto=%s" % (service_name, xproto_name))
+
 class TestSyncVEGServiceInstance(unittest.TestCase):
     def setUp(self):
         global SyncVEGTenant, LeastLoadedNodeScheduler, MockObjectList
@@ -41,7 +53,8 @@
         Config.init(config, 'synchronizer-config-schema.yaml')
 
         from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
-        build_mock_modelaccessor(xos_dir, services_dir, ["vEG/xos/veg.xproto", "addressmanager/xos/addressmanager.xproto"])
+        build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("vEG", "veg.xproto"),
+                                                         get_models_fn("addressmanager", "addressmanager.xproto")])
 
         import synchronizers.new_base.modelaccessor
         import synchronizers.new_base.model_policies.model_policy_tenantwithcontainer
diff --git a/xos/synchronizer/veg_config.yaml b/xos/synchronizer/veg_config.yaml
index af18596..0393ecf 100644
--- a/xos/synchronizer/veg_config.yaml
+++ b/xos/synchronizer/veg_config.yaml
@@ -12,13 +12,17 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-name: veg-synchronizer
+name: veg
 accessor:
   username: xosadmin@opencord.org
   password: "@/opt/xos/services/veg/credentials/xosadmin@opencord.org"
+required_models:
+  - VEGService
+  - VEGTenant
 dependency_graph: "/opt/xos/synchronizers/veg/model-deps"
 steps_dir: "/opt/xos/synchronizers/veg/steps"
 sys_dir: "/opt/xos/synchronizers/veg/sys"
+models_dir: "/opt/xos/synchronizers/veg/models"
 model_policies_dir: "/opt/xos/synchronizers/veg/model_policies"
 wrappers:
   - wrappers.veeserviceinstance
diff --git a/xos/tosca/resources/vegservice.py b/xos/tosca/resources/vegservice.py
deleted file mode 100644
index e91841d..0000000
--- a/xos/tosca/resources/vegservice.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.veg.models import VEGService
-from service import XOSService
-
-class XOSVegService(XOSService):
-    provides = "tosca.nodes.VEGService"
-    xos_model = VEGService
-    copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key",
-                    "private_key_fn", "versionNumber", "dns_servers", "node_label",
-                    "docker_image_name", "docker_insecure_registry"]
-
diff --git a/xos/tosca/resources/vegtenant.py b/xos/tosca/resources/vegtenant.py
deleted file mode 100644
index 15d80cf..0000000
--- a/xos/tosca/resources/vegtenant.py
+++ /dev/null
@@ -1,22 +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.veg.models import VEGTenant
-from serviceinstance import XOSServiceInstance
-
-class XOSVegTenant(XOSServiceInstance):
-    provides = "tosca.nodes.VEGTenant"
-    xos_model = VEGTenant
diff --git a/xos/veg-onboard.yaml b/xos/veg-onboard.yaml
index be20a52..a22775a 100644
--- a/xos/veg-onboard.yaml
+++ b/xos/veg-onboard.yaml
@@ -29,9 +29,5 @@
           base_url: file:///opt/xos_services/vEG/xos/
           # The following will concatenate with base_url automatically, if
           # base_url is non-null.
-          xproto: ./
-          tosca_custom_types: veg.yaml
-          tosca_resource: tosca/resources/vegservice.py, tosca/resources/vegtenant.py
           private_key: file:///opt/xos/key_import/veg_rsa
           public_key: file:///opt/xos/key_import/veg_rsa.pub
-
diff --git a/xos/veg.m4 b/xos/veg.m4
deleted file mode 100644
index 309db0b..0000000
--- a/xos/veg.m4
+++ /dev/null
@@ -1,59 +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.
-
-
-tosca_definitions_version: tosca_simple_yaml_1_0
-
-# compile this with "m4 veg.m4 > veg.yaml"
-
-# include macros
-include(macros.m4)
-
-node_types:
-    
-    tosca.nodes.VEGService:
-        description: >
-            CORD: The vEG Service.
-        derived_from: tosca.nodes.Root
-        capabilities:
-            xos_base_service_caps
-        properties:
-            xos_base_props
-            xos_base_service_props
-            backend_network_label:
-                type: string
-                required: false
-                description: Label that matches network used to connect HPC and BBS services.
-            dns_servers:
-                type: string
-                required: false
-            node_label:
-                type: string
-                required: false
-            docker_image_name:
-                type: string
-                required: false
-                description: Name of docker image to pull for vEG
-            docker_insecure_registry:
-                type: boolean
-                required: false
-                description: If true, then the hostname:port specified in docker_image_name will be treated as an insecure registry
-
-    tosca.nodes.VEGTenant:
-        derived_from: tosca.nodes.Root
-        description: >
-            A VEG Tenant.
-        properties:
-            xos_base_tenant_props
diff --git a/xos/veg.yaml b/xos/veg.yaml
deleted file mode 100644
index 659135e..0000000
--- a/xos/veg.yaml
+++ /dev/null
@@ -1,130 +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.
-
-
-tosca_definitions_version: tosca_simple_yaml_1_0
-
-# compile this with "m4 veg.m4 > veg.yaml"
-
-# include macros
-
-# Note: Tosca derived_from isn't working the way I think it should, it's not
-#    inheriting from the parent template. Until we get that figured out, use
-#    m4 macros do our inheritance
-
-
-# Service
-
-
-# Subscriber
-
-
-
-
-# end m4 macros
-
-
-
-node_types:
-    
-    tosca.nodes.VEGService:
-        description: >
-            CORD: The vEG Service.
-        derived_from: tosca.nodes.Root
-        capabilities:
-            scalable:
-                type: tosca.capabilities.Scalable
-            service:
-                type: tosca.capabilities.xos.Service
-        properties:
-            no-delete:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to delete this object
-            no-create:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to create this object
-            no-update:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to update this object
-            replaces:
-                type: string
-                required: false
-                descrption: Replaces/renames this object
-            kind:
-                type: string
-                default: generic
-                description: Type of service.
-            view_url:
-                type: string
-                required: false
-                description: URL to follow when icon is clicked in the Service Directory.
-            icon_url:
-                type: string
-                required: false
-                description: ICON to display in the Service Directory.
-            enabled:
-                type: boolean
-                default: true
-            published:
-                type: boolean
-                default: true
-                description: If True then display this Service in the Service Directory.
-            public_key:
-                type: string
-                required: false
-                description: Public key to install into Instances to allows Services to SSH into them.
-            private_key_fn:
-                type: string
-                required: false
-                description: Location of private key file
-            versionNumber:
-                type: string
-                required: false
-                description: Version number of Service.
-            backend_network_label:
-                type: string
-                required: false
-                description: Label that matches network used to connect HPC and BBS services.
-            dns_servers:
-                type: string
-                required: false
-            node_label:
-                type: string
-                required: false
-            docker_image_name:
-                type: string
-                required: false
-                description: Name of docker image to pull for vEG
-            docker_insecure_registry:
-                type: boolean
-                required: false
-                description: If true, then the hostname:port specified in docker_image_name will be treated as an insecure registry
-
-    tosca.nodes.VEGTenant:
-        derived_from: tosca.nodes.Root
-        description: >
-            A VEG Tenant.
-        properties:
-            kind:
-                type: string
-                default: generic
-                description: Kind of tenant
-            service_specific_id:
-                type: string
-                required: false
-                description: Service specific ID opaque to XOS but meaningful to service