Пример #1
0
    def __init__(self, log=None, **kwargs):
        #
        # Assign settings for image creation
        #
        self.log = log
        self.filesystem = {}
        self.volume = kwargs.get('volume')
        self.fstab = kwargs.get('fstab')
        self.generate_fstab = kwargs.get('generate_fstab', False)
        self.excludes = kwargs.get('exclude', [])
        self.includes = kwargs.get('include', [])
        self.bundle_all_dirs = kwargs.get('bundle_all_dirs', False)
        self.prefix = kwargs.get('prefix')
        self.filter = kwargs.get('filter', True)
        self.size = kwargs.get('size')
        self.destination = kwargs.get('destination') or mkdtemp(prefix='image-')
        self.image = os.path.join(self.destination,
                                  '{0}.img'.format(self.prefix))

        #
        # Validate settings
        #
        if not self.volume:
            raise ValueError("must supply a source volume.")
        self.volume = sanitize_path(self.volume)
        if not self.size:
            raise ValueError("must supply a size for the generated image.")
        if not self.prefix:
            raise ValueError("must supply a prefix.")
        if not self.volume:
            raise ValueError("must supply a volume.")
        if not (os.path.exists(self.destination) or
                os.path.isdir(self.destination)):
            raise ValueError("'{0}' is not a directory or does not exist."
                             .format(self.destination))
Пример #2
0
 def __init__(self, volume, image, log=None):
     self.log = log
     self.mpoint = mkdtemp(prefix='vol-')
     self.excludes = []
     self.filter = False
     self.fstab = None
     self.generate_fstab_file = False
     self.image = image
     self.includes = []
     self.volume = volume
     self.bundle_all_dirs = False
Пример #3
0
 def _populate_filesystem_info(self):
     """Create a temporary device node for the volume we're going
     to copy. We'll use it to get information about the source volume's
     filesystem.
     """
     st_dev = os.stat(self.volume).st_dev
     devid = os.makedev(os.major(st_dev), os.minor(st_dev))
     directory = mkdtemp(prefix='devnode-')
     devnode = os.path.join(directory, 'rootdev')
     os.mknod(devnode, 0o400 | stat.S_IFBLK, devid)
     try:
         for tag in BLKID_TAGS:
             try:
                 out = subprocess.Popen(
                     ['blkid', '-s', tag, '-ovalue', devnode],
                     stdout=subprocess.PIPE).communicate()[0]
                 self.filesystem[BLKID_TAGS[tag]] = out.rstrip()
             except subprocess.CalledProcessError:
                 pass
     finally:
         os.remove(devnode)
         os.rmdir(directory)
Пример #4
0
 def _populate_filesystem_info(self):
     """Create a temporary device node for the volume we're going
     to copy. We'll use it to get information about the source volume's
     filesystem.
     """
     st_dev = os.stat(self.volume).st_dev
     devid = os.makedev(os.major(st_dev), os.minor(st_dev))
     directory = mkdtemp(prefix='devnode-')
     devnode = os.path.join(directory, 'rootdev')
     os.mknod(devnode, 0o400 | stat.S_IFBLK, devid)
     try:
         for tag in BLKID_TAGS:
             try:
                 out = subprocess.Popen(['blkid', '-s', tag,
                                         '-ovalue', devnode],
                                        stdout=subprocess.PIPE
                                        ).communicate()[0]
                 self.filesystem[BLKID_TAGS[tag]] = out.rstrip()
             except subprocess.CalledProcessError:
                 pass
     finally:
         os.remove(devnode)
         os.rmdir(directory)