summaryrefslogtreecommitdiffstats
path: root/events
diff options
context:
space:
mode:
authorAravinda VK <avishwan@redhat.com>2016-09-26 17:08:31 +0530
committerAravinda VK <avishwan@redhat.com>2016-10-19 23:10:44 -0700
commita482645865af56b8d34a17430649c3c646f3d450 (patch)
treed255e93eaeafd384d0ba2c0c03c2e0f37aa9442e /events
parent460016428cf27484c333227f534c2e2f73a37fb1 (diff)
eventsapi: Auto convert Boolean and Int attributes
Before publishing in JSON format, automatically convert the attribute to "bool" or "int" if configured. For example, instead of sending force="1", convert to bool and send as force=True { "event": "VOLUME_START", "name" : "gv1", "force": "1" } Convert to, { "event": "VOLUME_START", "name" : "gv1", "force": true } BUG: 1379328 Change-Id: Iabc51fd61abc267a7c8dcf0aeac6b3c722d89649 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/15574 NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Prashanth Pai <ppai@redhat.com> Smoke: Gluster Build System <jenkins@build.gluster.org>
Diffstat (limited to 'events')
-rw-r--r--events/src/eventsapiconf.py.in2
-rw-r--r--events/src/glustereventsd.py13
-rw-r--r--events/src/utils.py8
3 files changed, 22 insertions, 1 deletions
diff --git a/events/src/eventsapiconf.py.in b/events/src/eventsapiconf.py.in
index ecccd3dbda4..e0028761bcc 100644
--- a/events/src/eventsapiconf.py.in
+++ b/events/src/eventsapiconf.py.in
@@ -24,3 +24,5 @@ RESTART_CONFIGS = ["port"]
EVENTS_ENABLED = @EVENTS_ENABLED@
UUID_FILE = "@GLUSTERD_WORKDIR@/glusterd.info"
PID_FILE = "@localstatedir@/run/glustereventsd.pid"
+AUTO_BOOL_ATTRIBUTES = ["force", "push-pem", "no-verify"]
+AUTO_INT_ATTRIBUTES = ["ssh-port"]
diff --git a/events/src/glustereventsd.py b/events/src/glustereventsd.py
index d057e097c97..86e64b01ad5 100644
--- a/events/src/glustereventsd.py
+++ b/events/src/glustereventsd.py
@@ -21,7 +21,8 @@ from eventtypes import all_events
import handlers
import utils
from eventsapiconf import SERVER_ADDRESS, PID_FILE
-from utils import logger, PidFile, PidFileLockFailed
+from eventsapiconf import AUTO_BOOL_ATTRIBUTES, AUTO_INT_ATTRIBUTES
+from utils import logger, PidFile, PidFileLockFailed, boolify
class GlusterEventsRequestHandler(SocketServer.BaseRequestHandler):
@@ -45,6 +46,16 @@ class GlusterEventsRequestHandler(SocketServer.BaseRequestHandler):
logger.warn("Unable to parse Event {0}".format(data))
return
+ for k, v in data_dict.iteritems():
+ try:
+ if k in AUTO_BOOL_ATTRIBUTES:
+ data_dict[k] = boolify(v)
+ if k in AUTO_INT_ATTRIBUTES:
+ data_dict[k] = int(v)
+ except ValueError:
+ # Auto Conversion failed, Retain the old value
+ continue
+
try:
# Event Type to Function Map, Recieved event data will be in
# the form <TIMESTAMP> <TYPE> <DETAIL>, Get Event name for the
diff --git a/events/src/utils.py b/events/src/utils.py
index dadd9ae3332..6f695c37eba 100644
--- a/events/src/utils.py
+++ b/events/src/utils.py
@@ -35,6 +35,14 @@ logger = logging.getLogger(__name__)
NodeID = None
+def boolify(value):
+ value = str(value)
+ if value.lower() in ["1", "on", "true", "yes"]:
+ return True
+ else:
+ return False
+
+
def get_node_uuid():
val = None
with open(UUID_FILE) as f: