CORD-2510 Migrate VNaaS to dynamic load
Change-Id: Ie786c452379ae96706b2319f98ccddfc82b8b205
diff --git a/xos/synchronizer/models/Makefile.service b/xos/synchronizer/models/Makefile.service
new file mode 100755
index 0000000..9fb96f4
--- /dev/null
+++ b/xos/synchronizer/models/Makefile.service
@@ -0,0 +1,18 @@
+# Replace the line below with the location of xosgen
+PREFIX=.
+XOSGEN=$(PREFIX)/tool/xosgen
+
+DJANGO_TARGET=$(PREFIX)/targets/service.xtarget
+XPROTOS_TMP := $(shell mktemp)
+
+xprotos = $(wildcard *.xproto)
+
+all: models.py
+
+models.py: $(xprotos)
+ $(XOSGEN) --attic attic --target $(DJANGO_TARGET) --output $@ $<
+
+.PHONY: all
+
+clean:
+ rm -f models.py
diff --git a/xos/synchronizer/models/attic/header.py b/xos/synchronizer/models/attic/header.py
new file mode 100755
index 0000000..b7100ed
--- /dev/null
+++ b/xos/synchronizer/models/attic/header.py
@@ -0,0 +1,22 @@
+
+# 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
+from core.models import XOSBase
+from core.models import Site
+
+
diff --git a/xos/synchronizer/models/attic/usernetworkinterface_model.py b/xos/synchronizer/models/attic/usernetworkinterface_model.py
new file mode 100755
index 0000000..121611e
--- /dev/null
+++ b/xos/synchronizer/models/attic/usernetworkinterface_model.py
@@ -0,0 +1,35 @@
+
+# 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 __xos_save_base(self, *args, **kwargs):
+
+ if self.latlng:
+ try:
+ latlng_value = getattr(self, 'latlng').strip()
+ if (latlng_value.startswith('[') and latlng_value.endswith(']') and latlng_value.index(',') > 0):
+ lat = latlng_value[1: latlng_value.index(',')].strip()
+ lng = latlng_value[latlng_value.index(',') + 1: len(latlng_value) - 1].strip()
+
+ # If lat and lng are not floats, the code below should result in an error.
+ lat_validation = float(lat)
+ lng_validation = float(lng)
+ else:
+ raise ValueError("The lat/lng value is not formatted correctly.")
+ except:
+ raise ValueError("The lat/lng value is not formatted correctly.")
+
+ return False # let xosbase know to save the model
+
diff --git a/xos/synchronizer/models/vnaas.xproto b/xos/synchronizer/models/vnaas.xproto
new file mode 100755
index 0000000..00d73b3
--- /dev/null
+++ b/xos/synchronizer/models/vnaas.xproto
@@ -0,0 +1,60 @@
+option name = "vnaas";
+option app_label = "vnaas";
+
+message EnterpriseLocation (XOSBase){
+ option verbose_name = "Enterprise Location";
+
+ required string name = 1 [help_text = "Name for this Enterprise Location", db_index = False, max_length = 256, null = False, blank = False];
+ required string cord_site_ip = 2 [help_text = "IP of the local site", db_index = False, max_length = 64, null = False, blank = False];
+ required int32 cord_site_port = 3 [help_text = "Port of the local site", db_index = False, null = False, blank = False];
+ required string cord_site_username = 4 [help_text = "Username of the local site", db_index = False, max_length = 64, null = False, blank = False];
+ required string cord_site_password = 5 [help_text = "Password of the local site", db_index = False, max_length = 64, null = False, blank = False];
+ required string cord_site_type = 6 [default = "xos", choices = "(('onos', 'ONOS'), ('xos', 'XOS'))", db_index = False, max_length = 64, null = False, blank = False];
+
+}
+
+message OnosModel (XOSBase){
+ option verbose_name = "Open Network Operating System";
+
+ required string name = 1 [db_index = False, max_length = 256, null = False, blank = False];
+ required string onos_ip = 2 [help_text = "IP of the transport manager", db_index = False, max_length = 64, null = False, blank = False];
+ required int32 onos_port = 3 [help_text = "Port of the transport manager", db_index = False, null = False, blank = False];
+ required string onos_username = 4 [help_text = "Username of the transport manager", db_index = False, max_length = 64, null = False, blank = False];
+ required string onos_password = 5 [help_text = "Password of the transport manager", db_index = False, max_length = 64, null = False, blank = False];
+ required string onos_type = 6 [default = "local", choices = "(('local', 'Local'), ('global', 'Global'))", db_index = False, max_length = 64, null = False, blank = False];
+
+}
+
+message UserNetworkInterface (XOSBase){
+ option verbose_name = "User Network Interface";
+
+ required string tenant = 1 [help_text = "Tenant name", db_index = False, max_length = 256, null = False, blank = False];
+ required string cpe_id = 2 [db_index = False, max_length = 1024, null = False, blank = False];
+ required string latlng = 3 [help_text = "Location, i.e. [37.773972, -122.431297]", db_index = False, max_length = 256, null = False, blank = False];
+ optional string name = 4 [help_text = "Name for this User Network Interface", db_index = False, max_length = 256, null = False, blank = False];
+}
+
+
+message BandwidthProfile (XOSBase){
+ option verbose_name = "Bandwidth Profile";
+
+ required string name = 1 [help_text = "Name for this Bandwidth Profile", db_index = False, max_length = 256, null = False, blank = False];
+ required int32 cbs = 2 [help_text = "Committed burst size", db_index = False, null = False, blank = False];
+ required int32 ebs = 3 [help_text = "Expected burst size", db_index = False, null = False, blank = False];
+ required int32 cir = 4 [help_text = "Committed information rate", db_index = False, null = False, blank = False];
+ required int32 eir = 5 [help_text = "Expected information rate", db_index = False, null = False, blank = False];
+
+}
+
+message ELine (XOSBase){
+ option verbose_name = "Ethernet Virtual Private Line";
+ option plural = "Elines";
+
+ required string name = 1 [help_text = "Name for this ELine", db_index = False, max_length = 256, null = False, blank = False];
+ required manytoone connect_point_1->UserNetworkInterface:incoming_eline = 2 [help_text = "Cpe_id of the first connection point", db_index = False, max_length = 256, null = False, blank = False];
+ required manytoone connect_point_2->UserNetworkInterface:outgoing_eline = 3 [help_text = "Cpe_id of the second connection point", db_index = False, max_length = 64, null = False, blank = False];
+ required string vlanids = 4 [help_text = "Comma separated list of vlanIds", db_index = False, null = False, blank = False];
+ required string cord_site_name = 5 [help_text = "Name of the CORD site", db_index = False, max_length = 64, null = False, blank = False];
+ required manytoone bwp->BandwidthProfile:elines = 6 [help_text = "Bandwidth profile name", db_index = False, max_length = 256, null = False, blank = False];
+
+}
diff --git a/xos/synchronizer/steps/test_sync_vnaaseline.py b/xos/synchronizer/steps/test_sync_vnaaseline.py
index 4aa34af..3fcd380 100644
--- a/xos/synchronizer/steps/test_sync_vnaaseline.py
+++ b/xos/synchronizer/steps/test_sync_vnaaseline.py
@@ -54,6 +54,18 @@
ELINE_VLANIDS = "100"
ELINE_NAME = "testeline"
+# 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 TestSyncvNaaSEline(unittest.TestCase):
def setUp(self):
global SyncvNaaSEline, MockObjectList
@@ -68,7 +80,7 @@
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, ["vnaas/xos/vnaas.xproto"])
+ build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("vnaas", "vnaas.xproto")])
import synchronizers.new_base.modelaccessor
import synchronizers.new_base.model_policies.model_policy_tenantwithcontainer
diff --git a/xos/synchronizer/vnaas_config.yaml b/xos/synchronizer/vnaas_config.yaml
index 0c8fb1e..f2bae31 100755
--- a/xos/synchronizer/vnaas_config.yaml
+++ b/xos/synchronizer/vnaas_config.yaml
@@ -12,10 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-name: vnaas-synchronizer
+name: vnaas
accessor:
username: xosadmin@opencord.org
password: "@/opt/xos/services/vnaas/credentials/xosadmin@opencord.org"
+required_models:
+ - ELine
+ - BandwidthProfile
+ - UserNetworkInterface
+ - OnosModel
+ - EnterpriseLocation
dependency_graph: "/opt/xos/synchronizers/vnaas/model-deps"
steps_dir: "/opt/xos/synchronizers/vnaas/steps"
sys_dir: "/opt/xos/synchronizers/vnaas/sys"
+models_dir: "/opt/xos/synchronizers/vnaas/models"