~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-02-10 11:25:38 UTC
  • mto: This revision was merged to the branch mainline in revision 65.
  • Revision ID: package-import@ubuntu.com-20120210112538-3jcp8w9huic41e45
Tags: upstream-2012.1~e4~20120210.12574
ImportĀ upstreamĀ versionĀ 2012.1~e4~20120210.12574

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
from decimal import Decimal, InvalidOperation
34
34
from xml.dom import minidom
35
35
 
36
 
from nova.common import cfg
 
36
from eventlet import greenthread
 
37
 
37
38
from nova import exception
38
39
from nova import flags
39
40
from nova.image import glance
40
41
from nova import log as logging
 
42
from nova.openstack.common import cfg
41
43
from nova import utils
42
44
from nova.compute import instance_types
43
45
from nova.compute import power_state
378
380
        """
379
381
        # NOTE(sirp): Currently we only support uploading images as VHD, there
380
382
        # is no RAW equivalent (yet)
381
 
        logging.debug(_("Asking xapi to upload %(vdi_uuids)s as"
382
 
                " ID %(image_id)s") % locals())
 
383
        LOG.debug(_("Asking xapi to upload %(vdi_uuids)s as"
 
384
                    " ID %(image_id)s") % locals())
383
385
 
384
386
        glance_host, glance_port = glance.pick_glance_api_server()
385
387
 
513
515
        # NOTE(jk0): We use a FAT32 filesystem for the Windows swap
514
516
        # partition because that is what parted supports.
515
517
        is_windows = instance.os_type == "windows"
516
 
        fs_type = "fat32" if is_windows else "linux-swap"
 
518
        fs_type = "vfat" if is_windows else "linux-swap"
517
519
 
518
520
        cls._generate_disk(session, instance, vm_ref, userdevice,
519
521
                           'swap', swap_mb, fs_type)
683
685
        if image_type == ImageType.DISK:
684
686
            # Make room for MBR.
685
687
            vdi_size += MBR_SIZE_BYTES
686
 
        elif image_type in (ImageType.KERNEL, ImageType.RAMDISK) and \
687
 
             vdi_size > FLAGS.max_kernel_ramdisk_size:
 
688
        elif (image_type in (ImageType.KERNEL, ImageType.RAMDISK) and
 
689
              vdi_size > FLAGS.max_kernel_ramdisk_size):
688
690
            max_size = FLAGS.max_kernel_ramdisk_size
689
691
            raise exception.Error(
690
692
                _("Kernel/Ramdisk image is too large: %(vdi_size)d bytes, "
921
923
                        ref = node.childNodes
922
924
                        # Name and Value
923
925
                        if len(ref) > 6:
924
 
                            diags[ref[0].firstChild.data] = \
925
 
                                ref[6].firstChild.data
 
926
                            _ref_zero = ref[0].firstChild.data
 
927
                            diags[_ref_zero] = ref[6].firstChild.data
926
928
            return diags
927
929
        except cls.XenAPI.Failure as e:
928
930
            return {"Unable to retrieve diagnostics": e}
1211
1213
            snapshot
1212
1214
    """
1213
1215
    max_attempts = FLAGS.xenapi_vhd_coalesce_max_attempts
1214
 
    attempts = {'counter': 0}
1215
 
 
1216
 
    def _poll_vhds():
1217
 
        attempts['counter'] += 1
1218
 
        if attempts['counter'] > max_attempts:
1219
 
            counter = attempts['counter']
1220
 
            msg = (_("VHD coalesce attempts exceeded (%(counter)d >"
1221
 
                    " %(max_attempts)d), giving up...") % locals())
1222
 
            raise exception.Error(msg)
1223
 
 
 
1216
    for i in xrange(max_attempts):
1224
1217
        VMHelper.scan_sr(session, instance, sr_ref)
1225
1218
        parent_uuid = get_vhd_parent_uuid(session, vdi_ref)
1226
1219
        if original_parent_uuid and (parent_uuid != original_parent_uuid):
1228
1221
                    " %(original_parent_uuid)s, waiting for coalesce...")
1229
1222
                    % locals())
1230
1223
        else:
1231
 
            # Breakout of the loop (normally) and return the parent_uuid
1232
 
            raise utils.LoopingCallDone(parent_uuid)
1233
 
 
1234
 
    loop = utils.LoopingCall(_poll_vhds)
1235
 
    loop.start(FLAGS.xenapi_vhd_coalesce_poll_interval, now=True)
1236
 
    parent_uuid = loop.wait()
1237
 
    return parent_uuid
 
1224
            return parent_uuid
 
1225
 
 
1226
        greenthread.sleep(FLAGS.xenapi_vhd_coalesce_poll_interval)
 
1227
 
 
1228
    msg = (_("VHD coalesce attempts exceeded (%(max_attempts)d)"
 
1229
             ", giving up...") % locals())
 
1230
    raise exception.Error(msg)
1238
1231
 
1239
1232
 
1240
1233
def remap_vbd_dev(dev):
1319
1312
    DEVICE_DETACH_REJECTED.  For reasons which I don't understand, we're
1320
1313
    seeing the device still in use, even when all processes using the device
1321
1314
    should be dead."""
1322
 
    # FIXME(sirp): We can use LoopingCall here w/o blocking sleep()
1323
1315
    while True:
1324
1316
        try:
1325
1317
            session.call_xenapi("VBD.unplug", vbd_ref)
1329
1321
            if (len(e.details) > 0 and
1330
1322
                e.details[0] == 'DEVICE_DETACH_REJECTED'):
1331
1323
                LOG.debug(_('VBD.unplug rejected: retrying...'))
1332
 
                time.sleep(1)
 
1324
                greenthread.sleep(1)
1333
1325
                LOG.debug(_('Not sleeping anymore!'))
1334
1326
            elif (len(e.details) > 0 and
1335
1327
                  e.details[0] == 'DEVICE_ALREADY_DETACHED'):
1446
1438
                  run_as_root=True)
1447
1439
 
1448
1440
    # fsck the disk
 
1441
    #
1449
1442
    # NOTE(sirp): using -p here to automatically repair filesystem, is
1450
1443
    # this okay?
1451
 
    utils.execute('e2fsck', '-f', '-p', partition_path, run_as_root=True)
 
1444
    #
 
1445
    # Exit Code 1 = File system errors corrected
 
1446
    #           2 = File system errors corrected, system needs a reboot
 
1447
    utils.execute('e2fsck', '-f', '-p', partition_path, run_as_root=True,
 
1448
                  check_exit_code=[0, 1, 2])
1452
1449
 
1453
1450
    if new_sectors < old_sectors:
1454
1451
        # Resizing down, resize filesystem before partition resize