CORD-2476 migrate olt service to dynamic load

Change-Id: I6e5041983422da8df12e25824eae400ce6114290
diff --git a/xos/synchronizer/models/attic/accessagent_model.py b/xos/synchronizer/models/attic/accessagent_model.py
new file mode 100644
index 0000000..b80d979
--- /dev/null
+++ b/xos/synchronizer/models/attic/accessagent_model.py
@@ -0,0 +1,17 @@
+
+# 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.
+
+
+def __unicode__(self): return u'%s' % (self.name)
diff --git a/xos/synchronizer/models/attic/accessdevice_model.py b/xos/synchronizer/models/attic/accessdevice_model.py
new file mode 100644
index 0000000..507cd58
--- /dev/null
+++ b/xos/synchronizer/models/attic/accessdevice_model.py
@@ -0,0 +1,17 @@
+
+# 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.
+
+
+def __unicode__(self): return u'%s-%d:%d' % (self.volt_device.name,self.uplink,self.vlan)
diff --git a/xos/synchronizer/models/attic/agentportmapping_model.py b/xos/synchronizer/models/attic/agentportmapping_model.py
new file mode 100644
index 0000000..d80baab
--- /dev/null
+++ b/xos/synchronizer/models/attic/agentportmapping_model.py
@@ -0,0 +1,17 @@
+
+# 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.
+
+
+def __unicode__(self): return u'%s-%s-%s' % (self.access_agent.name, self.port, self.mac)
diff --git a/xos/synchronizer/models/attic/header.py b/xos/synchronizer/models/attic/header.py
new file mode 100644
index 0000000..4555c8c
--- /dev/null
+++ b/xos/synchronizer/models/attic/header.py
@@ -0,0 +1,37 @@
+
+# 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 django.db import models
+from django.db.models import *
+from core.models import Service, XOSBase, Slice, Instance, ServiceInstance, ServiceInstanceLink, Node, Image, User, Flavor, NetworkParameter, NetworkParameterType, Port, AddressPool, User
+from core.models.xosbase import StrippedCharField
+import os
+from django.db import models, transaction
+from django.forms.models import model_to_dict
+from django.db.models import Q
+from operator import itemgetter, attrgetter, methodcaller
+from core.models import Tag
+from core.models.service import LeastLoadedNodeScheduler
+import traceback
+from xos.exceptions import *
+from xosconfig import Config
+
+class ConfigurationError(Exception):
+    pass
+
+VOLT_KIND = "vOLT"
+
+CORD_USE_VTN = getattr(Config(), "networking_use_vtn", False)
diff --git a/xos/synchronizer/models/attic/voltdevice_model.py b/xos/synchronizer/models/attic/voltdevice_model.py
new file mode 100644
index 0000000..b80d979
--- /dev/null
+++ b/xos/synchronizer/models/attic/voltdevice_model.py
@@ -0,0 +1,17 @@
+
+# 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.
+
+
+def __unicode__(self): return u'%s' % (self.name)
diff --git a/xos/synchronizer/models/attic/volttenant_model.py b/xos/synchronizer/models/attic/volttenant_model.py
new file mode 100644
index 0000000..9824a36
--- /dev/null
+++ b/xos/synchronizer/models/attic/volttenant_model.py
@@ -0,0 +1,33 @@
+
+# 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.
+
+
+def __init__(self, *args, **kwargs):
+    volt_services = VOLTService.objects.all()
+    if volt_services:
+        self._meta.get_field("owner").default = volt_services[0].id
+    super(VOLTTenant, self).__init__(*args, **kwargs)
+    self.cached_vcpe = None
+
+def __xos_save_base(self, *args, **kwargs):
+    if not self.creator:
+        if not getattr(self, "caller", None):
+            # caller must be set when creating a vCPE since it creates a slice
+            raise XOSProgrammingError("VOLTTenant's self.caller was not set")
+        self.creator = self.caller
+        if not self.creator:
+            raise XOSProgrammingError("VOLTTenant's self.creator was not set")
+
+    return False
diff --git a/xos/synchronizer/models/volt.xproto b/xos/synchronizer/models/volt.xproto
new file mode 100644
index 0000000..e1f5ddf
--- /dev/null
+++ b/xos/synchronizer/models/volt.xproto
@@ -0,0 +1,49 @@
+option name = "volt";
+
+message VOLTService (Service){
+     option verbose_name = "vOLT Service";
+     option kind = "vOLT";
+}
+
+message VOLTTenant (ServiceInstance){
+     option kind = "vOLT";
+     option verbose_name = "vOLT Tenant";
+
+     optional int32 s_tag = 1 [help_text = "s-tag", null = True, db_index = False, blank = True];
+     optional int32 c_tag = 2 [help_text = "c-tag", null = True, db_index = False, blank = True];
+     optional manytoone creator->User:created_volts = 3 [db_index = True, null = True, blank = True];
+}
+
+message AccessAgent (XOSBase){
+     option verbose_name = "Access Agent";
+
+     required string name = 1 [help_text = "name of agent", max_length = 254, null = False, db_index = False, blank = False];
+     required manytoone volt_service->VOLTService:access_agents = 2 [db_index = True, null = False, blank = False];
+     optional string mac = 3 [help_text = "MAC Address or Access Agent", max_length = 32, null = True, db_index = False, blank = True];
+}
+
+message VOLTDevice (XOSBase){
+     option verbose_name = "vOLT Device";
+
+     required string name = 1 [help_text = "name of device", max_length = 254, null = False, db_index = False, blank = False];
+     required manytoone volt_service->VOLTService:volt_devices = 2 [db_index = True, null = False, blank = False];
+     optional string openflow_id = 3 [help_text = "OpenFlow ID", max_length = 254, null = True, db_index = False, blank = True];
+     optional string driver = 4 [help_text = "driver", max_length = 254, null = True, db_index = False, blank = True];
+     optional manytoone access_agent->AccessAgent:volt_devices = 5 [db_index = True, null = True, blank = True];
+}
+
+message AccessDevice (XOSBase){
+     option verbose_name = "Access Device";
+
+     required manytoone volt_device->VOLTDevice:access_devices = 1 [db_index = True, null = False, blank = False];
+     optional int32 uplink = 2 [db_index = False, null = True, blank = True];
+     optional int32 vlan = 3 [db_index = False, null = True, blank = True];
+}
+
+message AgentPortMapping (XOSBase){
+     option verbose_name = "Agent Port Mapping";
+
+     required manytoone access_agent->AccessAgent:port_mappings = 1 [db_index = True, null = False, blank = False];
+     optional string mac = 2 [help_text = "MAC Address", max_length = 32, null = True, db_index = False, blank = True];
+     optional string port = 3 [help_text = "Openflow port ID", max_length = 32, null = True, db_index = False, blank = True];
+}
diff --git a/xos/synchronizer/volt_config.yaml b/xos/synchronizer/volt_config.yaml
index fdcd31f..b11266a 100644
--- a/xos/synchronizer/volt_config.yaml
+++ b/xos/synchronizer/volt_config.yaml
@@ -18,5 +18,12 @@
 accessor:
   username: xosadmin@opencord.org
   password: "@/opt/xos/services/volt/credentials/xosadmin@opencord.org"
+required_models:
+  - VOLTService
+  - VOLTTenant  
+  - VSGService
+  - VSGServiceInstance
+  - ServiceInstanceLink
 dependency_graph: "/opt/xos/synchronizers/volt/model-deps"
-model_policies_dir: "/opt/xos/synchronizers/volt/model_policies"
\ No newline at end of file
+model_policies_dir: "/opt/xos/synchronizers/volt/model_policies"
+models_dir: "/opt/xos/synchronizers/volt/models"