CORD-2941 empty synchronizer framework
Change-Id: I06d27acd11b98060237eccc5ed2ac287fe4642d9
diff --git a/Dockerfile.synchronizer b/Dockerfile.synchronizer
new file mode 100644
index 0000000..b71c315
--- /dev/null
+++ b/Dockerfile.synchronizer
@@ -0,0 +1,61 @@
+
+# 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.
+
+# docker build -t xosproject/kubernetes-synchronizer:candidate -f Dockerfile.synchronizer .
+
+# xosproject/kubernetes-synchronizer
+
+FROM xosproject/xos-synchronizer-base:candidate
+
+COPY xos/synchronizer /opt/xos/synchronizers/kubernetes
+COPY VERSION /opt/xos/synchronizers/kubernetes/
+
+RUN pip install kubernetes==6.0.0
+
+ENTRYPOINT []
+
+WORKDIR "/opt/xos/synchronizers/kubernetes"
+
+# Label image
+ARG org_label_schema_schema_version=1.0
+ARG org_label_schema_name=kubernetes-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 "service filebeat start; cd /opt/xos/synchronizers/kubernetes; python kubernetes-synchronizer.py"
+
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..3f6d5ce
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+6.0.0.dev0
diff --git a/xos/synchronizer/kubernetes-synchronizer.py b/xos/synchronizer/kubernetes-synchronizer.py
new file mode 100644
index 0000000..5c83aaf
--- /dev/null
+++ b/xos/synchronizer/kubernetes-synchronizer.py
@@ -0,0 +1,40 @@
+
+# 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.
+
+"""
+ kubernetes-synchronizer.py
+
+ This is the main entrypoint for the synchronizer. It loads the config file, and then starts the synchronizer.
+"""
+
+
+#!/usr/bin/env python
+
+# Runs the standard XOS synchronizer
+
+import importlib
+import os
+import sys
+from xosconfig import Config
+
+config_file = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/kubernetes_config.yaml')
+Config.init(config_file, 'synchronizer-config-schema.yaml')
+
+synchronizer_path = os.path.join(os.path.dirname(
+ os.path.realpath(__file__)), "../../synchronizers/new_base")
+sys.path.append(synchronizer_path)
+mod = importlib.import_module("xos-synchronizer")
+mod.main()
+
diff --git a/xos/synchronizer/kubernetes_config.yaml b/xos/synchronizer/kubernetes_config.yaml
new file mode 100644
index 0000000..2d3b882
--- /dev/null
+++ b/xos/synchronizer/kubernetes_config.yaml
@@ -0,0 +1,29 @@
+
+# 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: kubernetes
+accessor:
+ username: xosadmin@opencord.org
+ password: "@/opt/xos/services/kubernetes/credentials/xosadmin@opencord.org"
+required_models:
+ - KubernetesService
+ - KubernetesServiceInstance
+dependency_graph: "/opt/xos/synchronizers/kubernetes/model-deps"
+steps_dir: "/opt/xos/synchronizers/kubernetes/steps"
+sys_dir: "/opt/xos/synchronizers/kubernetes/sys"
+#model_policies_dir: "/opt/xos/synchronizers/kubernetes/model_policies"
+models_dir: "/opt/xos/synchronizers/kubernetes/models"
+pull_steps_dir: "/opt/xos/synchronizers/kubernetes/pull_steps"
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/kubernetes.xproto b/xos/synchronizer/models/kubernetes.xproto
new file mode 100644
index 0000000..1005057
--- /dev/null
+++ b/xos/synchronizer/models/kubernetes.xproto
@@ -0,0 +1,11 @@
+option app_label = "kubernetes";
+option name = "kubernetes";
+
+message KubernetesService (Service){
+ option verbose_name = "Kubernetes Service";
+
+}
+
+message KubernetesServiceInstance (ServiceInstance){
+ option verbose_name = "Kubernetes Service Instance";
+}
diff --git a/xos/synchronizer/pull_steps/pull_pods.py b/xos/synchronizer/pull_steps/pull_pods.py
new file mode 100644
index 0000000..bea45d7
--- /dev/null
+++ b/xos/synchronizer/pull_steps/pull_pods.py
@@ -0,0 +1,47 @@
+# 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.
+
+"""
+ pull_pods.py
+
+ Implements a syncstep to pull information about pods form Kubernetes.
+"""
+
+from synchronizers.new_base.pullstep import PullStep
+from synchronizers.new_base.modelaccessor import KubernetesServiceInstance
+
+from xosconfig import Config
+from multistructlog import create_logger
+
+from kubernetes import client as kubernetes_client, config as kubernetes_config
+
+log = create_logger(Config().get('logging'))
+
+class KubernetesServiceInstancePullStep(PullStep):
+ """
+ KubernetesServiceInstancePullStep
+
+ Pull information from Kubernetes.
+ """
+
+ def __init__(self):
+ super(KubernetesServiceInstancePullStep, self).__init__(observed_model=KubernetesServiceInstance)
+
+ kubernetes_config.load_incluster_config()
+ self.v1 = kubernetes_client.CoreV1Api()
+
+ def pull_records(self):
+ # TODO(smbaker): implement pull step here
+ pass
+
diff --git a/xos/synchronizer/steps/sync_kubernetesserviceinstance.py b/xos/synchronizer/steps/sync_kubernetesserviceinstance.py
new file mode 100644
index 0000000..400396d
--- /dev/null
+++ b/xos/synchronizer/steps/sync_kubernetesserviceinstance.py
@@ -0,0 +1,58 @@
+
+# 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.
+
+"""
+ sync_kubernetesserviceinstance.py
+
+ Synchronize KubernetesServiceInstance. See also the related pull_step.
+"""
+
+from synchronizers.new_base.syncstep import SyncStep
+from synchronizers.new_base.modelaccessor import KubernetesServiceInstance
+
+from xosconfig import Config
+from multistructlog import create_logger
+
+from kubernetes import client as kubernetes_client, config as kubernetes_config
+
+log = create_logger(Config().get('logging'))
+
+class SyncKubernetesServiceInstance(SyncStep):
+
+ """
+ SyncKubernetesServiceInstance
+
+ Implements sync step for syncing kubernetes service instances.
+ """
+
+ provides = [KubernetesServiceInstance]
+ observes = KubernetesServiceInstance
+ requested_interval = 0
+
+ def __init__(self, *args, **kwargs):
+ super(SyncKubernetesServiceInstance, self).__init__(*args, **kwargs)
+
+ kubernetes_config.load_incluster_config()
+ self.v1 = kubernetes_client.CoreV1Api()
+
+ def sync_record(self, o):
+ # TODO(smbaker): implement sync step here
+ pass
+
+
+ def delete_record(self, port):
+ # TODO(smbaker): implement delete sync step here
+ pass
+