summaryrefslogtreecommitdiffstats
path: root/vio
diff options
context:
space:
mode:
Diffstat (limited to 'vio')
-rw-r--r--vio/docker/Dockerfile2
-rwxr-xr-xvio/run.sh4
-rwxr-xr-xvio/vio/event_listener/.gitignore1
-rwxr-xr-xvio/vio/event_listener/__init__.py13
-rwxr-xr-xvio/vio/event_listener/i18n.py27
-rwxr-xr-xvio/vio/event_listener/listener.conf3
-rwxr-xr-xvio/vio/event_listener/server.py113
-rw-r--r--vio/vio/pub/config/config.py4
8 files changed, 166 insertions, 1 deletions
diff --git a/vio/docker/Dockerfile b/vio/docker/Dockerfile
index 3879b1c..9c67741 100644
--- a/vio/docker/Dockerfile
+++ b/vio/docker/Dockerfile
@@ -7,6 +7,8 @@ ENV AAI_PORT "8443"
ENV AAI_SCHEMA_VERSION "v11"
ENV AAI_USERNAME "AAI"
ENV AAI_PASSWORD "AAI"
+ENV MR_ADDR “127.0.0.1”
+ENV MR_PORT “3904”
EXPOSE 9004
diff --git a/vio/run.sh b/vio/run.sh
index 1c392e4..f3ba7a1 100755
--- a/vio/run.sh
+++ b/vio/run.sh
@@ -20,12 +20,14 @@ sed -i "s/AAI_PORT =.*/AAI_PORT = \"${AAI_PORT}\"/g" vio/pub/config/config.py
sed -i "s/AAI_SCHEMA_VERSION =.*/AAI_SCHEMA_VERSION = \"${AAI_SCHEMA_VERSION}\"/g" vio/pub/config/config.py
sed -i "s/AAI_USERNAME =.*/AAI_USERNAME = \"${AAI_USERNAME}\"/g" vio/pub/config/config.py
sed -i "s/AAI_PASSWORD =.*/AAI_PASSWORD = \"${AAI_PASSWORD}\"/g" vio/pub/config/config.py
-
+sed -i "s/MR_ADDR =.*/MR_ADDR = \"${MR_ADDR}\"/g" vio/pub/config/config.py
+sed -i "s/MR_PORT =.*/MR_PORT = \"${MR_PORT}\"/g" vio/pub/config/config.py
logDir="/var/log/onap/multicloud/vio"
nohup python manage.py runserver 0.0.0.0:9004 2>&1 &
+nohup python vio/event_listener/server.py 2>&1 &
while [ ! -f $logDir/vio.log ]; do
sleep 1
diff --git a/vio/vio/event_listener/.gitignore b/vio/vio/event_listener/.gitignore
new file mode 100755
index 0000000..0d20b64
--- /dev/null
+++ b/vio/vio/event_listener/.gitignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/vio/vio/event_listener/__init__.py b/vio/vio/event_listener/__init__.py
new file mode 100755
index 0000000..012fba8
--- /dev/null
+++ b/vio/vio/event_listener/__init__.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (c) 2017-2018 VMware, Inc.
+#
+# 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.
diff --git a/vio/vio/event_listener/i18n.py b/vio/vio/event_listener/i18n.py
new file mode 100755
index 0000000..772f4cd
--- /dev/null
+++ b/vio/vio/event_listener/i18n.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import oslo_i18n
+
+DOMAIN = "test_oslo"
+
+_translators = oslo_i18n.TranslatorFactory(domain=DOMAIN)
+
+# The primary translation function using the well-known name "_"
+_ = _translators.primary
+
+# The contextual translation function using the name "_C"
+_C = _translators.contextual_form
+
+# The plural translation function using the name "_P"
+_P = _translators.plural_form
+
+# Translators for log levels.
+#
+# The abbreviated names are meant to reflect the usual use of a short
+# name like '_'. The "L" is for "log" and the other letter comes from
+# the level.
+_LI = _translators.log_info
+_LW = _translators.log_warning
+_LE = _translators.log_error
+_LC = _translators.log_critical
diff --git a/vio/vio/event_listener/listener.conf b/vio/vio/event_listener/listener.conf
new file mode 100755
index 0000000..e57614f
--- /dev/null
+++ b/vio/vio/event_listener/listener.conf
@@ -0,0 +1,3 @@
+[Listener]
+rabbit_ip=10.154.9.172
+rabbit_passwd=6C2B96AsbinmFf1a9c6a \ No newline at end of file
diff --git a/vio/vio/event_listener/server.py b/vio/vio/event_listener/server.py
new file mode 100755
index 0000000..83b9e6f
--- /dev/null
+++ b/vio/vio/event_listener/server.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from oslo_config import cfg
+from oslo_log import log as logging
+from i18n import _LI
+import oslo_messaging
+import ConfigParser
+import json
+import os
+import requests
+from vio.pub.config.config import MR_ADDR
+from vio.pub.config.config import MR_PORT
+
+LOG = logging.getLogger(__name__)
+
+
+def prepare():
+
+ product_name = "oslo_server"
+ logging.register_options(cfg.CONF)
+ logging.setup(cfg.CONF, product_name)
+
+
+'''
+below items must be added into vio nova.conf then restart nova services:
+notification_driver=messaging
+notification_topics= notifications_test
+notify_on_state_change=vm_and_task_state
+notify_on_any_change=True
+instance_usage_audit=True
+instance_usage_audit_period=hour
+'''
+
+
+def getConfig(section, key):
+
+ config = ConfigParser.ConfigParser()
+ path = os.path.split(os.path.realpath(__file__))[0] + '/listener.conf'
+ config.read(path)
+ return config.get(section, key)
+
+
+class NotificationEndPoint():
+
+ filter_rule = oslo_messaging.NotificationFilter(
+ publisher_id='^compute.*')
+
+ def info(self, ctxt, publisher_id, event_type, payload, metadata):
+
+ VM_EVENTS = {
+ 'compute.instance.unpause.start',
+ 'compute.instance.pause.start',
+ 'compute.instance.power_off.start',
+ 'compute.instance.reboot.start',
+ 'compute.instance.create.start'
+ }
+
+ status = payload.get('state_description')
+ if status != '' and event_type in VM_EVENTS:
+ url = 'http://%s:%s/events/test' % (MR_ADDR, MR_PORT)
+ headers = {'Content-type': 'application/json'}
+ requests.post(url, json.dumps(payload), headers=headers)
+
+ LOG.info(event_type)
+ self.action(payload)
+
+ def action(self, data):
+ LOG.info(_LI(json.dumps(data)))
+
+
+class Server(object):
+
+ def __init__(self):
+ self.topic = 'notifications_test'
+ self.server = None
+ prepare()
+
+
+class NotificationServer(Server):
+
+ def __init__(self):
+ super(NotificationServer, self).__init__()
+ # rabbit IP and password come from listener.conf
+ url = 'rabbit://test:%s@%s:5672/' % (
+ getConfig('Listener', 'rabbit_passwd'),
+ getConfig('Listener', 'rabbit_ip')
+ )
+ self.transport = oslo_messaging.get_notification_transport(
+ cfg.CONF,
+ url=url)
+ # The exchange must be the same as
+ # control_exchange in transport setting in client.
+ self.targets = [oslo_messaging.Target(
+ topic=self.topic,
+ exchange='nova')]
+ self.endpoints = [NotificationEndPoint()]
+
+ def start(self):
+ LOG.info(_LI("Start Notification server..."))
+ self.server = oslo_messaging.get_notification_listener(
+ self.transport,
+ self.targets,
+ self.endpoints,
+ executor='threading')
+ self.server.start()
+ self.server.wait()
+
+
+if __name__ == '__main__':
+
+ notification_server = NotificationServer()
+ notification_server.start()
diff --git a/vio/vio/pub/config/config.py b/vio/vio/pub/config/config.py
index 9b4d6c8..cfb492d 100644
--- a/vio/vio/pub/config/config.py
+++ b/vio/vio/pub/config/config.py
@@ -28,6 +28,10 @@ AAI_SCHEMA_VERSION = "v13"
AAI_USERNAME = 'AAI'
AAI_PASSWORD = 'AAI'
+# [DMaaP]
+MR_ADDR = "127.0.0.1"
+MR_PORT = "3904"
+
# [MDC]
SERVICE_NAME = "multicloud-vio"
FORWARDED_FOR_FIELDS = ["HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED_HOST",