Refactor vBBU from 2.0 to 3.0, not for master
Change-Id: Ib2d68852ad4065d8c34599dca731123ed6297e84
diff --git a/xos/synchronizer/Dockerfile.synchronizer b/xos/synchronizer/Dockerfile.synchronizer
new file mode 100644
index 0000000..b31583e
--- /dev/null
+++ b/xos/synchronizer/Dockerfile.synchronizer
@@ -0,0 +1,39 @@
+# xosproject/vbbu-synchronizer
+FROM xosproject/xos-synchronizer-base:candidate
+
+COPY . /opt/xos/synchronizers/vbbu
+
+ENTRYPOINT []
+
+WORKDIR "/opt/xos/synchronizers/vbbu"
+
+# Label image
+ARG org_label_schema_schema_version=1.0
+ARG org_label_schema_name=vbbu-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/vbbu; ./run-from-api.sh"
\ No newline at end of file
diff --git a/xos/synchronizer/manifest b/xos/synchronizer/manifest
index 1eb3bf5..5fca47e 100644
--- a/xos/synchronizer/manifest
+++ b/xos/synchronizer/manifest
@@ -1,8 +1,8 @@
model-deps
vbbu-synchronizer.py
vbbu_config
-steps/sync_vbbu.py
-steps/sync_vbbu.yaml
+steps/sync_vbbutenant.py
+steps/vbbutenant_playbook.yaml
stop.sh
manifest
__init__.py
diff --git a/xos/synchronizer/run-from-api.sh b/xos/synchronizer/run-from-api.sh
new file mode 100755
index 0000000..b81baea
--- /dev/null
+++ b/xos/synchronizer/run-from-api.sh
@@ -0,0 +1,2 @@
+export XOS_DIR=/opt/xos
+python vbbu-synchronizer.py -C $XOS_DIR/synchronizers/vbbu/vbbu_from_api_config
\ No newline at end of file
diff --git a/xos/synchronizer/run.sh b/xos/synchronizer/run.sh
deleted file mode 100644
index 27d4e24..0000000
--- a/xos/synchronizer/run.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-# Runs the XOS observer using helloworldservice_config
-export XOS_DIR=/opt/xos
-python vbbu-synchronizer.py -C $XOS_DIR/synchronizers/vbbu/vbbu_config
diff --git a/xos/synchronizer/steps/sync_vbbu.py b/xos/synchronizer/steps/sync_vbbu.py
deleted file mode 100644
index a000230..0000000
--- a/xos/synchronizer/steps/sync_vbbu.py
+++ /dev/null
@@ -1,37 +0,0 @@
-import os
-import sys
-from django.db.models import Q, F
-from services.vbbu.models import MCORDService, VBBUComponent
-from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
-
-parentdir = os.path.join(os.path.dirname(__file__), "..")
-sys.path.insert(0, parentdir)
-
-class SyncVBBUComponent(SyncInstanceUsingAnsible):
-
- provides = [VBBUComponent]
-
- observes = VBBUComponent
-
- requested_interval = 0
-
- template_name = "sync_vbbu.yaml"
-
- service_key_name = "/opt/xos/configurations/mcord/mcord_private_key"
-
- def __init__(self, *args, **kwargs):
- super(SyncVBBUComponent, self).__init__(*args, **kwargs)
-
- def fetch_pending(self, deleted):
-
- if (not deleted):
- objs = VBBUComponent.get_tenant_objects().filter(
- Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
- else:
-
- objs = VBBUComponent.get_deleted_tenant_objects()
-
- return objs
-
- def get_extra_attributes(self, o):
- return {"display_message": o.display_message, "s1u_tag": o.s1u_tag, "s1mme_tag": o.s1mme_tag, "rru_tag": o.rru_tag}
diff --git a/xos/synchronizer/steps/sync_vbbutenant.py b/xos/synchronizer/steps/sync_vbbutenant.py
new file mode 100644
index 0000000..1ec4528
--- /dev/null
+++ b/xos/synchronizer/steps/sync_vbbutenant.py
@@ -0,0 +1,39 @@
+import os
+import sys
+from django.db.models import Q, F
+# from services.vbbu.models import MCORDService, VBBUTenant
+from synchronizers.new_base.modelaccessor import *
+from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+
+parentdir = os.path.join(os.path.dirname(__file__), "..")
+sys.path.insert(0, parentdir)
+
+class SyncVBBUTenant(SyncInstanceUsingAnsible):
+
+
+ provides = [VBBUTenant]
+
+ observes = VBBUTenant
+
+ requested_interval = 0
+
+ template_name = "vbbutenant_playbook.yaml"
+
+ service_key_name = "/opt/xos/configurations/mcord/mcord_private_key"
+
+ def __init__(self, *args, **kwargs):
+ super(SyncVBBUTenant, self).__init__(*args, **kwargs)
+
+ def fetch_pending(self, deleted):
+
+ if (not deleted):
+ objs = VBBUTenant.get_tenant_objects().filter(
+ Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
+ else:
+
+ objs = VBBUTenant.get_deleted_tenant_objects()
+
+ return objs
+
+ def get_extra_attributes(self, o):
+ return {"display_message": o.display_message, "s1u_tag": o.s1u_tag, "s1mme_tag": o.s1mme_tag, "rru_tag": o.rru_tag}
diff --git a/xos/synchronizer/steps/sync_vbbu.yaml b/xos/synchronizer/steps/vbbutenant_playbook.yaml
similarity index 100%
rename from xos/synchronizer/steps/sync_vbbu.yaml
rename to xos/synchronizer/steps/vbbutenant_playbook.yaml
diff --git a/xos/synchronizer/vbbu-synchronizer.py b/xos/synchronizer/vbbu-synchronizer.py
index 95f4081..0fb2fcb 100644
--- a/xos/synchronizer/vbbu-synchronizer.py
+++ b/xos/synchronizer/vbbu-synchronizer.py
@@ -7,7 +7,7 @@
import os
import sys
observer_path = os.path.join(os.path.dirname(
- os.path.realpath(__file__)), "../../synchronizers/base")
+ 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/vbbu_config b/xos/synchronizer/vbbu_config
deleted file mode 100644
index f85ecb3..0000000
--- a/xos/synchronizer/vbbu_config
+++ /dev/null
@@ -1,40 +0,0 @@
-# Required by XOS
-[db]
-name=xos
-user=postgres
-password=password
-host=xos_db
-port=5432
-
-# Required by XOS
-[api]
-nova_enabled=True
-
-# Sets options for the observer
-[observer]
-# Optional name
-name=vbbu
-# This is the location to the dependency graph you generate
-dependency_graph=/opt/xos/synchronizers/vbbu/model-deps
-# The location of your SyncSteps
-steps_dir=/opt/xos/synchronizers/vbbu/steps
-# A temporary directory that will be used by ansible
-sys_dir=/opt/xos/synchronizers/vbbu/sys
-# Location of the file to save logging messages to the backend log is often used
-logfile=/var/log/xos_backend.log
-# If this option is true, then nothing will change, we simply pretend to run
-pretend=False
-# If this is False then XOS will use an exponential backoff when the observer
-# fails, since we will be waiting for an instance, we don't want this.
-backoff_disabled=True
-# We want the output from ansible to be logged
-save_ansible_output=True
-# This determines how we SSH to a client, if this is set to True then we try
-# to ssh using the instance name as a proxy, if this is disabled we ssh using
-# the NAT IP of the instance. On CloudLab the first option will fail so we must
-# set this to False
-proxy_ssh=True
-proxy_ssh_key=/root/setup/id_rsa
-proxy_ssh_user=root
-[networking]
-use_vtn=True
diff --git a/xos/synchronizer/vbbu_from_api_config b/xos/synchronizer/vbbu_from_api_config
new file mode 100644
index 0000000..34a07ee
--- /dev/null
+++ b/xos/synchronizer/vbbu_from_api_config
@@ -0,0 +1,20 @@
+# Sets options for the synchronizer
+[observer]
+name=vbbu
+dependency_graph=/opt/xos/synchronizers/vbbu/model-deps
+steps_dir=/opt/xos/synchronizers/vbbu/steps
+sys_dir=/opt/xos/synchronizers/vbbu/sys
+#logfile=/var/log/xos_backend.log
+log_file=console
+log_level=debug
+pretend=False
+backoff_disabled=True
+save_ansible_output=True
+proxy_ssh=True
+proxy_ssh_key=/opt/cord_profile/node_key
+proxy_ssh_user=root
+accessor_kind=api
+accessor_password=@/opt/xos/services/vbbu/credentials/xosadmin@opencord.org
+
+[networking]
+use_vtn=True