+ self.logger.info("Publishing response:\nTopic={}\nKey={}\nValue={}"\
+ .format(topic, msg_key, metrics_data))
+ #Core producer
+ self.producer_metrics.publish(key=msg_key, value=json.dumps(metrics_data), topic=topic)
+
+
+ def verify_metric(self, metric_info):
+ """Verify if metric is supported or not
+ """
+ mon_plugin = MonPlugin()
+ metric_key_status = mon_plugin.verify_metric_support(metric_info)
+ return metric_key_status
+
+ def publish_create_metric_response(self, metric_info, metric_status):
+ """Publish create metric response
+ """
+ topic = 'metric_response'
+ msg_key = 'create_metric_response'
+ response_msg = {"schema_version":1.0,
+ "schema_type":"create_metric_response",
+ "correlation_id":metric_info['correlation_id'],
+ "metric_create_response":
+ {
+ "metric_uuid":0,
+ "resource_uuid":metric_info['metric_create']['resource_uuid'],
+ "status":metric_status
+ }
+ }
+ self.logger.info("Publishing response:\nTopic={}\nKey={}\nValue={}"\
+ .format(topic, msg_key, response_msg))
+ #Core producer
+ self.producer_metrics.publish(key=msg_key, value=json.dumps(response_msg), topic=topic)
+
+ def publish_update_metric_response(self, metric_info, metric_status):
+ """Publish update metric response
+ """
+ topic = 'metric_response'
+ msg_key = 'update_metric_response'
+ response_msg = {"schema_version":1.0,
+ "schema_type":"metric_update_response",
+ "correlation_id":metric_info['correlation_id'],
+ "metric_update_response":
+ {
+ "metric_uuid":0,
+ "resource_uuid":metric_info['metric_create']['resource_uuid'],
+ "status":metric_status
+ }
+ }
+ self.logger.info("Publishing response:\nTopic={}\nKey={}\nValue={}"\
+ .format(topic, msg_key, response_msg))
+ #Core producer
+ self.producer_metrics.publish(key=msg_key, value=json.dumps(response_msg), topic=topic)
+
+ def publish_delete_metric_response(self, metric_info):
+ """
+ """
+ topic = 'metric_response'
+ msg_key = 'delete_metric_response'
+ response_msg = {"schema_version":1.0,
+ "schema_type":"delete_metric_response",
+ "correlation_id":metric_info['correlation_id'],
+ "metric_name":metric_info['metric_name'],
+ "metric_uuid":0,
+ "resource_uuid":metric_info['resource_uuid'],
+ "tenant_uuid":metric_info['tenant_uuid'],
+ "status":False
+ }
+ self.logger.info("Publishing response:\nTopic={}\nKey={}\nValue={}"\
+ .format(topic, msg_key, response_msg))
+ #Core producer
+ self.producer_metrics.publish(key=msg_key, value=json.dumps(response_msg), topic=topic)
+
+ def list_alarms(self, list_alarm_input):
+ """Collect list of triggered alarms based on input
+ """
+ mon_plugin = MonPlugin()
+ triggered_alarms = mon_plugin.get_triggered_alarms_list(list_alarm_input)
+ return triggered_alarms
+
+
+ def publish_list_alarm_response(self, triggered_alarm_list, list_alarm_input):
+ """Publish list of triggered alarms
+ """
+ topic = 'alarm_response'
+ msg_key = 'list_alarm_response'
+ response_msg = {"schema_version":1.0,
+ "schema_type":"list_alarm_response",
+ "correlation_id":list_alarm_input['alarm_list_request']['correlation_id'],
+ #"resource_uuid":list_alarm_input['alarm_list_request']['resource_uuid'],
+ "list_alarm_resp":triggered_alarm_list
+ }
+ self.logger.info("Publishing response:\nTopic={}\nKey={}\nValue={}"\
+ .format(topic, msg_key, response_msg))
+ #Core producer
+ self.producer_alarms.publish(key=msg_key, value=json.dumps(response_msg), topic=topic)
+
+
+ def update_access_credentials(self, access_info):
+ """Verify if all the required access config params are provided and
+ updates access config in default vrops config file
+ """
+ update_status = False
+ wr_status = False
+ #Check if all the required config params are passed in request
+ if not all (keys in access_info for keys in req_config_params):
+ self.logger.debug("All required Access Config Parameters not provided")
+ self.logger.debug("List of required Access Config Parameters: {}".format(req_config_params))
+ self.logger.debug("List of given Access Config Parameters: {}".format(access_info))
+ return update_status
+
+ wr_status = self.write_access_config(access_info)
+ return wr_status #True/False
+
+ def write_access_config(self, access_info):
+ """Write access configuration to vROPs config file.
+ """
+ wr_status = False
+ try:
+ tree = XmlElementTree.parse(CONFIG_FILE_PATH)
+ root = tree.getroot()
+ alarmParams = {}
+ for config in root:
+ if config.tag == 'Access_Config':
+ for param in config:
+ for key,val in access_info.iteritems():
+ if param.tag == key:
+ #print param.tag, val
+ param.text = val
+
+ tree.write(CONFIG_FILE_PATH)
+ wr_status = True
+ except Exception as exp:
+ self.logger.warn("Failed to update Access Config Parameters: {}".format(exp))
+
+ return wr_status
+
+
+ def publish_access_update_response(self, access_update_status, access_info_req):
+ """Publish access update response
+ """
+ topic = 'access_credentials'
+ msg_key = 'vim_access_credentials_response'
+ response_msg = {"schema_version":1.0,
+ "schema_type":"vim_access_credentials_response",
+ "correlation_id":access_info_req['access_config']['correlation_id'],
+ "status":access_update_status
+ }
+ self.logger.info("Publishing response:\nTopic={}\nKey={}\nValue={}"\
+ .format(topic, msg_key, response_msg))
+ #Core Add producer
+ self.producer_access_credentials.publish(key=msg_key, value=json.dumps(response_msg), topic=topic)
+
+def main():
+ #log.basicConfig(filename='mon_vrops_log.log',level=log.DEBUG)
+ set_logger()
+ plugin_rcvr = PluginReceiver()
+ plugin_rcvr.consume()