コード例 #1
0
ファイル: image.py プロジェクト: pancyber/snf-image-creator
    def umount(self, lazy=False):
        """umount the previously mounted image file system"""

        assert self.mount_local_support, \
            "MOUNT LOCAL not supported for this build of libguestfs"

        assert self._mount_thread is not None, "Image is not mounted"

        try:
            # Maybe the image was umounted externally
            if not self._mount_thread.is_alive():
                self._mount_thread = None
                return True

            try:
                args = (['-l'] if lazy else []) + [self._mount_thread.mpoint]
                get_command('umount')(*args)
            except:
                return False

            # Wait for a little while. If the image is umounted,
            # mount_local_run should have terminated
            self._mount_thread.join(5)

            if self._mount_thread.is_alive():
                raise FatalError('Unable to join the mount thread')

            self._mount_thread = None
            return True
        finally:
            self.os.umount()
コード例 #2
0
    def umount(self, lazy=False):
        """umount the previously mounted image file system"""

        assert self.mount_local_support, \
            "MOUNT LOCAL not supported for this build of libguestfs"

        assert self._mount_thread is not None, "Image is not mounted"

        try:
            # Maybe the image was umounted externally
            if not self._mount_thread.is_alive():
                self._mount_thread = None
                return True

            try:
                args = (['-l'] if lazy else []) + [self._mount_thread.mpoint]
                get_command('umount')(*args)
            except:
                return False

            # Wait for a little while. If the image is umounted,
            # mount_local_run should have terminated
            self._mount_thread.join(5)

            if self._mount_thread.is_alive():
                raise FatalError('Unable to join the mount thread')

            self._mount_thread = None
            return True
        finally:
            self.os.umount()
コード例 #3
0
def mkfs(fs, device, uuid=None, label=None):
    """Create a filesystem on the device"""

    mkfs = get_command('mkfs.%s' % fs)

    args = []

    if 'force' in MKFS_OPTS[fs]:
        args.append(MKFS_OPTS[fs]['force'])

    if label:
        args.append(MKFS_OPTS[fs]['label'])
        args.append(label)

    if 'uuid' in MKFS_OPTS[fs] and uuid:
        args.append(MKFS_OPTS[fs]['uuid'])
        args.append(uuid)

    args.append(device)

    mkfs(*args)

    if 'uuid' not in MKFS_OPTS[fs] and 'uuid':
        UUID_UPDATE[fs](device, uuid)
コード例 #4
0
ファイル: disk.py プロジェクト: grnet/snf-image-creator
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Module hosting the Disk class."""

import stat
import os
import tempfile
import uuid
import shutil

from image_creator.util import get_command, try_fail_repeat, free_space, \
    FatalError, create_snapshot, image_info
from image_creator.bundle_volume import BundleVolume
from image_creator.image import Image

dd = get_command('dd')
dmsetup = get_command('dmsetup')
losetup = get_command('losetup')
blockdev = get_command('blockdev')


def get_tmp_dir(default=None):
    """Check tmp directory candidates and return the one with the most
    available space.
    """
    if default is not None:
        return default

    # TODO: I need to find a better way of choosing temporary directories.
    # Maybe check all available mount points.
    TMP_CANDIDATES = [t for t in ('/var/tmp', os.path.expanduser('~'), '/mnt')
コード例 #5
0
import os
import re
import tempfile
import uuid
from collections import namedtuple

import parted

from image_creator.rsync import Rsync
from image_creator.util import get_command
from image_creator.util import FatalError
from image_creator.util import try_fail_repeat
from image_creator.util import free_space
from image_creator.gpt import GPTPartitionTable

findfs = get_command('findfs')
dd = get_command('dd')
dmsetup = get_command('dmsetup')
losetup = get_command('losetup')
mount = get_command('mount')
umount = get_command('umount')
blkid = get_command('blkid')
tune2fs = get_command('tune2fs')

MKFS_OPTS = {'ext2': {'force': '-F', 'uuid': '-U', 'label': '-L'},
             'ext3': {'force': '-F', 'uuid': '-U', 'label': '-L'},
             'ext4': {'force': '-F', 'uuid': '-U', 'label': '-L'},
             'reiserfs': {'force': '-ff', 'uuid': '-u', 'label': '-l'},
             'btrfs':  {'force': '-f', 'label': '-L'},
             'minix': {},
             'xfs': {'force': '-f', 'label': '-L'},
コード例 #6
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Module hosting the Disk class."""

import stat
import os
import tempfile
import uuid
import shutil

from image_creator.util import get_command, try_fail_repeat, free_space, \
    FatalError, create_snapshot, image_info
from image_creator.bundle_volume import BundleVolume
from image_creator.image import Image

dd = get_command('dd')
dmsetup = get_command('dmsetup')
losetup = get_command('losetup')
blockdev = get_command('blockdev')


def get_tmp_dir(default=None):
    """Check tmp directory candidates and return the one with the most
    available space.
    """
    if default is not None:
        return default

    # TODO: I need to find a better way of choosing temporary directories.
    # Maybe check all available mount points.
    TMP_CANDIDATES = [