Create observer for vpn service
diff --git a/xos/observers/vpn/helloworldservice_config b/xos/observers/vpn/helloworldservice_config
new file mode 100644
index 0000000..8165ae1
--- /dev/null
+++ b/xos/observers/vpn/helloworldservice_config
@@ -0,0 +1,23 @@
+# Required by XOS
+[db]
+name=xos
+user=postgres
+password=password
+host=localhost
+port=5432
+
+# Required by XOS
+[api]
+nova_enabled=True
+
+# Sets options for the observer
+[observer]
+name=vpn
+dependency_graph=/opt/xos/observers/vpn/model-deps
+steps_dir=/opt/xos/observers/vpn/steps
+sys_dir=/opt/xos/observers/vpn/sys
+logfile=/var/log/xos_backend.log
+pretend=False
+backoff_disabled=True
+save_ansible_output=True
+proxy_ssh=False
diff --git a/xos/observers/vpn/model-deps b/xos/observers/vpn/model-deps
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/xos/observers/vpn/model-deps
@@ -0,0 +1 @@
+{}
diff --git a/xos/observers/vpn/run.sh b/xos/observers/vpn/run.sh
new file mode 100755
index 0000000..2fc0ca5
--- /dev/null
+++ b/xos/observers/vpn/run.sh
@@ -0,0 +1,2 @@
+export XOS_DIR=/opt/xos
+python vpn-observer.py -C $XOS_DIR/observers/vpn/vpn_config
diff --git a/xos/observers/vpn/steps/sync_vpntenant.py b/xos/observers/vpn/steps/sync_vpntenant.py
new file mode 100644
index 0000000..4632c8c
--- /dev/null
+++ b/xos/observers/vpn/steps/sync_vpntenant.py
@@ -0,0 +1,30 @@
+import os
+import sys
+from django.db.models import Q, F
+from helloworldservice_complete.models import VPNService, VPNTenant
+from observers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+
+parentdir = os.path.join(os.path.dirname(__file__), "..")
+sys.path.insert(0, parentdir)
+
+class SyncVPNTenant(SyncInstanceUsingAnsible):
+ provides = [VPNTenant]
+ observes = VPNTenant
+ requested_interval = 0
+ template_name = "sync_vpntenant.yaml"
+ service_key_name = "/opt/xos/observers/vpn/vpn_private_key"
+
+ def __init__(self, *args, **kwargs):
+ super(SyncVPNTenant, self).__init__(*args, **kwargs)
+
+ def fetch_pending(self, deleted):
+ if (not deleted):
+ objs = VPNTenant.get_tenant_objects().filter(
+ Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
+ else:
+ objs = VPNTenant.get_deleted_tenant_objects()
+
+ return objs
+
+ def get_extra_attributes(self, o):
+ return {"server_key": o.server_key}
diff --git a/xos/observers/vpn/steps/sync_vpntenant.yaml b/xos/observers/vpn/steps/sync_vpntenant.yaml
new file mode 100644
index 0000000..82193d0
--- /dev/null
+++ b/xos/observers/vpn/steps/sync_vpntenant.yaml
@@ -0,0 +1,18 @@
+---
+- hosts: {{ instance_name }}
+ gather_facts: False
+ connection: ssh
+ user: ubuntu
+ sudo: yes
+ tasks:
+ - name: install apache
+ apt: name=apache2 state=present update_cache=yes
+
+ - name: write message
+ shell: echo "{{ server_key }}" > /var/www/html/index.html
+
+ - name: stop apache
+ service: name=apache2 state=stopped
+
+ - name: start apache
+ service: name=apache2 state=started
diff --git a/xos/observers/vpn/stop.sh b/xos/observers/vpn/stop.sh
new file mode 100755
index 0000000..5feca3c
--- /dev/null
+++ b/xos/observers/vpn/stop.sh
@@ -0,0 +1,2 @@
+# Kill the observer
+pkill -9 -f vpn-observer.py
diff --git a/xos/observers/vpn/vpn-observer.py b/xos/observers/vpn/vpn-observer.py
new file mode 100755
index 0000000..2d7644f
--- /dev/null
+++ b/xos/observers/vpn/vpn-observer.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+
+import importlib
+import os
+import sys
+observer_path = os.path.join(os.path.dirname(
+ os.path.realpath(__file__)), "../..")
+sys.path.append(observer_path)
+mod = importlib.import_module("xos-observer")
+mod.main()