~ubuntu-branches/ubuntu/saucy/nova/saucy-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, Adam Gandleman, Chuck Short
  • Date: 2012-03-02 11:04:04 UTC
  • mfrom: (1.1.47)
  • Revision ID: package-import@ubuntu.com-20120302110404-fr230yakr8hov3dj
Tags: 2012.1~e4-0ubuntu1
[ Adam Gandleman ]
* debian/patches/libvirt-use-console-pipe.patch: Refreshed. 
* debain/nova-volume.upstart.in: Ensure lock directory is created
  (LP: #940780)
* debain/control: Fix nova-compute-$flavor Depends
* debian/control: Add python-iso8601 to python-nova Depends

[ Chuck Short ]
* debian/rules: Fix FTBFS.
* Merge Ubuntu/Debian packaging:
  - Thanks to Julien Danjou, Ghe Rivero, and Thomas Goirand
  - debian/copyright: Update copyright file.
  - debian/nova-api.init, debian/nova-compute.init,
    debian/nova-network.init, debian/nova-objectstore,
    debian/nova-scheduler, debian/nova-volume.init:
    Synchronize init scripts.
  - nova-common.install, debian/rules: Install policy.json
  - debian/rules, debian/nova-xcp-network.install,
    debian/nova-xcp-plugins.install, nova-xcp-plugins.postrm,
    debian/nova-xcp-plugins.doc, debian/nova-xcp-plugins.postinst,
    debian/README.xcp_and_openstack, debian/control,
    debian/ubuntu_xen-openvswitch-nova.rules,
    debian/patches/path-to-the-xenhost.conf-fixup.patch:
    Add Xen XCP support.
  - debian/control,
    debian/nova-compute-{kvm,lxc,qemu,xen,uml}.postinst: Make
    nova-compute a virtual package.
  - Dropped ubuntu_ubuntu_control_vars: We dont use it
* New upstream release.
* Dropped python-babel, it will be handled by langpacks.
* debian/patches/ec2-fixes.patch: Backport turnk fix for ec2
  permissions.
* debian/patches/path-to-the-xenhost.conf-fixup.patch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import os
26
26
import pickle
27
27
import re
28
 
import tempfile
29
28
import time
30
29
import urllib
31
30
import urlparse
1651
1650
                "virtual_size=%(virtual_size)d block_size=%(block_size)d"),
1652
1651
                locals())
1653
1652
 
1654
 
    with open(src_path, "r") as src:
1655
 
        with open(dst_path, "w") as dst:
1656
 
            data = src.read(min(block_size, left))
1657
 
            while data:
1658
 
                if data == EMPTY_BLOCK:
1659
 
                    dst.seek(block_size, os.SEEK_CUR)
1660
 
                    left -= block_size
1661
 
                    bytes_read += block_size
1662
 
                    skipped_bytes += block_size
1663
 
                else:
1664
 
                    dst.write(data)
1665
 
                    data_len = len(data)
1666
 
                    left -= data_len
1667
 
                    bytes_read += data_len
1668
 
 
1669
 
                if left <= 0:
1670
 
                    break
1671
 
 
1672
 
                data = src.read(min(block_size, left))
 
1653
    # NOTE(sirp): we need read/write access to the devices; since we don't have
 
1654
    # the luxury of shelling out to a sudo'd command, we temporarily take
 
1655
    # ownership of the devices.
 
1656
    with utils.temporary_chown(src_path):
 
1657
        with utils.temporary_chown(dst_path):
 
1658
            with open(src_path, "r") as src:
 
1659
                with open(dst_path, "w") as dst:
 
1660
                    data = src.read(min(block_size, left))
 
1661
                    while data:
 
1662
                        if data == EMPTY_BLOCK:
 
1663
                            dst.seek(block_size, os.SEEK_CUR)
 
1664
                            left -= block_size
 
1665
                            bytes_read += block_size
 
1666
                            skipped_bytes += block_size
 
1667
                        else:
 
1668
                            dst.write(data)
 
1669
                            data_len = len(data)
 
1670
                            left -= data_len
 
1671
                            bytes_read += data_len
 
1672
 
 
1673
                        if left <= 0:
 
1674
                            break
 
1675
 
 
1676
                        data = src.read(min(block_size, left))
1673
1677
 
1674
1678
    duration = time.time() - start_time
1675
1679
    compression_pct = float(skipped_bytes) / bytes_read * 100
1745
1749
    """Callback which runs with the image VDI attached"""
1746
1750
    # NB: Partition 1 hardcoded
1747
1751
    dev_path = utils.make_dev_path(device, partition=1)
1748
 
    tmpdir = tempfile.mkdtemp()
1749
 
    try:
 
1752
    with utils.tempdir() as tmpdir:
1750
1753
        # Mount only Linux filesystems, to avoid disturbing NTFS images
1751
1754
        err = _mount_filesystem(dev_path, tmpdir)
1752
1755
        if not err:
1765
1768
        else:
1766
1769
            LOG.info(_('Failed to mount filesystem (expected for '
1767
1770
                'non-linux instances): %s') % err)
1768
 
    finally:
1769
 
        # remove temporary directory
1770
 
        os.rmdir(tmpdir)
1771
1771
 
1772
1772
 
1773
1773
def _prepare_injectables(inst, networks_info):