Shared filesystem management project for OpenStack.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
7.1 KiB

# Copyright (c) 2015 Clinton Knight. 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
# 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.
NetApp cDOT NFS protocol helper class.
import uuid
from oslo_log import log
import six
from manila.common import constants
from manila import exception
from manila.share.drivers.netapp.dataontap.protocols import base
from manila.share.drivers.netapp import utils as na_utils
LOG = log.getLogger(__name__)
class NetAppCmodeNFSHelper(base.NetAppBaseHelper):
"""NetApp cDOT NFS protocol helper class."""
def _escaped_address(address):
if ':' in address:
return '[%s]' % address
return address
def create_share(self, share, share_name,
"""Creates NFS share."""
if clear_current_export_policy:
self._ensure_export_policy(share, share_name)
export_path = self._client.get_volume_junction_path(share_name)
# Return a callback that may be used for generating export paths
# for this share.
return (lambda export_address, export_path=export_path:
def delete_share(self, share, share_name):
"""Deletes NFS share."""
LOG.debug('Deleting NFS export policy for share %s', share['id'])
export_policy_name = self._get_export_policy_name(share)
def update_access(self, share, share_name, rules):
"""Replaces the list of access rules known to the backend storage."""
# Ensure rules are valid
for rule in rules:
# Sort rules by ascending network size
new_rules = {rule['access_to']: rule['access_level'] for rule in rules}
addresses = sorted(new_rules, reverse=True)
# Ensure current export policy has the name we expect
self._ensure_export_policy(share, share_name)
export_policy_name = self._get_export_policy_name(share)
# Make temp policy names so this non-atomic workflow remains resilient
# across process interruptions.
temp_new_export_policy_name = self._get_temp_export_policy_name()
temp_old_export_policy_name = self._get_temp_export_policy_name()
# Create new export policy
# Add new rules to new policy
for address in addresses:
temp_new_export_policy_name, address,
# Rename policy currently in force'Renaming NFS export policy for share %(share)s to '
{'share': share_name, 'policy': temp_old_export_policy_name})
# Switch share to the new policy'Setting NFS export policy for share %(share)s to '
{'share': share_name, 'policy': temp_new_export_policy_name})
share_name, temp_new_export_policy_name)
# Delete old policy
# Rename new policy to its final name'Renaming NFS export policy for share %(share)s to '
{'share': share_name, 'policy': export_policy_name})
def _validate_access_rule(self, rule):
"""Checks whether access rule type and level are valid."""
if rule['access_type'] != 'ip':
msg = ("Clustered Data ONTAP supports only 'ip' type for share "
"access rules with NFS protocol.")
raise exception.InvalidShareAccess(reason=msg)
if rule['access_level'] not in constants.ACCESS_LEVELS:
raise exception.InvalidShareAccessLevel(level=rule['access_level'])
def get_target(self, share):
"""Returns ID of target OnTap device based on export location."""
return self._get_export_location(share)[0]
def get_share_name_for_share(self, share):
"""Returns the flexvol name that hosts a share."""
_, volume_junction_path = self._get_export_location(share)
volume = self._client.get_volume_at_junction_path(volume_junction_path)
return volume.get('name') if volume else None
def _get_export_location(share):
"""Returns IP address and export location of an NFS share."""
export_location = share['export_location'] or ':'
return export_location.rsplit(':', 1)
def _get_temp_export_policy_name():
"""Builds export policy name for an NFS share."""
return 'temp_' + six.text_type(uuid.uuid1()).replace('-', '_')
def _get_export_policy_name(share):
"""Builds export policy name for an NFS share."""
return 'policy_' + share['id'].replace('-', '_')
def _ensure_export_policy(self, share, share_name):
"""Ensures a flexvol/share has an export policy.
This method ensures a flexvol has an export policy with a name
containing the share ID. For legacy reasons, this may not
always be the case.
expected_export_policy = self._get_export_policy_name(share)
actual_export_policy = self._client.get_nfs_export_policy_for_volume(
if actual_export_policy == expected_export_policy:
elif actual_export_policy == 'default':
share_name, expected_export_policy)