~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/virt/xenapi/volume_utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import re
23
23
import string
24
24
 
 
25
from nova import context
25
26
from nova import db
26
 
from nova import context
27
27
from nova import exception
28
28
from nova import flags
29
29
from nova import log as logging
71
71
            LOG.debug(_('Created %(label)s as %(sr_ref)s.') % locals())
72
72
            return sr_ref
73
73
 
74
 
        except cls.XenAPI.Failure, exc:
 
74
        except session.XenAPI.Failure, exc:
75
75
            LOG.exception(exc)
76
76
            raise StorageError(_('Unable to create Storage Repository'))
77
77
 
111
111
            session.call_xenapi("SR.scan", sr_ref)
112
112
            return sr_ref
113
113
 
114
 
        except cls.XenAPI.Failure, exc:
 
114
        except session.XenAPI.Failure, exc:
115
115
            LOG.exception(exc)
116
116
            raise StorageError(_('Unable to introduce Storage Repository'))
117
117
 
122
122
        """
123
123
        try:
124
124
            sr_ref = session.call_xenapi("SR.get_by_uuid", sr_uuid)
125
 
        except cls.XenAPI.Failure, exc:
 
125
        except session.XenAPI.Failure, exc:
126
126
            LOG.exception(exc)
127
127
            raise StorageError(_('Unable to get SR using uuid'))
128
128
 
132
132
            cls.unplug_pbds(session, sr_ref)
133
133
            sr_ref = session.call_xenapi("SR.forget", sr_ref)
134
134
 
135
 
        except cls.XenAPI.Failure, exc:
 
135
        except session.XenAPI.Failure, exc:
136
136
            LOG.exception(exc)
137
137
            raise StorageError(_('Unable to forget Storage Repository'))
138
138
 
169
169
            try:
170
170
                LOG.debug(_('Introduced %(label)s as %(sr_ref)s.') % locals())
171
171
                return sr_ref
172
 
            except cls.XenAPI.Failure, exc:
 
172
            except session.XenAPI.Failure, exc:
173
173
                LOG.exception(exc)
174
174
                raise StorageError(_('Unable to create Storage Repository'))
175
175
        else:
181
181
        try:
182
182
            vdi_ref = session.call_xenapi("VBD.get_VDI", vbd_ref)
183
183
            sr_ref = session.call_xenapi("VDI.get_SR", vdi_ref)
184
 
        except cls.XenAPI.Failure, exc:
 
184
        except session.XenAPI.Failure, exc:
185
185
            LOG.exception(exc)
186
186
            raise StorageError(_('Unable to find SR from VBD %s') % vbd_ref)
187
187
        return sr_ref
200
200
        pbds = []
201
201
        try:
202
202
            pbds = session.call_xenapi("SR.get_PBDs", sr_ref)
203
 
        except cls.XenAPI.Failure, exc:
 
203
        except session.XenAPI.Failure, exc:
204
204
            LOG.warn(_('Ignoring exception %(exc)s when getting PBDs'
205
205
                    ' for %(sr_ref)s') % locals())
206
206
        for pbd in pbds:
207
207
            try:
208
208
                session.call_xenapi("PBD.unplug", pbd)
209
 
            except cls.XenAPI.Failure, exc:
 
209
            except session.XenAPI.Failure, exc:
210
210
                LOG.warn(_('Ignoring exception %(exc)s when unplugging'
211
211
                        ' PBD %(pbd)s') % locals())
212
212
 
229
229
                        break
230
230
            else:
231
231
                vdi_ref = (session.call_xenapi("SR.get_VDIs", sr_ref))[0]
232
 
        except cls.XenAPI.Failure, exc:
 
232
        except session.XenAPI.Failure, exc:
233
233
            LOG.exception(exc)
234
234
            raise StorageError(_('Unable to introduce VDI on SR %s') % sr_ref)
235
235
 
237
237
            vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref)
238
238
            LOG.debug(vdi_rec)
239
239
            LOG.debug(type(vdi_rec))
240
 
        except cls.XenAPI.Failure, exc:
 
240
        except session.XenAPI.Failure, exc:
241
241
            LOG.exception(exc)
242
242
            raise StorageError(_('Unable to get record'
243
243
                                 ' of VDI %s on') % vdi_ref)
259
259
                                        vdi_rec['location'],
260
260
                                        vdi_rec['xenstore_data'],
261
261
                                        vdi_rec['sm_config'])
262
 
        except cls.XenAPI.Failure, exc:
 
262
        except session.XenAPI.Failure, exc:
263
263
            LOG.exception(exc)
264
264
            raise StorageError(_('Unable to introduce VDI for SR %s')
265
265
                                % sr_ref)
384
384
    elif iscsi_string is None or FLAGS.iqn_prefix:
385
385
        volume_id = _get_volume_id(id)
386
386
        return '%s:%s' % (FLAGS.iqn_prefix, volume_id)
387
 
 
388
 
 
389
 
def _get_target(volume_id):
390
 
    """
391
 
    Gets iscsi name and portal from volume name and host.
392
 
    For this method to work the following are needed:
393
 
    1) volume_ref['host'] must resolve to something rather than loopback
394
 
    """
395
 
    volume_ref = db.volume_get(context.get_admin_context(),
396
 
                               volume_id)
397
 
    result = (None, None)
398
 
    try:
399
 
        (r, _e) = utils.execute('iscsiadm',
400
 
                                '-m', 'discovery',
401
 
                                '-t', 'sendtargets',
402
 
                                '-p', volume_ref['host'], run_as_root=True)
403
 
    except exception.ProcessExecutionError, exc:
404
 
        LOG.exception(exc)
405
 
    else:
406
 
        volume_name = "volume-%08x" % volume_id
407
 
        for target in r.splitlines():
408
 
            if FLAGS.iscsi_ip_prefix in target and volume_name in target:
409
 
                (location, _sep, iscsi_name) = target.partition(" ")
410
 
                break
411
 
        iscsi_portal = location.split(",")[0]
412
 
        result = (iscsi_name, iscsi_portal)
413
 
    return result