CORD-2476 Migrate onos to dynamic load
Change-Id: I9fe0a470363dfed53ea62887df4191eb08d59c0a
diff --git a/xos/attic/onosapp_model.py b/xos/attic/onosapp_model.py
deleted file mode 100644
index 3516f8f..0000000
--- a/xos/attic/onosapp_model.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.
-
-
-def __init__(self, *args, **kwargs):
- onos_services = ONOSService.objects.all()
- if onos_services:
- self._meta.get_field("owner").default = onos_services[0].id
- super(ONOSApp, self).__init__(*args, **kwargs)
-
diff --git a/xos/header.py b/xos/header.py
deleted file mode 100755
index d86dc29..0000000
--- a/xos/header.py
+++ /dev/null
@@ -1,29 +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 django.db import models
-from core.models import Service, XOSBase, Slice, Instance, ServiceInstance, Node, Image, User, Flavor
-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 *
-from operator import itemgetter, attrgetter, methodcaller
-import traceback
-from xos.exceptions import *
-from core.models import SlicePrivilege, SitePrivilege
-from sets import Set
-
diff --git a/xos/onos-onboard.yaml b/xos/onos-onboard.yaml
index c6dd3ea..e4cbe20 100644
--- a/xos/onos-onboard.yaml
+++ b/xos/onos-onboard.yaml
@@ -29,8 +29,6 @@
base_url: file:///opt/xos_services/onos-service/xos/
# The following will concatenate with base_url automatically, if
# base_url is non-null.
- xproto: ./
- tosca_resource: tosca/resources/onosservice.py, tosca/resources/onosapp.py
private_key: file:///opt/xos/key_import/onos_rsa
public_key: file:///opt/xos/key_import/onos_rsa.pub
diff --git a/xos/synchronizer/models/models.py b/xos/synchronizer/models/models.py
new file mode 100644
index 0000000..4e7c71a
--- /dev/null
+++ b/xos/synchronizer/models/models.py
@@ -0,0 +1,31 @@
+
+# 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 xos.exceptions import *
+from models_decl import *
+
+class ONOSApp(ONOSApp_decl):
+ class Meta:
+ proxy = True
+
+ def __init__(self, *args, **kwargs):
+ onos_services = ONOSService.objects.all()
+ if onos_services:
+ self._meta.get_field("owner").default = onos_services[0].id
+ super(ONOSApp, self).__init__(*args, **kwargs)
+
+class ONOSService(ONOSService_decl):
+ class Meta:
+ proxy = True
diff --git a/xos/onos.xproto b/xos/synchronizer/models/onos.xproto
similarity index 97%
rename from xos/onos.xproto
rename to xos/synchronizer/models/onos.xproto
index 5c79b44..bc8a590 100644
--- a/xos/onos.xproto
+++ b/xos/synchronizer/models/onos.xproto
@@ -1,6 +1,7 @@
option kind="onos";
option app_label = "onos";
option name="onos";
+option legacy="True";
message ONOSApp (ServiceInstance){
option verbose_name="ONOS Application";
diff --git a/xos/synchronizer/onos_config.yaml b/xos/synchronizer/onos_config.yaml
index 63b010b..aa84d2c 100644
--- a/xos/synchronizer/onos_config.yaml
+++ b/xos/synchronizer/onos_config.yaml
@@ -14,10 +14,11 @@
# limitations under the License.
-name: onos-synchronizer
+name: onos
accessor:
username: xosadmin@opencord.org
password: "@/opt/xos/services/onos/credentials/xosadmin@opencord.org"
dependency_graph: "/opt/xos/synchronizers/onos/model-deps"
steps_dir: "/opt/xos/synchronizers/onos/steps"
-sys_dir: "/opt/xos/synchronizers/onos/sys"
\ No newline at end of file
+sys_dir: "/opt/xos/synchronizers/onos/sys"
+models_dir: "/opt/xos/synchronizers/onos/models"
diff --git a/xos/tosca/resources/onosapp.py b/xos/tosca/resources/onosapp.py
deleted file mode 100644
index d1c587a..0000000
--- a/xos/tosca/resources/onosapp.py
+++ /dev/null
@@ -1,74 +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 xosresource import XOSResource
-from core.models import User, ServiceInstanceAttribute, Service, ServiceInstanceLink
-from services.onos.models import ONOSApp, ONOSService
-
-class XOSONOSApp(XOSResource):
- provides = ["tosca.nodes.ONOSApp", "tosca.nodes.ONOSvBNGApp", "tosca.nodes.ONOSvOLTApp", "tosca.nodes.ONOSVTNApp", "tosca.nodes.ONOSvRouterApp"]
- xos_model = ONOSApp
- copyin_props = ["service_specific_id", "dependencies", "install_dependencies"]
-
- def get_xos_args(self, throw_exception=True):
- args = super(XOSONOSApp, self).get_xos_args()
-
- # provider_service is mandatory and must be the ONOS Service
- provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=throw_exception)
- if provider_name:
- args["owner"] = self.get_xos_object(ONOSService, throw_exception=throw_exception, name=provider_name)
-
- return args
-
- def set_tenant_attr(self, obj, prop_name, value):
- value = self.try_intrinsic_function(value)
- if value:
- attrs = ServiceInstanceAttribute.objects.filter(service_instance=obj, name=prop_name)
- if attrs:
- attr = attrs[0]
- if attr.value != value:
- self.info("updating attribute %s" % prop_name)
- attr.value = value
- attr.save()
- else:
- self.info("adding attribute %s" % prop_name)
- ta = ServiceInstanceAttribute(service_instance=obj, name=prop_name, value=value)
- ta.save()
-
- def postprocess(self, obj):
- props = self.nodetemplate.get_properties()
- for (k,d) in props.items():
- v = d.value
- if k.startswith("config_"):
- self.set_tenant_attr(obj, k, v)
- elif k.startswith("rest_") and (k!="rest_hostname") and (k!="rest_port"):
- self.set_tenant_attr(obj, k, v)
- elif k.startswith("component_config"):
- self.set_tenant_attr(obj, k, v)
- elif k == "autogenerate":
- self.set_tenant_attr(obj, k, v)
-
- # subscriber_service is optional and can be any service
- subscriber_name = self.get_requirement("tosca.relationships.UsedByService", throw_exception=False)
- if subscriber_name:
- sub_serv = self.get_xos_object(Service, throw_exception=True, name=subscriber_name)
- existing_links = ServiceInstanceLink.objects.filter(provider_service_instance_id = obj.id, subscriber_service_id = sub_serv.id)
- if not existing_links:
- link = ServiceInstanceLink(provider_service_instance = obj, subscriber_service = sub_serv)
- link.save()
-
- def can_delete(self, obj):
- return super(XOSONOSApp, self).can_delete(obj)
diff --git a/xos/tosca/resources/onosservice.py b/xos/tosca/resources/onosservice.py
deleted file mode 100644
index b274d5b..0000000
--- a/xos/tosca/resources/onosservice.py
+++ /dev/null
@@ -1,49 +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 service import XOSService
-from core.models import ServiceAttribute
-from services.onos.models import ONOSService
-
-class XOSONOSService(XOSService):
- provides = "tosca.nodes.ONOSService"
- xos_model = ONOSService
- copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "versionNumber", "rest_hostname", "rest_port", "no_container", "node_key"]
-
- def set_service_attr(self, obj, prop_name, value):
- value = self.try_intrinsic_function(value)
- if value:
- attrs = ServiceAttribute.objects.filter(service=obj, name=prop_name)
- if attrs:
- attr = attrs[0]
- if attr.value != value:
- self.info("updating attribute %s" % prop_name)
- attr.value = value
- attr.save()
- else:
- self.info("adding attribute %s" % prop_name)
- ta = ServiceAttribute(service=obj, name=prop_name, value=value)
- ta.save()
-
- def postprocess(self, obj):
- props = self.nodetemplate.get_properties()
- for (k,d) in props.items():
- v = d.value
- if k.startswith("config_"):
- self.set_service_attr(obj, k, v)
- elif k.startswith("rest_") and (k!="rest_hostname") and (k!="rest_port"):
- self.set_service_attr(obj, k, v)
-