Ejemplo n.º 1
0
    def do_nfvi_metrics(self, account, vm_id):
        try:
            samples = self._get_driver(account).ceilo_nfvi_metrics(vm_id)

            metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics()

            vcpu = samples.get("cpu_util", {})
            memory = samples.get("memory_usage", {})
            storage = samples.get("disk_usage", {})

            metrics.vcpu.utilization = vcpu.get("volume", 0)
            metrics.memory.used = memory.get("volume", 0)
            metrics.storage.used = storage.get("volume", 0)

            def convert_timestamp(t):
                return dateutil.parser.parse(t).timestamp()

            timestamps = []
            if 'timestamp' in vcpu:
                timestamps.append(convert_timestamp(vcpu['timestamp']))
            if 'timestamp' in memory:
                timestamps.append(convert_timestamp(memory['timestamp']))
            if 'timestamp' in storage:
                timestamps.append(convert_timestamp(storage['timestamp']))

            metrics.timestamp = max(timestamps) if timestamps else 0.0

            return metrics

        except Exception as e:
            logger.exception(e)
Ejemplo n.º 2
0
    def test_null_data_source(self):
        """
        By default, the NFVI metrics plugin mock installs a 'null'
        implementation that simply returns empty NFVI structures.

        """
        status, metrics = self.plugin.nfvi_metrics(self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(metrics,
                         RwmonYang.YangData_RwProject_Project_NfviMetrics())

        status, metrics = self.plugin.nfvi_vcpu_metrics(
            self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(
            metrics, RwmonYang.YangData_RwProject_Project_NfviMetrics_Vcpu())

        status, metrics = self.plugin.nfvi_memory_metrics(
            self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(
            metrics, RwmonYang.YangData_RwProject_Project_NfviMetrics_Memory())

        status, metrics = self.plugin.nfvi_storage_metrics(
            self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(
            metrics,
            RwmonYang.YangData_RwProject_Project_NfviMetrics_Storage())

        status, result = self.plugin.nfvi_metrics_available(self.account)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertTrue(result)
Ejemplo n.º 3
0
 def __init__(self):
     self._metrics = dict()
     self._metrics['test-vim-id-1'] = RwmonYang.YangData_RwProject_Project_NfviMetrics()
     self._metrics['test-vim-id-2'] = RwmonYang.YangData_RwProject_Project_NfviMetrics()
Ejemplo n.º 4
0
 def __init__(self):
     self.metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics()
Ejemplo n.º 5
0
 def nfvi_metrics(self, account, vim_id):
     metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics()
     metrics.vcpu.utilization = 0.5
     return metrics
Ejemplo n.º 6
0
 def nfvi_metrics(self, account, vm_id):
     metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics()
     metrics.vcpu = self.nfvi_vcpu_metrics(account, vm_id)
     metrics.memory = self.nfvi_memory_metrics(account, vm_id)
     metrics.storage = self.nfvi_storage_metrics(account, vm_id)
     return metrics
Ejemplo n.º 7
0
 def nfvi_metrics(self, account, vm_id):
     return rwmon.YangData_RwProject_Project_NfviMetrics()