Adds yaml format in OpenStack plugin 76/5976/1
authorBenjamin Diaz <bdiaz@whitestack.com>
Wed, 11 Apr 2018 00:57:17 +0000 (21:57 -0300)
committerBenjamin Diaz <bdiaz@whitestack.com>
Mon, 16 Apr 2018 17:12:54 +0000 (14:12 -0300)
Makes config property in vimcredentials optional
Fixes mapping name of average_memory_utilization metric
Adds support for config properties region_name and endpoint_type

Signed-off-by: Benjamin Diaz <bdiaz@whitestack.com>
osm_mon/core/auth.py
osm_mon/core/database.py
osm_mon/core/message_bus/common_consumer.py
osm_mon/plugins/OpenStack/Aodh/alarming.py
osm_mon/plugins/OpenStack/Gnocchi/metrics.py
osm_mon/plugins/OpenStack/common.py

index 6f5e20a..947175a 100644 (file)
@@ -28,7 +28,6 @@ from osm_mon.core.database import VimCredentials, DatabaseManager
 
 
 class AuthManager:
-
     def __init__(self):
         self.database_manager = DatabaseManager()
 
@@ -41,15 +40,8 @@ class AuthManager:
         credentials.user = creds_dict['vim_user']
         credentials.password = creds_dict['vim_password']
         credentials.tenant_name = creds_dict['vim_tenant_name']
-        credentials.config = json.dumps(creds_dict['config'])
-        if creds_dict.get('OS_REGION_NAME'):
-            credentials.region_name = creds_dict['OS_REGION_NAME']
-        else:
-            credentials.region_name = "RegionOne"
-        if creds_dict.get('OS_ENDPOINT_TYPE'):
-            credentials.endpoint_type = creds_dict['OS_ENDPOINT_TYPE']
-        else:
-            credentials.endpoint_type = "publicURL"
+        if 'config' in creds_dict:
+            credentials.config = json.dumps(creds_dict['config'])
         self.database_manager.save_credentials(credentials)
 
     def get_credentials(self, vim_uuid):
@@ -59,4 +51,3 @@ class AuthManager:
         credentials = self.get_credentials(creds_dict['_id'])
         if credentials:
             credentials.delete_instance()
-
index 7e4bf7c..1d66264 100644 (file)
@@ -48,9 +48,8 @@ class VimCredentials(BaseModel):
     user = CharField()
     password = CharField()
     tenant_name = CharField()
-    config = TextField()
-    region_name = CharField()
-    endpoint_type = CharField()
+    config = TextField(null=True)
+
 
 class Alarm(BaseModel):
     alarm_id = CharField()
index 25aee43..97e37fa 100755 (executable)
@@ -25,11 +25,16 @@ import os
 import sys
 import yaml
 
+import yaml
+import logstash
+
 logging.basicConfig(stream=sys.stdout,
                     format='%(asctime)s %(message)s',
                     datefmt='%m/%d/%Y %I:%M:%S %p',
                     level=logging.INFO)
 log = logging.getLogger(__name__)
+log.addHandler(logstash.TCPLogstashHandler('dockerelk_logstash_1', 5000, version=1))
+
 
 sys.path.append(os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..', '..')))
 
@@ -78,14 +83,13 @@ aws_access_credentials = AccessCredentials()
 vrops_rcvr = plugin_receiver.PluginReceiver()
 
 
-def get_vim_type(msg):
+def get_vim_type(vim_uuid):
     """Get the vim type that is required by the message."""
     try:
-        vim_uuid = json.loads(msg.value)["vim_uuid"].lower()
         credentials = database_manager.get_credentials(vim_uuid)
         return credentials.type
     except Exception as exc:
-        log.warn("vim_type is not configured correctly; %s", exc)
+        log.exception("Error getting vim_type: ")
     return None
 
 
@@ -100,12 +104,12 @@ for message in common_consumer:
     try:
         try:
             values = json.loads(message.value)
-        except:
+        except ValueError:
             values = yaml.safe_load(message.value)
         # Check the message topic
         if message.topic == "metric_request":
             # Check the vim desired by the message
-            vim_type = get_vim_type(message)
+            vim_type = get_vim_type(values['vim_uuid'])
 
             if vim_type == "openstack":
                 log.info("This message is for the OpenStack plugin.")
@@ -125,7 +129,7 @@ for message in common_consumer:
 
         elif message.topic == "alarm_request":
             # Check the vim desired by the message
-            vim_type = get_vim_type(message)
+            vim_type = get_vim_type(values['vim_uuid'])
             if vim_type == "openstack":
                 log.info("This message is for the OpenStack plugin.")
                 openstack_alarms.alarming(message)
@@ -152,7 +156,7 @@ for message in common_consumer:
         # TODO: Remove in the near future when all plugins support vim_uuid. Modify tests accordingly.
         elif message.topic == "access_credentials":
             # Check the vim desired by the message
-            vim_type = get_vim_type(message)
+            vim_type = get_vim_type(values['vim_uuid'])
 
             if vim_type == "aws":
                 log.info("This message is for the CloudWatch plugin.")
index 156a0f1..b0602bd 100644 (file)
@@ -25,6 +25,7 @@ import json
 import logging
 
 import six
+import yaml
 
 from osm_mon.core.database import DatabaseManager
 from osm_mon.core.message_bus.producer import KafkaProducer
@@ -91,7 +92,10 @@ class Alarming(object):
 
     def alarming(self, message):
         """Consume info from the message bus to manage alarms."""
-        values = json.loads(message.value)
+        try:
+            values = json.loads(message.value)
+        except ValueError:
+            values = yaml.safe_load(message.value)
 
         log.info("OpenStack alarm action required.")
         vim_uuid = values['vim_uuid']
index 1dc9496..2724508 100644 (file)
@@ -28,6 +28,7 @@ import logging
 import time
 
 import six
+import yaml
 
 from osm_mon.core.message_bus.producer import KafkaProducer
 from osm_mon.plugins.OpenStack.common import Common
@@ -38,7 +39,7 @@ from osm_mon.plugins.OpenStack.settings import Config
 log = logging.getLogger(__name__)
 
 METRIC_MAPPINGS = {
-    "average_memory_utilization": "memory.percent",
+    "average_memory_utilization": "memory.usage",
     "disk_read_ops": "disk.read.requests",
     "disk_write_ops": "disk.write.requests",
     "disk_read_bytes": "disk.read.bytes",
@@ -78,7 +79,10 @@ class Metrics(object):
 
     def metric_calls(self, message):
         """Consume info from the message bus to manage metric requests."""
-        values = json.loads(message.value)
+        try:
+            values = json.loads(message.value)
+        except ValueError:
+            values = yaml.safe_load(message.value)
         log.info("OpenStack metric action required.")
 
         auth_token = Common.get_auth_token(values['vim_uuid'])
index 2540a3f..7525395 100644 (file)
@@ -60,10 +60,17 @@ class Common(object):
                            username=creds.user,
                            password=creds.password,
                            tenant_name=creds.tenant_name)
+        endpoint_type = 'publicURL'
+        region_name = 'regionOne'
+        if creds.config is not None:
+            if 'endpoint_type' in creds.config:
+                endpoint_type = creds.config['endpoint_type']
+            if 'region_name' in creds.config:
+                region_name = creds.config['region_name']
         return ks.service_catalog.url_for(
             service_type=service_type,
-            endpoint_type=creds.endpoint_type,
-            region_name=creds.region_name)
+            endpoint_type=endpoint_type,
+            region_name=region_name)
 
     @staticmethod
     def perform_request(url, auth_token,