Skip to content

Commit

Permalink
Implement review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-v committed Mar 12, 2021
1 parent aa15eae commit e4c64a7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 99 deletions.
4 changes: 2 additions & 2 deletions delfin/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 28 additions & 28 deletions delfin/db/sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -198,25 +198,25 @@ 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))


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):
Expand Down
16 changes: 3 additions & 13 deletions delfin/drivers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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."""
Expand Down
61 changes: 6 additions & 55 deletions delfin/drivers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion delfin/drivers/fake_storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
9 changes: 9 additions & 0 deletions delfin/task_manager/tasks/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ def sync(self):
db.filesystems_create(self.context, add_list)
except AttributeError as e:
LOG.error(e)
except NotImplementedError:
# Ignore this exception because driver may not support it.
pass
except Exception as e:
msg = _('Failed to sync filesystems entry in DB: {0}'
.format(e))
Expand Down Expand Up @@ -486,6 +489,9 @@ def sync(self):
db.qtrees_create(self.context, add_list)
except AttributeError as e:
LOG.error(e)
except NotImplementedError:
# Ignore this exception because driver may not support it.
pass
except Exception as e:
msg = _('Failed to sync Qtrees entry in DB: {0}'
.format(e))
Expand Down Expand Up @@ -537,6 +543,9 @@ def sync(self):
db.shares_create(self.context, add_list)
except AttributeError as e:
LOG.error(e)
except NotImplementedError:
# Ignore this exception because driver may not support it.
pass
except Exception as e:
msg = _('Failed to sync Shares entry in DB: {0}'
.format(e))
Expand Down

0 comments on commit e4c64a7

Please sign in to comment.