class AuthManager:
-
def __init__(self):
self.database_manager = DatabaseManager()
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):
credentials = self.get_credentials(creds_dict['_id'])
if credentials:
credentials.delete_instance()
-
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()
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__), '..', '..', '..', '..')))
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
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.")
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)
# 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.")
import logging
import six
+import yaml
from osm_mon.core.database import DatabaseManager
from osm_mon.core.message_bus.producer import KafkaProducer
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']
import time
import six
+import yaml
from osm_mon.core.message_bus.producer import KafkaProducer
from osm_mon.plugins.OpenStack.common import Common
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",
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'])
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,