Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host mapping feature merge #642

Merged
merged 8 commits into from
Jun 26, 2021
Merged
56 changes: 56 additions & 0 deletions delfin/api/v1/masking_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2021 The SODA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from delfin import db
from delfin.api import api_utils
from delfin.api.common import wsgi
from delfin.api.views import masking_views


class MaskingViewController(wsgi.Controller):

def __init__(self):
super(MaskingViewController, self).__init__()
self.search_options = ['name', 'id', 'storage_id',
'native_storage_host_group_id',
'native_storage_port_group_id',
'native_storage_volume_group_id',
'native_storage_host_id',
'native_volume_id',
'native_port_id',
'native_masking_view_id']

def _get_masking_view_search_options(self):
"""Return masking view search options allowed ."""
return self.search_options

def show(self, req, id):
ctxt = req.environ['delfin.context']
query_params = {"storage_id": id}
query_params.update(req.GET)
# Update options other than filters
sort_keys, sort_dirs = api_utils.get_sort_params(query_params)
marker, limit, offset = api_utils.get_pagination_params(query_params)
# Strip out options except supported search options
api_utils.remove_invalid_options(
ctxt, query_params, self._get_masking_view_search_options())

masking_view_lists = db.masking_views_get_all(ctxt, marker, limit,
sort_keys, sort_dirs,
query_params, offset)
return masking_views.build_masking_views(masking_view_lists)


def create_resource():
return wsgi.Resource(MaskingViewController())
49 changes: 49 additions & 0 deletions delfin/api/v1/port_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2021 The SODA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from delfin import db
from delfin.api import api_utils
from delfin.api.common import wsgi
from delfin.api.views import port_groups as port_group_view


class PortGroupController(wsgi.Controller):

def __init__(self):
super(PortGroupController, self).__init__()
self.search_options = ['name', 'id', 'storage_id',
'native_port_group_id']

def _get_port_group_search_options(self):
"""Return port group search options allowed ."""
return self.search_options

def show(self, req, id):
ctxt = req.environ['delfin.context']
query_params = {"storage_id": id}
query_params.update(req.GET)
# Update options other than filters
sort_keys, sort_dirs = api_utils.get_sort_params(query_params)
marker, limit, offset = api_utils.get_pagination_params(query_params)
# Strip out options except supported search options
api_utils.remove_invalid_options(
ctxt, query_params, self._get_port_group_search_options())

port_groups = db.port_groups_get_all(
ctxt, marker, limit, sort_keys, sort_dirs, query_params, offset)
return port_group_view.build_port_groups(port_groups)


def create_resource():
return wsgi.Resource(PortGroupController())
47 changes: 47 additions & 0 deletions delfin/api/v1/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
from delfin.api.v1 import storage_pools
from delfin.api.v1 import storages
from delfin.api.v1 import volumes
from delfin.api.v1 import storage_hosts
from delfin.api.v1 import storage_host_initiators
from delfin.api.v1 import storage_host_groups
from delfin.api.v1 import port_groups
from delfin.api.v1 import volume_groups
from delfin.api.v1 import masking_views


class APIRouter(common.APIRouter):
Expand Down Expand Up @@ -136,3 +142,44 @@ def _setup_routes(self, mapper):
self.resources['shares'] = shares.create_resource()
mapper.resource("shares", "shares",
controller=self.resources['shares'])

self.resources['storage_host_initiators'] \
= storage_host_initiators.create_resource()
mapper.connect("storages", "/storages/{id}/storage-host-initiators",
controller=self.resources['storage_host_initiators'],
action="show",
conditions={"method": ["GET"]})

self.resources['storage_hosts'] = storage_hosts.create_resource()
mapper.connect("storages", "/storages/{id}/storage-hosts",
controller=self.resources['storage_hosts'],
action="show",
conditions={"method": ["GET"]})

self.resources['storage_host_groups'] \
= storage_host_groups.create_resource()
mapper.connect("storages", "/storages/{id}/storage-host-groups",
controller=self.resources['storage_host_groups'],
action="show",
conditions={"method": ["GET"]})

self.resources['port_groups'] \
= port_groups.create_resource()
mapper.connect("storages", "/storages/{id}/port-groups",
controller=self.resources['port_groups'],
action="show",
conditions={"method": ["GET"]})

self.resources['volume_groups'] \
= volume_groups.create_resource()
mapper.connect("storages", "/storages/{id}/volume-groups",
controller=self.resources['volume_groups'],
action="show",
conditions={"method": ["GET"]})

self.resources['masking_views'] \
= masking_views.create_resource()
mapper.connect("storages", "/storages/{id}/masking-views",
controller=self.resources['masking_views'],
action="show",
conditions={"method": ["GET"]})
50 changes: 50 additions & 0 deletions delfin/api/v1/storage_host_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2021 The SODA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from delfin import db
from delfin.api import api_utils
from delfin.api.common import wsgi
from delfin.api.views import storage_host_groups as storage_host_group_view


class StorageHostGroupController(wsgi.Controller):

def __init__(self):
super(StorageHostGroupController, self).__init__()
self.search_options = ['name', 'id', 'storage_id',
'native_storage_host_group_id']

def _get_storage_host_group_search_options(self):
"""Return storage host group search options allowed ."""
return self.search_options

def show(self, req, id):
ctxt = req.environ['delfin.context']
query_params = {"storage_id": id}
query_params.update(req.GET)
# Update options other than filters
sort_keys, sort_dirs = api_utils.get_sort_params(query_params)
marker, limit, offset = api_utils.get_pagination_params(query_params)
# Strip out options except supported search options
api_utils.remove_invalid_options(
ctxt, query_params, self._get_storage_host_group_search_options())

storage_host_groups = db.storage_host_groups_get_all(
ctxt, marker, limit, sort_keys, sort_dirs, query_params, offset)
return storage_host_group_view\
.build_storage_host_groups(storage_host_groups)


def create_resource():
return wsgi.Resource(StorageHostGroupController())
53 changes: 53 additions & 0 deletions delfin/api/v1/storage_host_initiators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2021 The SODA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from delfin import db
from delfin.api import api_utils
from delfin.api.common import wsgi
from delfin.api.views import storage_host_initiators as \
storage_host_initiator_view


class StorageHostInitiatorController(wsgi.Controller):

def __init__(self):
super(StorageHostInitiatorController, self).__init__()
self.search_options = ['name', 'status', 'wwn', 'id', 'storage_id',
'native_storage_host_id',
'native_storage_host_initiator_id']

def _get_storage_host_initiator_search_options(self):
"""Return storage host initiator search options allowed ."""
return self.search_options

def show(self, req, id):
ctxt = req.environ['delfin.context']
query_params = {"storage_id": id}
query_params.update(req.GET)
# Update options other than filters
sort_keys, sort_dirs = api_utils.get_sort_params(query_params)
marker, limit, offset = api_utils.get_pagination_params(query_params)
# Strip out options except supported search options
api_utils.remove_invalid_options(
ctxt, query_params,
self._get_storage_host_initiator_search_options())

storage_host_initiators = db.storage_host_initiators_get_all(
ctxt, marker, limit, sort_keys, sort_dirs, query_params, offset)
return storage_host_initiator_view.build_storage_host_initiators(
storage_host_initiators)


def create_resource():
return wsgi.Resource(StorageHostInitiatorController())
67 changes: 67 additions & 0 deletions delfin/api/v1/storage_hosts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2021 The SODA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from delfin import db
from delfin.api import api_utils
from delfin.api.common import wsgi
from delfin.api.views import storage_hosts as storage_host_view


class StorageHostController(wsgi.Controller):

def __init__(self):
super(StorageHostController, self).__init__()
self.search_options = ['name', 'status', 'id', 'storage_id',
'native_storage_host_id']

def _get_storage_host_search_options(self):
"""Return storage host search options allowed ."""
return self.search_options

def _fill_storage_host_initiators(self, ctxt, storage_host, storage_id):
"""Fills initiator list for storage host."""

storage_host_initiators = db.storage_host_initiators_get_all(
ctxt, filters={"storage_id": storage_id,
"native_storage_host_id":
storage_host['native_storage_host_id']})
storage_host_initiator_list = []
for storage_host_initiator in storage_host_initiators:
storage_host_initiator_list.append(
storage_host_initiator['native_storage_host_initiator_id'])
return storage_host_initiator_list

def show(self, req, id):
ctxt = req.environ['delfin.context']
query_params = {"storage_id": id}
query_params.update(req.GET)
# Update options other than filters
sort_keys, sort_dirs = api_utils.get_sort_params(query_params)
marker, limit, offset = api_utils.get_pagination_params(query_params)
# Strip out options except supported search options
api_utils.remove_invalid_options(
ctxt, query_params, self._get_storage_host_search_options())

storage_hosts = db.storage_hosts_get_all(ctxt, marker, limit,
sort_keys, sort_dirs,
query_params, offset)
for storage_host in storage_hosts:
storage_host['storage_host_initiators'] \
= self._fill_storage_host_initiators(ctxt, storage_host, id)

return storage_host_view.build_storage_hosts(storage_hosts)


def create_resource():
return wsgi.Resource(StorageHostController())
49 changes: 49 additions & 0 deletions delfin/api/v1/volume_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2021 The SODA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from delfin import db
from delfin.api import api_utils
from delfin.api.common import wsgi
from delfin.api.views import volume_groups as volume_group_view


class VolumeGroupController(wsgi.Controller):

def __init__(self):
super(VolumeGroupController, self).__init__()
self.search_options = ['name', 'id', 'storage_id',
'native_volume_group_id']

def _get_volume_group_search_options(self):
"""Return volume group search options allowed ."""
return self.search_options

def show(self, req, id):
ctxt = req.environ['delfin.context']
query_params = {"storage_id": id}
query_params.update(req.GET)
# Update options other than filters
sort_keys, sort_dirs = api_utils.get_sort_params(query_params)
marker, limit, offset = api_utils.get_pagination_params(query_params)
# Strip out options except supported search options
api_utils.remove_invalid_options(
ctxt, query_params, self._get_volume_group_search_options())

volume_groups = db.volume_groups_get_all(
ctxt, marker, limit, sort_keys, sort_dirs, query_params, offset)
return volume_group_view.build_volume_groups(volume_groups)


def create_resource():
return wsgi.Resource(VolumeGroupController())
Loading