Move NetAppApiClient to separate module
Created module manila.share.drivers.netapp.api. Implements bp add-netapp-clustered-share-driver Change-Id: I944fc688c18dceeeb114b5b84b5a8b6b1bf23b45
This commit is contained in:
parent
a8166d2e29
commit
488b11bdd1
|
@ -0,0 +1,113 @@
|
|||
import suds
|
||||
from suds.sax import text
|
||||
|
||||
from manila import exception
|
||||
from manila.openstack.common import log
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class NetAppApiClient(object):
|
||||
"""Wrapper around DFM commands."""
|
||||
|
||||
REQUIRED_FLAGS = ['netapp_nas_wsdl_url',
|
||||
'netapp_nas_login',
|
||||
'netapp_nas_password',
|
||||
'netapp_nas_server_hostname',
|
||||
'netapp_nas_server_port']
|
||||
|
||||
def __init__(self, configuration):
|
||||
self.configuration = configuration
|
||||
self._client = None
|
||||
|
||||
def do_setup(self):
|
||||
"""Setup suds (web services) client."""
|
||||
protocol = 'https' if self.configuration.netapp_nas_server_secure \
|
||||
else 'http'
|
||||
soap_url = ('%s://%s:%s/apis/soap/v1' %
|
||||
(protocol,
|
||||
self.configuration.netapp_nas_server_hostname,
|
||||
self.configuration.netapp_nas_server_port))
|
||||
|
||||
self._client = \
|
||||
suds.client.Client(self.configuration.netapp_nas_wsdl_url,
|
||||
username=self.configuration.netapp_nas_login,
|
||||
password=self.configuration.netapp_nas_password,
|
||||
location=soap_url)
|
||||
|
||||
LOG.info('NetApp RPC client started')
|
||||
|
||||
def send_request_to(self, target, request, xml_args=None,
|
||||
do_response_check=True):
|
||||
"""
|
||||
Sends RPC :request: to :target:.
|
||||
:param target: IP address, ID or network name of OnTap device
|
||||
:param request: API name
|
||||
:param xml_args: call arguments
|
||||
:param do_response_check: if set to True and RPC call has failed,
|
||||
raises exception.
|
||||
"""
|
||||
client = self._client
|
||||
srv = client.service
|
||||
|
||||
rpc = client.factory.create('Request')
|
||||
rpc.Name = request
|
||||
rpc.Args = text.Raw(xml_args)
|
||||
response = srv.ApiProxy(Request=rpc, Target=target)
|
||||
|
||||
if do_response_check:
|
||||
_check_response(rpc, response)
|
||||
|
||||
return response
|
||||
|
||||
def get_available_aggregates(self):
|
||||
"""Returns list of aggregates known by DFM."""
|
||||
srv = self._client.service
|
||||
resp = srv.AggregateListInfoIterStart()
|
||||
tag = resp.Tag
|
||||
|
||||
try:
|
||||
avail_aggrs = srv.AggregateListInfoIterNext(Tag=tag,
|
||||
Maximum=resp.Records)
|
||||
finally:
|
||||
srv.AggregateListInfoIterEnd(tag)
|
||||
|
||||
return avail_aggrs
|
||||
|
||||
def get_host_ip_by(self, host_id):
|
||||
"""Returns IP address of a host known by DFM."""
|
||||
if (type(host_id) is str or type(host_id) is unicode) and \
|
||||
len(host_id.split('.')) == 4:
|
||||
# already IP
|
||||
return host_id
|
||||
|
||||
client = self._client
|
||||
srv = client.service
|
||||
|
||||
filer_filter = client.factory.create('HostListInfoIterStart')
|
||||
filer_filter.ObjectNameOrId = host_id
|
||||
resp = srv.HostListInfoIterStart(HostListInfoIterStart=filer_filter)
|
||||
tag = resp.Tag
|
||||
|
||||
try:
|
||||
filers = srv.HostListInfoIterNext(Tag=tag, Maximum=resp.Records)
|
||||
finally:
|
||||
srv.HostListInfoIterEnd(Tag=tag)
|
||||
|
||||
ip = None
|
||||
for host in filers.Hosts.HostInfo:
|
||||
if int(host.HostId) == int(host_id):
|
||||
ip = host.HostAddress
|
||||
|
||||
return ip
|
||||
|
||||
@staticmethod
|
||||
def check_configuration(config_object):
|
||||
"""Ensure that the flags we care about are set."""
|
||||
for flag in NetAppApiClient.REQUIRED_FLAGS:
|
||||
if not getattr(config_object, flag, None):
|
||||
raise exception.Error(_('%s is not set') % flag)
|
|
@ -19,13 +19,10 @@ NetApp specific NAS storage driver. Supports NFS and CIFS protocols.
|
|||
This driver requires NetApp OnCommand 5.0 and one or more Data
|
||||
ONTAP 7-mode storage systems with installed CIFS and NFS licenses.
|
||||
"""
|
||||
import suds
|
||||
from suds.sax import text
|
||||
|
||||
from manila import exception
|
||||
from manila.openstack.common import log
|
||||
from manila.share import driver
|
||||
|
||||
from manila.share.drivers.netapp.api import NetAppApiClient
|
||||
from oslo.config import cfg
|
||||
|
||||
|
||||
|
@ -318,108 +315,6 @@ def _get_valid_snapshot_name(snapshot_id):
|
|||
return 'share_snapshot_' + snapshot_id.replace('-', '_')
|
||||
|
||||
|
||||
class NetAppApiClient(object):
|
||||
"""Wrapper around DFM commands."""
|
||||
|
||||
REQUIRED_FLAGS = ['netapp_nas_wsdl_url',
|
||||
'netapp_nas_login',
|
||||
'netapp_nas_password',
|
||||
'netapp_nas_server_hostname',
|
||||
'netapp_nas_server_port']
|
||||
|
||||
def __init__(self, configuration):
|
||||
self.configuration = configuration
|
||||
self._client = None
|
||||
|
||||
def do_setup(self):
|
||||
"""Setup suds (web services) client."""
|
||||
protocol = 'https' if self.configuration.netapp_nas_server_secure \
|
||||
else 'http'
|
||||
soap_url = ('%s://%s:%s/apis/soap/v1' %
|
||||
(protocol,
|
||||
self.configuration.netapp_nas_server_hostname,
|
||||
self.configuration.netapp_nas_server_port))
|
||||
|
||||
self._client = \
|
||||
suds.client.Client(self.configuration.netapp_nas_wsdl_url,
|
||||
username=self.configuration.netapp_nas_login,
|
||||
password=self.configuration.netapp_nas_password,
|
||||
location=soap_url)
|
||||
|
||||
LOG.info('NetApp RPC client started')
|
||||
|
||||
def send_request_to(self, target, request, xml_args=None,
|
||||
do_response_check=True):
|
||||
"""
|
||||
Sends RPC :request: to :target:.
|
||||
:param target: IP address, ID or network name of OnTap device
|
||||
:param request: API name
|
||||
:param xml_args: call arguments
|
||||
:param do_response_check: if set to True and RPC call has failed,
|
||||
raises exception.
|
||||
"""
|
||||
client = self._client
|
||||
srv = client.service
|
||||
|
||||
rpc = client.factory.create('Request')
|
||||
rpc.Name = request
|
||||
rpc.Args = text.Raw(xml_args)
|
||||
response = srv.ApiProxy(Request=rpc, Target=target)
|
||||
|
||||
if do_response_check:
|
||||
_check_response(rpc, response)
|
||||
|
||||
return response
|
||||
|
||||
def get_available_aggregates(self):
|
||||
"""Returns list of aggregates known by DFM."""
|
||||
srv = self._client.service
|
||||
resp = srv.AggregateListInfoIterStart()
|
||||
tag = resp.Tag
|
||||
|
||||
try:
|
||||
avail_aggrs = srv.AggregateListInfoIterNext(Tag=tag,
|
||||
Maximum=resp.Records)
|
||||
finally:
|
||||
srv.AggregateListInfoIterEnd(tag)
|
||||
|
||||
return avail_aggrs
|
||||
|
||||
def get_host_ip_by(self, host_id):
|
||||
"""Returns IP address of a host known by DFM."""
|
||||
if (type(host_id) is str or type(host_id) is unicode) and \
|
||||
len(host_id.split('.')) == 4:
|
||||
# already IP
|
||||
return host_id
|
||||
|
||||
client = self._client
|
||||
srv = client.service
|
||||
|
||||
filer_filter = client.factory.create('HostListInfoIterStart')
|
||||
filer_filter.ObjectNameOrId = host_id
|
||||
resp = srv.HostListInfoIterStart(HostListInfoIterStart=filer_filter)
|
||||
tag = resp.Tag
|
||||
|
||||
try:
|
||||
filers = srv.HostListInfoIterNext(Tag=tag, Maximum=resp.Records)
|
||||
finally:
|
||||
srv.HostListInfoIterEnd(Tag=tag)
|
||||
|
||||
ip = None
|
||||
for host in filers.Hosts.HostInfo:
|
||||
if int(host.HostId) == int(host_id):
|
||||
ip = host.HostAddress
|
||||
|
||||
return ip
|
||||
|
||||
@staticmethod
|
||||
def check_configuration(config_object):
|
||||
"""Ensure that the flags we care about are set."""
|
||||
for flag in NetAppApiClient.REQUIRED_FLAGS:
|
||||
if not getattr(config_object, flag, None):
|
||||
raise exception.Error(_('%s is not set') % flag)
|
||||
|
||||
|
||||
class NetAppNASHelperBase(object):
|
||||
"""Interface for protocol-specific NAS drivers."""
|
||||
def __init__(self, suds_client, config_object):
|
||||
|
|
Loading…
Reference in New Issue