CORD-2509 migrate mcord profile from static to dynamic load
Change-Id: I69a56875db0ec13ad61d9fbc3261da0735adcb9b
diff --git a/xos/synchronizer/Dockerfile.synchronizer b/xos/synchronizer/Dockerfile.synchronizer
new file mode 100644
index 0000000..c407a81
--- /dev/null
+++ b/xos/synchronizer/Dockerfile.synchronizer
@@ -0,0 +1,55 @@
+
+# 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.
+
+
+# xosproject/mcord-synchronizer
+FROM xosproject/xos-synchronizer-base:candidate
+
+COPY . /opt/xos/synchronizers/mcord
+
+ENTRYPOINT []
+
+WORKDIR "/opt/xos/synchronizers/mcord"
+
+# Label image
+ARG org_label_schema_schema_version=1.0
+ARG org_label_schema_name=mcord-synchronizer
+ARG org_label_schema_version=unknown
+ARG org_label_schema_vcs_url=unknown
+ARG org_label_schema_vcs_ref=unknown
+ARG org_label_schema_build_date=unknown
+ARG org_opencord_vcs_commit_date=unknown
+ARG org_opencord_component_chameleon_version=unknown
+ARG org_opencord_component_chameleon_vcs_url=unknown
+ARG org_opencord_component_chameleon_vcs_ref=unknown
+ARG org_opencord_component_xos_version=unknown
+ARG org_opencord_component_xos_vcs_url=unknown
+ARG org_opencord_component_xos_vcs_ref=unknown
+
+LABEL org.label-schema.schema-version=$org_label_schema_schema_version \
+ org.label-schema.name=$org_label_schema_name \
+ org.label-schema.version=$org_label_schema_version \
+ org.label-schema.vcs-url=$org_label_schema_vcs_url \
+ org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
+ org.label-schema.build-date=$org_label_schema_build_date \
+ org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
+ org.opencord.component.chameleon.version=$org_opencord_component_chameleon_version \
+ org.opencord.component.chameleon.vcs-url=$org_opencord_component_chameleon_vcs_url \
+ org.opencord.component.chameleon.vcs-ref=$org_opencord_component_chameleon_vcs_ref \
+ org.opencord.component.xos.version=$org_opencord_component_xos_version \
+ org.opencord.component.xos.vcs-url=$org_opencord_component_xos_vcs_url \
+ org.opencord.component.xos.vcs-ref=$org_opencord_component_xos_vcs_ref
+
+CMD bash -c "cd /opt/xos/synchronizers/mcord; ./run-from-api.sh"
diff --git a/xos/synchronizer/mcord-synchronizer.py b/xos/synchronizer/mcord-synchronizer.py
new file mode 100644
index 0000000..57dc508
--- /dev/null
+++ b/xos/synchronizer/mcord-synchronizer.py
@@ -0,0 +1,32 @@
+
+# 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.
+
+
+#!/usr/bin/env python
+
+# This imports and runs ../../xos-observer.py
+
+import importlib
+import os
+import sys
+from xosconfig import Config
+
+config_file = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/mcord_config.yaml')
+Config.init(config_file, 'synchronizer-config-schema.yaml')
+
+observer_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"../../synchronizers/new_base")
+sys.path.append(observer_path)
+mod = importlib.import_module("xos-synchronizer")
+mod.main()
diff --git a/xos/synchronizer/mcord_config.yaml b/xos/synchronizer/mcord_config.yaml
new file mode 100644
index 0000000..373ef97
--- /dev/null
+++ b/xos/synchronizer/mcord_config.yaml
@@ -0,0 +1,24 @@
+
+# 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.
+
+
+name: mcord
+accessor:
+ username: xosadmin@opencord.org
+ password: "@/opt/xos/services/mcord/credentials/xosadmin@opencord.org"
+dependency_graph: "/opt/xos/synchronizers/mcord/model-deps"
+sys_dir: "/opt/xos/synchronizers/mcord/sys"
+models_dir: "/opt/xos/synchronizers/mcord/models"
+
diff --git a/xos/synchronizer/model-deps b/xos/synchronizer/model-deps
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/xos/synchronizer/model-deps
@@ -0,0 +1 @@
+{}
diff --git a/xos/synchronizer/models/mcord.xproto b/xos/synchronizer/models/mcord.xproto
new file mode 100644
index 0000000..033e0c7
--- /dev/null
+++ b/xos/synchronizer/models/mcord.xproto
@@ -0,0 +1,19 @@
+option app_label = "mcord";
+option name = "mcord";
+option legacy = "True";
+
+message MCordSubscriberService (Service) {
+ option verbose_name = "MCORD Service";
+ option description = "The Mobile Subscriber service in CORD";
+}
+
+message MCordSubscriberInstance (ServiceInstance) {
+ option verbose_name = "MCORD Subscriber";
+ option description = "This model holds the informations of a Mobile Subscriber in CORD";
+ option owner_class_name="MCordSubscriberService";
+
+ required string imsi_number = 1 [max_length = 30, content_type = "stripped", blank = False, null = False, db_index = False];
+ optional string apn_number = 2 [max_length = 30, content_type = "stripped", blank = True, null = True, db_index = False];
+ optional int32 ue_status = 3 [default = "0", choices = "(('0', 'Detached'), ('1', 'Attached'))", blank = True, null = True, db_index = False];
+ optional string created_by = 4 [null = True, blank = True, gui_hidden = True];
+}
diff --git a/xos/synchronizer/models/models.py b/xos/synchronizer/models/models.py
new file mode 100644
index 0000000..c1471f4
--- /dev/null
+++ b/xos/synchronizer/models/models.py
@@ -0,0 +1,39 @@
+from xos.exceptions import XOSValidationError
+
+from models_decl import MCordSubscriberService_decl
+from models_decl import MCordSubscriberInstance_decl
+
+
+
+
+class MCordSubscriberService(MCordSubscriberService_decl):
+ class Meta:
+ proxy = True
+
+
+class MCordSubscriberInstance(MCordSubscriberInstance_decl):
+ class Meta:
+ proxy = True
+
+ def save(self, *args, **kwargs):
+ # if we don't have a name, use the IMSI number has a name
+ if not self.name:
+ self.name = self.imsi_number
+
+ # prevent IMSI duplicate
+ try:
+ instance_with_same_imsi = MCordSubscriberInstance.objects.get(imsi_number=self.imsi_number)
+
+ if (not self.pk and instance_with_same_imsi) or (self.pk and self.pk != instance_with_same_imsi.pk):
+ raise XOSValidationError("An MCORDSubscriber with imsi_number '%s' already exists" % self.imsi_number)
+ except self.DoesNotExist:
+ pass
+
+ if self.is_new and not self.created_by:
+ # NOTE if created_by is null it has been created by XOS
+ self.created_by = "XOS"
+
+ self.backend_code = 0
+ self.backend_status = "In Progress"
+
+ super(MCordSubscriberInstance, self).save(*args, **kwargs)
diff --git a/xos/synchronizer/run-from-api.sh b/xos/synchronizer/run-from-api.sh
new file mode 100755
index 0000000..8623ab3
--- /dev/null
+++ b/xos/synchronizer/run-from-api.sh
@@ -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.
+
+
+python mcord-synchronizer.py