From e003ac514cdc4a17bb71582bd67d9505b24242c0 Mon Sep 17 00:00:00 2001 From: sushanthakumar Date: Sun, 6 Jun 2021 20:20:03 +0530 Subject: [PATCH 1/6] db models for host mapping --- delfin/db/sqlalchemy/models.py | 115 ++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/delfin/db/sqlalchemy/models.py b/delfin/db/sqlalchemy/models.py index f458c0219..32c37e55b 100644 --- a/delfin/db/sqlalchemy/models.py +++ b/delfin/db/sqlalchemy/models.py @@ -23,7 +23,8 @@ from oslo_config import cfg from oslo_db.sqlalchemy import models from oslo_db.sqlalchemy.types import JsonEncodedDict -from sqlalchemy import Column, Integer, String, Boolean, BigInteger, DateTime +from sqlalchemy import Column, Integer, String, Boolean, BigInteger, \ + DateTime, Text from sqlalchemy.ext.declarative import declarative_base from delfin.common import constants @@ -286,3 +287,115 @@ class FailedTask(BASE, DelfinBase): job_id = Column(String(36)) deleted_at = Column(DateTime) deleted = Column(Boolean, default=False) + + +class StorageInitiator(BASE, DelfinBase): + """Represents the storage initiator attributes.""" + __tablename__ = 'storage_initiators' + id = Column(String(36), primary_key=True) + storage_id = Column(String(36)) + name = Column(String(255)) + description = Column(String(255)) + wwn = Column(String(255)) + status = Column(String(255)) + native_storage_host_id = Column(String(255)) + native_storage_initiator_id = Column(String(255)) + + +class StorageHost(BASE, DelfinBase): + """Represents the storage host attributes.""" + __tablename__ = 'storage_hosts' + id = Column(String(36), primary_key=True) + storage_id = Column(String(36)) + name = Column(String(255)) + description = Column(String(255)) + os_type = Column(String(255)) + storage_initiators = Column(Text) + ip_address = Column(String(255)) + status = Column(String(255)) + native_storage_host_id = Column(String(255)) + + +class StorageHostGroup(BASE, DelfinBase): + """Represents the storage host group attributes.""" + __tablename__ = 'storage_host_groups' + id = Column(String(36), primary_key=True) + storage_id = Column(String(36)) + name = Column(String(255)) + description = Column(String(255)) + storage_hosts = Column(Text) + native_storage_host_group_id = Column(String(255)) + + +class PortGroup(BASE, DelfinBase): + """Represents the port group attributes.""" + __tablename__ = 'port_groups' + id = Column(String(36), primary_key=True) + storage_id = Column(String(36)) + name = Column(String(255)) + description = Column(String(255)) + ports = Column(Text) + native_port_group_id = Column(String(255)) + + +class VolumeGroup(BASE, DelfinBase): + """Represents the volume group attributes.""" + __tablename__ = 'volume_groups' + id = Column(String(36), primary_key=True) + storage_id = Column(String(36)) + name = Column(String(255)) + description = Column(String(255)) + volumes = Column(Text) + native_volume_group_id = Column(String(255)) + + +class MaskingView(BASE, DelfinBase): + """Represents the masking view attributes.""" + __tablename__ = 'masking_views' + id = Column(String(36), primary_key=True) + storage_id = Column(String(36)) + name = Column(String(255)) + description = Column(String(255)) + native_storage_host_group_id = Column(String(255)) + native_volume_group_id = Column(String(255)) + native_port_group_id = Column(String(255)) + native_storage_host_id = Column(String(255)) + storage_initiators = Column(Text) + volumes = Column(Text) + ports = Column(Text) + native_masking_view_id = Column(String(255)) + + +class StorageHostGrpStorageHostRelation(BASE, DelfinBase): + """Represents the storage host group and storage host relation + attributes. + """ + __tablename__ = 'storage_host_group_storage_host_relations' + id = Column(String(36), primary_key=True) + storage_id = Column(String(36)) + name = Column(String(255)) + description = Column(String(255)) + native_storage_host_group_id = Column(String(255)) + native_storage_host_id = Column(String(255)) + + +class PortGrpPortRelation(BASE, DelfinBase): + """Represents port group and port relation attributes.""" + __tablename__ = 'port_group_port_relations' + id = Column(String(36), primary_key=True) + storage_id = Column(String(36)) + name = Column(String(255)) + description = Column(String(255)) + native_port_group_id = Column(String(255)) + native_port_id = Column(String(255)) + + +class VolumeGrpVolumeRelation(BASE, DelfinBase): + """Represents the volume group and volume relation attributes.""" + __tablename__ = 'volume_group_volume_relations' + id = Column(String(36), primary_key=True) + storage_id = Column(String(36)) + name = Column(String(255)) + description = Column(String(255)) + native_volume_group_id = Column(String(255)) + native_volume_id = Column(String(255)) From c7a6bdb8358b789724964bad7211aae293acba20 Mon Sep 17 00:00:00 2001 From: sushanthakumar Date: Mon, 14 Jun 2021 07:54:41 +0530 Subject: [PATCH 2/6] DB API changes --- delfin/db/api.py | 488 +++++++++++++++++ delfin/db/sqlalchemy/api.py | 1024 +++++++++++++++++++++++++++++++++++ delfin/exception.py | 36 ++ 3 files changed, 1548 insertions(+) diff --git a/delfin/db/api.py b/delfin/db/api.py index 37b683572..f7acd342a 100644 --- a/delfin/db/api.py +++ b/delfin/db/api.py @@ -841,3 +841,491 @@ def failed_task_delete_by_storage(context, storage_id): does not exist. """ return IMPL.failed_task_delete_by_storage(context, storage_id) + + +def storage_initiators_create(context, values): + """Create a storage initiator entry from the values dictionary.""" + return IMPL.storage_initiators_create(context, values) + + +def storage_initiators_update(context, values): + """Update a storage initiator with the values dictionary.""" + return IMPL.storage_initiators_update(context, values) + + +def storage_initiators_delete(context, values): + """Delete multiple storage initiators.""" + return IMPL.storage_initiators_delete(context, values) + + +def storage_initiators_get(context, storage_initiator_id): + """Get a storage initiator or raise an exception if it does not exist.""" + return IMPL.storage_initiators_get(context, storage_initiator_id) + + +def storage_initiators_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, filters=None, + offset=None): + """Retrieves all storage initiators. + + If no sort parameters are specified then the returned storage initiators + are sorted first by the 'created_at' key and then by the 'id' key in + descending order. + + :param context: context of this request, it's helpful to trace the request + :param marker: the last item of the previous page, used to determine the + next page of results to return + :param limit: maximum number of items to return + :param sort_keys: list of attributes by which results should be sorted, + paired with corresponding item in sort_dirs + :param sort_dirs: list of directions in which results should be sorted, + paired with corresponding item in sort_keys, for example + 'desc' for descending order + :param filters: dictionary of filters + :param offset: number of items to skip + :returns: list of storage initiators + """ + return IMPL.storage_initiators_get_all(context, marker, limit, sort_keys, + sort_dirs, filters, offset) + + +def storage_initiators_delete_by_storage(context, storage_id): + """Delete all the storage initiators of a device.""" + return IMPL.storage_initiators_delete_by_storage(context, storage_id) + + +def storage_hosts_create(context, values): + """Create a storage host entry from the values dictionary.""" + return IMPL.storage_hosts_create(context, values) + + +def storage_hosts_update(context, values): + """Update a storage host with the values dictionary.""" + return IMPL.storage_hosts_update(context, values) + + +def storage_hosts_delete(context, values): + """Delete multiple storage hosts.""" + return IMPL.storage_hosts_delete(context, values) + + +def storage_hosts_get(context, storage_host_id): + """Get a storage host or raise an exception if it does not exist.""" + return IMPL.storage_hosts_get(context, storage_host_id) + + +def storage_hosts_get_all(context, marker=None, limit=None, sort_keys=None, + sort_dirs=None, filters=None, offset=None): + """Retrieves all storage hosts. + + If no sort parameters are specified then the returned storage hosts are + sorted first by the 'created_at' key and then by the 'id' key in + descending order. + + :param context: context of this request, it's helpful to trace the request + :param marker: the last item of the previous page, used to determine the + next page of results to return + :param limit: maximum number of items to return + :param sort_keys: list of attributes by which results should be sorted, + paired with corresponding item in sort_dirs + :param sort_dirs: list of directions in which results should be sorted, + paired with corresponding item in sort_keys, for example + 'desc' for descending order + :param filters: dictionary of filters + :param offset: number of items to skip + :returns: list of storage hosts + """ + return IMPL.storage_hosts_get_all(context, marker, limit, sort_keys, + sort_dirs, filters, offset) + + +def storage_hosts_delete_by_storage(context, storage_id): + """Delete all the storage hosts of a device.""" + return IMPL.storage_hosts_delete_by_storage(context, storage_id) + + +def storage_host_groups_create(context, values): + """Create a storage host grp entry from the values dictionary.""" + return IMPL.storage_host_groups_create(context, values) + + +def storage_host_groups_update(context, values): + """Update a storage host grp with the values dictionary.""" + return IMPL.storage_host_groups_update(context, values) + + +def storage_host_groups_delete(context, values): + """Delete multiple storage host groups.""" + return IMPL.storage_host_groups_delete(context, values) + + +def storage_host_groups_get(context, storage_host_grp_id): + """Get a storage host group or raise an exception if it does not exist.""" + return IMPL.storage_host_groups_get(context, storage_host_grp_id) + + +def storage_host_groups_get_all(context, marker=None, limit=None, + sort_keys=None, + sort_dirs=None, filters=None, offset=None): + """Retrieves all storage host groups. + + If no sort parameters are specified then the returned storage host groups + are sorted first by the 'created_at' key and then by the 'id' key in + descending order. + + :param context: context of this request, it's helpful to trace the request + :param marker: the last item of the previous page, used to determine the + next page of results to return + :param limit: maximum number of items to return + :param sort_keys: list of attributes by which results should be sorted, + paired with corresponding item in sort_dirs + :param sort_dirs: list of directions in which results should be sorted, + paired with corresponding item in sort_keys, for example + 'desc' for descending order + :param filters: dictionary of filters + :param offset: number of items to skip + :returns: list of storage host groups + """ + return IMPL.storage_host_groups_get_all(context, marker, limit, sort_keys, + sort_dirs, filters, offset) + + +def storage_host_groups_delete_by_storage(context, storage_id): + """Delete all the storage host groups of a device.""" + return IMPL.storage_host_groups_delete_by_storage(context, storage_id) + + +def port_groups_create(context, values): + """Create a port group entry from the values dictionary.""" + return IMPL.port_groups_create(context, values) + + +def port_groups_update(context, values): + """Update a port group with the values dictionary.""" + return IMPL.port_groups_update(context, values) + + +def port_groups_delete(context, values): + """Delete multiple port groups.""" + return IMPL.port_groups_delete(context, values) + + +def port_groups_get(context, port_grp_id): + """Get a port group or raise an exception if it does not exist.""" + return IMPL.port_groups_get(context, port_grp_id) + + +def port_groups_get_all(context, marker=None, limit=None, + sort_keys=None, + sort_dirs=None, filters=None, offset=None): + """Retrieves all port groups. + + If no sort parameters are specified then the returned port groups are + sorted first by the 'created_at' key and then by the 'id' key in + descending order. + + :param context: context of this request, it's helpful to trace the request + :param marker: the last item of the previous page, used to determine the + next page of results to return + :param limit: maximum number of items to return + :param sort_keys: list of attributes by which results should be sorted, + paired with corresponding item in sort_dirs + :param sort_dirs: list of directions in which results should be sorted, + paired with corresponding item in sort_keys, for example + 'desc' for descending order + :param filters: dictionary of filters + :param offset: number of items to skip + :returns: list of port groups + """ + return IMPL.port_groups_get_all(context, marker, limit, sort_keys, + sort_dirs, filters, offset) + + +def port_groups_delete_by_storage(context, storage_id): + """Delete all the port groups of a device.""" + return IMPL.port_groups_delete_by_storage(context, storage_id) + + +def volume_groups_create(context, values): + """Create a volume group entry from the values dictionary.""" + return IMPL.volume_groups_create(context, values) + + +def volume_groups_update(context, values): + """Update a volume group with the values dictionary.""" + return IMPL.volume_groups_update(context, values) + + +def volume_groups_delete(context, values): + """Delete multiple volume groups.""" + return IMPL.volume_groups_delete(context, values) + + +def volume_groups_get(context, volume_grp_id): + """Get a volume group or raise an exception if it does not exist.""" + return IMPL.volume_groups_get(context, volume_grp_id) + + +def volume_groups_get_all(context, marker=None, limit=None, + sort_keys=None, + sort_dirs=None, filters=None, offset=None): + """Retrieves all volume groups. + + If no sort parameters are specified then the returned volume groups are + sorted first by the 'created_at' key and then by the 'id' key in + descending order. + + :param context: context of this request, it's helpful to trace the request + :param marker: the last item of the previous page, used to determine the + next page of results to return + :param limit: maximum number of items to return + :param sort_keys: list of attributes by which results should be sorted, + paired with corresponding item in sort_dirs + :param sort_dirs: list of directions in which results should be sorted, + paired with corresponding item in sort_keys, for example + 'desc' for descending order + :param filters: dictionary of filters + :param offset: number of items to skip + :returns: list of volume groups + """ + return IMPL.volume_groups_get_all(context, marker, limit, sort_keys, + sort_dirs, filters, offset) + + +def volume_groups_delete_by_storage(context, storage_id): + """Delete all the volume groups of a device.""" + return IMPL.volume_groups_delete_by_storage(context, storage_id) + + +def masking_views_create(context, values): + """Create a masking view entry from the values dictionary.""" + return IMPL.masking_views_create(context, values) + + +def masking_views_update(context, values): + """Update a masking view with the values dictionary.""" + return IMPL.masking_views_update(context, values) + + +def masking_views_delete(context, values): + """Delete multiple masking views.""" + return IMPL.masking_views_delete(context, values) + + +def masking_views_get(context, masking_view_id): + """Get a masking view or raise an exception if it does not exist.""" + return IMPL.masking_views_get(context, masking_view_id) + + +def masking_views_get_all(context, marker=None, limit=None, + sort_keys=None, + sort_dirs=None, filters=None, offset=None): + """Retrieves all masking views. + + If no sort parameters are specified then the returned masking views are + sorted first by the 'created_at' key and then by the 'id' key in + descending order. + + :param context: context of this request, it's helpful to trace the request + :param marker: the last item of the previous page, used to determine the + next page of results to return + :param limit: maximum number of items to return + :param sort_keys: list of attributes by which results should be sorted, + paired with corresponding item in sort_dirs + :param sort_dirs: list of directions in which results should be sorted, + paired with corresponding item in sort_keys, for example + 'desc' for descending order + :param filters: dictionary of filters + :param offset: number of items to skip + :returns: list of masking views + """ + return IMPL.masking_views_get_all(context, marker, limit, sort_keys, + sort_dirs, filters, offset) + + +def masking_views_delete_by_storage(context, storage_id): + """Delete all the masking views of a device.""" + return IMPL.masking_views_delete_by_storage(context, storage_id) + + +def storage_host_grp_host_relations_create(context, values): + """Create a storage host grp host relation entry from the values + dictionary. + """ + return IMPL.storage_host_grp_host_relations_create(context, values) + + +def storage_host_grp_host_relations_update(context, values): + """Update a storage host grp host relation with the values dictionary.""" + return IMPL.storage_host_grp_host_relations_update(context, values) + + +def storage_host_grp_host_relations_delete(context, values): + """Delete multiple storage host grp host relations.""" + return IMPL.storage_host_grp_host_relations_delete(context, values) + + +def storage_host_grp_host_relations_get(context, host_grp_host_relation_id): + """Get a storage host grp host relation or raise an exception if it does + not exist. + """ + return IMPL.storage_host_grp_host_relations_get(context, + host_grp_host_relation_id) + + +def storage_host_grp_host_relations_get_all(context, marker=None, limit=None, + sort_keys=None, + sort_dirs=None, filters=None, + offset=None): + """Retrieves all storage host grp host relation. + + If no sort parameters are specified then the returned + storage host grp host relations are + sorted first by the 'created_at' key and then by the 'id' key in + descending order. + + :param context: context of this request, it's helpful to trace the request + :param marker: the last item of the previous page, used to determine the + next page of results to return + :param limit: maximum number of items to return + :param sort_keys: list of attributes by which results should be sorted, + paired with corresponding item in sort_dirs + :param sort_dirs: list of directions in which results should be sorted, + paired with corresponding item in sort_keys, for example + 'desc' for descending order + :param filters: dictionary of filters + :param offset: number of items to skip + :returns: list of storage host grp host relations + """ + return IMPL.storage_host_grp_host_relations_get_all(context, marker, limit, + sort_keys, + sort_dirs, filters, + offset) + + +def storage_host_grp_host_relations_delete_by_storage(context, storage_id): + """Delete all the storage host grp host relations of a device.""" + return IMPL.storage_host_grp_host_relations_delete_by_storage(context, + storage_id) + + +def port_grp_port_relations_create(context, values): + """Create a port grp port relation entry from the values + dictionary. + """ + return IMPL.port_grp_port_relations_create(context, values) + + +def port_grp_port_relations_update(context, values): + """Update a port grp port relation with the values dictionary.""" + return IMPL.port_grp_port_relations_update(context, values) + + +def port_grp_port_relations_delete(context, values): + """Delete multiple port grp port relations.""" + return IMPL.port_grp_port_relations_delete(context, values) + + +def port_grp_port_relations_get(context, port_grp_port_relation_id): + """Get a port grp port relation or raise an exception if it does + not exist. + """ + return IMPL.port_grp_port_relations_get(context, + port_grp_port_relation_id) + + +def port_grp_port_relations_get_all(context, marker=None, limit=None, + sort_keys=None, + sort_dirs=None, filters=None, + offset=None): + """Retrieves all port grp port relation. + + If no sort parameters are specified then the returned + port grp port relations are + sorted first by the 'created_at' key and then by the 'id' key in + descending order. + + :param context: context of this request, it's helpful to trace the request + :param marker: the last item of the previous page, used to determine the + next page of results to return + :param limit: maximum number of items to return + :param sort_keys: list of attributes by which results should be sorted, + paired with corresponding item in sort_dirs + :param sort_dirs: list of directions in which results should be sorted, + paired with corresponding item in sort_keys, for example + 'desc' for descending order + :param filters: dictionary of filters + :param offset: number of items to skip + :returns: list of port grp port relations + """ + return IMPL.port_grp_port_relations_get_all(context, marker, limit, + sort_keys, + sort_dirs, filters, + offset) + + +def port_grp_port_relations_delete_by_storage(context, storage_id): + """Delete all the port grp port relations of a device.""" + return IMPL.port_grp_port_relations_delete_by_storage(context, + storage_id) + + +def volume_grp_volume_relations_create(context, values): + """Create a volume grp volume relation entry from the values + dictionary. + """ + return IMPL.volume_grp_volume_relations_create(context, values) + + +def volume_grp_volume_relations_update(context, values): + """Update a volume grp volume relation with the values dictionary.""" + return IMPL.volume_grp_volume_relations_update(context, values) + + +def volume_grp_volume_relations_delete(context, values): + """Delete multiple volume grp volume relations.""" + return IMPL.volume_grp_volume_relations_delete(context, values) + + +def volume_grp_volume_relations_get(context, volume_grp_volume_relation_id): + """Get a volume grp volume relation or raise an exception if it does + not exist. + """ + return IMPL.volume_grp_volume_relations_get(context, + volume_grp_volume_relation_id) + + +def volume_grp_volume_relations_get_all(context, marker=None, limit=None, + sort_keys=None, + sort_dirs=None, filters=None, + offset=None): + """Retrieves all volume grp volume relation. + + If no sort parameters are specified then the returned + volume grp volume relations are + sorted first by the 'created_at' key and then by the 'id' key in + descending order. + + :param context: context of this request, it's helpful to trace the request + :param marker: the last item of the previous page, used to determine the + next page of results to return + :param limit: maximum number of items to return + :param sort_keys: list of attributes by which results should be sorted, + paired with corresponding item in sort_dirs + :param sort_dirs: list of directions in which results should be sorted, + paired with corresponding item in sort_keys, for example + 'desc' for descending order + :param filters: dictionary of filters + :param offset: number of items to skip + :returns: list of volume grp volume relations + """ + return IMPL.volume_grp_volume_relations_get_all(context, marker, limit, + sort_keys, + sort_dirs, filters, + offset) + + +def volume_grp_volume_relations_delete_by_storage(context, storage_id): + """Delete all the volume grp volume relations of a device.""" + return IMPL.volume_grp_volume_relations_delete_by_storage(context, + storage_id) diff --git a/delfin/db/sqlalchemy/api.py b/delfin/db/sqlalchemy/api.py index 232fcc1eb..906c76d8f 100644 --- a/delfin/db/sqlalchemy/api.py +++ b/delfin/db/sqlalchemy/api.py @@ -1851,6 +1851,999 @@ def _process_failed_tasks_info_filters(query, filters): return query +def _storage_initiators_get_query(context, session=None): + return model_query(context, models.StorageInitiator, session=session) + + +def _storage_initiators_get(context, storage_initiator_id, session=None): + result = (_storage_initiators_get_query(context, session=session) + .filter_by(id=storage_initiator_id) + .first()) + + if not result: + raise exception.StorageInitiatorNotFound(storage_initiator_id) + + return result + + +def storage_initiators_create(context, storage_initiators): + """Create multiple storage initiators.""" + session = get_session() + initiator_refs = [] + with session.begin(): + + for initiator in storage_initiators: + LOG.debug('Adding new storage initiator for ' + 'native_storage_initiator_id {0}:' + .format(initiator.get('native_storage_initiator_id'))) + if not initiator.get('id'): + initiator['id'] = uuidutils.generate_uuid() + + initiator_ref = models.StorageInitiator() + initiator_ref.update(initiator) + initiator_refs.append(initiator_ref) + + session.add_all(initiator_refs) + + return initiator_refs + + +def storage_initiators_delete(context, storage_initiators_id_list): + """Delete multiple storage initiators.""" + session = get_session() + with session.begin(): + for initiator_id in storage_initiators_id_list: + LOG.debug('Deleting storage initiator {0}:'.format(initiator_id)) + query = _storage_initiators_get_query(context, session) + result = query.filter_by(id=initiator_id).delete() + + if not result: + LOG.error(exception.StorageInitiatorNotFound(initiator_id)) + return + + +def storage_initiators_update(context, storage_initiators): + """Update multiple storage initiators.""" + session = get_session() + with session.begin(): + for initiator in storage_initiators: + LOG.debug('Updating storage initiator {0}:' + .format(initiator.get('id'))) + query = _storage_initiators_get_query(context, session) + result = query.filter_by(id=initiator.get('id') + ).update(initiator) + + if not result: + LOG.error(exception.StorageInitiatorNotFound(initiator + .get('id'))) + + +def storage_initiators_get(context, storage_initiator_id): + """Get a storage initiator or raise an exception if it does not exist.""" + return _storage_initiators_get(context, storage_initiator_id) + + +def storage_initiators_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, filters=None, + offset=None): + """Retrieves all storage initiators""" + session = get_session() + with session.begin(): + # Generate the query + query = _generate_paginate_query(context, session, + models.StorageInitiator, marker, + limit, sort_keys, sort_dirs, + filters, offset) + # No storage initiator would match, return empty list + if query is None: + return [] + return query.all() + + +@apply_like_filters(model=models.StorageInitiator) +def _process_storage_initiators_info_filters(query, filters): + """Common filter processing for storage initiators queries.""" + if filters: + if not is_valid_model_filters(models.StorageInitiator, filters): + return + query = query.filter_by(**filters) + + return query + + +def storage_initiators_delete_by_storage(context, storage_id): + """Delete all the storage initiators of a device""" + _storage_initiators_get_query(context).filter_by(storage_id=storage_id)\ + .delete() + + +def _storage_hosts_get_query(context, session=None): + return model_query(context, models.StorageHost, session=session) + + +def _storage_hosts_get(context, storage_host_id, session=None): + result = (_storage_hosts_get_query(context, session=session) + .filter_by(id=storage_host_id) + .first()) + + if not result: + raise exception.StorageHostNotFound(storage_host_id) + + return result + + +def storage_hosts_create(context, storage_hosts): + """Create multiple storage hosts.""" + session = get_session() + host_refs = [] + with session.begin(): + + for host in storage_hosts: + LOG.debug('Adding new storage host for ' + 'native_host_id {0}:' + .format(host.get('native_host_id'))) + if not host.get('id'): + host['id'] = uuidutils.generate_uuid() + + host_ref = models.StorageHost() + host_ref.update(host) + host_refs.append(host_ref) + + session.add_all(host_refs) + + return host_refs + + +def storage_hosts_delete(context, storage_hosts_id_list): + """Delete multiple storage hosts.""" + session = get_session() + with session.begin(): + for host_id in storage_hosts_id_list: + LOG.debug('Deleting volume {0}:'.format(host_id)) + query = _storage_hosts_get_query(context, session) + result = query.filter_by(id=host_id).delete() + + if not result: + LOG.error(exception.StorageHostNotFound(host_id)) + return + + +def storage_hosts_update(context, storage_hosts): + """Update multiple storage hosts.""" + session = get_session() + with session.begin(): + for host in storage_hosts: + LOG.debug('Updating storage hosts {0}:'.format(host.get('id'))) + query = _storage_hosts_get_query(context, session) + result = query.filter_by(id=host.get('id') + ).update(host) + + if not result: + LOG.error(exception.StorageHostNotFound(host + .get('id'))) + + +def storage_hosts_get(context, storage_host_id): + """Get a storage host or raise an exception if it does not exist.""" + return _storage_hosts_get(context, storage_host_id) + + +def storage_hosts_get_all(context, marker=None, limit=None, sort_keys=None, + sort_dirs=None, filters=None, offset=None): + """Retrieves all storage hosts""" + session = get_session() + with session.begin(): + # Generate the query + query = _generate_paginate_query(context, session, + models.StorageHost, marker, limit, + sort_keys, sort_dirs, filters, offset) + # No storage host would match, return empty list + if query is None: + return [] + return query.all() + + +@apply_like_filters(model=models.StorageHost) +def _process_storage_hosts_info_filters(query, filters): + """Common filter processing for storage hosts queries.""" + if filters: + if not is_valid_model_filters(models.StorageHost, filters): + return + query = query.filter_by(**filters) + + return query + + +def storage_hosts_delete_by_storage(context, storage_id): + """Delete all the storage hosts of a device""" + _storage_hosts_get_query(context).filter_by(storage_id=storage_id)\ + .delete() + + +def _storage_host_groups_get_query(context, session=None): + return model_query(context, models.StorageHostGroup, session=session) + + +def _storage_host_groups_get(context, storage_host_grp_id, session=None): + result = (_storage_host_groups_get_query(context, session=session) + .filter_by(id=storage_host_grp_id) + .first()) + + if not result: + raise exception.StorageHostGroupNotFound(storage_host_grp_id) + + return result + + +def storage_host_groups_create(context, storage_host_groups): + """Create multiple storage host groups.""" + session = get_session() + host_groups_refs = [] + with session.begin(): + + for host_group in storage_host_groups: + LOG.debug('Adding new storage host group for ' + 'native_storage_host_group_id {0}:' + .format(host_group.get('native_storage_host_group_id'))) + if not host_group.get('id'): + host_group['id'] = uuidutils.generate_uuid() + + host_group_ref = models.StorageHostGroup() + host_group_ref.update(host_group) + host_groups_refs.append(host_group_ref) + + session.add_all(host_groups_refs) + + return host_groups_refs + + +def storage_host_groups_delete(context, storage_host_groups_id_list): + """Delete multiple storage host groups.""" + session = get_session() + with session.begin(): + for host_group_id in storage_host_groups_id_list: + LOG.debug('Deleting storage host group {0}:'.format(host_group_id)) + query = _storage_host_groups_get_query(context, session) + result = query.filter_by(id=host_group_id).delete() + + if not result: + LOG.error(exception.StorageHostGroupNotFound(host_group_id)) + return + + +def storage_host_groups_update(context, storage_host_groups): + """Update multiple storage host groups.""" + session = get_session() + with session.begin(): + for host_group in storage_host_groups: + LOG.debug('Updating storage host groups {0}:' + .format(host_group.get('id'))) + query = _storage_host_groups_get_query(context, session) + result = query.filter_by(id=host_group.get('id') + ).update(host_group) + + if not result: + LOG.error(exception.StorageHostGroupNotFound(host_group + .get('id'))) + + +def storage_host_groups_get(context, storage_host_group_id): + """Get a storage host group or raise an exception if it does not exist.""" + return _storage_host_groups_get(context, storage_host_group_id) + + +def storage_host_groups_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, offset=None): + """Retrieves all storage host groups""" + session = get_session() + with session.begin(): + # Generate the query + query = _generate_paginate_query(context, session, + models.StorageHostGroup, marker, + limit, sort_keys, sort_dirs, + filters, offset) + # No storage host group would match, return empty list + if query is None: + return [] + return query.all() + + +@apply_like_filters(model=models.StorageHostGroup) +def _process_storage_host_groups_info_filters(query, filters): + """Common filter processing for storage host groups queries.""" + if filters: + if not is_valid_model_filters(models.StorageHostGroup, filters): + return + query = query.filter_by(**filters) + + return query + + +def storage_host_groups_delete_by_storage(context, storage_id): + """Delete all the storage host groups of a device""" + _storage_host_groups_get_query(context).filter_by(storage_id=storage_id)\ + .delete() + + +def _port_groups_get_query(context, session=None): + return model_query(context, models.PortGroup, session=session) + + +def _port_groups_get(context, port_grp_id, session=None): + result = (_port_groups_get_query(context, session=session) + .filter_by(id=port_grp_id) + .first()) + + if not result: + raise exception.PortGroupNotFound(port_grp_id) + + return result + + +def port_groups_create(context, port_groups): + """Create multiple port groups.""" + session = get_session() + port_groups_refs = [] + with session.begin(): + + for port_group in port_groups: + LOG.debug('Adding new port group for ' + 'native_port_group_id {0}:' + .format(port_group.get('native_port_group_id'))) + if not port_group.get('id'): + port_group['id'] = uuidutils.generate_uuid() + + port_group_ref = models.PortGroup() + port_group_ref.update(port_group) + port_groups_refs.append(port_group_ref) + + session.add_all(port_groups_refs) + + return port_groups_refs + + +def port_groups_delete(context, port_groups_id_list): + """Delete multiple port groups.""" + session = get_session() + with session.begin(): + for port_group_id in port_groups_id_list: + LOG.debug('Deleting port group {0}:'.format(port_group_id)) + query = _port_groups_get_query(context, session) + result = query.filter_by(id=port_group_id).delete() + + if not result: + LOG.error(exception.PortGroupNotFound(port_group_id)) + return + + +def port_groups_update(context, port_groups): + """Update multiple port groups.""" + session = get_session() + with session.begin(): + for port_group in port_groups: + LOG.debug('Updating port groups {0}:' + .format(port_group.get('id'))) + query = _port_groups_get_query(context, session) + result = query.filter_by(id=port_group.get('id') + ).update(port_group) + + if not result: + LOG.error(exception.PortGroupNotFound(port_group + .get('id'))) + + +def port_groups_get(context, port_group_id): + """Get a port group or raise an exception if it does not exist.""" + return _port_groups_get(context, port_group_id) + + +def port_groups_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, offset=None): + """Retrieves all port groups""" + session = get_session() + with session.begin(): + # Generate the query + query = _generate_paginate_query(context, session, + models.PortGroup, marker, + limit, sort_keys, sort_dirs, + filters, offset) + # No port group would match, return empty list + if query is None: + return [] + return query.all() + + +@apply_like_filters(model=models.PortGroup) +def _process_port_groups_info_filters(query, filters): + """Common filter processing for port groups queries.""" + if filters: + if not is_valid_model_filters(models.PortGroup, filters): + return + query = query.filter_by(**filters) + + return query + + +def port_groups_delete_by_storage(context, storage_id): + """Delete all the port groups of a device""" + _port_groups_get_query(context).filter_by(storage_id=storage_id)\ + .delete() + + +def _volume_groups_get_query(context, session=None): + return model_query(context, models.VolumeGroup, session=session) + + +def _volume_groups_get(context, volume_grp_id, session=None): + result = (_volume_groups_get_query(context, session=session) + .filter_by(id=volume_grp_id) + .first()) + + if not result: + raise exception.VolumeGroupNotFound(volume_grp_id) + + return result + + +def volume_groups_create(context, volume_groups): + """Create multiple volume groups.""" + session = get_session() + volume_groups_refs = [] + with session.begin(): + + for volume_group in volume_groups: + LOG.debug('Adding new volume group for ' + 'native_volume_group_id {0}:' + .format(volume_group.get('native_volume_group_id'))) + if not volume_group.get('id'): + volume_group['id'] = uuidutils.generate_uuid() + + volume_group_ref = models.VolumeGroup() + volume_group_ref.update(volume_group) + volume_groups_refs.append(volume_group_ref) + + session.add_all(volume_groups_refs) + + return volume_groups_refs + + +def volume_groups_delete(context, volume_groups_id_list): + """Delete multiple volume groups.""" + session = get_session() + with session.begin(): + for volume_group_id in volume_groups_id_list: + LOG.debug('Deleting volume group {0}:'.format(volume_group_id)) + query = _volume_groups_get_query(context, session) + result = query.filter_by(id=volume_group_id).delete() + + if not result: + LOG.error(exception.VolumeGroupNotFound(volume_group_id)) + return + + +def volume_groups_update(context, volume_groups): + """Update multiple volume groups.""" + session = get_session() + with session.begin(): + for volume_group in volume_groups: + LOG.debug('Updating volume groups {0}:' + .format(volume_group.get('id'))) + query = _volume_groups_get_query(context, session) + result = query.filter_by(id=volume_group.get('id') + ).update(volume_group) + + if not result: + LOG.error(exception.VolumeGroupNotFound(volume_group + .get('id'))) + + +def volume_groups_get(context, volume_group_id): + """Get a volume group or raise an exception if it does not exist.""" + return _volume_groups_get(context, volume_group_id) + + +def volume_groups_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, offset=None): + """Retrieves all volume groups""" + session = get_session() + with session.begin(): + # Generate the query + query = _generate_paginate_query(context, session, + models.VolumeGroup, marker, + limit, sort_keys, sort_dirs, + filters, offset) + # No volume group would match, return empty list + if query is None: + return [] + return query.all() + + +@apply_like_filters(model=models.VolumeGroup) +def _process_volume_groups_info_filters(query, filters): + """Common filter processing for volume groups queries.""" + if filters: + if not is_valid_model_filters(models.VolumeGroup, filters): + return + query = query.filter_by(**filters) + + return query + + +def volume_groups_delete_by_storage(context, storage_id): + """Delete all the volume groups of a device""" + _volume_groups_get_query(context).filter_by(storage_id=storage_id)\ + .delete() + + +def _masking_views_get_query(context, session=None): + return model_query(context, models.MaskingView, session=session) + + +def _masking_views_get(context, masking_view_id, session=None): + result = (_masking_views_get_query(context, session=session) + .filter_by(id=masking_view_id) + .first()) + + if not result: + raise exception.MaskingViewNotFound(masking_view_id) + + return result + + +def masking_views_create(context, masking_views): + """Create multiple masking views.""" + session = get_session() + masking_views_refs = [] + with session.begin(): + + for masking_view in masking_views: + LOG.debug('Adding new masking view for ' + 'native_masking_view_id {0}:' + .format(masking_view.get('native_masking_view_id'))) + if not masking_view.get('id'): + masking_view['id'] = uuidutils.generate_uuid() + + masking_view_ref = models.MaskingView() + masking_view_ref.update(masking_view) + masking_views_refs.append(masking_view_ref) + + session.add_all(masking_views_refs) + + return masking_views_refs + + +def masking_views_delete(context, masking_views_id_list): + """Delete multiple masking views.""" + session = get_session() + with session.begin(): + for masking_view_id in masking_views_id_list: + LOG.debug('Deleting masking view {0}:'.format(masking_view_id)) + query = _masking_views_get_query(context, session) + result = query.filter_by(id=masking_view_id).delete() + + if not result: + LOG.error(exception.MaskingViewNotFound(masking_view_id)) + return + + +def masking_views_update(context, masking_views): + """Update multiple masking views.""" + session = get_session() + with session.begin(): + for masking_view in masking_views: + LOG.debug('Updating masking views {0}:' + .format(masking_view.get('id'))) + query = _masking_views_get_query(context, session) + result = query.filter_by(id=masking_view.get('id') + ).update(masking_view) + + if not result: + LOG.error(exception.MaskingViewNotFound(masking_view + .get('id'))) + + +def masking_views_get(context, masking_view_id): + """Get a masking view or raise an exception if it does not exist.""" + return _masking_views_get(context, masking_view_id) + + +def masking_views_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, offset=None): + """Retrieves all masking views""" + session = get_session() + with session.begin(): + # Generate the query + query = _generate_paginate_query(context, session, + models.MaskingView, marker, + limit, sort_keys, sort_dirs, + filters, offset) + # No masking view would match, return empty list + if query is None: + return [] + return query.all() + + +@apply_like_filters(model=models.MaskingView) +def _process_masking_views_info_filters(query, filters): + """Common filter processing for masking views queries.""" + if filters: + if not is_valid_model_filters(models.MaskingView, filters): + return + query = query.filter_by(**filters) + + return query + + +def masking_views_delete_by_storage(context, storage_id): + """Delete all the masking views of a device""" + _masking_views_get_query(context).filter_by(storage_id=storage_id)\ + .delete() + + +def _storage_host_grp_host_relations_get_query(context, session=None): + return model_query(context, models.StorageHostGrpStorageHostRelation, + session=session) + + +def _storage_host_grp_host_relations_get(context, host_grp_host_relation_id, + session=None): + result = ( + _storage_host_grp_host_relations_get_query(context, session=session) + .filter_by(id=host_grp_host_relation_id).first()) + + if not result: + raise exception.StorageHostGrpHostRelationNotFound( + host_grp_host_relation_id) + + return result + + +def storage_host_grp_host_relations_create(context, + host_grp_host_relations): + """Create multiple storage host grp host relations.""" + session = get_session() + host_grp_host_relation_refs = [] + with session.begin(): + + for host_grp_host_relation in host_grp_host_relations: + LOG.debug('Adding new storage host group host relation for ' + 'native storage host group id {0}:' + .format(host_grp_host_relation + .get('native_storage_host_group_id'))) + if not host_grp_host_relation.get('id'): + host_grp_host_relation['id'] = uuidutils.generate_uuid() + + host_grp_host_relation_ref \ + = models.StorageHostGrpStorageHostRelation() + host_grp_host_relation_ref.update(host_grp_host_relation) + host_grp_host_relation_refs.append(host_grp_host_relation_ref) + + session.add_all(host_grp_host_relation_refs) + + return host_grp_host_relation_refs + + +def storage_host_grp_host_relations_delete(context, + host_grp_host_relations_list): + """Delete multiple storage host grp host relations.""" + session = get_session() + with session.begin(): + for host_grp_host_relation_id in host_grp_host_relations_list: + LOG.debug('deleting storage host grp host relation {0}:'.format( + host_grp_host_relation_id)) + query = _storage_host_grp_host_relations_get_query(context, + session) + result = query.filter_by(id=host_grp_host_relation_id).delete() + + if not result: + LOG.error(exception.StorageHostGrpHostRelationNotFound( + host_grp_host_relation_id)) + return + + +def storage_host_grp_host_relations_update(context, + host_grp_host_relations_list): + """Update multiple storage host grp host relations.""" + session = get_session() + with session.begin(): + for host_grp_host_relation in host_grp_host_relations_list: + LOG.debug('Updating storage host grp host relations {0}:' + .format(host_grp_host_relation.get('id'))) + query = _storage_host_grp_host_relations_get_query(context, + session) + result = query.filter_by(id=host_grp_host_relation.get('id') + ).update(host_grp_host_relation) + + if not result: + LOG.error(exception.StorageHostGrpHostRelationNotFound( + host_grp_host_relation.get('id'))) + + +def storage_host_grp_host_relations_get(context, host_grp_host_relation_id): + """Get a storage host grp host relation or raise an exception if it does + not exist. + """ + return _storage_host_grp_host_relations_get(context, + host_grp_host_relation_id) + + +def storage_host_grp_host_relations_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, offset=None): + """Retrieves all storage host grp host relations""" + session = get_session() + with session.begin(): + # Generate the query + query = _generate_paginate_query(context, session, models + .StorageHostGrpStorageHostRelation, + marker, limit, sort_keys, sort_dirs, + filters, offset) + # No storage host grp host relation would match, return empty list + if query is None: + return [] + return query.all() + + +@apply_like_filters(model=models.StorageHostGrpStorageHostRelation) +def _process_storage_host_grp_host_relations_info_filters(query, filters): + """Common filter processing for storage host grp host relations queries.""" + if filters: + if not is_valid_model_filters(models.StorageHostGrpStorageHostRelation, + filters): + return + query = query.filter_by(**filters) + + return query + + +def storage_host_grp_host_relations_delete_by_storage(context, storage_id): + """Delete all the storage host grp host relations of a device""" + _storage_host_grp_host_relations_get_query(context)\ + .filter_by(storage_id=storage_id).delete() + + +def _port_grp_port_relations_get_query(context, session=None): + return model_query(context, models.PortGrpPortRelation, + session=session) + + +def _port_grp_port_relations_get(context, port_grp_port_relation_id, + session=None): + result = (_port_grp_port_relations_get_query(context, session=session) + .filter_by(id=port_grp_port_relation_id).first()) + + if not result: + raise exception.PortGrpPortRelationNotFound(port_grp_port_relation_id) + + return result + + +def port_grp_port_relations_create(context, port_grp_port_relations): + """Create multiple port grp port relations.""" + session = get_session() + port_grp_port_relation_refs = [] + with session.begin(): + + for port_grp_port_relation in port_grp_port_relations: + LOG.debug('adding new port group port relation for ' + 'native port group id {0}:' + .format(port_grp_port_relation + .get('native_port_group_id'))) + if not port_grp_port_relation.get('id'): + port_grp_port_relation['id'] = uuidutils.generate_uuid() + + port_grp_port_relation_ref \ + = models.PortGrpPortRelation() + port_grp_port_relation_ref.update(port_grp_port_relation) + port_grp_port_relation_refs.append(port_grp_port_relation_ref) + + session.add_all(port_grp_port_relation_refs) + + return port_grp_port_relation_refs + + +def port_grp_port_relations_delete(context, + port_grp_port_relations_list): + """Delete multiple port grp port relations.""" + session = get_session() + with session.begin(): + for port_grp_port_relation_id in port_grp_port_relations_list: + LOG.debug('deleting port grp port relation {0}:'.format( + port_grp_port_relation_id)) + query = _port_grp_port_relations_get_query(context, session) + result = query.filter_by(id=port_grp_port_relation_id).delete() + + if not result: + LOG.error(exception.PortGrpPortRelationNotFound( + port_grp_port_relation_id)) + return + + +def port_grp_port_relations_update(context, + port_grp_port_relations_list): + """Update multiple port grp port relations.""" + session = get_session() + with session.begin(): + for port_grp_port_relation in port_grp_port_relations_list: + LOG.debug('Updating port grp port relations {0}:' + .format(port_grp_port_relation.get('id'))) + query = _port_grp_port_relations_get_query(context, + session) + result = query.filter_by(id=port_grp_port_relation.get('id') + ).update(port_grp_port_relation) + + if not result: + LOG.error(exception.PortGrpPortRelationNotFound( + port_grp_port_relation.get('id'))) + + +def port_grp_port_relations_get(context, port_grp_port_relation_id): + """Get a port grp port relation or raise an exception if it does + not exist. + """ + return _port_grp_port_relations_get(context, + port_grp_port_relation_id) + + +def port_grp_port_relations_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, offset=None): + """Retrieves all port grp port relations""" + session = get_session() + with session.begin(): + # Generate the query + query = _generate_paginate_query(context, session, models. + PortGrpPortRelation, + marker, limit, sort_keys, sort_dirs, + filters, offset) + # No port grp port relation would match, return empty list + if query is None: + return [] + return query.all() + + +@apply_like_filters(model=models.PortGrpPortRelation) +def _process_port_grp_port_relations_info_filters(query, filters): + """Common filter processing for port grp port relations queries.""" + if filters: + if not is_valid_model_filters(models.PortGrpPortRelation, + filters): + return + query = query.filter_by(**filters) + + return query + + +def port_grp_port_relations_delete_by_storage(context, storage_id): + """Delete all the port grp port relations of a device""" + _port_grp_port_relations_get_query(context)\ + .filter_by(storage_id=storage_id).delete() + + +def _volume_grp_volume_relations_get_query(context, session=None): + return model_query(context, models.VolumeGrpVolumeRelation, + session=session) + + +def _volume_grp_volume_relations_get(context, volume_grp_volume_relation_id, + session=None): + result = (_volume_grp_volume_relations_get_query(context, session=session) + .filter_by(id=volume_grp_volume_relation_id).first()) + + if not result: + raise exception.VolumeGrpVolumeRelationNotFound( + volume_grp_volume_relation_id) + + return result + + +def volume_grp_volume_relations_create(context, volume_grp_volume_relations): + """Create multiple volume grp volume relations.""" + session = get_session() + volume_grp_volume_relation_refs = [] + with session.begin(): + + for volume_grp_volume_relation in volume_grp_volume_relations: + LOG.debug('adding new volume group volume relation for ' + 'native volume group id {0}:' + .format(volume_grp_volume_relation + .get('native_volume_group_id'))) + if not volume_grp_volume_relation.get('id'): + volume_grp_volume_relation['id'] = uuidutils.generate_uuid() + + volume_grp_volume_relation_ref \ + = models.VolumeGrpVolumeRelation() + volume_grp_volume_relation_ref.update(volume_grp_volume_relation) + volume_grp_volume_relation_refs.append( + volume_grp_volume_relation_ref) + + session.add_all(volume_grp_volume_relation_refs) + + return volume_grp_volume_relation_refs + + +def volume_grp_volume_relations_delete(context, + volume_grp_volume_relations_list): + """Delete multiple volume grp volume relations.""" + session = get_session() + with session.begin(): + for volume_grp_volume_relation_id in volume_grp_volume_relations_list: + LOG.debug('deleting volume grp volume relation {0}:'.format( + volume_grp_volume_relation_id)) + query = _volume_grp_volume_relations_get_query(context, session) + result = query.filter_by(id=volume_grp_volume_relation_id).delete() + + if not result: + LOG.error(exception.VolumeGrpVolumeRelationNotFound( + volume_grp_volume_relation_id)) + return + + +def volume_grp_volume_relations_update(context, + volume_grp_volume_relations_list): + """Update multiple volume grp volume relations.""" + session = get_session() + with session.begin(): + for volume_grp_volume_relation in volume_grp_volume_relations_list: + LOG.debug('Updating volume grp volume relations {0}:' + .format(volume_grp_volume_relation.get('id'))) + query = _volume_grp_volume_relations_get_query(context, + session) + result = query.filter_by(id=volume_grp_volume_relation.get('id') + ).update(volume_grp_volume_relation) + + if not result: + LOG.error(exception.VolumeGrpVolumeRelationNotFound( + volume_grp_volume_relation.get('id'))) + + +def volume_grp_volume_relations_get(context, volume_grp_volume_relation_id): + """Get a volume grp volume relation or raise an exception if it does + not exist. + """ + return _volume_grp_volume_relations_get(context, + volume_grp_volume_relation_id) + + +def volume_grp_volume_relations_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, offset=None): + """Retrieves all volume grp volume relations""" + session = get_session() + with session.begin(): + # Generate the query + query = _generate_paginate_query(context, session, models. + VolumeGrpVolumeRelation, + marker, limit, sort_keys, sort_dirs, + filters, offset) + # No volume grp volume relation would match, return empty list + if query is None: + return [] + return query.all() + + +@apply_like_filters(model=models.VolumeGrpVolumeRelation) +def _process_volume_grp_volume_relations_info_filters(query, filters): + """Common filter processing for volume grp volume relations queries.""" + if filters: + if not is_valid_model_filters(models.VolumeGrpVolumeRelation, + filters): + return + query = query.filter_by(**filters) + + return query + + +def volume_grp_volume_relations_delete_by_storage(context, storage_id): + """Delete all the volume grp volume relations of a device""" + _volume_grp_volume_relations_get_query(context)\ + .filter_by(storage_id=storage_id).delete() + + PAGINATION_HELPERS = { models.AccessInfo: (_access_info_get_query, _process_access_info_filters, _access_info_get), @@ -1884,6 +2877,37 @@ def _process_failed_tasks_info_filters(query, filters): models.FailedTask: (_failed_tasks_get_query, _process_failed_tasks_info_filters, _failed_tasks_get), + models.StorageInitiator: (_storage_initiators_get_query, + _process_storage_initiators_info_filters, + _storage_initiators_get), + models.StorageHost: (_storage_hosts_get_query, + _process_storage_hosts_info_filters, + _storage_hosts_get), + models.StorageHostGroup: (_storage_host_groups_get_query, + _process_storage_host_groups_info_filters, + _storage_host_groups_get), + models.PortGroup: (_port_groups_get_query, + _process_port_groups_info_filters, + _port_groups_get), + models.VolumeGroup: (_volume_groups_get_query, + _process_volume_groups_info_filters, + _volume_groups_get), + models.MaskingView: (_masking_views_get_query, + _process_masking_views_info_filters, + _masking_views_get), + models.StorageHostGrpStorageHostRelation: ( + _storage_host_grp_host_relations_get_query, + _process_storage_host_grp_host_relations_info_filters, + _storage_host_grp_host_relations_get), + + models.PortGrpPortRelation: (_port_grp_port_relations_get_query, + _process_port_grp_port_relations_info_filters, + _port_grp_port_relations_get), + models.VolumeGrpVolumeRelation: ( + _volume_grp_volume_relations_get_query, + _process_volume_grp_volume_relations_info_filters, + _volume_grp_volume_relations_get), + } diff --git a/delfin/exception.py b/delfin/exception.py index ca7d8bb94..ac07d9d09 100644 --- a/delfin/exception.py +++ b/delfin/exception.py @@ -170,6 +170,42 @@ class VolumeNotFound(NotFound): msg_fmt = _("Volume {0} could not be found.") +class StorageInitiatorNotFound(NotFound): + msg_fmt = _("Storage initiator {0} could not be found.") + + +class StorageHostNotFound(NotFound): + msg_fmt = _("Storage host {0} could not be found.") + + +class StorageHostGroupNotFound(NotFound): + msg_fmt = _("Storage host group {0} could not be found.") + + +class PortGroupNotFound(NotFound): + msg_fmt = _("Port group {0} could not be found.") + + +class VolumeGroupNotFound(NotFound): + msg_fmt = _("Port group {0} could not be found.") + + +class MaskingViewNotFound(NotFound): + msg_fmt = _("Masking View {0} could not be found.") + + +class StorageHostGrpHostRelationNotFound(NotFound): + msg_fmt = _("Storage Host Group Host Relation {0} could not be found.") + + +class PortGrpPortRelationNotFound(NotFound): + msg_fmt = _("Port Group Port Relation {0} could not be found.") + + +class VolumeGrpVolumeRelationNotFound(NotFound): + msg_fmt = _("Volume Group Volume Relation {0} could not be found.") + + class ControllerNotFound(NotFound): msg_fmt = _("Controller {0} could not be found.") From 4287ba7e3c2027e57bfdb98aa0f4584a9d65ca98 Mon Sep 17 00:00:00 2001 From: sushanthakumar Date: Tue, 15 Jun 2021 23:01:50 +0530 Subject: [PATCH 3/6] Updated attribute names and api names --- delfin/db/api.py | 39 +++++++------- delfin/db/sqlalchemy/api.py | 98 ++++++++++++++++++---------------- delfin/db/sqlalchemy/models.py | 12 ++--- delfin/exception.py | 4 +- 4 files changed, 81 insertions(+), 72 deletions(-) diff --git a/delfin/db/api.py b/delfin/db/api.py index f7acd342a..a19cbcfd1 100644 --- a/delfin/db/api.py +++ b/delfin/db/api.py @@ -843,29 +843,31 @@ def failed_task_delete_by_storage(context, storage_id): return IMPL.failed_task_delete_by_storage(context, storage_id) -def storage_initiators_create(context, values): - """Create a storage initiator entry from the values dictionary.""" - return IMPL.storage_initiators_create(context, values) +def storage_host_initiators_create(context, values): + """Create a storage host initiator entry from the values dictionary.""" + return IMPL.storage_host_initiators_create(context, values) -def storage_initiators_update(context, values): - """Update a storage initiator with the values dictionary.""" - return IMPL.storage_initiators_update(context, values) +def storage_host_initiators_update(context, values): + """Update a storage host initiator with the values dictionary.""" + return IMPL.storage_host_initiators_update(context, values) -def storage_initiators_delete(context, values): +def storage_host_initiators_delete(context, values): """Delete multiple storage initiators.""" - return IMPL.storage_initiators_delete(context, values) + return IMPL.storage_host_initiators_delete(context, values) -def storage_initiators_get(context, storage_initiator_id): - """Get a storage initiator or raise an exception if it does not exist.""" - return IMPL.storage_initiators_get(context, storage_initiator_id) +def storage_host_initiators_get(context, storage_host_initiator_id): + """Get a storage host initiator or raise an exception if it does not + exist. + """ + return IMPL.storage_host_initiators_get(context, storage_host_initiator_id) -def storage_initiators_get_all(context, marker=None, limit=None, - sort_keys=None, sort_dirs=None, filters=None, - offset=None): +def storage_host_initiators_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, offset=None): """Retrieves all storage initiators. If no sort parameters are specified then the returned storage initiators @@ -885,13 +887,14 @@ def storage_initiators_get_all(context, marker=None, limit=None, :param offset: number of items to skip :returns: list of storage initiators """ - return IMPL.storage_initiators_get_all(context, marker, limit, sort_keys, - sort_dirs, filters, offset) + return IMPL.storage_host_initiators_get_all(context, marker, limit, + sort_keys, sort_dirs, + filters, offset) -def storage_initiators_delete_by_storage(context, storage_id): +def storage_host_initiators_delete_by_storage(context, storage_id): """Delete all the storage initiators of a device.""" - return IMPL.storage_initiators_delete_by_storage(context, storage_id) + return IMPL.storage_host_initiators_delete_by_storage(context, storage_id) def storage_hosts_create(context, values): diff --git a/delfin/db/sqlalchemy/api.py b/delfin/db/sqlalchemy/api.py index 906c76d8f..2e99d0324 100644 --- a/delfin/db/sqlalchemy/api.py +++ b/delfin/db/sqlalchemy/api.py @@ -1851,35 +1851,37 @@ def _process_failed_tasks_info_filters(query, filters): return query -def _storage_initiators_get_query(context, session=None): - return model_query(context, models.StorageInitiator, session=session) +def _storage_host_initiators_get_query(context, session=None): + return model_query(context, models.StorageHostInitiator, session=session) -def _storage_initiators_get(context, storage_initiator_id, session=None): - result = (_storage_initiators_get_query(context, session=session) - .filter_by(id=storage_initiator_id) +def _storage_host_initiators_get(context, storage_host_initiator_id, + session=None): + result = (_storage_host_initiators_get_query(context, session=session) + .filter_by(id=storage_host_initiator_id) .first()) if not result: - raise exception.StorageInitiatorNotFound(storage_initiator_id) + raise exception.StorageHostInitiatorNotFound(storage_host_initiator_id) return result -def storage_initiators_create(context, storage_initiators): +def storage_host_initiators_create(context, storage_host_initiators): """Create multiple storage initiators.""" session = get_session() initiator_refs = [] with session.begin(): - for initiator in storage_initiators: - LOG.debug('Adding new storage initiator for ' - 'native_storage_initiator_id {0}:' - .format(initiator.get('native_storage_initiator_id'))) + for initiator in storage_host_initiators: + LOG.debug('Adding new storage host initiator for ' + 'native_storage_host_initiator_id {0}:' + .format(initiator + .get('native_storage_host_initiator_id'))) if not initiator.get('id'): initiator['id'] = uuidutils.generate_uuid() - initiator_ref = models.StorageInitiator() + initiator_ref = models.StorageHostInitiator() initiator_ref.update(initiator) initiator_refs.append(initiator_ref) @@ -1888,73 +1890,77 @@ def storage_initiators_create(context, storage_initiators): return initiator_refs -def storage_initiators_delete(context, storage_initiators_id_list): +def storage_host_initiators_delete(context, storage_host_initiators_id_list): """Delete multiple storage initiators.""" session = get_session() with session.begin(): - for initiator_id in storage_initiators_id_list: - LOG.debug('Deleting storage initiator {0}:'.format(initiator_id)) - query = _storage_initiators_get_query(context, session) + for initiator_id in storage_host_initiators_id_list: + LOG.debug('Deleting storage host initiator{0}:' + .format(initiator_id)) + query = _storage_host_initiators_get_query(context, session) result = query.filter_by(id=initiator_id).delete() if not result: - LOG.error(exception.StorageInitiatorNotFound(initiator_id)) + LOG.error(exception.StorageHostInitiatorNotFound(initiator_id)) return -def storage_initiators_update(context, storage_initiators): +def storage_host_initiators_update(context, storage_host_initiators): """Update multiple storage initiators.""" session = get_session() with session.begin(): - for initiator in storage_initiators: - LOG.debug('Updating storage initiator {0}:' + for initiator in storage_host_initiators: + LOG.debug('Updating storage host initiator{0}:' .format(initiator.get('id'))) - query = _storage_initiators_get_query(context, session) + query = _storage_host_initiators_get_query(context, session) result = query.filter_by(id=initiator.get('id') ).update(initiator) if not result: - LOG.error(exception.StorageInitiatorNotFound(initiator - .get('id'))) + LOG.error(exception.StorageHostInitiatorNotFound(initiator + .get('id'))) -def storage_initiators_get(context, storage_initiator_id): - """Get a storage initiator or raise an exception if it does not exist.""" - return _storage_initiators_get(context, storage_initiator_id) +def storage_host_initiators_get(context, storage_host_initiator_id): + """Get a storage host initiator or raise an exception if it does not + exist. + """ + return _storage_host_initiators_get(context, storage_host_initiator_id) -def storage_initiators_get_all(context, marker=None, limit=None, - sort_keys=None, sort_dirs=None, filters=None, - offset=None): +def storage_host_initiators_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, + offset=None): """Retrieves all storage initiators""" session = get_session() with session.begin(): # Generate the query query = _generate_paginate_query(context, session, - models.StorageInitiator, marker, + models.StorageHostInitiator, marker, limit, sort_keys, sort_dirs, filters, offset) - # No storage initiator would match, return empty list + # No storage host initiator would match, return empty list if query is None: return [] return query.all() -@apply_like_filters(model=models.StorageInitiator) -def _process_storage_initiators_info_filters(query, filters): +@apply_like_filters(model=models.StorageHostInitiator) +def _process_storage_host_initiators_info_filters(query, filters): """Common filter processing for storage initiators queries.""" if filters: - if not is_valid_model_filters(models.StorageInitiator, filters): + if not is_valid_model_filters(models.StorageHostInitiator, filters): return query = query.filter_by(**filters) return query -def storage_initiators_delete_by_storage(context, storage_id): +def storage_host_initiators_delete_by_storage(context, storage_id): """Delete all the storage initiators of a device""" - _storage_initiators_get_query(context).filter_by(storage_id=storage_id)\ - .delete() + _storage_host_initiators_get_query(context)\ + .filter_by(storage_id=storage_id).delete() def _storage_hosts_get_query(context, session=None): @@ -2056,7 +2062,7 @@ def _process_storage_hosts_info_filters(query, filters): def storage_hosts_delete_by_storage(context, storage_id): """Delete all the storage hosts of a device""" - _storage_hosts_get_query(context).filter_by(storage_id=storage_id)\ + _storage_hosts_get_query(context).filter_by(storage_id=storage_id) \ .delete() @@ -2268,8 +2274,7 @@ def _process_port_groups_info_filters(query, filters): def port_groups_delete_by_storage(context, storage_id): """Delete all the port groups of a device""" - _port_groups_get_query(context).filter_by(storage_id=storage_id)\ - .delete() + _port_groups_get_query(context).filter_by(storage_id=storage_id).delete() def _volume_groups_get_query(context, session=None): @@ -2374,7 +2379,7 @@ def _process_volume_groups_info_filters(query, filters): def volume_groups_delete_by_storage(context, storage_id): """Delete all the volume groups of a device""" - _volume_groups_get_query(context).filter_by(storage_id=storage_id)\ + _volume_groups_get_query(context).filter_by(storage_id=storage_id) \ .delete() @@ -2720,7 +2725,7 @@ def _process_port_grp_port_relations_info_filters(query, filters): def port_grp_port_relations_delete_by_storage(context, storage_id): """Delete all the port grp port relations of a device""" - _port_grp_port_relations_get_query(context)\ + _port_grp_port_relations_get_query(context) \ .filter_by(storage_id=storage_id).delete() @@ -2840,7 +2845,7 @@ def _process_volume_grp_volume_relations_info_filters(query, filters): def volume_grp_volume_relations_delete_by_storage(context, storage_id): """Delete all the volume grp volume relations of a device""" - _volume_grp_volume_relations_get_query(context)\ + _volume_grp_volume_relations_get_query(context) \ .filter_by(storage_id=storage_id).delete() @@ -2877,9 +2882,10 @@ def volume_grp_volume_relations_delete_by_storage(context, storage_id): models.FailedTask: (_failed_tasks_get_query, _process_failed_tasks_info_filters, _failed_tasks_get), - models.StorageInitiator: (_storage_initiators_get_query, - _process_storage_initiators_info_filters, - _storage_initiators_get), + models.StorageHostInitiator: ( + _storage_host_initiators_get_query, + _process_storage_host_initiators_info_filters, + _storage_host_initiators_get), models.StorageHost: (_storage_hosts_get_query, _process_storage_hosts_info_filters, _storage_hosts_get), diff --git a/delfin/db/sqlalchemy/models.py b/delfin/db/sqlalchemy/models.py index 32c37e55b..c535147dc 100644 --- a/delfin/db/sqlalchemy/models.py +++ b/delfin/db/sqlalchemy/models.py @@ -289,9 +289,9 @@ class FailedTask(BASE, DelfinBase): deleted = Column(Boolean, default=False) -class StorageInitiator(BASE, DelfinBase): - """Represents the storage initiator attributes.""" - __tablename__ = 'storage_initiators' +class StorageHostInitiator(BASE, DelfinBase): + """Represents the storage host initiator attributes.""" + __tablename__ = 'storage_host_initiators' id = Column(String(36), primary_key=True) storage_id = Column(String(36)) name = Column(String(255)) @@ -299,7 +299,7 @@ class StorageInitiator(BASE, DelfinBase): wwn = Column(String(255)) status = Column(String(255)) native_storage_host_id = Column(String(255)) - native_storage_initiator_id = Column(String(255)) + native_storage_host_initiator_id = Column(String(255)) class StorageHost(BASE, DelfinBase): @@ -310,7 +310,7 @@ class StorageHost(BASE, DelfinBase): name = Column(String(255)) description = Column(String(255)) os_type = Column(String(255)) - storage_initiators = Column(Text) + storage_host_initiators = Column(Text) ip_address = Column(String(255)) status = Column(String(255)) native_storage_host_id = Column(String(255)) @@ -360,7 +360,7 @@ class MaskingView(BASE, DelfinBase): native_volume_group_id = Column(String(255)) native_port_group_id = Column(String(255)) native_storage_host_id = Column(String(255)) - storage_initiators = Column(Text) + storage_host_initiators = Column(Text) volumes = Column(Text) ports = Column(Text) native_masking_view_id = Column(String(255)) diff --git a/delfin/exception.py b/delfin/exception.py index ac07d9d09..24d8cc72c 100644 --- a/delfin/exception.py +++ b/delfin/exception.py @@ -170,8 +170,8 @@ class VolumeNotFound(NotFound): msg_fmt = _("Volume {0} could not be found.") -class StorageInitiatorNotFound(NotFound): - msg_fmt = _("Storage initiator {0} could not be found.") +class StorageHostInitiatorNotFound(NotFound): + msg_fmt = _("Storage host initiator{0} could not be found.") class StorageHostNotFound(NotFound): From cdf299b2b20d94f52ee48ffd66890807c3f406b4 Mon Sep 17 00:00:00 2001 From: sushanthakumar Date: Fri, 18 Jun 2021 20:44:33 +0530 Subject: [PATCH 4/6] Removed initiator list from host --- delfin/db/sqlalchemy/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/delfin/db/sqlalchemy/models.py b/delfin/db/sqlalchemy/models.py index c535147dc..29be1e48b 100644 --- a/delfin/db/sqlalchemy/models.py +++ b/delfin/db/sqlalchemy/models.py @@ -310,7 +310,6 @@ class StorageHost(BASE, DelfinBase): name = Column(String(255)) description = Column(String(255)) os_type = Column(String(255)) - storage_host_initiators = Column(Text) ip_address = Column(String(255)) status = Column(String(255)) native_storage_host_id = Column(String(255)) From f63c741655c1f76a566e5f59445c32395b8f6fd6 Mon Sep 17 00:00:00 2001 From: sushanthakumar Date: Tue, 22 Jun 2021 12:46:28 +0530 Subject: [PATCH 5/6] Review comment update --- delfin/db/api.py | 120 +++++++++--------- delfin/db/sqlalchemy/api.py | 214 ++++++++++++++++----------------- delfin/db/sqlalchemy/models.py | 16 ++- delfin/exception.py | 10 +- 4 files changed, 179 insertions(+), 181 deletions(-) diff --git a/delfin/db/api.py b/delfin/db/api.py index a19cbcfd1..e55d29806 100644 --- a/delfin/db/api.py +++ b/delfin/db/api.py @@ -1151,35 +1151,35 @@ def masking_views_delete_by_storage(context, storage_id): return IMPL.masking_views_delete_by_storage(context, storage_id) -def storage_host_grp_host_relations_create(context, values): +def storage_host_grp_host_rels_create(context, values): """Create a storage host grp host relation entry from the values dictionary. """ - return IMPL.storage_host_grp_host_relations_create(context, values) + return IMPL.storage_host_grp_host_rels_create(context, values) -def storage_host_grp_host_relations_update(context, values): +def storage_host_grp_host_rels_update(context, values): """Update a storage host grp host relation with the values dictionary.""" - return IMPL.storage_host_grp_host_relations_update(context, values) + return IMPL.storage_host_grp_host_rels_update(context, values) -def storage_host_grp_host_relations_delete(context, values): +def storage_host_grp_host_rels_delete(context, values): """Delete multiple storage host grp host relations.""" - return IMPL.storage_host_grp_host_relations_delete(context, values) + return IMPL.storage_host_grp_host_rels_delete(context, values) -def storage_host_grp_host_relations_get(context, host_grp_host_relation_id): +def storage_host_grp_host_rels_get(context, host_grp_host_relation_id): """Get a storage host grp host relation or raise an exception if it does not exist. """ - return IMPL.storage_host_grp_host_relations_get(context, - host_grp_host_relation_id) + return IMPL.storage_host_grp_host_rels_get(context, + host_grp_host_relation_id) -def storage_host_grp_host_relations_get_all(context, marker=None, limit=None, - sort_keys=None, - sort_dirs=None, filters=None, - offset=None): +def storage_host_grp_host_rels_get_all(context, marker=None, limit=None, + sort_keys=None, + sort_dirs=None, filters=None, + offset=None): """Retrieves all storage host grp host relation. If no sort parameters are specified then the returned @@ -1200,47 +1200,47 @@ def storage_host_grp_host_relations_get_all(context, marker=None, limit=None, :param offset: number of items to skip :returns: list of storage host grp host relations """ - return IMPL.storage_host_grp_host_relations_get_all(context, marker, limit, - sort_keys, - sort_dirs, filters, - offset) + return IMPL.storage_host_grp_host_rels_get_all(context, marker, limit, + sort_keys, + sort_dirs, filters, + offset) -def storage_host_grp_host_relations_delete_by_storage(context, storage_id): +def storage_host_grp_host_rels_delete_by_storage(context, storage_id): """Delete all the storage host grp host relations of a device.""" - return IMPL.storage_host_grp_host_relations_delete_by_storage(context, - storage_id) + return IMPL.storage_host_grp_host_rels_delete_by_storage(context, + storage_id) -def port_grp_port_relations_create(context, values): +def port_grp_port_rels_create(context, values): """Create a port grp port relation entry from the values dictionary. """ - return IMPL.port_grp_port_relations_create(context, values) + return IMPL.port_grp_port_rels_create(context, values) -def port_grp_port_relations_update(context, values): +def port_grp_port_rels_update(context, values): """Update a port grp port relation with the values dictionary.""" - return IMPL.port_grp_port_relations_update(context, values) + return IMPL.port_grp_port_rels_update(context, values) -def port_grp_port_relations_delete(context, values): +def port_grp_port_rels_delete(context, values): """Delete multiple port grp port relations.""" - return IMPL.port_grp_port_relations_delete(context, values) + return IMPL.port_grp_port_rels_delete(context, values) -def port_grp_port_relations_get(context, port_grp_port_relation_id): +def port_grp_port_rels_get(context, port_grp_port_relation_id): """Get a port grp port relation or raise an exception if it does not exist. """ - return IMPL.port_grp_port_relations_get(context, - port_grp_port_relation_id) + return IMPL.port_grp_port_rels_get(context, + port_grp_port_relation_id) -def port_grp_port_relations_get_all(context, marker=None, limit=None, - sort_keys=None, - sort_dirs=None, filters=None, - offset=None): +def port_grp_port_rels_get_all(context, marker=None, limit=None, + sort_keys=None, + sort_dirs=None, filters=None, + offset=None): """Retrieves all port grp port relation. If no sort parameters are specified then the returned @@ -1261,47 +1261,47 @@ def port_grp_port_relations_get_all(context, marker=None, limit=None, :param offset: number of items to skip :returns: list of port grp port relations """ - return IMPL.port_grp_port_relations_get_all(context, marker, limit, - sort_keys, - sort_dirs, filters, - offset) + return IMPL.port_grp_port_rels_get_all(context, marker, limit, + sort_keys, + sort_dirs, filters, + offset) -def port_grp_port_relations_delete_by_storage(context, storage_id): +def port_grp_port_rels_delete_by_storage(context, storage_id): """Delete all the port grp port relations of a device.""" - return IMPL.port_grp_port_relations_delete_by_storage(context, - storage_id) + return IMPL.port_grp_port_rels_delete_by_storage(context, + storage_id) -def volume_grp_volume_relations_create(context, values): +def vol_grp_vol_rels_create(context, values): """Create a volume grp volume relation entry from the values dictionary. """ - return IMPL.volume_grp_volume_relations_create(context, values) + return IMPL.vol_grp_vol_rels_create(context, values) -def volume_grp_volume_relations_update(context, values): +def vol_grp_vol_rels_update(context, values): """Update a volume grp volume relation with the values dictionary.""" - return IMPL.volume_grp_volume_relations_update(context, values) + return IMPL.vol_grp_vol_rels_update(context, values) -def volume_grp_volume_relations_delete(context, values): +def vol_grp_vol_rels_delete(context, values): """Delete multiple volume grp volume relations.""" - return IMPL.volume_grp_volume_relations_delete(context, values) + return IMPL.vol_grp_vol_rels_delete(context, values) -def volume_grp_volume_relations_get(context, volume_grp_volume_relation_id): +def vol_grp_vol_rels_get(context, volume_grp_volume_relation_id): """Get a volume grp volume relation or raise an exception if it does not exist. """ - return IMPL.volume_grp_volume_relations_get(context, - volume_grp_volume_relation_id) + return IMPL.vol_grp_vol_rels_get(context, + volume_grp_volume_relation_id) -def volume_grp_volume_relations_get_all(context, marker=None, limit=None, - sort_keys=None, - sort_dirs=None, filters=None, - offset=None): +def vol_grp_vol_rels_get_all(context, marker=None, limit=None, + sort_keys=None, + sort_dirs=None, filters=None, + offset=None): """Retrieves all volume grp volume relation. If no sort parameters are specified then the returned @@ -1322,13 +1322,13 @@ def volume_grp_volume_relations_get_all(context, marker=None, limit=None, :param offset: number of items to skip :returns: list of volume grp volume relations """ - return IMPL.volume_grp_volume_relations_get_all(context, marker, limit, - sort_keys, - sort_dirs, filters, - offset) + return IMPL.vol_grp_vol_rels_get_all(context, marker, limit, + sort_keys, + sort_dirs, filters, + offset) -def volume_grp_volume_relations_delete_by_storage(context, storage_id): +def vol_grp_vol_rels_delete_by_storage(context, storage_id): """Delete all the volume grp volume relations of a device.""" - return IMPL.volume_grp_volume_relations_delete_by_storage(context, - storage_id) + return IMPL.vol_grp_vol_rels_delete_by_storage(context, + storage_id) diff --git a/delfin/db/sqlalchemy/api.py b/delfin/db/sqlalchemy/api.py index 2e99d0324..755fa65c0 100644 --- a/delfin/db/sqlalchemy/api.py +++ b/delfin/db/sqlalchemy/api.py @@ -2489,26 +2489,26 @@ def masking_views_delete_by_storage(context, storage_id): .delete() -def _storage_host_grp_host_relations_get_query(context, session=None): - return model_query(context, models.StorageHostGrpStorageHostRelation, +def _storage_host_grp_host_rels_get_query(context, session=None): + return model_query(context, models.StorageHostGrpHostRel, session=session) -def _storage_host_grp_host_relations_get(context, host_grp_host_relation_id, - session=None): +def _storage_host_grp_host_rels_get(context, host_grp_host_relation_id, + session=None): result = ( - _storage_host_grp_host_relations_get_query(context, session=session) + _storage_host_grp_host_rels_get_query(context, session=session) .filter_by(id=host_grp_host_relation_id).first()) if not result: - raise exception.StorageHostGrpHostRelationNotFound( + raise exception.StorageHostGrpHostRelNotFound( host_grp_host_relation_id) return result -def storage_host_grp_host_relations_create(context, - host_grp_host_relations): +def storage_host_grp_host_rels_create(context, + host_grp_host_relations): """Create multiple storage host grp host relations.""" session = get_session() host_grp_host_relation_refs = [] @@ -2523,7 +2523,7 @@ def storage_host_grp_host_relations_create(context, host_grp_host_relation['id'] = uuidutils.generate_uuid() host_grp_host_relation_ref \ - = models.StorageHostGrpStorageHostRelation() + = models.StorageHostGrpHostRel() host_grp_host_relation_ref.update(host_grp_host_relation) host_grp_host_relation_refs.append(host_grp_host_relation_ref) @@ -2532,59 +2532,59 @@ def storage_host_grp_host_relations_create(context, return host_grp_host_relation_refs -def storage_host_grp_host_relations_delete(context, - host_grp_host_relations_list): +def storage_host_grp_host_rels_delete(context, + host_grp_host_relations_list): """Delete multiple storage host grp host relations.""" session = get_session() with session.begin(): for host_grp_host_relation_id in host_grp_host_relations_list: LOG.debug('deleting storage host grp host relation {0}:'.format( host_grp_host_relation_id)) - query = _storage_host_grp_host_relations_get_query(context, - session) + query = _storage_host_grp_host_rels_get_query(context, + session) result = query.filter_by(id=host_grp_host_relation_id).delete() if not result: - LOG.error(exception.StorageHostGrpHostRelationNotFound( + LOG.error(exception.StorageHostGrpHostRelNotFound( host_grp_host_relation_id)) return -def storage_host_grp_host_relations_update(context, - host_grp_host_relations_list): +def storage_host_grp_host_rels_update(context, + host_grp_host_relations_list): """Update multiple storage host grp host relations.""" session = get_session() with session.begin(): for host_grp_host_relation in host_grp_host_relations_list: LOG.debug('Updating storage host grp host relations {0}:' .format(host_grp_host_relation.get('id'))) - query = _storage_host_grp_host_relations_get_query(context, - session) + query = _storage_host_grp_host_rels_get_query(context, + session) result = query.filter_by(id=host_grp_host_relation.get('id') ).update(host_grp_host_relation) if not result: - LOG.error(exception.StorageHostGrpHostRelationNotFound( + LOG.error(exception.StorageHostGrpHostRelNotFound( host_grp_host_relation.get('id'))) -def storage_host_grp_host_relations_get(context, host_grp_host_relation_id): +def storage_host_grp_host_rels_get(context, host_grp_host_relation_id): """Get a storage host grp host relation or raise an exception if it does not exist. """ - return _storage_host_grp_host_relations_get(context, - host_grp_host_relation_id) + return _storage_host_grp_host_rels_get(context, + host_grp_host_relation_id) -def storage_host_grp_host_relations_get_all(context, marker=None, limit=None, - sort_keys=None, sort_dirs=None, - filters=None, offset=None): +def storage_host_grp_host_rels_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, offset=None): """Retrieves all storage host grp host relations""" session = get_session() with session.begin(): # Generate the query query = _generate_paginate_query(context, session, models - .StorageHostGrpStorageHostRelation, + .StorageHostGrpHostRel, marker, limit, sort_keys, sort_dirs, filters, offset) # No storage host grp host relation would match, return empty list @@ -2593,11 +2593,11 @@ def storage_host_grp_host_relations_get_all(context, marker=None, limit=None, return query.all() -@apply_like_filters(model=models.StorageHostGrpStorageHostRelation) -def _process_storage_host_grp_host_relations_info_filters(query, filters): +@apply_like_filters(model=models.StorageHostGrpHostRel) +def _process_storage_host_grp_host_rels_info_filters(query, filters): """Common filter processing for storage host grp host relations queries.""" if filters: - if not is_valid_model_filters(models.StorageHostGrpStorageHostRelation, + if not is_valid_model_filters(models.StorageHostGrpHostRel, filters): return query = query.filter_by(**filters) @@ -2605,35 +2605,35 @@ def _process_storage_host_grp_host_relations_info_filters(query, filters): return query -def storage_host_grp_host_relations_delete_by_storage(context, storage_id): +def storage_host_grp_host_rels_delete_by_storage(context, storage_id): """Delete all the storage host grp host relations of a device""" - _storage_host_grp_host_relations_get_query(context)\ + _storage_host_grp_host_rels_get_query(context) \ .filter_by(storage_id=storage_id).delete() -def _port_grp_port_relations_get_query(context, session=None): - return model_query(context, models.PortGrpPortRelation, +def _port_grp_port_rels_get_query(context, session=None): + return model_query(context, models.PortGrpPortRel, session=session) -def _port_grp_port_relations_get(context, port_grp_port_relation_id, - session=None): - result = (_port_grp_port_relations_get_query(context, session=session) +def _port_grp_port_rels_get(context, port_grp_port_relation_id, + session=None): + result = (_port_grp_port_rels_get_query(context, session=session) .filter_by(id=port_grp_port_relation_id).first()) if not result: - raise exception.PortGrpPortRelationNotFound(port_grp_port_relation_id) + raise exception.PortGrpPortRelNotFound(port_grp_port_relation_id) return result -def port_grp_port_relations_create(context, port_grp_port_relations): +def port_grp_port_rels_create(context, port_grp_port_rels): """Create multiple port grp port relations.""" session = get_session() port_grp_port_relation_refs = [] with session.begin(): - for port_grp_port_relation in port_grp_port_relations: + for port_grp_port_relation in port_grp_port_rels: LOG.debug('adding new port group port relation for ' 'native port group id {0}:' .format(port_grp_port_relation @@ -2642,7 +2642,7 @@ def port_grp_port_relations_create(context, port_grp_port_relations): port_grp_port_relation['id'] = uuidutils.generate_uuid() port_grp_port_relation_ref \ - = models.PortGrpPortRelation() + = models.PortGrpPortRel() port_grp_port_relation_ref.update(port_grp_port_relation) port_grp_port_relation_refs.append(port_grp_port_relation_ref) @@ -2651,58 +2651,58 @@ def port_grp_port_relations_create(context, port_grp_port_relations): return port_grp_port_relation_refs -def port_grp_port_relations_delete(context, - port_grp_port_relations_list): +def port_grp_port_rels_delete(context, + port_grp_port_rels_list): """Delete multiple port grp port relations.""" session = get_session() with session.begin(): - for port_grp_port_relation_id in port_grp_port_relations_list: + for port_grp_port_relation_id in port_grp_port_rels_list: LOG.debug('deleting port grp port relation {0}:'.format( port_grp_port_relation_id)) - query = _port_grp_port_relations_get_query(context, session) + query = _port_grp_port_rels_get_query(context, session) result = query.filter_by(id=port_grp_port_relation_id).delete() if not result: - LOG.error(exception.PortGrpPortRelationNotFound( + LOG.error(exception.PortGrpPortRelNotFound( port_grp_port_relation_id)) return -def port_grp_port_relations_update(context, - port_grp_port_relations_list): +def port_grp_port_rels_update(context, + port_grp_port_rels_list): """Update multiple port grp port relations.""" session = get_session() with session.begin(): - for port_grp_port_relation in port_grp_port_relations_list: + for port_grp_port_relation in port_grp_port_rels_list: LOG.debug('Updating port grp port relations {0}:' .format(port_grp_port_relation.get('id'))) - query = _port_grp_port_relations_get_query(context, - session) + query = _port_grp_port_rels_get_query(context, + session) result = query.filter_by(id=port_grp_port_relation.get('id') ).update(port_grp_port_relation) if not result: - LOG.error(exception.PortGrpPortRelationNotFound( + LOG.error(exception.PortGrpPortRelNotFound( port_grp_port_relation.get('id'))) -def port_grp_port_relations_get(context, port_grp_port_relation_id): +def port_grp_port_rels_get(context, port_grp_port_relation_id): """Get a port grp port relation or raise an exception if it does not exist. """ - return _port_grp_port_relations_get(context, - port_grp_port_relation_id) + return _port_grp_port_rels_get(context, + port_grp_port_relation_id) -def port_grp_port_relations_get_all(context, marker=None, limit=None, - sort_keys=None, sort_dirs=None, - filters=None, offset=None): +def port_grp_port_rels_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, offset=None): """Retrieves all port grp port relations""" session = get_session() with session.begin(): # Generate the query query = _generate_paginate_query(context, session, models. - PortGrpPortRelation, + PortGrpPortRel, marker, limit, sort_keys, sort_dirs, filters, offset) # No port grp port relation would match, return empty list @@ -2711,11 +2711,11 @@ def port_grp_port_relations_get_all(context, marker=None, limit=None, return query.all() -@apply_like_filters(model=models.PortGrpPortRelation) -def _process_port_grp_port_relations_info_filters(query, filters): +@apply_like_filters(model=models.PortGrpPortRel) +def _process_port_grp_port_rels_info_filters(query, filters): """Common filter processing for port grp port relations queries.""" if filters: - if not is_valid_model_filters(models.PortGrpPortRelation, + if not is_valid_model_filters(models.PortGrpPortRel, filters): return query = query.filter_by(**filters) @@ -2723,36 +2723,36 @@ def _process_port_grp_port_relations_info_filters(query, filters): return query -def port_grp_port_relations_delete_by_storage(context, storage_id): +def port_grp_port_rels_delete_by_storage(context, storage_id): """Delete all the port grp port relations of a device""" - _port_grp_port_relations_get_query(context) \ + _port_grp_port_rels_get_query(context) \ .filter_by(storage_id=storage_id).delete() -def _volume_grp_volume_relations_get_query(context, session=None): - return model_query(context, models.VolumeGrpVolumeRelation, +def _vol_grp_vol_rels_get_query(context, session=None): + return model_query(context, models.VolGrpVolRel, session=session) -def _volume_grp_volume_relations_get(context, volume_grp_volume_relation_id, - session=None): - result = (_volume_grp_volume_relations_get_query(context, session=session) +def _vol_grp_vol_rels_get(context, volume_grp_volume_relation_id, + session=None): + result = (_vol_grp_vol_rels_get_query(context, session=session) .filter_by(id=volume_grp_volume_relation_id).first()) if not result: - raise exception.VolumeGrpVolumeRelationNotFound( + raise exception.VolGrpVolRelNotFound( volume_grp_volume_relation_id) return result -def volume_grp_volume_relations_create(context, volume_grp_volume_relations): +def vol_grp_vol_rels_create(context, vol_grp_vol_rels): """Create multiple volume grp volume relations.""" session = get_session() volume_grp_volume_relation_refs = [] with session.begin(): - for volume_grp_volume_relation in volume_grp_volume_relations: + for volume_grp_volume_relation in vol_grp_vol_rels: LOG.debug('adding new volume group volume relation for ' 'native volume group id {0}:' .format(volume_grp_volume_relation @@ -2761,7 +2761,7 @@ def volume_grp_volume_relations_create(context, volume_grp_volume_relations): volume_grp_volume_relation['id'] = uuidutils.generate_uuid() volume_grp_volume_relation_ref \ - = models.VolumeGrpVolumeRelation() + = models.VolGrpVolRel() volume_grp_volume_relation_ref.update(volume_grp_volume_relation) volume_grp_volume_relation_refs.append( volume_grp_volume_relation_ref) @@ -2771,58 +2771,58 @@ def volume_grp_volume_relations_create(context, volume_grp_volume_relations): return volume_grp_volume_relation_refs -def volume_grp_volume_relations_delete(context, - volume_grp_volume_relations_list): +def vol_grp_vol_rels_delete(context, + vol_grp_vol_rels_list): """Delete multiple volume grp volume relations.""" session = get_session() with session.begin(): - for volume_grp_volume_relation_id in volume_grp_volume_relations_list: + for volume_grp_volume_relation_id in vol_grp_vol_rels_list: LOG.debug('deleting volume grp volume relation {0}:'.format( volume_grp_volume_relation_id)) - query = _volume_grp_volume_relations_get_query(context, session) + query = _vol_grp_vol_rels_get_query(context, session) result = query.filter_by(id=volume_grp_volume_relation_id).delete() if not result: - LOG.error(exception.VolumeGrpVolumeRelationNotFound( + LOG.error(exception.VolGrpVolRelationNotFound( volume_grp_volume_relation_id)) return -def volume_grp_volume_relations_update(context, - volume_grp_volume_relations_list): +def vol_grp_vol_rels_update(context, + vol_grp_vol_rels_list): """Update multiple volume grp volume relations.""" session = get_session() with session.begin(): - for volume_grp_volume_relation in volume_grp_volume_relations_list: + for volume_grp_volume_relation in vol_grp_vol_rels_list: LOG.debug('Updating volume grp volume relations {0}:' .format(volume_grp_volume_relation.get('id'))) - query = _volume_grp_volume_relations_get_query(context, - session) + query = _vol_grp_vol_rels_get_query(context, + session) result = query.filter_by(id=volume_grp_volume_relation.get('id') ).update(volume_grp_volume_relation) if not result: - LOG.error(exception.VolumeGrpVolumeRelationNotFound( + LOG.error(exception.VolGrpVolRelationNotFound( volume_grp_volume_relation.get('id'))) -def volume_grp_volume_relations_get(context, volume_grp_volume_relation_id): +def vol_grp_vol_rels_get(context, volume_grp_volume_relation_id): """Get a volume grp volume relation or raise an exception if it does not exist. """ - return _volume_grp_volume_relations_get(context, - volume_grp_volume_relation_id) + return _vol_grp_vol_rels_get(context, + volume_grp_volume_relation_id) -def volume_grp_volume_relations_get_all(context, marker=None, limit=None, - sort_keys=None, sort_dirs=None, - filters=None, offset=None): +def vol_grp_vol_rels_get_all(context, marker=None, limit=None, + sort_keys=None, sort_dirs=None, + filters=None, offset=None): """Retrieves all volume grp volume relations""" session = get_session() with session.begin(): # Generate the query query = _generate_paginate_query(context, session, models. - VolumeGrpVolumeRelation, + VolGrpVolRelation, marker, limit, sort_keys, sort_dirs, filters, offset) # No volume grp volume relation would match, return empty list @@ -2831,11 +2831,11 @@ def volume_grp_volume_relations_get_all(context, marker=None, limit=None, return query.all() -@apply_like_filters(model=models.VolumeGrpVolumeRelation) -def _process_volume_grp_volume_relations_info_filters(query, filters): +@apply_like_filters(model=models.VolGrpVolRel) +def _process_vol_grp_vol_rels_info_filters(query, filters): """Common filter processing for volume grp volume relations queries.""" if filters: - if not is_valid_model_filters(models.VolumeGrpVolumeRelation, + if not is_valid_model_filters(models.VolGrpVolRel, filters): return query = query.filter_by(**filters) @@ -2843,9 +2843,9 @@ def _process_volume_grp_volume_relations_info_filters(query, filters): return query -def volume_grp_volume_relations_delete_by_storage(context, storage_id): +def vol_grp_vol_rels_delete_by_storage(context, storage_id): """Delete all the volume grp volume relations of a device""" - _volume_grp_volume_relations_get_query(context) \ + _vol_grp_vol_rels_get_query(context) \ .filter_by(storage_id=storage_id).delete() @@ -2901,18 +2901,18 @@ def volume_grp_volume_relations_delete_by_storage(context, storage_id): models.MaskingView: (_masking_views_get_query, _process_masking_views_info_filters, _masking_views_get), - models.StorageHostGrpStorageHostRelation: ( - _storage_host_grp_host_relations_get_query, - _process_storage_host_grp_host_relations_info_filters, - _storage_host_grp_host_relations_get), - - models.PortGrpPortRelation: (_port_grp_port_relations_get_query, - _process_port_grp_port_relations_info_filters, - _port_grp_port_relations_get), - models.VolumeGrpVolumeRelation: ( - _volume_grp_volume_relations_get_query, - _process_volume_grp_volume_relations_info_filters, - _volume_grp_volume_relations_get), + models.StorageHostGrpHostRel: ( + _storage_host_grp_host_rels_get_query, + _process_storage_host_grp_host_rels_info_filters, + _storage_host_grp_host_rels_get), + + models.PortGrpPortRel: (_port_grp_port_rels_get_query, + _process_port_grp_port_rels_info_filters, + _port_grp_port_rels_get), + models.VolGrpVolRel: ( + _vol_grp_vol_rels_get_query, + _process_vol_grp_vol_rels_info_filters, + _vol_grp_vol_rels_get), } diff --git a/delfin/db/sqlalchemy/models.py b/delfin/db/sqlalchemy/models.py index 29be1e48b..d0e15db12 100644 --- a/delfin/db/sqlalchemy/models.py +++ b/delfin/db/sqlalchemy/models.py @@ -296,6 +296,7 @@ class StorageHostInitiator(BASE, DelfinBase): storage_id = Column(String(36)) name = Column(String(255)) description = Column(String(255)) + alias = Column(String(255)) wwn = Column(String(255)) status = Column(String(255)) native_storage_host_id = Column(String(255)) @@ -322,7 +323,6 @@ class StorageHostGroup(BASE, DelfinBase): storage_id = Column(String(36)) name = Column(String(255)) description = Column(String(255)) - storage_hosts = Column(Text) native_storage_host_group_id = Column(String(255)) @@ -333,7 +333,6 @@ class PortGroup(BASE, DelfinBase): storage_id = Column(String(36)) name = Column(String(255)) description = Column(String(255)) - ports = Column(Text) native_port_group_id = Column(String(255)) @@ -344,7 +343,6 @@ class VolumeGroup(BASE, DelfinBase): storage_id = Column(String(36)) name = Column(String(255)) description = Column(String(255)) - volumes = Column(Text) native_volume_group_id = Column(String(255)) @@ -365,11 +363,11 @@ class MaskingView(BASE, DelfinBase): native_masking_view_id = Column(String(255)) -class StorageHostGrpStorageHostRelation(BASE, DelfinBase): +class StorageHostGrpHostRel(BASE, DelfinBase): """Represents the storage host group and storage host relation attributes. """ - __tablename__ = 'storage_host_group_storage_host_relations' + __tablename__ = 'storage_host_grp_host_rels' id = Column(String(36), primary_key=True) storage_id = Column(String(36)) name = Column(String(255)) @@ -378,9 +376,9 @@ class StorageHostGrpStorageHostRelation(BASE, DelfinBase): native_storage_host_id = Column(String(255)) -class PortGrpPortRelation(BASE, DelfinBase): +class PortGrpPortRel(BASE, DelfinBase): """Represents port group and port relation attributes.""" - __tablename__ = 'port_group_port_relations' + __tablename__ = 'port_grp_port_rels' id = Column(String(36), primary_key=True) storage_id = Column(String(36)) name = Column(String(255)) @@ -389,9 +387,9 @@ class PortGrpPortRelation(BASE, DelfinBase): native_port_id = Column(String(255)) -class VolumeGrpVolumeRelation(BASE, DelfinBase): +class VolGrpVolRel(BASE, DelfinBase): """Represents the volume group and volume relation attributes.""" - __tablename__ = 'volume_group_volume_relations' + __tablename__ = 'vol_grp_vol_rels' id = Column(String(36), primary_key=True) storage_id = Column(String(36)) name = Column(String(255)) diff --git a/delfin/exception.py b/delfin/exception.py index 24d8cc72c..0391657b7 100644 --- a/delfin/exception.py +++ b/delfin/exception.py @@ -171,7 +171,7 @@ class VolumeNotFound(NotFound): class StorageHostInitiatorNotFound(NotFound): - msg_fmt = _("Storage host initiator{0} could not be found.") + msg_fmt = _("Storage host initiator {0} could not be found.") class StorageHostNotFound(NotFound): @@ -187,22 +187,22 @@ class PortGroupNotFound(NotFound): class VolumeGroupNotFound(NotFound): - msg_fmt = _("Port group {0} could not be found.") + msg_fmt = _("Volume group {0} could not be found.") class MaskingViewNotFound(NotFound): msg_fmt = _("Masking View {0} could not be found.") -class StorageHostGrpHostRelationNotFound(NotFound): +class StorageHostGrpHostRelNotFound(NotFound): msg_fmt = _("Storage Host Group Host Relation {0} could not be found.") -class PortGrpPortRelationNotFound(NotFound): +class PortGrpPortRelNotFound(NotFound): msg_fmt = _("Port Group Port Relation {0} could not be found.") -class VolumeGrpVolumeRelationNotFound(NotFound): +class VolGrpVolRelationNotFound(NotFound): msg_fmt = _("Volume Group Volume Relation {0} could not be found.") From 80b25638055dd8706a4b547d5627d142fe8f4e45 Mon Sep 17 00:00:00 2001 From: sushanthakumar Date: Sat, 26 Jun 2021 13:36:38 +0530 Subject: [PATCH 6/6] Updated for masking view model change --- delfin/db/sqlalchemy/models.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/delfin/db/sqlalchemy/models.py b/delfin/db/sqlalchemy/models.py index d0e15db12..6152d8cd8 100644 --- a/delfin/db/sqlalchemy/models.py +++ b/delfin/db/sqlalchemy/models.py @@ -23,8 +23,7 @@ from oslo_config import cfg from oslo_db.sqlalchemy import models from oslo_db.sqlalchemy.types import JsonEncodedDict -from sqlalchemy import Column, Integer, String, Boolean, BigInteger, \ - DateTime, Text +from sqlalchemy import Column, Integer, String, Boolean, BigInteger, DateTime from sqlalchemy.ext.declarative import declarative_base from delfin.common import constants @@ -357,9 +356,8 @@ class MaskingView(BASE, DelfinBase): native_volume_group_id = Column(String(255)) native_port_group_id = Column(String(255)) native_storage_host_id = Column(String(255)) - storage_host_initiators = Column(Text) - volumes = Column(Text) - ports = Column(Text) + native_volume_id = Column(String(255)) + native_port_id = Column(String(255)) native_masking_view_id = Column(String(255))