"Fossies" - the Fresh Open Source Software Archive

Member "cinder-13.0.7/cinder/volume/drivers/netapp/dataontap/utils/utils.py" (4 Oct 2019, 4177 Bytes) of package /linux/misc/openstack/cinder-13.0.7.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. For more information about "utils.py" see the Fossies "Dox" file reference documentation.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 """
   13 Utilities for NetApp FAS drivers.
   14 
   15 This module contains common utilities to be used by one or more
   16 NetApp FAS drivers to achieve the desired functionality.
   17 """
   18 
   19 import json
   20 import socket
   21 
   22 from oslo_config import cfg
   23 from oslo_log import log
   24 
   25 from cinder import exception
   26 from cinder.i18n import _
   27 from cinder import utils
   28 from cinder.volume import configuration
   29 from cinder.volume import driver
   30 from cinder.volume.drivers.netapp.dataontap.client import client_cmode
   31 from cinder.volume.drivers.netapp import options as na_opts
   32 
   33 LOG = log.getLogger(__name__)
   34 CONF = cfg.CONF
   35 
   36 
   37 def get_backend_configuration(backend_name):
   38     """Get a cDOT configuration object for a specific backend."""
   39 
   40     config_stanzas = CONF.list_all_sections()
   41     if backend_name not in config_stanzas:
   42         msg = _("Could not find backend stanza %(backend_name)s in "
   43                 "configuration. Available stanzas are %(stanzas)s")
   44         params = {
   45             "stanzas": config_stanzas,
   46             "backend_name": backend_name,
   47         }
   48         raise exception.ConfigNotFound(message=msg % params)
   49 
   50     config = configuration.Configuration(driver.volume_opts,
   51                                          config_group=backend_name)
   52     config.append_config_values(na_opts.netapp_proxy_opts)
   53     config.append_config_values(na_opts.netapp_connection_opts)
   54     config.append_config_values(na_opts.netapp_transport_opts)
   55     config.append_config_values(na_opts.netapp_basicauth_opts)
   56     config.append_config_values(na_opts.netapp_provisioning_opts)
   57     config.append_config_values(na_opts.netapp_cluster_opts)
   58     config.append_config_values(na_opts.netapp_san_opts)
   59     config.append_config_values(na_opts.netapp_replication_opts)
   60     config.append_config_values(na_opts.netapp_support_opts)
   61 
   62     return config
   63 
   64 
   65 def get_client_for_backend(backend_name, vserver_name=None):
   66     """Get a cDOT API client for a specific backend."""
   67 
   68     config = get_backend_configuration(backend_name)
   69     client = client_cmode.Client(
   70         transport_type=config.netapp_transport_type,
   71         username=config.netapp_login,
   72         password=config.netapp_password,
   73         hostname=config.netapp_server_hostname,
   74         port=config.netapp_server_port,
   75         vserver=vserver_name or config.netapp_vserver,
   76         trace=utils.TRACE_API,
   77         api_trace_pattern=config.netapp_api_trace_pattern)
   78 
   79     return client
   80 
   81 
   82 def _build_base_ems_log_message(driver_name, app_version):
   83 
   84     ems_log = {
   85         'computer-name': socket.gethostname() or 'Cinder_node',
   86         'event-source': 'Cinder driver %s' % driver_name,
   87         'app-version': app_version,
   88         'category': 'provisioning',
   89         'log-level': '5',
   90         'auto-support': 'false',
   91     }
   92     return ems_log
   93 
   94 
   95 def build_ems_log_message_0(driver_name, app_version):
   96     """Construct EMS Autosupport log message with deployment info."""
   97     ems_log = _build_base_ems_log_message(driver_name, app_version)
   98     ems_log['event-id'] = '0'
   99     ems_log['event-description'] = 'OpenStack Cinder connected to cluster node'
  100     return ems_log
  101 
  102 
  103 def build_ems_log_message_1(driver_name, app_version, vserver,
  104                             flexvol_pools, aggregate_pools):
  105     """Construct EMS Autosupport log message with storage pool info."""
  106 
  107     message = {
  108         'pools': {
  109             'vserver': vserver,
  110             'aggregates': aggregate_pools,
  111             'flexvols': flexvol_pools,
  112         },
  113     }
  114 
  115     ems_log = _build_base_ems_log_message(driver_name, app_version)
  116     ems_log['event-id'] = '1'
  117     ems_log['event-description'] = json.dumps(message)
  118     return ems_log