Files
manila/manila/api/v2/share_network_subnets.py
T
Felipe Rodrigues 2b57d15c64 Add multiple subnets per AZ support
Manila can now configure a share network with multiple subnets
in an availability zone. Also, it can add a new subnet for an
availability that has share servers, which will triger an update
share server allocations.

Changes:
- API:
  - Bump version to 2.70.
  - setup share network with multiple subents per az.
  - Block manage server with multiple subnets.
  - Allow add subnet for in-use share servers.
  - `share_network_subnet_id` is dropped from ShareServer view
  - `share_network_subnet_ids` is added in ShareServer view
  - `network_allocation_update_support` is added to ShareServer and
    ShareNetwork views.
  - Add a check operation for share network subnet create.

- DB:
  - Remove `share_network_subnet_id` from share_servers.
  - Create mapping table `share_server_share_network_subnet_mappings`.
  - Fix queries with new db design.
  - Add migration downgrade and upgrade alembic.
  - Add `share_network_subnet_id` to the NetworkAllocations.

- Scheduler:
  - Change `AvailabilityZoneFilter` to take in account if the
    host supports the allocation required by the setup request.

- Manager:
  - Bump RPC API version.
  - `_setup_server` allocating multiple subnets.
  - Modify signature of driver `_setup_server` interface, passing a
    list of `network_info` for each subnet.
  - Share server DB creation to inform a list of subnets and
    create with `network_allocation_update_support`.
  - Implement `check_update_share_server_network_allocations` and
    `update_share_server_network_allocations`.

- Drivers:
  - For legacy compatibility, all drivers implementing `_setup_server`
    consume the first element of the `network_ino`.
  - Dummy Driver:
    - Implement `_setup_server` with new signature as multiple subnet.
    - Modify the `backend_details` to save allocations for all subnets.
    - Report update allocation and share server multiple subnet support.
    - Implement `check_update_share_server_network_allocations` and
      `update_share_server_network_allocations` interfaces.

Signed-off-by: Felipe Rodrigues <felipefuty01@gmail.com>
Co-Authored-By: Andre Beltrami <debeltrami@gmail.com>
Co-Authored-By: Fábio Oliveira <fabioaurelio1269@gmail.com>
Co-Authored-By: Nahim Alves de Souza <nahimsouza@outlook.com>
Co-Authored-By: Caique Mello <caique_mellosbo@hotmail.com>

DocImpact
APIImpact
Partially-Implements: blueprint multiple-share-network-subnets

Change-Id: I7de9de4ae509182e9494bba604979cce03acceec
2022-03-03 02:31:11 +00:00

187 lines
7.8 KiB
Python

# Copyright 2019 NetApp, Inc.
# All Rights Reserved.
#
# 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 http import client as http_client
from manila.api import common
from oslo_db import exception as db_exception
from oslo_log import log
import webob
from webob import exc
from manila.api.openstack import api_version_request as api_version
from manila.api.openstack import wsgi
from manila.api.views import share_network_subnets as subnet_views
from manila.db import api as db_api
from manila import exception
from manila.i18n import _
from manila import share
from manila.share import rpcapi as share_rpcapi
LOG = log.getLogger(__name__)
class ShareNetworkSubnetController(wsgi.Controller):
"""The Share Network Subnet API controller for the OpenStack API."""
resource_name = 'share_network_subnet'
_view_builder_class = subnet_views.ViewBuilder
def __init__(self):
super(ShareNetworkSubnetController, self).__init__()
self.share_rpcapi = share_rpcapi.ShareAPI()
self.share_api = share.API()
@wsgi.Controller.api_version("2.51")
@wsgi.Controller.authorize
def index(self, req, share_network_id):
"""Returns a list of share network subnets."""
context = req.environ['manila.context']
try:
share_network = db_api.share_network_get(context, share_network_id)
except exception.ShareNetworkNotFound as e:
raise exc.HTTPNotFound(explanation=e.msg)
return self._view_builder.build_share_network_subnets(
req, share_network.get('share_network_subnets'))
def _all_share_servers_are_auto_deletable(self, share_network_subnet):
return all([ss['is_auto_deletable'] for ss
in share_network_subnet['share_servers']])
@wsgi.Controller.api_version('2.51')
@wsgi.Controller.authorize
def delete(self, req, share_network_id, share_network_subnet_id):
"""Delete specified share network subnet."""
context = req.environ['manila.context']
try:
db_api.share_network_get(context, share_network_id)
except exception.ShareNetworkNotFound as e:
raise exc.HTTPNotFound(explanation=e.msg)
try:
share_network_subnet = db_api.share_network_subnet_get(
context, share_network_subnet_id)
except exception.ShareNetworkSubnetNotFound as e:
raise exc.HTTPNotFound(explanation=e.msg)
for share_server in share_network_subnet['share_servers'] or []:
shares = db_api.share_instances_get_all_by_share_server(
context, share_server['id'])
if shares:
msg = _("Cannot delete share network subnet %(id)s, it has "
"one or more shares.") % {
'id': share_network_subnet_id}
LOG.error(msg)
raise exc.HTTPConflict(explanation=msg)
# NOTE(silvacarlose): Do not allow the deletion of any share server
# if any of them has the flag is_auto_deletable = False
if not self._all_share_servers_are_auto_deletable(
share_network_subnet):
msg = _("The service cannot determine if there are any "
"non-managed shares on the share network subnet %(id)s,"
"so it cannot be deleted. Please contact the cloud "
"administrator to rectify.") % {
'id': share_network_subnet_id}
LOG.error(msg)
raise exc.HTTPConflict(explanation=msg)
for share_server in share_network_subnet['share_servers']:
self.share_rpcapi.delete_share_server(context, share_server)
db_api.share_network_subnet_delete(context, share_network_subnet_id)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.Controller.api_version("2.51")
@wsgi.Controller.authorize
def create(self, req, share_network_id, body):
"""Add a new share network subnet into the share network."""
context = req.environ['manila.context']
if not self.is_valid_body(body, 'share-network-subnet'):
msg = _("Share Network Subnet is missing from the request body.")
raise exc.HTTPBadRequest(explanation=msg)
data = body['share-network-subnet']
data['share_network_id'] = share_network_id
multiple_subnet_support = (req.api_version_request >=
api_version.APIVersionRequest("2.70"))
share_network, existing_subnets = common.validate_subnet_create(
context, share_network_id, data, multiple_subnet_support)
# create subnet operation on subnets with share servers means that an
# allocation update is requested.
if existing_subnets and existing_subnets[0]['share_servers']:
# NOTE(felipe_rodrigues): all subnets have the same set of share
# servers, so we can just get the servers from one of them. Not
# necessarily all share servers from the specified AZ will be
# updated, only the ones created with subnets in the AZ. Others
# created with default AZ will only have its allocations updated
# when default subnet set is updated.
data['share_servers'] = existing_subnets[0]['share_servers']
try:
share_network_subnet = (
self.share_api.update_share_server_network_allocations(
context, share_network, data))
except exception.ServiceIsDown as e:
msg = _('Could not add the share network subnet.')
LOG.error(e)
raise exc.HTTPInternalServerError(explanation=msg)
except exception.InvalidShareNetwork as e:
raise exc.HTTPBadRequest(explanation=e.msg)
except db_exception.DBError as e:
msg = _('Could not add the share network subnet.')
LOG.error(e)
raise exc.HTTPInternalServerError(explanation=msg)
else:
try:
share_network_subnet = db_api.share_network_subnet_create(
context, data)
except db_exception.DBError as e:
msg = _('Could not create the share network subnet.')
LOG.error(e)
raise exc.HTTPInternalServerError(explanation=msg)
share_network_subnet = db_api.share_network_subnet_get(
context, share_network_subnet['id'])
return self._view_builder.build_share_network_subnet(
req, share_network_subnet)
@wsgi.Controller.api_version('2.51')
@wsgi.Controller.authorize
def show(self, req, share_network_id, share_network_subnet_id):
"""Show share network subnet."""
context = req.environ['manila.context']
try:
db_api.share_network_get(context, share_network_id)
except exception.ShareNetworkNotFound as e:
raise exc.HTTPNotFound(explanation=e.msg)
try:
share_network_subnet = db_api.share_network_subnet_get(
context, share_network_subnet_id)
except exception.ShareNetworkSubnetNotFound as e:
raise exc.HTTPNotFound(explanation=e.msg)
return self._view_builder.build_share_network_subnet(
req, share_network_subnet)
def create_resource():
return wsgi.Resource(ShareNetworkSubnetController())