"Fossies" - the Fresh Open Source Software Archive

Member "manila-8.1.3/manila/share/drivers/dell_emc/plugins/unity/connection.py" (20 Jul 2020, 28939 Bytes) of package /linux/misc/openstack/manila-8.1.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "connection.py": 8.1.2_vs_8.1.3.

    1 # Copyright (c) 2016 EMC Corporation.
    2 # All Rights Reserved.
    3 #
    4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 #    not use this file except in compliance with the License. You may obtain
    6 #    a copy of the License at
    7 #
    8 #         http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 #    Unless required by applicable law or agreed to in writing, software
   11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 #    License for the specific language governing permissions and limitations
   14 #    under the License.
   15 """Unity backend for the EMC Manila driver."""
   16 import random
   17 
   18 from oslo_config import cfg
   19 from oslo_log import log
   20 from oslo_utils import excutils
   21 from oslo_utils import importutils
   22 from oslo_utils import netutils
   23 
   24 storops = importutils.try_import('storops')
   25 if storops:
   26     # pylint: disable=import-error
   27     from storops import exception as storops_ex
   28     from storops.unity import enums
   29 
   30 from manila.common import constants as const
   31 from manila import exception
   32 from manila.i18n import _
   33 from manila.share.drivers.dell_emc.common.enas import utils as enas_utils
   34 from manila.share.drivers.dell_emc.plugins import base as driver
   35 from manila.share.drivers.dell_emc.plugins.unity import client
   36 from manila.share.drivers.dell_emc.plugins.unity import utils as unity_utils
   37 from manila.share import utils as share_utils
   38 from manila import utils
   39 
   40 """Version history:
   41      6.1.1 - Fix parsing management IPv6 address
   42      6.1.2 - Bugfix: failed to delete CIFS share if wrong access was set
   43 """
   44 
   45 VERSION = "6.1.2"
   46 
   47 LOG = log.getLogger(__name__)
   48 SUPPORTED_NETWORK_TYPES = (None, 'flat', 'vlan')
   49 
   50 UNITY_OPTS = [
   51     cfg.StrOpt('unity_server_meta_pool',
   52                required=True,
   53                deprecated_name='emc_nas_server_pool',
   54                help='Pool to persist the meta-data of NAS server.'),
   55     cfg.ListOpt('unity_share_data_pools',
   56                 deprecated_name='emc_nas_pool_names',
   57                 help='Comma separated list of pools that can be used to '
   58                      'persist share data.'),
   59     cfg.ListOpt('unity_ethernet_ports',
   60                 deprecated_name='emc_interface_ports',
   61                 help='Comma separated list of ports that can be used for '
   62                      'share server interfaces. Members of the list '
   63                      'can be Unix-style glob expressions.'),
   64     cfg.StrOpt('emc_nas_server_container',
   65                deprecated_for_removal=True,
   66                deprecated_reason='Unity driver supports nas server auto load '
   67                                  'balance.',
   68                help='Storage processor to host the NAS server. Obsolete.'),
   69 ]
   70 
   71 CONF = cfg.CONF
   72 CONF.register_opts(UNITY_OPTS)
   73 
   74 
   75 @enas_utils.decorate_all_methods(enas_utils.log_enter_exit,
   76                                  debug_only=True)
   77 class UnityStorageConnection(driver.StorageConnection):
   78     """Implements Unity specific functionality for EMC Manila driver."""
   79 
   80     IP_ALLOCATIONS = 1
   81 
   82     @enas_utils.log_enter_exit
   83     def __init__(self, *args, **kwargs):
   84         super(UnityStorageConnection, self).__init__(*args, **kwargs)
   85         if 'configuration' in kwargs:
   86             kwargs['configuration'].append_config_values(UNITY_OPTS)
   87 
   88         self.client = None
   89         self.pool_set = None
   90         self.nas_server_pool = None
   91         self.reserved_percentage = None
   92         self.max_over_subscription_ratio = None
   93         self.port_ids_conf = None
   94         self.ipv6_implemented = True
   95         self.revert_to_snap_support = True
   96         self.shrink_share_support = True
   97 
   98         # props from super class.
   99         self.driver_handles_share_servers = True
  100 
  101     def connect(self, emc_share_driver, context):
  102         """Connect to Unity storage."""
  103         config = emc_share_driver.configuration
  104         storage_ip = enas_utils.convert_ipv6_format_if_needed(
  105             config.emc_nas_server)
  106         username = config.emc_nas_login
  107         password = config.emc_nas_password
  108         self.client = client.UnityClient(storage_ip, username, password)
  109 
  110         pool_conf = config.safe_get('unity_share_data_pools')
  111         self.pool_set = self._get_managed_pools(pool_conf)
  112 
  113         self.reserved_percentage = config.safe_get(
  114             'reserved_share_percentage')
  115         if self.reserved_percentage is None:
  116             self.reserved_percentage = 0
  117 
  118         self.max_over_subscription_ratio = config.safe_get(
  119             'max_over_subscription_ratio')
  120         self.port_ids_conf = config.safe_get('unity_ethernet_ports')
  121         self.validate_port_configuration(self.port_ids_conf)
  122         pool_name = config.unity_server_meta_pool
  123         self._config_pool(pool_name)
  124 
  125     def validate_port_configuration(self, port_ids_conf):
  126         """Initializes the SP and ports based on the port option."""
  127 
  128         ports = self.client.get_file_ports()
  129 
  130         sp_ports_map, unmanaged_port_ids = unity_utils.match_ports(
  131             ports, port_ids_conf)
  132 
  133         if not sp_ports_map:
  134             msg = (_("All the specified storage ports to be managed "
  135                      "do not exist. Please check your configuration "
  136                      "unity_ethernet_ports in manila.conf. "
  137                      "The available ports in the backend are %s.") %
  138                    ",".join([port.get_id() for port in ports]))
  139             raise exception.BadConfigurationException(reason=msg)
  140 
  141         if unmanaged_port_ids:
  142             LOG.info("The following specified ports are not managed by "
  143                      "the backend: %(unmanaged)s. This host will only "
  144                      "manage the storage ports: %(exist)s",
  145                      {'unmanaged': ",".join(unmanaged_port_ids),
  146                       'exist': ",".join(map(",".join,
  147                                             sp_ports_map.values()))})
  148         else:
  149             LOG.debug("Ports: %s will be managed.",
  150                       ",".join(map(",".join, sp_ports_map.values())))
  151 
  152         if len(sp_ports_map) == 1:
  153             LOG.info("Only ports of %s are configured. Configure ports "
  154                      "of both SPA and SPB to use both of the SPs.",
  155                      list(sp_ports_map)[0])
  156 
  157         return sp_ports_map
  158 
  159     def check_for_setup_error(self):
  160         """Check for setup error."""
  161 
  162     def create_share(self, context, share, share_server=None):
  163         """Create a share and export it based on protocol used."""
  164         share_name = share['id']
  165         size = share['size']
  166 
  167         # Check share's protocol.
  168         # Throw an exception immediately if it is an invalid protocol.
  169         share_proto = share['share_proto'].upper()
  170         proto_enum = self._get_proto_enum(share_proto)
  171 
  172         # Get pool name from share host field
  173         pool_name = self._get_pool_name_from_host(share['host'])
  174         # Get share server name from share server
  175         server_name = self._get_server_name(share_server)
  176 
  177         pool = self.client.get_pool(pool_name)
  178         try:
  179             nas_server = self.client.get_nas_server(server_name)
  180         except storops_ex.UnityResourceNotFoundError:
  181             message = (_("Failed to get NAS server %(server)s when "
  182                          "creating the share %(share)s.") %
  183                        {'server': server_name, 'share': share_name})
  184             LOG.exception(message)
  185             raise exception.EMCUnityError(err=message)
  186 
  187         locations = None
  188         if share_proto == 'CIFS':
  189             filesystem = self.client.create_filesystem(
  190                 pool, nas_server, share_name,
  191                 size, proto=proto_enum)
  192             self.client.create_cifs_share(filesystem, share_name)
  193 
  194             locations = self._get_cifs_location(
  195                 nas_server.file_interface, share_name)
  196         elif share_proto == 'NFS':
  197             self.client.create_nfs_filesystem_and_share(
  198                 pool, nas_server, share_name, size)
  199 
  200             locations = self._get_nfs_location(
  201                 nas_server.file_interface, share_name)
  202 
  203         return locations
  204 
  205     def create_share_from_snapshot(self, context, share, snapshot,
  206                                    share_server=None):
  207         """Create a share from a snapshot - clone a snapshot."""
  208         share_name = share['id']
  209 
  210         # Check share's protocol.
  211         # Throw an exception immediately if it is an invalid protocol.
  212         share_proto = share['share_proto'].upper()
  213         self._validate_share_protocol(share_proto)
  214 
  215         # Get share server name from share server
  216         server_name = self._get_server_name(share_server)
  217 
  218         try:
  219             nas_server = self.client.get_nas_server(server_name)
  220         except storops_ex.UnityResourceNotFoundError:
  221             message = (_("Failed to get NAS server %(server)s when "
  222                          "creating the share %(share)s.") %
  223                        {'server': server_name, 'share': share_name})
  224             LOG.exception(message)
  225             raise exception.EMCUnityError(err=message)
  226 
  227         backend_snap = self.client.create_snap_of_snap(snapshot['id'],
  228                                                        share_name)
  229 
  230         locations = None
  231         if share_proto == 'CIFS':
  232             self.client.create_cifs_share(backend_snap, share_name)
  233 
  234             locations = self._get_cifs_location(
  235                 nas_server.file_interface, share_name)
  236         elif share_proto == 'NFS':
  237             self.client.create_nfs_share(backend_snap, share_name)
  238 
  239             locations = self._get_nfs_location(
  240                 nas_server.file_interface, share_name)
  241 
  242         return locations
  243 
  244     def delete_share(self, context, share, share_server=None):
  245         """Delete a share."""
  246         share_name = share['id']
  247         try:
  248             backend_share = self.client.get_share(share_name,
  249                                                   share['share_proto'])
  250         except storops_ex.UnityResourceNotFoundError:
  251             LOG.warning("Share %s is not found when deleting the share",
  252                         share_name)
  253             return
  254 
  255         # Share created by the API create_share_from_snapshot()
  256         if self._is_share_from_snapshot(backend_share):
  257             filesystem = backend_share.snap.filesystem
  258             self.client.delete_snapshot(backend_share.snap)
  259         else:
  260             filesystem = backend_share.filesystem
  261             self.client.delete_share(backend_share)
  262 
  263         if self._is_isolated_filesystem(filesystem):
  264             self.client.delete_filesystem(filesystem)
  265 
  266     def extend_share(self, share, new_size, share_server=None):
  267         backend_share = self.client.get_share(share['id'],
  268                                               share['share_proto'])
  269 
  270         if not self._is_share_from_snapshot(backend_share):
  271             self.client.extend_filesystem(backend_share.filesystem,
  272                                           new_size)
  273         else:
  274             share_id = share['id']
  275             reason = ("Driver does not support extending a "
  276                       "snapshot based share.")
  277             raise exception.ShareExtendingError(share_id=share_id,
  278                                                 reason=reason)
  279 
  280     def shrink_share(self, share, new_size, share_server=None):
  281         """Shrinks a share to new size.
  282 
  283         :param share: Share that will be shrunk.
  284         :param new_size: New size of share.
  285         :param share_server: Data structure with share server information.
  286             Not used by this driver.
  287         """
  288         share_id = share['id']
  289         backend_share = self.client.get_share(share_id,
  290                                               share['share_proto'])
  291         if self._is_share_from_snapshot(backend_share):
  292             reason = ("Driver does not support shrinking a "
  293                       "snapshot based share.")
  294             raise exception.ShareShrinkingError(share_id=share_id,
  295                                                 reason=reason)
  296         self.client.shrink_filesystem(share_id, backend_share.filesystem,
  297                                       new_size)
  298         LOG.info("Share %(shr_id)s successfully shrunk to "
  299                  "%(shr_size)sG.",
  300                  {'shr_id': share_id,
  301                   'shr_size': new_size})
  302 
  303     def create_snapshot(self, context, snapshot, share_server=None):
  304         """Create snapshot from share."""
  305         share_name = snapshot['share_id']
  306         share_proto = snapshot['share']['share_proto']
  307         backend_share = self.client.get_share(share_name, share_proto)
  308 
  309         snapshot_name = snapshot['id']
  310         if self._is_share_from_snapshot(backend_share):
  311             self.client.create_snap_of_snap(backend_share.snap, snapshot_name)
  312         else:
  313             self.client.create_snapshot(backend_share.filesystem,
  314                                         snapshot_name)
  315 
  316     def delete_snapshot(self, context, snapshot, share_server=None):
  317         """Delete a snapshot."""
  318         snap = self.client.get_snapshot(snapshot['id'])
  319         self.client.delete_snapshot(snap)
  320 
  321     def update_access(self, context, share, access_rules, add_rules,
  322                       delete_rules, share_server=None):
  323         # adding rules
  324         if add_rules:
  325             for rule in add_rules:
  326                 self.allow_access(context, share, rule, share_server)
  327 
  328         # deleting rules
  329         if delete_rules:
  330             for rule in delete_rules:
  331                 self.deny_access(context, share, rule, share_server)
  332 
  333         # recovery mode
  334         if not (add_rules or delete_rules):
  335             white_list = []
  336             for rule in access_rules:
  337                 self.allow_access(context, share, rule, share_server)
  338                 white_list.append(rule['access_to'])
  339             self.clear_access(share, white_list)
  340 
  341     def clear_access(self, share, white_list=None):
  342         share_proto = share['share_proto'].upper()
  343         share_name = share['id']
  344         if share_proto == 'CIFS':
  345             self.client.cifs_clear_access(share_name, white_list)
  346         elif share_proto == 'NFS':
  347             self.client.nfs_clear_access(share_name, white_list)
  348 
  349     def allow_access(self, context, share, access, share_server=None):
  350         """Allow access to a share."""
  351         access_level = access['access_level']
  352         if access_level not in const.ACCESS_LEVELS:
  353             raise exception.InvalidShareAccessLevel(level=access_level)
  354 
  355         share_proto = share['share_proto'].upper()
  356 
  357         self._validate_share_protocol(share_proto)
  358         self._validate_share_access_type(share, access)
  359 
  360         if share_proto == 'CIFS':
  361             self._cifs_allow_access(share, access)
  362         elif share_proto == 'NFS':
  363             self._nfs_allow_access(share, access)
  364 
  365     def deny_access(self, context, share, access, share_server):
  366         """Deny access to a share."""
  367         share_proto = share['share_proto'].upper()
  368 
  369         self._validate_share_protocol(share_proto)
  370         self._validate_share_access_type(share, access)
  371 
  372         if share_proto == 'CIFS':
  373             self._cifs_deny_access(share, access)
  374         elif share_proto == 'NFS':
  375             self._nfs_deny_access(share, access)
  376 
  377     def ensure_share(self, context, share, share_server):
  378         """Ensure that the share is exported."""
  379         share_name = share['id']
  380         share_proto = share['share_proto']
  381 
  382         backend_share = self.client.get_share(share_name, share_proto)
  383         if not backend_share.existed:
  384             raise exception.ShareNotFound(share_id=share_name)
  385 
  386     def update_share_stats(self, stats_dict):
  387         """Communicate with EMCNASClient to get the stats."""
  388         stats_dict['driver_version'] = VERSION
  389         stats_dict['pools'] = []
  390 
  391         for pool in self.client.get_pool():
  392             if pool.name in self.pool_set:
  393                 # the unit of following numbers are GB
  394                 total_size = float(pool.size_total)
  395                 used_size = float(pool.size_used)
  396 
  397                 pool_stat = {
  398                     'pool_name': pool.name,
  399                     'thin_provisioning': True,
  400                     'total_capacity_gb': total_size,
  401                     'free_capacity_gb': total_size - used_size,
  402                     'allocated_capacity_gb': used_size,
  403                     'provisioned_capacity_gb': float(pool.size_subscribed),
  404                     'qos': False,
  405                     'reserved_percentage': self.reserved_percentage,
  406                     'max_over_subscription_ratio':
  407                         self.max_over_subscription_ratio,
  408                 }
  409                 stats_dict['pools'].append(pool_stat)
  410 
  411         if not stats_dict.get('pools'):
  412             message = _("Failed to update storage pool.")
  413             LOG.error(message)
  414             raise exception.EMCUnityError(err=message)
  415 
  416     def get_pool(self, share):
  417         """Get the pool name of the share."""
  418         backend_share = self.client.get_share(
  419             share['id'], share['share_proto'])
  420 
  421         return backend_share.filesystem.pool.name
  422 
  423     def get_network_allocations_number(self):
  424         """Returns number of network allocations for creating VIFs."""
  425         return self.IP_ALLOCATIONS
  426 
  427     def setup_server(self, network_info, metadata=None):
  428         """Set up and configures share server with given network parameters."""
  429         server_name = network_info['server_id']
  430         segmentation_id = network_info['segmentation_id']
  431         network = self.validate_network(network_info)
  432         mtu = network['mtu']
  433         tenant = self.client.get_tenant(network_info['server_id'],
  434                                         segmentation_id)
  435 
  436         sp_ports_map = unity_utils.find_ports_by_mtu(
  437             self.client.get_file_ports(),
  438             self.port_ids_conf, mtu)
  439 
  440         sp = self._choose_sp(sp_ports_map)
  441         nas_server = self.client.create_nas_server(server_name,
  442                                                    sp,
  443                                                    self.nas_server_pool,
  444                                                    tenant=tenant)
  445         sp = nas_server.home_sp
  446         port_id = self._choose_port(sp_ports_map, sp)
  447         try:
  448             self._create_network_interface(nas_server, network, port_id)
  449 
  450             self._handle_security_services(
  451                 nas_server, network_info['security_services'])
  452 
  453             return {'share_server_name': server_name}
  454 
  455         except Exception:
  456             with excutils.save_and_reraise_exception():
  457                 LOG.exception('Could not setup server.')
  458                 server_details = {'share_server_name': server_name}
  459                 self.teardown_server(
  460                     server_details, network_info['security_services'])
  461 
  462     def teardown_server(self, server_details, security_services=None):
  463         """Teardown share server."""
  464         if not server_details:
  465             LOG.debug('Server details are empty.')
  466             return
  467 
  468         server_name = server_details.get('share_server_name')
  469         if not server_name:
  470             LOG.debug('No share server found for server %s.',
  471                       server_details.get('instance_id'))
  472             return
  473 
  474         username = None
  475         password = None
  476         for security_service in security_services:
  477             if security_service['type'] == 'active_directory':
  478                 username = security_service['user']
  479                 password = security_service['password']
  480                 break
  481 
  482         self.client.delete_nas_server(server_name, username, password)
  483 
  484     def _cifs_allow_access(self, share, access):
  485         """Allow access to CIFS share."""
  486         self.client.cifs_allow_access(
  487             share['id'], access['access_to'], access['access_level'])
  488 
  489     def _cifs_deny_access(self, share, access):
  490         """Deny access to CIFS share."""
  491         self.client.cifs_deny_access(share['id'], access['access_to'])
  492 
  493     def _config_pool(self, pool_name):
  494         try:
  495             self.nas_server_pool = self.client.get_pool(pool_name)
  496         except storops_ex.UnityResourceNotFoundError:
  497             message = (_("The storage pools %s to store NAS server "
  498                          "configuration do not exist.") % pool_name)
  499             LOG.exception(message)
  500             raise exception.BadConfigurationException(reason=message)
  501 
  502     @staticmethod
  503     def validate_network(network_info):
  504         network = network_info['network_allocations'][0]
  505         if network['network_type'] not in SUPPORTED_NETWORK_TYPES:
  506             msg = _('The specified network type %s is unsupported by '
  507                     'the EMC Unity driver')
  508             raise exception.NetworkBadConfigurationException(
  509                 reason=msg % network['network_type'])
  510         return network
  511 
  512     def _create_network_interface(self, nas_server, network, port_id):
  513         kargs = {'ip_addr': network['ip_address'],
  514                  'gateway': network['gateway'],
  515                  'vlan_id': network['segmentation_id'],
  516                  'port_id': port_id}
  517 
  518         if netutils.is_valid_ipv6_cidr(kargs['ip_addr']):
  519             kargs['netmask'] = None
  520             kargs['prefix_length'] = str(utils.cidr_to_prefixlen(
  521                 network['cidr']))
  522         else:
  523             kargs['netmask'] = utils.cidr_to_netmask(network['cidr'])
  524 
  525         # Create the interfaces on NAS server
  526         self.client.create_interface(nas_server, **kargs)
  527 
  528     def _choose_sp(self, sp_ports_map):
  529         sp = None
  530         if len(sp_ports_map.keys()) == 1:
  531             # Only one storage processor has usable ports,
  532             # create NAS server on that SP.
  533             sp = self.client.get_storage_processor(
  534                 sp_id=list(sp_ports_map.keys())[0])
  535             LOG.debug('All the usable ports belong to  %s. '
  536                       'Creating NAS server on this SP without '
  537                       'load balance.', sp.get_id())
  538         return sp
  539 
  540     @staticmethod
  541     def _choose_port(sp_ports_map, sp):
  542         ports = sp_ports_map[sp.get_id()]
  543         return random.choice(list(ports))
  544 
  545     @staticmethod
  546     def _get_cifs_location(file_interfaces, share_name):
  547         return [
  548             {'path': r'\\%(interface)s\%(share_name)s' % {
  549                 'interface': enas_utils.export_unc_path(interface.ip_address),
  550                 'share_name': share_name}
  551              }
  552             for interface in file_interfaces
  553         ]
  554 
  555     def _get_managed_pools(self, pool_conf):
  556         # Get the real pools from the backend storage
  557         real_pools = set(pool.name for pool in self.client.get_pool())
  558 
  559         if not pool_conf:
  560             LOG.debug("No storage pool is specified, so all pools in storage "
  561                       "system will be managed.")
  562             return real_pools
  563 
  564         matched_pools, unmanaged_pools = unity_utils.do_match(real_pools,
  565                                                               pool_conf)
  566 
  567         if not matched_pools:
  568             msg = (_("All the specified storage pools to be managed "
  569                      "do not exist. Please check your configuration "
  570                      "emc_nas_pool_names in manila.conf. "
  571                      "The available pools in the backend are %s") %
  572                    ",".join(real_pools))
  573             raise exception.BadConfigurationException(reason=msg)
  574 
  575         if unmanaged_pools:
  576             LOG.info("The following specified storage pools "
  577                      "are not managed by the backend: "
  578                      "%(un_managed)s. This host will only manage "
  579                      "the storage pools: %(exist)s",
  580                      {'un_managed': ",".join(unmanaged_pools),
  581                       'exist': ",".join(matched_pools)})
  582         else:
  583             LOG.debug("Storage pools: %s will be managed.",
  584                       ",".join(matched_pools))
  585 
  586         return matched_pools
  587 
  588     @staticmethod
  589     def _get_nfs_location(file_interfaces, share_name):
  590         return [
  591             {'path': '%(interface)s:/%(share_name)s' % {
  592                 'interface': enas_utils.convert_ipv6_format_if_needed(
  593                     interface.ip_address),
  594                 'share_name': share_name}
  595              }
  596             for interface in file_interfaces
  597         ]
  598 
  599     @staticmethod
  600     def _get_pool_name_from_host(host):
  601         pool_name = share_utils.extract_host(host, level='pool')
  602         if not pool_name:
  603             message = (_("Pool is not available in the share host %s.") %
  604                        host)
  605             raise exception.InvalidHost(reason=message)
  606 
  607         return pool_name
  608 
  609     @staticmethod
  610     def _get_proto_enum(share_proto):
  611         share_proto = share_proto.upper()
  612         UnityStorageConnection._validate_share_protocol(share_proto)
  613 
  614         if share_proto == 'CIFS':
  615             return enums.FSSupportedProtocolEnum.CIFS
  616         elif share_proto == 'NFS':
  617             return enums.FSSupportedProtocolEnum.NFS
  618 
  619     @staticmethod
  620     def _get_server_name(share_server):
  621         if not share_server:
  622             msg = _('Share server not provided.')
  623             raise exception.InvalidInput(reason=msg)
  624 
  625         server_name = share_server.get(
  626             'backend_details', {}).get('share_server_name')
  627 
  628         if server_name is None:
  629             msg = (_("Name of the share server %s not found.")
  630                    % share_server['id'])
  631             LOG.error(msg)
  632             raise exception.InvalidInput(reason=msg)
  633 
  634         return server_name
  635 
  636     def _handle_security_services(self, nas_server, security_services):
  637         kerberos_enabled = False
  638         # Support 'active_directory' and 'kerberos'
  639         for security_service in security_services:
  640             service_type = security_service['type']
  641             if service_type == 'active_directory':
  642                 # Create DNS server for NAS server
  643                 domain = security_service['domain']
  644                 dns_ip = security_service['dns_ip']
  645                 self.client.create_dns_server(nas_server,
  646                                               domain,
  647                                               dns_ip)
  648 
  649                 # Enable CIFS service
  650                 username = security_service['user']
  651                 password = security_service['password']
  652                 self.client.enable_cifs_service(nas_server,
  653                                                 domain=domain,
  654                                                 username=username,
  655                                                 password=password)
  656             elif service_type == 'kerberos':
  657                 # Enable NFS service with kerberos
  658                 kerberos_enabled = True
  659                 # TODO(jay.xu): enable nfs service with kerberos
  660                 LOG.warning('Kerberos is not supported by '
  661                             'EMC Unity manila driver plugin.')
  662             elif service_type == 'ldap':
  663                 LOG.warning('LDAP is not supported by '
  664                             'EMC Unity manila driver plugin.')
  665             else:
  666                 LOG.warning('Unknown security service type: %s.',
  667                             service_type)
  668 
  669         if not kerberos_enabled:
  670             # Enable NFS service without kerberos
  671             self.client.enable_nfs_service(nas_server)
  672 
  673     def _nfs_allow_access(self, share, access):
  674         """Allow access to NFS share."""
  675         self.client.nfs_allow_access(
  676             share['id'], access['access_to'], access['access_level'])
  677 
  678     def _nfs_deny_access(self, share, access):
  679         """Deny access to NFS share."""
  680         self.client.nfs_deny_access(share['id'], access['access_to'])
  681 
  682     @staticmethod
  683     def _is_isolated_filesystem(filesystem):
  684         filesystem.update()
  685         return (
  686             not filesystem.has_snap() and
  687             not (filesystem.cifs_share or filesystem.nfs_share)
  688         )
  689 
  690     @staticmethod
  691     def _is_share_from_snapshot(share):
  692         return True if share.snap else False
  693 
  694     @staticmethod
  695     def _validate_share_access_type(share, access):
  696         reason = None
  697         share_proto = share['share_proto'].upper()
  698 
  699         if share_proto == 'CIFS' and access['access_type'] != 'user':
  700             reason = _('Only user access type allowed for CIFS share.')
  701         elif share_proto == 'NFS' and access['access_type'] != 'ip':
  702             reason = _('Only IP access type allowed for NFS share.')
  703 
  704         if reason:
  705             raise exception.InvalidShareAccess(reason=reason)
  706 
  707     @staticmethod
  708     def _validate_share_protocol(share_proto):
  709         if share_proto not in ('NFS', 'CIFS'):
  710             raise exception.InvalidShare(
  711                 reason=(_('Invalid NAS protocol supplied: %s.') %
  712                         share_proto))
  713 
  714     def revert_to_snapshot(self, context, snapshot, share_access_rules,
  715                            snapshot_access_rules, share_server=None):
  716         """Reverts a share (in place) to the specified snapshot."""
  717         return self.client.restore_snapshot(snapshot['id'])