1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011 Justin Santa Barbara
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
18
Default Driver for san-stored volumes.
20
The unique thing about a SAN is that we don't expect that we can run the volume
21
controller on the SAN hardware. We expect to access it over SSH or some API.
27
from eventlet import greenthread
29
from cinder import exception
30
from cinder import flags
31
from cinder.openstack.common import cfg
32
from cinder.openstack.common import log as logging
33
from cinder import utils
34
from cinder.volume.driver import ISCSIDriver
37
LOG = logging.getLogger(__name__)
40
cfg.BoolOpt('san_thin_provision',
42
help='Use thin provisioning for SAN volumes?'),
45
help='IP address of SAN controller'),
46
cfg.StrOpt('san_login',
48
help='Username for SAN controller'),
49
cfg.StrOpt('san_password',
51
help='Password for SAN controller'),
52
cfg.StrOpt('san_private_key',
54
help='Filename of private key to use for SSH authentication'),
55
cfg.StrOpt('san_clustername',
57
help='Cluster name to use for creating volumes'),
58
cfg.IntOpt('san_ssh_port',
60
help='SSH port to use with SAN'),
61
cfg.BoolOpt('san_is_local',
63
help='Execute commands locally instead of over SSH; '
64
'use if the volume service is running on the SAN device'),
65
cfg.IntOpt('ssh_conn_timeout',
67
help="SSH connection timeout in seconds"),
68
cfg.IntOpt('ssh_min_pool_conn',
70
help='Minimum ssh connections in the pool'),
71
cfg.IntOpt('ssh_max_pool_conn',
73
help='Maximum ssh connections in the pool'),
77
FLAGS.register_opts(san_opts)
80
class SanISCSIDriver(ISCSIDriver):
81
"""Base class for SAN-style storage volumes
83
A SAN-style storage value is 'different' because the volume controller
84
probably won't run on it, so we need to access is over SSH or another
88
def __init__(self, *args, **kwargs):
89
super(SanISCSIDriver, self).__init__(*args, **kwargs)
90
self.run_local = FLAGS.san_is_local
93
def _build_iscsi_target_name(self, volume):
94
return "%s%s" % (FLAGS.iscsi_target_prefix, volume['name'])
96
def _execute(self, *cmd, **kwargs):
98
return utils.execute(*cmd, **kwargs)
100
check_exit_code = kwargs.pop('check_exit_code', None)
101
command = ' '.join(cmd)
102
return self._run_ssh(command, check_exit_code)
104
def _run_ssh(self, command, check_exit_code=True, attempts=1):
106
self.sshpool = utils.SSHPool(FLAGS.san_ip,
108
FLAGS.ssh_conn_timeout,
110
password=FLAGS.san_password,
111
privatekey=FLAGS.san_private_key,
112
min_size=FLAGS.ssh_min_pool_conn,
113
max_size=FLAGS.ssh_max_pool_conn)
115
total_attempts = attempts
116
with self.sshpool.item() as ssh:
120
return utils.ssh_execute(ssh, command,
121
check_exit_code=check_exit_code)
122
except Exception as e:
124
greenthread.sleep(random.randint(20, 500) / 100.0)
125
raise paramiko.SSHException(_("SSH Command failed after "
126
"'%(total_attempts)r' attempts"
127
": '%(command)s'"), locals())
128
except Exception as e:
129
LOG.error(_("Error running ssh command: %s") % command)
132
def ensure_export(self, context, volume):
133
"""Synchronously recreates an export for a logical volume."""
136
def create_export(self, context, volume):
137
"""Exports the volume."""
140
def remove_export(self, context, volume):
141
"""Removes an export for a logical volume."""
144
def check_for_setup_error(self):
145
"""Returns an error if prerequisites aren't met."""
146
if not self.run_local:
147
if not (FLAGS.san_password or FLAGS.san_private_key):
148
raise exception.InvalidInput(
149
reason=_('Specify san_password or san_private_key'))
151
# The san_ip must always be set, because we use it for the target
153
raise exception.InvalidInput(reason=_("san_ip must be set"))