Merge "Get Metric_UUID directly from VIM Change-Id: I9b8c47b2fd7987f8834dc7c90e826d9d...
authorhoban <adrian.hoban@intel.com>
Tue, 17 Apr 2018 14:10:07 +0000 (16:10 +0200)
committerGerrit Code Review <root@osm.etsi.org>
Tue, 17 Apr 2018 14:10:07 +0000 (16:10 +0200)
1  2 
osm_mon/plugins/OpenStack/Gnocchi/metrics.py

@@@ -28,7 -28,6 +28,7 @@@ import loggin
  import time
  
  import six
 +import yaml
  
  from osm_mon.core.message_bus.producer import KafkaProducer
  from osm_mon.plugins.OpenStack.common import Common
@@@ -39,7 -38,7 +39,7 @@@ from osm_mon.plugins.OpenStack.setting
  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",
@@@ -79,10 -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'])
  
              # Generate and send a response message
              try:
+                 metric_id = self.get_metric_id(endpoint, auth_token, METRIC_MAPPINGS[values['metric_name']],
+                                           values['resource_uuid'])
                  resp_message = self._response.generate_response(
                      'read_metric_data_response',
-                     m_id=values['metric_uuid'],
+                     m_id=metric_id,
                      m_name=values['metric_name'],
                      r_id=values['resource_uuid'],
                      cor_id=values['correlation_id'],
  
          elif message.key == "delete_metric_request":
              # delete the specified metric in the request
-             metric_id = values['metric_uuid']
+             metric_id = self.get_metric_id(endpoint, auth_token, METRIC_MAPPINGS[values['metric_name']],
+                                            values['resource_uuid'])
              status = self.delete_metric(
                  endpoint, auth_token, metric_id)
  
      def get_metric_id(self, endpoint, auth_token, metric_name, resource_id):
          """Check if the desired metric already exists for the resource."""
          url = "{}/v1/resource/generic/%s".format(endpoint) % resource_id
          try:
              # Try return the metric id if it exists
              result = Common.perform_request(
          timestamps = []
          data = []
          try:
+             #get metric_id
+             metric_id = self.get_metric_id(endpoint, auth_token, METRIC_MAPPINGS[values['metric_name']], values['resource_uuid'])
              # Try and collect measures
-             metric_id = values['metric_uuid']
              collection_unit = values['collection_unit'].upper()
              collection_period = values['collection_period']