From 6e7ce7c118486bf4a447690f925fc571ad16608b Mon Sep 17 00:00:00 2001 From: Joseph Vazhappilly Date: Thu, 11 Mar 2021 15:44:56 +0530 Subject: [PATCH] Implement review comments --- delfin/common/constants.py | 4 +- delfin/db/sqlalchemy/models.py | 56 +++++++++++------------ delfin/drivers/api.py | 16 ++----- delfin/drivers/driver.py | 61 +++---------------------- delfin/drivers/fake_storage/__init__.py | 2 +- delfin/task_manager/tasks/resources.py | 6 +++ 6 files changed, 46 insertions(+), 99 deletions(-) diff --git a/delfin/common/constants.py b/delfin/common/constants.py index 13c8257a2..992d29b8c 100644 --- a/delfin/common/constants.py +++ b/delfin/common/constants.py @@ -178,9 +178,9 @@ class ShareProtocol(object): CIFS = 'cifs' NFS = 'nfs' FTP = 'ftp' - UNKNOWN = 'unknown' + HDFS = 'hdfs' - ALL = (CIFS, NFS, FTP, UNKNOWN) + ALL = (CIFS, NFS, FTP, HDFS) # Enumerations for alert severity diff --git a/delfin/db/sqlalchemy/models.py b/delfin/db/sqlalchemy/models.py index d6bde33a6..c9bb2abea 100644 --- a/delfin/db/sqlalchemy/models.py +++ b/delfin/db/sqlalchemy/models.py @@ -65,19 +65,19 @@ class Storage(BASE, DelfinBase): __tablename__ = 'storages' id = Column(String(36), primary_key=True) name = Column(String(255)) - vendor = Column(String(255)) description = Column(String(255)) - model = Column(String(255)) + location = Column(String(255)) status = Column(String(255)) + sync_status = Column(Integer, default=constants.SyncStatus.SYNCED) + vendor = Column(String(255)) + model = Column(String(255)) serial_number = Column(String(255)) firmware_version = Column(String(255)) - location = Column(String(255)) total_capacity = Column(BigInteger) used_capacity = Column(BigInteger) free_capacity = Column(BigInteger) raw_capacity = Column(BigInteger) subscribed_capacity = Column(BigInteger) - sync_status = Column(Integer, default=constants.SyncStatus.SYNCED) deleted_at = Column(DateTime) deleted = Column(Boolean, default=False) @@ -86,14 +86,14 @@ class Volume(BASE, DelfinBase): """Represents a volume object.""" __tablename__ = 'volumes' id = Column(String(36), primary_key=True) + native_volume_id = Column(String(255)) name = Column(String(255)) - storage_id = Column(String(36)) - native_storage_pool_id = Column(String(255)) description = Column(String(255)) + type = Column(String(255)) status = Column(String(255)) - native_volume_id = Column(String(255)) + storage_id = Column(String(36)) + native_storage_pool_id = Column(String(255)) wwn = Column(String(255)) - type = Column(String(255)) total_capacity = Column(BigInteger) used_capacity = Column(BigInteger) free_capacity = Column(BigInteger) @@ -105,12 +105,12 @@ class StoragePool(BASE, DelfinBase): """Represents a storage_pool object.""" __tablename__ = 'storage_pools' id = Column(String(36), primary_key=True) - name = Column(String(255)) - storage_id = Column(String(36)) native_storage_pool_id = Column(String(255)) + name = Column(String(255)) description = Column(String(255)) - status = Column(String(255)) storage_type = Column(String(255)) + status = Column(String(255)) + storage_id = Column(String(36)) total_capacity = Column(BigInteger) used_capacity = Column(BigInteger) free_capacity = Column(BigInteger) @@ -123,19 +123,19 @@ class Disk(BASE, DelfinBase): id = Column(String(36), primary_key=True) native_disk_id = Column(String(255)) name = Column(String(255)) + physical_type = Column(String(255)) + logical_type = Column(String(255)) + status = Column(String(255)) + location = Column(String(255)) + storage_id = Column(String(255)) + native_disk_group_id = Column(String(255)) serial_number = Column(String(255)) manufacturer = Column(String(255)) model = Column(String(255)) firmware = Column(String(255)) speed = Column(Integer) capacity = Column(BigInteger) - status = Column(String(255)) - physical_type = Column(String(255)) - logical_type = Column(String(255)) health_score = Column(Integer) - native_disk_group_id = Column(String(255)) - storage_id = Column(String(255)) - location = Column(String(255)) class Controller(BASE, DelfinBase): @@ -159,14 +159,14 @@ class Port(BASE, DelfinBase): native_port_id = Column(String(255)) name = Column(String(255)) location = Column(String(255)) - connection_status = Column(String(255)) - health_status = Column(String(255)) type = Column(String(255)) logical_type = Column(String(255)) - speed = Column(Integer) - max_speed = Column(Integer) + connection_status = Column(String(255)) + health_status = Column(String(255)) storage_id = Column(String(36)) native_parent_id = Column(String(255)) + speed = Column(Integer) + max_speed = Column(Integer) wwn = Column(String(255)) mac_address = Column(String(255)) ipv4 = Column(String(255)) @@ -179,12 +179,12 @@ class Filesystem(BASE, DelfinBase): """Represents a filesystem object.""" __tablename__ = 'filesystems' id = Column(String(36), primary_key=True) + native_filesystem_id = Column(String(255)) name = Column(String(255)) + type = Column(String(255)) + status = Column(String(255)) storage_id = Column(String(36)) - native_filesystem_id = Column(String(255)) native_pool_id = Column(String(255)) - status = Column(String(255)) - type = Column(String(255)) security_mode = Column(String(255)) total_capacity = Column(BigInteger) used_capacity = Column(BigInteger) @@ -198,11 +198,11 @@ class Qtree(BASE, DelfinBase): """Represents a qtree object.""" __tablename__ = 'qtrees' id = Column(String(36), primary_key=True) + native_qtree_id = Column(String(255)) name = Column(String(255)) + path = Column(String(255)) storage_id = Column(String(36)) - native_qtree_id = Column(String(255)) native_filesystem_id = Column(String(255)) - path = Column(String(255)) security_mode = Column(String(255)) @@ -210,13 +210,13 @@ class Share(BASE, DelfinBase): """Represents a share object.""" __tablename__ = 'shares' id = Column(String(36), primary_key=True) + native_share_id = Column(String(255)) name = Column(String(255)) + path = Column(String(255)) storage_id = Column(String(36)) - native_share_id = Column(String(255)) native_filesystem_id = Column(String(255)) native_qtree_id = Column(String(255)) protocol = Column(String(255)) - path = Column(String(255)) class AlertSource(BASE, DelfinBase): diff --git a/delfin/drivers/api.py b/delfin/drivers/api.py index 3c0801c69..0880a8115 100644 --- a/delfin/drivers/api.py +++ b/delfin/drivers/api.py @@ -20,7 +20,6 @@ from delfin import db from delfin.drivers import helper from delfin.drivers import manager -from delfin.drivers.driver import NASDriver LOG = log.getLogger(__name__) @@ -106,26 +105,17 @@ def list_disks(self, context, storage_id): def list_filesystems(self, context, storage_id): """List all filesystems from storage system.""" driver = self.driver_manager.get_driver(context, storage_id=storage_id) - if isinstance(driver, NASDriver): - return driver.list_filesystems(context) - else: - return [] + return driver.list_filesystems(context) def list_qtrees(self, context, storage_id): """List all qtrees from storage system.""" driver = self.driver_manager.get_driver(context, storage_id=storage_id) - if isinstance(driver, NASDriver): - return driver.list_qtrees(context) - else: - return [] + return driver.list_qtrees(context) def list_shares(self, context, storage_id): """List all shares from storage system.""" driver = self.driver_manager.get_driver(context, storage_id=storage_id) - if isinstance(driver, NASDriver): - return driver.list_shares(context) - else: - return [] + return driver.list_shares(context) def add_trap_config(self, context, storage_id, trap_config): """Config the trap receiver in storage system.""" diff --git a/delfin/drivers/driver.py b/delfin/drivers/driver.py index 9f2001980..9522f3f72 100644 --- a/delfin/drivers/driver.py +++ b/delfin/drivers/driver.py @@ -116,66 +116,17 @@ def clear_alert(self, context, sequence_number): """Clear alert from storage system.""" pass - -@six.add_metaclass(abc.ABCMeta) -class NASDriver(StorageDriver): - - def __init__(self, **kwargs): - """ - :param kwargs: A dictionary, include access information. Pay - attention that it's not safe to save username and password - in memory, so suggest each driver use them to get session - instead of save them in memory directly. - """ - super(NASDriver, self).__init__(**kwargs) - - @abc.abstractmethod def list_filesystems(self, context): """List all filesystems from storage system.""" - pass + raise NotImplementedError( + "Driver API list_filesystems() is not Implemented") - @abc.abstractmethod def list_qtrees(self, context): """List all qtrees from storage system.""" - pass + raise NotImplementedError( + "Driver API list_qtrees() is not Implemented") - @abc.abstractmethod def list_shares(self, context): """List all shares from storage system.""" - pass - - # @abc.abstractmethod - # def list_quotas(self, context): - # """List all quota from storage system.""" - # pass - - -@six.add_metaclass(abc.ABCMeta) -class SANDriver(StorageDriver): - - def __init__(self, **kwargs): - """ - :param kwargs: A dictionary, include access information. Pay - attention that it's not safe to save username and password - in memory, so suggest each driver use them to get session - instead of save them in memory directly. - """ - super(SANDriver, self).__init__(**kwargs) - - # @abc.abstractmethod - # def list_blocks(self, context): - # """List all blocks from storage system.""" - # pass - - -@six.add_metaclass(abc.ABCMeta) -class UnifiedStorageDriver(SANDriver, NASDriver): - - def __init__(self, **kwargs): - """ - :param kwargs: A dictionary, include access information. Pay - attention that it's not safe to save username and password - in memory, so suggest each driver use them to get session - instead of save them in memory directly. - """ - super(UnifiedStorageDriver, self).__init__(**kwargs) + raise NotImplementedError( + "Driver API list_shares() is not Implemented") diff --git a/delfin/drivers/fake_storage/__init__.py b/delfin/drivers/fake_storage/__init__.py index 1c1da83c2..0371087c9 100644 --- a/delfin/drivers/fake_storage/__init__.py +++ b/delfin/drivers/fake_storage/__init__.py @@ -83,7 +83,7 @@ def _wait(f, *a, **k): return _wait -class FakeStorageDriver(driver.UnifiedStorageDriver): +class FakeStorageDriver(driver.StorageDriver): """FakeStorageDriver shows how to implement the StorageDriver, it also plays a role as faker to fake data for being tested by clients. """ diff --git a/delfin/task_manager/tasks/resources.py b/delfin/task_manager/tasks/resources.py index a6b0dc953..b07cb4d8f 100644 --- a/delfin/task_manager/tasks/resources.py +++ b/delfin/task_manager/tasks/resources.py @@ -435,6 +435,8 @@ def sync(self): db.filesystems_create(self.context, add_list) except AttributeError as e: LOG.error(e) + except NotImplementedError as e: + LOG.info(e) except Exception as e: msg = _('Failed to sync filesystems entry in DB: {0}' .format(e)) @@ -486,6 +488,8 @@ def sync(self): db.qtrees_create(self.context, add_list) except AttributeError as e: LOG.error(e) + except NotImplementedError as e: + LOG.info(e) except Exception as e: msg = _('Failed to sync Qtrees entry in DB: {0}' .format(e)) @@ -537,6 +541,8 @@ def sync(self): db.shares_create(self.context, add_list) except AttributeError as e: LOG.error(e) + except NotImplementedError as e: + LOG.info(e) except Exception as e: msg = _('Failed to sync Shares entry in DB: {0}' .format(e))