Skip to content

Commit

Permalink
Merge pull request #793 from joseph-v/host-mapping-rel
Browse files Browse the repository at this point in the history
Modify driver api list_*_groups() to return relations
  • Loading branch information
skdwriting authored Jan 10, 2022
2 parents 8c7b697 + fedc39b commit 6774a9a
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 114 deletions.
1 change: 0 additions & 1 deletion delfin/api/v1/masking_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(self):
'native_storage_volume_group_id',
'native_storage_host_id',
'native_volume_id',
'native_port_id',
'native_masking_view_id']

def _get_masking_view_search_options(self):
Expand Down
1 change: 0 additions & 1 deletion delfin/db/sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ class MaskingView(BASE, DelfinBase):
native_port_group_id = Column(String(255))
native_storage_host_id = Column(String(255))
native_volume_id = Column(String(255))
native_port_id = Column(String(255))
native_masking_view_id = Column(String(255))


Expand Down
28 changes: 19 additions & 9 deletions delfin/drivers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,13 @@ def list_storage_hosts(self, context):
"Driver API list_storage_hosts() is not Implemented")

def list_storage_host_groups(self, context):
"""List all storage host groups from storage system."""
"""
*********Model description**********
Returns a dict with following
'storage_host_groups': <List storage host groups from storage system>,
'storage_host_grp_host_rels': <List host groups to host relation>,
"""
"""
********* storage_host_groups Model description**********
native_storage_host_group_id: Native id of host grp at backend side
(mandatory)
name: Name of the host grp
Expand All @@ -226,9 +230,13 @@ def list_storage_host_groups(self, context):
"Driver API list_storage_host_groups() is not Implemented")

def list_port_groups(self, context):
"""List all port groups from storage system."""
"""
*********Model description**********
Returns a dict with following
'port_groups': <List port groups from storage system>,
'port_grp_port_rels': <List port groups to port relation>,
"""
"""
********* port_groups Model description**********
native_port_group_id: Native id of port grp at backend side (mandatory)
name: Name of the port grp
description: Description of the port grp
Expand All @@ -239,9 +247,13 @@ def list_port_groups(self, context):
"Driver API list_port_groups() is not Implemented")

def list_volume_groups(self, context):
"""List all volume groups from storage system."""
"""
*********Model description**********
Returns a dict with following
'volume_groups': <List volume groups from storage system>,
'vol_grp_vol_rels': <List volume groups to port relation>,
"""
"""
********* volume_groups Model description**********
native_volume_group_id: Native id of volume grp at backend side
(mandatory)
name: Name of the volume grp
Expand All @@ -265,7 +277,6 @@ def list_masking_views(self, context):
native_volume_group_id: Native id of volume grp at backend side
native_storage_host_id: Native id of host at backend side
native_volume_id: Native id of volume at backend side
native_port_id: Native id of port at backend side
storage_id: Storage id at delfin side
Masking view filling guidelines:
Expand All @@ -281,8 +292,7 @@ def list_masking_views(self, context):
| native_storage_host_id)
From volume side: Mandatorily one of the (native_volume_group_id
| native_volume_id)
From port side: Optionally One of the (native_port_group_id
| native_port_id)
From port side: Optionally (native_port_group_id)
"""
raise NotImplementedError(
"Driver API list_masking_views() is not Implemented")
Expand Down
72 changes: 66 additions & 6 deletions delfin/drivers/fake_storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,30 @@ def list_storage_host_groups(self, ctx):
"storage_hosts": storage_hosts
}
storage_host_grp_list.append(f)
return storage_host_grp_list

storage_host_grp_relation_list = []
for storage_host_group in storage_host_grp_list:
storage_hosts = storage_host_group.pop('storage_hosts', None)
if not storage_hosts:
continue
storage_hosts = storage_hosts.split(',')

for storage_host in storage_hosts:
storage_host_group_relation = {
'storage_id': self.storage_id,
'native_storage_host_group_id':
storage_host_group['native_storage_host_group_id'],
'native_storage_host_id': storage_host
}
storage_host_grp_relation_list \
.append(storage_host_group_relation)

result = {
'storage_host_groups': storage_host_grp_list,
'storage_host_grp_host_rels': storage_host_grp_relation_list
}

return result

def list_port_groups(self, ctx):
rd_port_groups_count = random.randint(MIN_PORT_GROUPS,
Expand Down Expand Up @@ -965,7 +988,27 @@ def list_port_groups(self, ctx):
}

port_grp_list.append(f)
return port_grp_list

port_group_relation_list = []
for port_group in port_grp_list:
ports = port_group.pop('ports', None)
if not ports:
continue
ports = ports.split(',')

for port in ports:
port_group_relation = {
'storage_id': self.storage_id,
'native_port_group_id':
port_group['native_port_group_id'],
'native_port_id': port
}
port_group_relation_list.append(port_group_relation)
result = {
'port_groups': port_grp_list,
'port_grp_port_rels': port_group_relation_list
}
return result

def list_volume_groups(self, ctx):
rd_volume_groups_count = random.randint(MIN_VOLUME_GROUPS,
Expand Down Expand Up @@ -1000,7 +1043,27 @@ def list_volume_groups(self, ctx):
"volumes": volumes
}
volume_grp_list.append(f)
return volume_grp_list

volume_group_relation_list = []
for volume_group in volume_grp_list:
volumes = volume_group.pop('volumes', None)
if not volumes:
continue
volumes = volumes.split(',')

for volume in volumes:
volume_group_relation = {
'storage_id': self.storage_id,
'native_volume_group_id':
volume_group['native_volume_group_id'],
'native_volume_id': volume}
volume_group_relation_list.append(volume_group_relation)

result = {
'volume_groups': volume_grp_list,
'vol_grp_vol_rels': volume_group_relation_list
}
return result

def list_masking_views(self, ctx):
rd_masking_views_count = random.randint(MIN_MASKING_VIEWS,
Expand All @@ -1018,15 +1081,13 @@ def list_masking_views(self, ctx):
native_port_group_id = "port_group_" + str(idx)
native_storage_host_id = ""
native_volume_id = ""
native_port_id = ""

else:
native_storage_host_group_id = ""
native_volume_group_id = ""
native_port_group_id = ""
native_storage_host_id = "storage_host_" + str(idx)
native_volume_id = "volume_" + str(idx)
native_port_id = "port_" + str(idx)

f = {
"name": "masking_view_" + str(idx),
Expand All @@ -1038,7 +1099,6 @@ def list_masking_views(self, ctx):
"native_port_group_id": native_port_group_id,
"native_storage_host_id": native_storage_host_id,
"native_volume_id": native_volume_id,
"native_port_id": native_port_id
}
masking_view_list.append(f)
return masking_view_list
103 changes: 20 additions & 83 deletions delfin/task_manager/tasks/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

from delfin import coordination
from delfin import db
from delfin.db.sqlalchemy.models import StorageHostGrpHostRel
from delfin.db.sqlalchemy.models import VolGrpVolRel
from delfin.db.sqlalchemy.models import PortGrpPortRel
from delfin import exception
from delfin.common import constants
from delfin.drivers import api as driverapi
Expand Down Expand Up @@ -84,77 +81,6 @@ def _check_deleted(func, *args, **kwargs):
return _check_deleted


def _build_storage_host_group_relations(ctx, storage_id,
storage_host_groups):
""" Builds storage host group to host relations."""
db.storage_host_grp_host_rels_delete_by_storage(ctx,
storage_id)
storage_host_grp_relation_list = []
for storage_host_group in storage_host_groups:
storage_hosts = storage_host_group.pop('storage_hosts', None)
if not storage_hosts:
continue
storage_hosts = storage_hosts.split(',')

for storage_host in storage_hosts:
storage_host_group_relation = {
StorageHostGrpHostRel.storage_id.name: storage_id,
StorageHostGrpHostRel.native_storage_host_group_id.name:
storage_host_group['native_storage_host_group_id'],
StorageHostGrpHostRel.native_storage_host_id.name:
storage_host
}
storage_host_grp_relation_list \
.append(storage_host_group_relation)

db.storage_host_grp_host_rels_create(
ctx, storage_host_grp_relation_list)


def _build_volume_group_relations(ctx, storage_id, volume_groups):
""" Builds volume group to volume relations."""
db.vol_grp_vol_rels_delete_by_storage(ctx, storage_id)
volume_group_relation_list = []
for volume_group in volume_groups:
volumes = volume_group.pop('volumes', None)
if not volumes:
continue
volumes = volumes.split(',')

for volume in volumes:
volume_group_relation = {
VolGrpVolRel.storage_id.name: storage_id,
VolGrpVolRel.native_volume_group_id.name:
volume_group['native_volume_group_id'],
VolGrpVolRel.native_volume_id.name: volume}
volume_group_relation_list.append(volume_group_relation)

db.vol_grp_vol_rels_create(ctx, volume_group_relation_list)


def _build_port_group_relations(ctx, storage_id, port_groups):
""" Builds resource group to resource relations."""
db.port_grp_port_rels_delete_by_storage(ctx, storage_id)

port_group_relation_list = []
for port_group in port_groups:
ports = port_group.pop('ports', None)
if not ports:
continue
ports = ports.split(',')

for port in ports:
port_group_relation = {
PortGrpPortRel.storage_id.name: storage_id,
PortGrpPortRel.native_port_group_id .name:
port_group['native_port_group_id'],
PortGrpPortRel.native_port_id.name: port
}
port_group_relation_list.append(port_group_relation)

db.port_grp_port_rels_create(ctx, port_group_relation_list)


class StorageResourceTask(object):
NATIVE_RESOURCE_ID = None

Expand Down Expand Up @@ -618,11 +544,15 @@ def sync(self):
try:
# Collect the storage host group list from driver and database.
# Build relation between host grp and host to be handled here.
storage_host_groups = self.driver_api \
storage_hg_obj = self.driver_api \
.list_storage_host_groups(self.context, self.storage_id)
storage_host_groups = storage_hg_obj['storage_host_groups']
storage_host_rels = storage_hg_obj['storage_host_grp_host_rels']
if storage_host_groups:
_build_storage_host_group_relations(
self.context, self.storage_id, storage_host_groups)
db.storage_host_grp_host_rels_delete_by_storage(
self.context, self.storage_id)
db.storage_host_grp_host_rels_create(
self.context, storage_host_rels)
LOG.info('Building host group relations successful for '
'storage id:{0}'.format(self.storage_id))

Expand Down Expand Up @@ -682,11 +612,15 @@ def sync(self):
try:
# Collect the port groups from driver and database
# Build relation between port grp and port to be handled here.
port_groups = self.driver_api \
port_groups_obj = self.driver_api \
.list_port_groups(self.context, self.storage_id)
port_groups = port_groups_obj['port_groups']
port_group_relation_list = port_groups_obj['port_grp_port_rels']
if port_groups:
_build_port_group_relations(
self.context, self.storage_id, port_groups)
db.port_grp_port_rels_delete_by_storage(
self.context, self.storage_id)
db.port_grp_port_rels_create(
self.context, port_group_relation_list)
LOG.info('Building port group relations successful for '
'storage id:{0}'.format(self.storage_id))

Expand Down Expand Up @@ -744,11 +678,14 @@ def sync(self):
try:
# Collect the volume groups from driver and database
# Build relation between volume grp and volume to be handled here.
volume_groups = self.driver_api \
volume_groups_obj = self.driver_api \
.list_volume_groups(self.context, self.storage_id)
volume_groups = volume_groups_obj['volume_groups']
volume_groups_rels = volume_groups_obj['vol_grp_vol_rels']
if volume_groups:
_build_volume_group_relations(
self.context, self.storage_id, volume_groups)
db.vol_grp_vol_rels_delete_by_storage(
self.context, self.storage_id)
db.vol_grp_vol_rels_create(self.context, volume_groups_rels)
LOG.info('Building volume group relations successful for '
'storage id:{0}'.format(self.storage_id))

Expand Down
2 changes: 0 additions & 2 deletions delfin/tests/unit/fake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ def fake_masking_view_create():
'updated_at': '2020-06-10T07:17:08.707356',
'native_storage_host_id': 'storage_host_1',
'native_volume_id': 'volume_1',
'native_port_id': 'port_1',
'native_masking_view_id': 'masking_view_1', }
return fake_masking_views

Expand All @@ -282,7 +281,6 @@ def fake_expected_masking_views_create():
"storage_id": '12c2d52f-01bc-41f5-b73f-7abf6f38a2a6',
"native_storage_host_id": "storage_host_1",
"native_volume_id": "volume_1",
"native_port_id": "port_1",
"native_storage_host_group_id": None,
"native_port_group_id": None,
"native_volume_group_id": None,
Expand Down
Loading

0 comments on commit 6774a9a

Please sign in to comment.