Merge from OSM SO master
[osm/SO.git] / rwlaunchpad / plugins / rwmonitor / rift / tasklets / rwmonitor / core.py
index b97b2f5..f43da6f 100644 (file)
@@ -231,7 +231,7 @@ class NfviMetrics(object):
         self._account = account
         self._plugin = plugin
         self._timestamp = 0
-        self._metrics = RwVnfrYang.YangData_Vnfr_VnfrCatalog_Vnfr_Vdur_NfviMetrics()
+        self._metrics = RwVnfrYang.YangData_RwProject_Project_VnfrCatalog_Vnfr_Vdur_NfviMetrics()
         self._vdur = vdur
         self._vim_id = vdur.vim_id
         self._updating = None
@@ -305,7 +305,7 @@ class NfviMetrics(object):
 
             try:
                 # Create uninitialized metric structure
-                vdu_metrics = RwVnfrYang.YangData_Vnfr_VnfrCatalog_Vnfr_Vdur_NfviMetrics()
+                vdu_metrics = RwVnfrYang.YangData_RwProject_Project_VnfrCatalog_Vnfr_Vdur_NfviMetrics()
 
                 # VCPU
                 vdu_metrics.vcpu.total = self.vdur.vm_flavor.vcpu_count
@@ -317,9 +317,22 @@ class NfviMetrics(object):
                 vdu_metrics.memory.utilization = 100 * vdu_metrics.memory.used / vdu_metrics.memory.total
 
                 # Storage
-                vdu_metrics.storage.used = metrics.storage.used
-                vdu_metrics.storage.total = 1e9 * self.vdur.vm_flavor.storage_gb
-                vdu_metrics.storage.utilization = 100 * vdu_metrics.storage.used / vdu_metrics.storage.total
+                try:
+                    vdu_metrics.storage.used = metrics.storage.used
+                    if self.vdur.has_field('volumes'):
+                        for volume in self.vdur.volumes:
+                            if vdu_metrics.storage.total is None:
+                               vdu_metrics.storage.total = 1e9 * volume.size
+                            else:
+                               vdu_metrics.storage.total += (1e9 * volume.size)
+                    else:
+                        vdu_metrics.storage.total = 1e9 * self.vdur.vm_flavor.storage_gb
+                    utilization = 100 * vdu_metrics.storage.used / vdu_metrics.storage.total
+                    if utilization > 100:
+                        utilization = 100
+                    vdu_metrics.storage.utilization = utilization
+                except ZeroDivisionError:
+                    vdu_metrics.storage.utilization = 0
 
                 # Network (incoming)
                 vdu_metrics.network.incoming.packets = metrics.network.incoming.packets
@@ -536,17 +549,19 @@ class Monitor(object):
     different sub-systems that are used to monitor the NFVI.
     """
 
-    def __init__(self, loop, log, config):
+    def __init__(self, loop, log, config, project):
         """Create a Monitor object
 
         Arguments:
-            loop   - an event loop
-            log    - the logger used by this object
-            config - an instance of InstanceConfiguration
+            loop    - an event loop
+            log     - the logger used by this object
+            config  - an instance of InstanceConfiguration
+            project - an instance of the project
 
         """
         self._loop = loop
         self._log = log
+        self._project = project
 
         self._cloud_accounts = dict()
         self._nfvi_plugins = NfviMetricsPluginManager(log)
@@ -567,6 +582,10 @@ class Monitor(object):
         """The event log used by this object"""
         return self._log
 
+    @property
+    def project(self):
+        return self._project
+
     @property
     def cache(self):
         """The NFVI metrics cache"""