import os import subprocess import tempfile from servus import validators as valid from servus import tools #from servus.block.blktools import blockround, is_blockdevice, get_majorminor, \ # get_disksize # from servus.exceptions import DiskError import servus.exceptions as exc from servus.block import qemu, blktools, parted from servus import log from servus import PartitionConfig LOG = log.get_logger() QEMU_NBD = tools.which('qemu-nbd') # start block for all partitions #PART_STARTPOS = 2048 * 512 def part_config2part(part, def_filesystem=None): if not isinstance(part, PartitionConfig): raise TypeError('part argument has to be an instance of '\ '\'servus.PartitionConfig\'') if part.filesystem is None: fsys = def_filesystem else: fsys = part.filesystem pobj = Partition(size=part.size, filesystem=fsys, mkfs=part.mkfs,
'''Image fetching''' import urllib2 import urlparse import os import threading import subprocess import sys import hashlib from servus.exceptions import FetchError from servus.log import get_logger from servus.tools import which LOG = get_logger() SUPP_PROTOCOLS = ['http', 'https', 'ftp', 'file'] HASHLIBS = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') class Copythread(threading.Thread): def __init__(self, stdin, hashfunc=None, bufsize=4096): '''Workaround for a Python bug. If you pipe data from urllib2.urlopen() into a subprocess, about 8 KiB at the beginning of the fetched file gets lost. To circumvent the problem we have to pipe it through another pipe. This is also a good point to calculate the checksum of the file. :param pipe stdin: pipe or file which to read from