From 2f72682bc2e8ab653c92b0fe61d50e2f8ee0ccff Mon Sep 17 00:00:00 2001 From: John Griffith Date: Fri, 12 Apr 2013 11:11:38 -0600 Subject: [PATCH] Add stats reporting to Nexenta Driver Nexenta driver was never updated to report stats. This change doesn't include support for backend_name assignment via configs, there's some other work that will need to be done to enable that. Fixes bug: 1166607 Change-Id: Id9cfff24df8815a67e42393aa18fd41ac1b9e6b3 (cherry picked from commit 781055bc1f30cebe08848130f3a40764f7f1bb4f) --- cinder/tests/test_nexenta.py | 23 +++++++++-- cinder/volume/drivers/nexenta/volume.py | 55 +++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/cinder/tests/test_nexenta.py b/cinder/tests/test_nexenta.py index e430809c0..aadefc1ff 100644 --- a/cinder/tests/test_nexenta.py +++ b/cinder/tests/test_nexenta.py @@ -23,7 +23,7 @@ import base64 import urllib2 import cinder.flags -import cinder.test +from cinder import test from cinder.volume.drivers import nexenta from cinder.volume.drivers.nexenta import jsonrpc from cinder.volume.drivers.nexenta import volume @@ -31,7 +31,7 @@ from cinder.volume.drivers.nexenta import volume FLAGS = cinder.flags.FLAGS -class TestNexentaDriver(cinder.test.TestCase): +class TestNexentaDriver(test.TestCase): TEST_VOLUME_NAME = 'volume1' TEST_VOLUME_NAME2 = 'volume2' TEST_SNAPSHOT_NAME = 'snapshot1' @@ -197,8 +197,25 @@ class TestNexentaDriver(cinder.test.TestCase): self.mox.ReplayAll() self.drv.remove_export({}, self.TEST_VOLUME_REF) + def test_get_volume_stats(self): + stats = {'size': '5368709120G', + 'used': '5368709120G', + 'available': '5368709120G', + 'health': 'ONLINE'} + self.nms_mock.volume.get_child_props( + FLAGS.nexenta_volume, + 'health|size|used|available').AndReturn(stats) + self.mox.ReplayAll() + stats = self.drv.get_volume_stats(True) + self.assertEquals(stats['storage_protocol'], 'iSCSI') + self.assertEquals(stats['volume_backend_name'], 'NexentaDriver') + self.assertEquals(stats['total_capacity_gb'], 5368709120.0) + self.assertEquals(stats['free_capacity_gb'], 5368709120.0) + self.assertEquals(stats['reserved_percentage'], 0) + self.assertEquals(stats['QoS_support'], False) + -class TestNexentaJSONRPC(cinder.test.TestCase): +class TestNexentaJSONRPC(test.TestCase): URL = 'http://example.com/' URL_S = 'https://example.com/' USER = 'user' diff --git a/cinder/volume/drivers/nexenta/volume.py b/cinder/volume/drivers/nexenta/volume.py index 2b752314f..f657a0c7c 100644 --- a/cinder/volume/drivers/nexenta/volume.py +++ b/cinder/volume/drivers/nexenta/volume.py @@ -31,6 +31,7 @@ from cinder.volume import driver from cinder.volume.drivers import nexenta from cinder.volume.drivers.nexenta import jsonrpc +VERSION = '1.0' LOG = logging.getLogger(__name__) FLAGS = flags.FLAGS @@ -293,3 +294,57 @@ class NexentaDriver(driver.ISCSIDriver): # pylint: disable=R0921 def create_cloned_volume(self, volume, src_vref): """Creates a clone of the specified volume.""" raise NotImplementedError() + + def get_volume_stats(self, refresh=False): + """Get volume status. + + If 'refresh' is True, run update the stats first.""" + if refresh: + self._update_volume_status() + + return self._stats + + def _update_volume_status(self): + """Retrieve status info for Nexenta device.""" + + # NOTE(jdg): Aimon Bustardo was kind enough to point out the + # info he had regarding Nexenta Capabilities, ideally it would + # be great if somebody from Nexenta looked this over at some point + + KB = 1024 + MB = KB ** 2 + + LOG.debug(_("Updating volume status")) + data = {} + data["volume_backend_name"] = self.__class__.__name__ + data["vendor_name"] = 'Nexenta' + data["driver_version"] = VERSION + data["storage_protocol"] = 'iSCSI' + + stats = self.nms.volume.get_child_props(FLAGS.nexenta_volume, + 'health|size|used|available') + total_unit = stats['size'][-1] + total_amount = float(stats['size'][:-1]) + free_unit = stats['available'][-1] + free_amount = float(stats['available'][:-1]) + + if total_unit == "T": + total_amount = total_amount * KB + elif total_unit == "M": + total_amount = total_amount / KB + elif total_unit == "B": + total_amount = total_amount / MB + + if free_unit == "T": + free_amount = free_amount * KB + elif free_unit == "M": + free_amount = free_amount / KB + elif free_unit == "B": + free_amount = free_amount / MB + + data['total_capacity_gb'] = total_amount + data['free_capacity_gb'] = free_amount + + data['reserved_percentage'] = 0 + data['QoS_support'] = False + self._stats = data -- 2.45.2