Merge lp:~justin-fathomdb/nova/justinsb-hpsan2 into lp:~hudson-openstack/nova/trunk

Proposed by justinsb
Status: Merged
Approved by: Jay Pipes
Approved revision: 707
Merge reported by: justinsb
Merged at revision: not available
Proposed branch: lp:~justin-fathomdb/nova/justinsb-hpsan2
Merge into: lp:~hudson-openstack/nova/trunk
Prerequisite: lp:~justin-fathomdb/nova/justinsb-metadata3
Diff against target: 741 lines (+514/-60)
5 files modified
nova/db/sqlalchemy/migrate_repo/versions/006_add_provider_data_to_volumes.py (+72/-0)
nova/db/sqlalchemy/models.py (+3/-0)
nova/volume/driver.py (+152/-27)
nova/volume/manager.py (+6/-2)
nova/volume/san.py (+281/-31)
To merge this branch: bzr merge lp:~justin-fathomdb/nova/justinsb-hpsan2
Reviewer Review Type Date Requested Status
Todd Willey (community) Approve
Devin Carlen (community) Approve
Jay Pipes (community) Approve
Review via email: mp+50869@code.launchpad.net

This proposal supersedes a proposal from 2011-02-22.

Description of the change

Support HP/LeftHand SANs. We control the SAN by SSHing and issuing CLIQ commands. Also improved the way iSCSI volumes are mounted: try to store the iSCSI connection info in the volume entity, in preference to doing discovery. Also CHAP authentication support.

CHAP support is necessary to avoid the attach-volume command require an export on the SAN device. If we had to do that, the attach command would have to hit both the volume controller and the compute controller, and that would be complex.

To post a comment you must log in.
Revision history for this message
Jay Pipes (jaypipes) wrote : Posted in a previous version of this proposal

Hi! As I said on IRC, not much I can review as far as the volume stuff goes, so here is some general feedback :)

1 === added file 'nova/db/sqlalchemy/migrate_repo/versions/003_cactus.py'

As you mentioned on IRC, I think it would be best to name this something like 003_add_provider_columns.py instead of 003_cactus.py, to make the actual migration file more descriptive of its contents...

74 + # Create tables
75 + for table in (
76 + #certificates, consoles, console_pools, instance_actions
77 + ):
78 + try:
79 + table.create()
80 + except Exception:
81 + logging.info(repr(table))
82 + logging.exception('Exception while creating table')
83 + raise
84 +
85 + # Alter column types
86 + # auth_tokens.c.user_id.alter(type=String(length=255,
87 + # convert_unicode=False,
88 + # assert_unicode=None,
89 + # unicode_error=None,
90 + # _warn_on_bytestring=False))

I recognize you probably commented that stuff out thinking that we are only using a single 003_cactus.py migration file, but if that migration file is renamed to something more descriptive (and we can have >1 migration file per release), obviously I think you should remove all that commented out code :)

Missed i18n in these locations:

139 + LOG.warn("ISCSI provider_location not stored, using discovery")
175 + LOG.debug("ISCSI Discovery: Found %s" % (location))
552 + raise exception.Error("local_path not supported")

For 175 above, please use the following instead:

LOG.debug(_("ISCSI Discovery: Found %s"), location)

Not sure if you meant to i18n this or not :)

457 + message = ("Unexpected number of virtual ips for cluster %s. "
458 + "Result=%s" %
459 + (cluster_name, ElementTree.tostring(cluster_xml)))

But if so, should be:

message = _("Unexpected number of virtual ips for cluster %(cluster)s. "
            "Result=%(result)s" % {'cluster': cluster_name,
                           'result': ElementTree.tostring(cluster_xml)})

Other than those little nits above, the only other advice I could give would be to maybe sprinkle a few LOG.debug()s around HpSanISCSIDriver methods and maybe add a bit of docstring documentation to HpSanISCSIDriver that gives the rough flow of the commands executed against the volume controller?

Cheers, and thanks for a great contribution!
jay

review: Needs Fixing
Revision history for this message
Todd Willey (xtoddx) wrote : Posted in a previous version of this proposal

If we're going to do something special with the return value of driver.create_volume and driver.update_volume, those should be documented as such, probably in nova/volume/driver.py#VolumeDriver (since all the others inherit from that).

I'm not well versed in iscsi, but I'd hope there would be a way to get more specific matches in _do_iscsi_discovery, maybe by making sure a field is surrounded by spaces, etc. The line I'm referencing is "if FLAGS.iscsi_ip_prefix in target and volume_name in target:". I'd hate for a target on 10.1.2.30 to match when we're looking for 10.1.2.3 just because one is a substring of the other.

It would also be great to document what fields should be in iscsi_properties, since this is a class that is inherited other places. A central point would be better than having to look it up in _run_iscsiadmin, discover_volume, etc, getting just a few of the fields each time.

I also see in HpSanISCSIDriver you're using CHAP, but in ISCSIDriver._do_iscsi_discovery you have a note that discovery doesn't work with CHAP. Can you let me know what I'm missing?

Also, I think it is strange for the volume layer to have knowledge of the database schema, and have to know column names and have a variable it returns called 'db_update'. Maybe just renaming it 'state_changes' or something would assuage my fear, and make me feel that if there was a schema change that would be okay because we don't actually have to pass the return value to database calls.

All in all a very nice contribution. ☺

Revision history for this message
Jay Pipes (jaypipes) wrote : Posted in a previous version of this proposal

Thanks for fixing up the few nits I brought up Justin. Approved from me from a style/overview perspective. I trust Todd and some others will more thoroughly review the call sequences to the volume drivers.

Cheers!
jay

review: Approve
Revision history for this message
justinsb (justin-fathomdb) wrote : Posted in a previous version of this proposal

I documented the return value in VolumeDriver create_volume & create_export.

I changed the name of the model state change Dictionary from db_update to model_update, based on your suggestion. The volume drivers are tightly coupled to the model definitions, so I don't think we're violating any separation of concerns. However, the naming "DB" was violating the separation, so I renamed it. Thanks for pointing this out.

The two new properties are 'provider_auth' and 'provider_location'. They're intended to be opaque properties for the driver's own use, but the natural assumption is that _location would be data as to the location and _auth info about authentication. I could use a dictionary instead, but I tried to pick two sensible fields that are hopefully fairly generic across drivers. Using a dictionary is problematic in terms of how it gets serialized efficiently. I documented the default iSCSI use of provider_location and provider_auth on ISCSIDriver.

The iSCSI discovery code is inherited, though the indentation level changed (I'm probably not blameless on the original code though!) I agree that it's fragile, so I'd like to move away from it. HP SANs and Solaris 'SANs' no longer use it; I can fix OpenISCSI next but that's a behavioural change on code that is potentially in active use so probably belongs in its own patch. There's a note that discovery is deprecated, but this code path is there until I can fix it for OpeniSCSI, but it is the same code as before. If you think I should clean it up in this patch I can do that, but I think it's best not to.

The CHAP authentication issue with discovery will go away when discovery is removed. HP SANs don't use discovery, and they're also the only ones using CHAP right now. If CHAP is supported with discovery (?), we'd definitely have to pass some extra parameters which aren't being passed right now, and I don't see the point of making this chaneg if I'm going to remove this code anyway :-)

I documented the current iscsi_properties (though I really don't know how to format this so it doesn't look terrible)

Revision history for this message
justinsb (justin-fathomdb) wrote : Posted in a previous version of this proposal

Fixed up code. Can't merge (or even run unit tests) until metadata patch merges though, because of numbering issues on the DB migrations.

Revision history for this message
Jay Pipes (jaypipes) wrote : Posted in a previous version of this proposal

> Fixed up code. Can't merge (or even run unit tests) until metadata patch
> merges though, because of numbering issues on the DB migrations.

Hi! There's a little-known feature of Launchpad's merge proposal system that allows you to set a "prerequisite branch". Edit the merge proposal and set the pre-requisite branch to your metadata branch, and Launchpad will:

* Not show any changes from the metadata branch in this merge proposal diff (this is so you can, say, merge your local metadata branch into this hpsan branch and not have the metadata changes show up in the merge diff here)
* Not allow someone to set this to Approved before the metadata branch is merged into trunk.

Cheers!
jay

Revision history for this message
justinsb (justin-fathomdb) wrote :

Added metadata as prerequisite branch. But can we get that merged please? I think it's good to go...

Revision history for this message
Todd Willey (xtoddx) wrote :

Looks pretty good. I'd suggest one more pass on the docstrings. Pep-257 outlines the format for multi-line docstrings, which is essentially that a short sentence goes on the first line, then you write the rest, and you end with a blank line.

You can look at nova/db/api.py to see how the flags in the database layer are documented in RST, which should be a good way to document the properties here as well.

Revision history for this message
Jay Pipes (jaypipes) wrote :

lgtm3

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve
Revision history for this message
FUJITA Tomonori (fujita-tomonori-deactivatedaccount) wrote :

I'm still learning how the volume stuff works but here are some comments about iSCSI stuff:

- Avoiding discovery session sounds better. You can directly insert the target info into open-iscsi db and let open-iscsi log in it.

- iSCSI supports the mutual authentication (the initiator can verify the target too) so it might be better to make 'provider_auth' capable to handle it.

- If you will not remove the discovery session, 'provider_auth' needs to handle discovery session CHAP auth too.

Revision history for this message
justinsb (justin-fathomdb) wrote :

Todd: Fixed docstrings so that they look better and comply with PEP 257. Is there an easy preview tool and PEP 257 checker?

FUJITA: The goal is to remove discovery. It's not done in this patch, but it's coming for OpeniSCSI. So I don't want to invest time in supporting CHAP at the moment for discovery, because that is hopefully going away, and CHAP isn't used with OpenISCSI at the moment anyway.

I do agree that mutual authentication would be nice, but I'd like to keep this patch as focused as is possible. It would be great if you want to add support!

Revision history for this message
Todd Willey (xtoddx) wrote :

Lets get this done!

review: Approve
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

No proposals found for merge of lp:~justin-fathomdb/nova/justinsb-metadata3 into lp:nova.

Revision history for this message
justinsb (justin-fathomdb) wrote :

Ah - I accidentally pushed trunk to the (already merged) justinsb-metadata3 branch, which I think is the cause of the above error from Hudson. Nonetheless, it looks like this branch did merge clean. I'm just double-checking that, but I put it back to 'merged' to stop mergebot getting really confused!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'nova/db/sqlalchemy/migrate_repo/versions/006_add_provider_data_to_volumes.py'
2--- nova/db/sqlalchemy/migrate_repo/versions/006_add_provider_data_to_volumes.py 1970-01-01 00:00:00 +0000
3+++ nova/db/sqlalchemy/migrate_repo/versions/006_add_provider_data_to_volumes.py 2011-02-24 06:50:14 +0000
4@@ -0,0 +1,72 @@
5+# vim: tabstop=4 shiftwidth=4 softtabstop=4
6+
7+# Copyright 2011 Justin Santa Barbara.
8+# All Rights Reserved.
9+#
10+# Licensed under the Apache License, Version 2.0 (the "License"); you may
11+# not use this file except in compliance with the License. You may obtain
12+# a copy of the License at
13+#
14+# http://www.apache.org/licenses/LICENSE-2.0
15+#
16+# Unless required by applicable law or agreed to in writing, software
17+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
19+# License for the specific language governing permissions and limitations
20+# under the License.
21+
22+from sqlalchemy import *
23+from migrate import *
24+
25+from nova import log as logging
26+
27+
28+meta = MetaData()
29+
30+
31+# Table stub-definitions
32+# Just for the ForeignKey and column creation to succeed, these are not the
33+# actual definitions of instances or services.
34+#
35+volumes = Table('volumes', meta,
36+ Column('id', Integer(), primary_key=True, nullable=False),
37+ )
38+
39+
40+#
41+# New Tables
42+#
43+# None
44+
45+#
46+# Tables to alter
47+#
48+# None
49+
50+#
51+# Columns to add to existing tables
52+#
53+
54+volumes_provider_location = Column('provider_location',
55+ String(length=256,
56+ convert_unicode=False,
57+ assert_unicode=None,
58+ unicode_error=None,
59+ _warn_on_bytestring=False))
60+
61+volumes_provider_auth = Column('provider_auth',
62+ String(length=256,
63+ convert_unicode=False,
64+ assert_unicode=None,
65+ unicode_error=None,
66+ _warn_on_bytestring=False))
67+
68+
69+def upgrade(migrate_engine):
70+ # Upgrade operations go here. Don't create your own engine;
71+ # bind migrate_engine to your metadata
72+ meta.bind = migrate_engine
73+
74+ # Add columns to existing tables
75+ volumes.create_column(volumes_provider_location)
76+ volumes.create_column(volumes_provider_auth)
77
78=== modified file 'nova/db/sqlalchemy/models.py'
79--- nova/db/sqlalchemy/models.py 2011-02-17 23:00:18 +0000
80+++ nova/db/sqlalchemy/models.py 2011-02-24 06:50:14 +0000
81@@ -243,6 +243,9 @@
82 display_name = Column(String(255))
83 display_description = Column(String(255))
84
85+ provider_location = Column(String(255))
86+ provider_auth = Column(String(255))
87+
88
89 class Quota(BASE, NovaBase):
90 """Represents quota overrides for a project."""
91
92=== modified file 'nova/volume/driver.py'
93--- nova/volume/driver.py 2011-02-04 17:04:55 +0000
94+++ nova/volume/driver.py 2011-02-24 06:50:14 +0000
95@@ -21,6 +21,7 @@
96 """
97
98 import time
99+import os
100
101 from nova import exception
102 from nova import flags
103@@ -36,6 +37,8 @@
104 'Which device to export the volumes on')
105 flags.DEFINE_string('num_shell_tries', 3,
106 'number of times to attempt to run flakey shell commands')
107+flags.DEFINE_string('num_iscsi_scan_tries', 3,
108+ 'number of times to rescan iSCSI target to find volume')
109 flags.DEFINE_integer('num_shelves',
110 100,
111 'Number of vblade shelves')
112@@ -88,7 +91,8 @@
113 % FLAGS.volume_group)
114
115 def create_volume(self, volume):
116- """Creates a logical volume."""
117+ """Creates a logical volume. Can optionally return a Dictionary of
118+ changes to the volume object to be persisted."""
119 if int(volume['size']) == 0:
120 sizestr = '100M'
121 else:
122@@ -123,7 +127,8 @@
123 raise NotImplementedError()
124
125 def create_export(self, context, volume):
126- """Exports the volume."""
127+ """Exports the volume. Can optionally return a Dictionary of changes
128+ to the volume object to be persisted."""
129 raise NotImplementedError()
130
131 def remove_export(self, context, volume):
132@@ -222,7 +227,18 @@
133
134
135 class ISCSIDriver(VolumeDriver):
136- """Executes commands relating to ISCSI volumes."""
137+ """Executes commands relating to ISCSI volumes.
138+
139+ We make use of model provider properties as follows:
140+
141+ :provider_location: if present, contains the iSCSI target information
142+ in the same format as an ietadm discovery
143+ i.e. '<ip>:<port>,<portal> <target IQN>'
144+
145+ :provider_auth: if present, contains a space-separated triple:
146+ '<auth method> <auth username> <auth password>'.
147+ `CHAP` is the only auth_method in use at the moment.
148+ """
149
150 def ensure_export(self, context, volume):
151 """Synchronously recreates an export for a logical volume."""
152@@ -294,40 +310,149 @@
153 self._execute("sudo ietadm --op delete --tid=%s" %
154 iscsi_target)
155
156- def _get_name_and_portal(self, volume):
157- """Gets iscsi name and portal from volume name and host."""
158+ def _do_iscsi_discovery(self, volume):
159+ #TODO(justinsb): Deprecate discovery and use stored info
160+ #NOTE(justinsb): Discovery won't work with CHAP-secured targets (?)
161+ LOG.warn(_("ISCSI provider_location not stored, using discovery"))
162+
163 volume_name = volume['name']
164- host = volume['host']
165+
166 (out, _err) = self._execute("sudo iscsiadm -m discovery -t "
167- "sendtargets -p %s" % host)
168+ "sendtargets -p %s" % (volume['host']))
169 for target in out.splitlines():
170 if FLAGS.iscsi_ip_prefix in target and volume_name in target:
171- (location, _sep, iscsi_name) = target.partition(" ")
172- break
173- iscsi_portal = location.split(",")[0]
174- return (iscsi_name, iscsi_portal)
175+ return target
176+ return None
177+
178+ def _get_iscsi_properties(self, volume):
179+ """Gets iscsi configuration
180+
181+ We ideally get saved information in the volume entity, but fall back
182+ to discovery if need be. Discovery may be completely removed in future
183+ The properties are:
184+
185+ :target_discovered: boolean indicating whether discovery was used
186+
187+ :target_iqn: the IQN of the iSCSI target
188+
189+ :target_portal: the portal of the iSCSI target
190+
191+ :auth_method:, :auth_username:, :auth_password:
192+
193+ the authentication details. Right now, either auth_method is not
194+ present meaning no authentication, or auth_method == `CHAP`
195+ meaning use CHAP with the specified credentials.
196+ """
197+
198+ properties = {}
199+
200+ location = volume['provider_location']
201+
202+ if location:
203+ # provider_location is the same format as iSCSI discovery output
204+ properties['target_discovered'] = False
205+ else:
206+ location = self._do_iscsi_discovery(volume)
207+
208+ if not location:
209+ raise exception.Error(_("Could not find iSCSI export "
210+ " for volume %s") %
211+ (volume['name']))
212+
213+ LOG.debug(_("ISCSI Discovery: Found %s") % (location))
214+ properties['target_discovered'] = True
215+
216+ (iscsi_target, _sep, iscsi_name) = location.partition(" ")
217+
218+ iscsi_portal = iscsi_target.split(",")[0]
219+
220+ properties['target_iqn'] = iscsi_name
221+ properties['target_portal'] = iscsi_portal
222+
223+ auth = volume['provider_auth']
224+
225+ if auth:
226+ (auth_method, auth_username, auth_secret) = auth.split()
227+
228+ properties['auth_method'] = auth_method
229+ properties['auth_username'] = auth_username
230+ properties['auth_password'] = auth_secret
231+
232+ return properties
233+
234+ def _run_iscsiadm(self, iscsi_properties, iscsi_command):
235+ command = ("sudo iscsiadm -m node -T %s -p %s %s" %
236+ (iscsi_properties['target_iqn'],
237+ iscsi_properties['target_portal'],
238+ iscsi_command))
239+ (out, err) = self._execute(command)
240+ LOG.debug("iscsiadm %s: stdout=%s stderr=%s" %
241+ (iscsi_command, out, err))
242+ return (out, err)
243+
244+ def _iscsiadm_update(self, iscsi_properties, property_key, property_value):
245+ iscsi_command = ("--op update -n %s -v %s" %
246+ (property_key, property_value))
247+ return self._run_iscsiadm(iscsi_properties, iscsi_command)
248
249 def discover_volume(self, volume):
250 """Discover volume on a remote host."""
251- iscsi_name, iscsi_portal = self._get_name_and_portal(volume)
252- self._execute("sudo iscsiadm -m node -T %s -p %s --login" %
253- (iscsi_name, iscsi_portal))
254- self._execute("sudo iscsiadm -m node -T %s -p %s --op update "
255- "-n node.startup -v automatic" %
256- (iscsi_name, iscsi_portal))
257- return "/dev/disk/by-path/ip-%s-iscsi-%s-lun-0" % (iscsi_portal,
258- iscsi_name)
259+ iscsi_properties = self._get_iscsi_properties(volume)
260+
261+ if not iscsi_properties['target_discovered']:
262+ self._run_iscsiadm(iscsi_properties, "--op new")
263+
264+ if iscsi_properties.get('auth_method'):
265+ self._iscsiadm_update(iscsi_properties,
266+ "node.session.auth.authmethod",
267+ iscsi_properties['auth_method'])
268+ self._iscsiadm_update(iscsi_properties,
269+ "node.session.auth.username",
270+ iscsi_properties['auth_username'])
271+ self._iscsiadm_update(iscsi_properties,
272+ "node.session.auth.password",
273+ iscsi_properties['auth_password'])
274+
275+ self._run_iscsiadm(iscsi_properties, "--login")
276+
277+ self._iscsiadm_update(iscsi_properties, "node.startup", "automatic")
278+
279+ mount_device = ("/dev/disk/by-path/ip-%s-iscsi-%s-lun-0" %
280+ (iscsi_properties['target_portal'],
281+ iscsi_properties['target_iqn']))
282+
283+ # The /dev/disk/by-path/... node is not always present immediately
284+ # TODO(justinsb): This retry-with-delay is a pattern, move to utils?
285+ tries = 0
286+ while not os.path.exists(mount_device):
287+ if tries >= FLAGS.num_iscsi_scan_tries:
288+ raise exception.Error(_("iSCSI device not found at %s") %
289+ (mount_device))
290+
291+ LOG.warn(_("ISCSI volume not yet found at: %(mount_device)s. "
292+ "Will rescan & retry. Try number: %(tries)s") %
293+ locals())
294+
295+ # The rescan isn't documented as being necessary(?), but it helps
296+ self._run_iscsiadm(iscsi_properties, "--rescan")
297+
298+ tries = tries + 1
299+ if not os.path.exists(mount_device):
300+ time.sleep(tries ** 2)
301+
302+ if tries != 0:
303+ LOG.debug(_("Found iSCSI node %(mount_device)s "
304+ "(after %(tries)s rescans)") %
305+ locals())
306+
307+ return mount_device
308
309 def undiscover_volume(self, volume):
310 """Undiscover volume on a remote host."""
311- iscsi_name, iscsi_portal = self._get_name_and_portal(volume)
312- self._execute("sudo iscsiadm -m node -T %s -p %s --op update "
313- "-n node.startup -v manual" %
314- (iscsi_name, iscsi_portal))
315- self._execute("sudo iscsiadm -m node -T %s -p %s --logout " %
316- (iscsi_name, iscsi_portal))
317- self._execute("sudo iscsiadm -m node --op delete "
318- "--targetname %s" % iscsi_name)
319+ iscsi_properties = self._get_iscsi_properties(volume)
320+ self._iscsiadm_update(iscsi_properties, "node.startup", "manual")
321+ self._run_iscsiadm(iscsi_properties, "--logout")
322+ self._run_iscsiadm(iscsi_properties, "--op delete")
323
324
325 class FakeISCSIDriver(ISCSIDriver):
326
327=== modified file 'nova/volume/manager.py'
328--- nova/volume/manager.py 2011-02-15 18:19:52 +0000
329+++ nova/volume/manager.py 2011-02-24 06:50:14 +0000
330@@ -107,10 +107,14 @@
331 vol_size = volume_ref['size']
332 LOG.debug(_("volume %(vol_name)s: creating lv of"
333 " size %(vol_size)sG") % locals())
334- self.driver.create_volume(volume_ref)
335+ model_update = self.driver.create_volume(volume_ref)
336+ if model_update:
337+ self.db.volume_update(context, volume_ref['id'], model_update)
338
339 LOG.debug(_("volume %s: creating export"), volume_ref['name'])
340- self.driver.create_export(context, volume_ref)
341+ model_update = self.driver.create_export(context, volume_ref)
342+ if model_update:
343+ self.db.volume_update(context, volume_ref['id'], model_update)
344 except Exception:
345 self.db.volume_update(context,
346 volume_ref['id'], {'status': 'error'})
347
348=== modified file 'nova/volume/san.py'
349--- nova/volume/san.py 2011-02-09 19:25:18 +0000
350+++ nova/volume/san.py 2011-02-24 06:50:14 +0000
351@@ -16,13 +16,16 @@
352 # under the License.
353 """
354 Drivers for san-stored volumes.
355+
356 The unique thing about a SAN is that we don't expect that we can run the volume
357- controller on the SAN hardware. We expect to access it over SSH or some API.
358+controller on the SAN hardware. We expect to access it over SSH or some API.
359 """
360
361 import os
362 import paramiko
363
364+from xml.etree import ElementTree
365+
366 from nova import exception
367 from nova import flags
368 from nova import log as logging
369@@ -41,37 +44,19 @@
370 'Password for SAN controller')
371 flags.DEFINE_string('san_privatekey', '',
372 'Filename of private key to use for SSH authentication')
373+flags.DEFINE_string('san_clustername', '',
374+ 'Cluster name to use for creating volumes')
375+flags.DEFINE_integer('san_ssh_port', 22,
376+ 'SSH port to use with SAN')
377
378
379 class SanISCSIDriver(ISCSIDriver):
380 """ Base class for SAN-style storage volumes
381- (storage providers we access over SSH)"""
382- #Override because SAN ip != host ip
383- def _get_name_and_portal(self, volume):
384- """Gets iscsi name and portal from volume name and host."""
385- volume_name = volume['name']
386-
387- # TODO(justinsb): store in volume, remerge with generic iSCSI code
388- host = FLAGS.san_ip
389-
390- (out, _err) = self._execute("sudo iscsiadm -m discovery -t "
391- "sendtargets -p %s" % host)
392-
393- location = None
394- find_iscsi_name = self._build_iscsi_target_name(volume)
395- for target in out.splitlines():
396- if find_iscsi_name in target:
397- (location, _sep, iscsi_name) = target.partition(" ")
398- break
399- if not location:
400- raise exception.Error(_("Could not find iSCSI export "
401- " for volume %s") %
402- volume_name)
403-
404- iscsi_portal = location.split(",")[0]
405- LOG.debug("iscsi_name=%s, iscsi_portal=%s" %
406- (iscsi_name, iscsi_portal))
407- return (iscsi_name, iscsi_portal)
408+
409+ A SAN-style storage value is 'different' because the volume controller
410+ probably won't run on it, so we need to access is over SSH or another
411+ remote protocol.
412+ """
413
414 def _build_iscsi_target_name(self, volume):
415 return "%s%s" % (FLAGS.iscsi_target_prefix, volume['name'])
416@@ -85,6 +70,7 @@
417 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
418 if FLAGS.san_password:
419 ssh.connect(FLAGS.san_ip,
420+ port=FLAGS.san_ssh_port,
421 username=FLAGS.san_login,
422 password=FLAGS.san_password)
423 elif FLAGS.san_privatekey:
424@@ -92,10 +78,11 @@
425 # It sucks that paramiko doesn't support DSA keys
426 privatekey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
427 ssh.connect(FLAGS.san_ip,
428+ port=FLAGS.san_ssh_port,
429 username=FLAGS.san_login,
430 pkey=privatekey)
431 else:
432- raise exception.Error("Specify san_password or san_privatekey")
433+ raise exception.Error(_("Specify san_password or san_privatekey"))
434 return ssh
435
436 def _run_ssh(self, command, check_exit_code=True):
437@@ -124,10 +111,10 @@
438 def check_for_setup_error(self):
439 """Returns an error if prerequisites aren't met"""
440 if not (FLAGS.san_password or FLAGS.san_privatekey):
441- raise exception.Error("Specify san_password or san_privatekey")
442+ raise exception.Error(_("Specify san_password or san_privatekey"))
443
444 if not (FLAGS.san_ip):
445- raise exception.Error("san_ip must be set")
446+ raise exception.Error(_("san_ip must be set"))
447
448
449 def _collect_lines(data):
450@@ -155,17 +142,27 @@
451
452 class SolarisISCSIDriver(SanISCSIDriver):
453 """Executes commands relating to Solaris-hosted ISCSI volumes.
454+
455 Basic setup for a Solaris iSCSI server:
456+
457 pkg install storage-server SUNWiscsit
458+
459 svcadm enable stmf
460+
461 svcadm enable -r svc:/network/iscsi/target:default
462+
463 pfexec itadm create-tpg e1000g0 ${MYIP}
464+
465 pfexec itadm create-target -t e1000g0
466
467+
468 Then grant the user that will be logging on lots of permissions.
469 I'm not sure exactly which though:
470+
471 zfs allow justinsb create,mount,destroy rpool
472+
473 usermod -P'File System Management' justinsb
474+
475 usermod -P'Primary Administrator' justinsb
476
477 Also make sure you can login using san_login & san_password/san_privatekey
478@@ -306,6 +303,17 @@
479 self._run_ssh("pfexec /usr/sbin/stmfadm add-view -t %s %s" %
480 (target_group_name, luid))
481
482+ #TODO(justinsb): Is this always 1? Does it matter?
483+ iscsi_portal_interface = '1'
484+ iscsi_portal = FLAGS.san_ip + ":3260," + iscsi_portal_interface
485+
486+ db_update = {}
487+ db_update['provider_location'] = ("%s %s" %
488+ (iscsi_portal,
489+ iscsi_name))
490+
491+ return db_update
492+
493 def remove_export(self, context, volume):
494 """Removes an export for a logical volume."""
495
496@@ -333,3 +341,245 @@
497 if self._is_lu_created(volume):
498 self._run_ssh("pfexec /usr/sbin/sbdadm delete-lu %s" %
499 (luid))
500+
501+
502+class HpSanISCSIDriver(SanISCSIDriver):
503+ """Executes commands relating to HP/Lefthand SAN ISCSI volumes.
504+
505+ We use the CLIQ interface, over SSH.
506+
507+ Rough overview of CLIQ commands used:
508+
509+ :createVolume: (creates the volume)
510+
511+ :getVolumeInfo: (to discover the IQN etc)
512+
513+ :getClusterInfo: (to discover the iSCSI target IP address)
514+
515+ :assignVolumeChap: (exports it with CHAP security)
516+
517+ The 'trick' here is that the HP SAN enforces security by default, so
518+ normally a volume mount would need both to configure the SAN in the volume
519+ layer and do the mount on the compute layer. Multi-layer operations are
520+ not catered for at the moment in the nova architecture, so instead we
521+ share the volume using CHAP at volume creation time. Then the mount need
522+ only use those CHAP credentials, so can take place exclusively in the
523+ compute layer.
524+ """
525+
526+ def _cliq_run(self, verb, cliq_args):
527+ """Runs a CLIQ command over SSH, without doing any result parsing"""
528+ cliq_arg_strings = []
529+ for k, v in cliq_args.items():
530+ cliq_arg_strings.append(" %s=%s" % (k, v))
531+ cmd = verb + ''.join(cliq_arg_strings)
532+
533+ return self._run_ssh(cmd)
534+
535+ def _cliq_run_xml(self, verb, cliq_args, check_cliq_result=True):
536+ """Runs a CLIQ command over SSH, parsing and checking the output"""
537+ cliq_args['output'] = 'XML'
538+ (out, _err) = self._cliq_run(verb, cliq_args)
539+
540+ LOG.debug(_("CLIQ command returned %s"), out)
541+
542+ result_xml = ElementTree.fromstring(out)
543+ if check_cliq_result:
544+ response_node = result_xml.find("response")
545+ if response_node is None:
546+ msg = (_("Malformed response to CLIQ command "
547+ "%(verb)s %(cliq_args)s. Result=%(out)s") %
548+ locals())
549+ raise exception.Error(msg)
550+
551+ result_code = response_node.attrib.get("result")
552+
553+ if result_code != "0":
554+ msg = (_("Error running CLIQ command %(verb)s %(cliq_args)s. "
555+ " Result=%(out)s") %
556+ locals())
557+ raise exception.Error(msg)
558+
559+ return result_xml
560+
561+ def _cliq_get_cluster_info(self, cluster_name):
562+ """Queries for info about the cluster (including IP)"""
563+ cliq_args = {}
564+ cliq_args['clusterName'] = cluster_name
565+ cliq_args['searchDepth'] = '1'
566+ cliq_args['verbose'] = '0'
567+
568+ result_xml = self._cliq_run_xml("getClusterInfo", cliq_args)
569+
570+ return result_xml
571+
572+ def _cliq_get_cluster_vip(self, cluster_name):
573+ """Gets the IP on which a cluster shares iSCSI volumes"""
574+ cluster_xml = self._cliq_get_cluster_info(cluster_name)
575+
576+ vips = []
577+ for vip in cluster_xml.findall("response/cluster/vip"):
578+ vips.append(vip.attrib.get('ipAddress'))
579+
580+ if len(vips) == 1:
581+ return vips[0]
582+
583+ _xml = ElementTree.tostring(cluster_xml)
584+ msg = (_("Unexpected number of virtual ips for cluster "
585+ " %(cluster_name)s. Result=%(_xml)s") %
586+ locals())
587+ raise exception.Error(msg)
588+
589+ def _cliq_get_volume_info(self, volume_name):
590+ """Gets the volume info, including IQN"""
591+ cliq_args = {}
592+ cliq_args['volumeName'] = volume_name
593+ result_xml = self._cliq_run_xml("getVolumeInfo", cliq_args)
594+
595+ # Result looks like this:
596+ #<gauche version="1.0">
597+ # <response description="Operation succeeded." name="CliqSuccess"
598+ # processingTime="87" result="0">
599+ # <volume autogrowPages="4" availability="online" blockSize="1024"
600+ # bytesWritten="0" checkSum="false" clusterName="Cluster01"
601+ # created="2011-02-08T19:56:53Z" deleting="false" description=""
602+ # groupName="Group01" initialQuota="536870912" isPrimary="true"
603+ # iscsiIqn="iqn.2003-10.com.lefthandnetworks:group01:25366:vol-b"
604+ # maxSize="6865387257856" md5="9fa5c8b2cca54b2948a63d833097e1ca"
605+ # minReplication="1" name="vol-b" parity="0" replication="2"
606+ # reserveQuota="536870912" scratchQuota="4194304"
607+ # serialNumber="9fa5c8b2cca54b2948a63d833097e1ca0000000000006316"
608+ # size="1073741824" stridePages="32" thinProvision="true">
609+ # <status description="OK" value="2"/>
610+ # <permission access="rw"
611+ # authGroup="api-34281B815713B78-(trimmed)51ADD4B7030853AA7"
612+ # chapName="chapusername" chapRequired="true" id="25369"
613+ # initiatorSecret="" iqn="" iscsiEnabled="true"
614+ # loadBalance="true" targetSecret="supersecret"/>
615+ # </volume>
616+ # </response>
617+ #</gauche>
618+
619+ # Flatten the nodes into a dictionary; use prefixes to avoid collisions
620+ volume_attributes = {}
621+
622+ volume_node = result_xml.find("response/volume")
623+ for k, v in volume_node.attrib.items():
624+ volume_attributes["volume." + k] = v
625+
626+ status_node = volume_node.find("status")
627+ if not status_node is None:
628+ for k, v in status_node.attrib.items():
629+ volume_attributes["status." + k] = v
630+
631+ # We only consider the first permission node
632+ permission_node = volume_node.find("permission")
633+ if not permission_node is None:
634+ for k, v in status_node.attrib.items():
635+ volume_attributes["permission." + k] = v
636+
637+ LOG.debug(_("Volume info: %(volume_name)s => %(volume_attributes)s") %
638+ locals())
639+ return volume_attributes
640+
641+ def create_volume(self, volume):
642+ """Creates a volume."""
643+ cliq_args = {}
644+ cliq_args['clusterName'] = FLAGS.san_clustername
645+ #TODO(justinsb): Should we default to inheriting thinProvision?
646+ cliq_args['thinProvision'] = '1' if FLAGS.san_thin_provision else '0'
647+ cliq_args['volumeName'] = volume['name']
648+ if int(volume['size']) == 0:
649+ cliq_args['size'] = '100MB'
650+ else:
651+ cliq_args['size'] = '%sGB' % volume['size']
652+
653+ self._cliq_run_xml("createVolume", cliq_args)
654+
655+ volume_info = self._cliq_get_volume_info(volume['name'])
656+ cluster_name = volume_info['volume.clusterName']
657+ iscsi_iqn = volume_info['volume.iscsiIqn']
658+
659+ #TODO(justinsb): Is this always 1? Does it matter?
660+ cluster_interface = '1'
661+
662+ cluster_vip = self._cliq_get_cluster_vip(cluster_name)
663+ iscsi_portal = cluster_vip + ":3260," + cluster_interface
664+
665+ model_update = {}
666+ model_update['provider_location'] = ("%s %s" %
667+ (iscsi_portal,
668+ iscsi_iqn))
669+
670+ return model_update
671+
672+ def delete_volume(self, volume):
673+ """Deletes a volume."""
674+ cliq_args = {}
675+ cliq_args['volumeName'] = volume['name']
676+ cliq_args['prompt'] = 'false' # Don't confirm
677+
678+ self._cliq_run_xml("deleteVolume", cliq_args)
679+
680+ def local_path(self, volume):
681+ # TODO(justinsb): Is this needed here?
682+ raise exception.Error(_("local_path not supported"))
683+
684+ def ensure_export(self, context, volume):
685+ """Synchronously recreates an export for a logical volume."""
686+ return self._do_export(context, volume, force_create=False)
687+
688+ def create_export(self, context, volume):
689+ return self._do_export(context, volume, force_create=True)
690+
691+ def _do_export(self, context, volume, force_create):
692+ """Supports ensure_export and create_export"""
693+ volume_info = self._cliq_get_volume_info(volume['name'])
694+
695+ is_shared = 'permission.authGroup' in volume_info
696+
697+ model_update = {}
698+
699+ should_export = False
700+
701+ if force_create or not is_shared:
702+ should_export = True
703+ # Check that we have a project_id
704+ project_id = volume['project_id']
705+ if not project_id:
706+ project_id = context.project_id
707+
708+ if project_id:
709+ #TODO(justinsb): Use a real per-project password here
710+ chap_username = 'proj_' + project_id
711+ # HP/Lefthand requires that the password be >= 12 characters
712+ chap_password = 'project_secret_' + project_id
713+ else:
714+ msg = (_("Could not determine project for volume %s, "
715+ "can't export") %
716+ (volume['name']))
717+ if force_create:
718+ raise exception.Error(msg)
719+ else:
720+ LOG.warn(msg)
721+ should_export = False
722+
723+ if should_export:
724+ cliq_args = {}
725+ cliq_args['volumeName'] = volume['name']
726+ cliq_args['chapName'] = chap_username
727+ cliq_args['targetSecret'] = chap_password
728+
729+ self._cliq_run_xml("assignVolumeChap", cliq_args)
730+
731+ model_update['provider_auth'] = ("CHAP %s %s" %
732+ (chap_username, chap_password))
733+
734+ return model_update
735+
736+ def remove_export(self, context, volume):
737+ """Removes an export for a logical volume."""
738+ cliq_args = {}
739+ cliq_args['volumeName'] = volume['name']
740+
741+ self._cliq_run_xml("unassignVolume", cliq_args)