def single_partition_device_1_x(device, vars, log):

    lvm_flag = parted.partition_flag_get_by_name("lvm")

    try:
        log.write("Using pyparted 1.x\n")
        # wipe the old partition table
        utils.sysexec("dd if=/dev/zero of=%s bs=512 count=1" % device, log)

        # get the device
        dev = parted.PedDevice.get(device)

        # create a new partition table
        disk = dev.disk_new_fresh(parted.disk_type_get("msdos"))

        # create one big partition on each block device
        constraint = dev.constraint_any()

        new_part = disk.partition_new(parted.PARTITION_PRIMARY, parted.file_system_type_get("ext2"), 0, 1)

        # make it an lvm partition
        new_part.set_flag(lvm_flag, 1)

        # actually add the partition to the disk
        disk.add_partition(new_part, constraint)

        disk.maximize_partition(new_part, constraint)

        disk.commit()
        del disk

    except BootManagerException, e:
        log.write("BootManagerException while running: %s\n" % str(e))
        return 0
示例#2
0
class ext3FileSystem(extFileSystem):
    name = "ext3"
    #extraFormatArgs = [ "-j", "-F" ]
    extraFormatArgs = []
    partedFileSystemType = parted.file_system_type_get("ext3")
    partedFileSystemName = "ext3"
    vmdkable = True
    supported = True

    def __init__(self, label=None):
        extFileSystem.__init__(self, label)

    def formatDevice(self, devicePath="", progress=None, chroot='/'):
        extFileSystem.formatDevice(self, devicePath, progress, chroot)

        # XXX - crufty hack for ext3
        os.system('touch /etc/mtab')

        # XXX - add back -Odir_index when htree is safe
        args = ["/usr/sbin/tune2fs", "-c0", "-i0", "-j", devicePath]

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError(
                "Could not enable journalling on a linux partition.", e)
示例#3
0
文件: disk.py 项目: kholia/pyrpm
        def set_type(self, type):
#            if not type in Partition.nativeType.keys():
#                log.error("Unknown partition type '%s'." % type)
            try:
                fst = parted.file_system_type_get(type)
            except Exception, msg:
                log.error(msg)
                return
示例#4
0
class ext2FileSystem(extFileSystem):
    name = "ext2"
    partedFileSystemType = parted.file_system_type_get("ext2")
    partedFileSystemName = "ext2"
    supported = True

    def __init__(self, label=None):
        extFileSystem.__init__(self, label)
示例#5
0
文件: disk.py 项目: devzero2000/pyrpm
 def set_type(self, type):
     #            if not type in Partition.nativeType.keys():
     #                log.error("Unknown partition type '%s'." % type)
     try:
         fst = parted.file_system_type_get(type)
     except Exception, msg:
         log.error(msg)
         return
示例#6
0
def single_partition_device_1_x(device, vars, log):

    lvm_flag = parted.partition_flag_get_by_name('lvm')

    try:
        log.write("Using pyparted 1.x\n")
        # wipe the old partition table
        utils.sysexec("dd if=/dev/zero of={} bs=512 count=1".format(device),
                      log)

        # get the device
        dev = parted.PedDevice.get(device)

        # create a new partition table
        disk = dev.disk_new_fresh(parted.disk_type_get("msdos"))

        # create one big partition on each block device
        constraint = dev.constraint_any()

        new_part = disk.partition_new(parted.PARTITION_PRIMARY,
                                      parted.file_system_type_get("ext2"), 0,
                                      1)

        # make it an lvm partition
        new_part.set_flag(lvm_flag, 1)

        # actually add the partition to the disk
        disk.add_partition(new_part, constraint)

        disk.maximize_partition(new_part, constraint)

        disk.commit()
        del disk

    except BootManagerException as e:
        log.write("BootManagerException while running: {}\n".format(str(e)))
        return 0

    except parted.error as e:
        log.write("parted exception while running: {}\n".format(str(e)))
        return 0

    return 1
示例#7
0
文件: disk.py 项目: devzero2000/pyrpm
        def add_partition(self, id, start, end, type, fstype):
            _fstype = None
            if fstype:
                if fstype in ["raid", "lvm"]:
                    _fstype = None
                else:
                    _fstype = parted.file_system_type_get(fstype)

            temp = []
            s = start
            # create temporary partitions for all free primary ids up to the
            # desired id
            if self.ped_disk.type.name == "msdos":
                i = 1
                while i < id and id <= 4:
                    if not self["partition"].has_key(i):
                        if s >= end:
                            raise Exception, "Unable to create partition."

                        part = self.ped_disk.partition_new( \
                                Partition.PARTITION_PRIMARY, None, s, s)
                        constraint = self.ped_disk.dev.constraint_any()
                        r = self.ped_disk.add_partition(part, constraint)
                        if r:
                            raise Exception, "Unable to create partition."
                        temp.append(part)
                        i += 1
                        s += self["units"]

            part = self.ped_disk.partition_new(type, _fstype, s, end)
            if fstype == "raid":
                part.set_flag(parted.PARTITION_RAID, 1)
            elif fstype == "lvm":
                part.set_flag(parted.PARTITION_LVM, 1)
            constraint = self.ped_disk.dev.constraint_any()
            r = self.ped_disk.add_partition(part, constraint)
            if r:
                raise Exception, "Unable to create partition."
            if len(temp) > 0:
                for part in temp:
                    self.ped_disk.delete_partition(part)
            self.reload()
            return part.num
示例#8
0
文件: disk.py 项目: kholia/pyrpm
        def add_partition(self, id, start, end, type, fstype):
            _fstype = None
            if fstype:
                if fstype in [ "raid", "lvm" ]:
                    _fstype = None
                else:
                    _fstype = parted.file_system_type_get(fstype)

            temp = [ ]
            s = start
            # create temporary partitions for all free primary ids up to the
            # desired id
            if self.ped_disk.type.name == "msdos":
                i = 1
                while i < id and id <= 4:
                    if not self["partition"].has_key(i):
                        if s >= end:
                            raise Exception, "Unable to create partition."

                        part = self.ped_disk.partition_new( \
                                Partition.PARTITION_PRIMARY, None, s, s)
                        constraint = self.ped_disk.dev.constraint_any()
                        r = self.ped_disk.add_partition(part, constraint)
                        if r:
                            raise Exception, "Unable to create partition."
                        temp.append(part)
                        i += 1
                        s += self["units"]

            part = self.ped_disk.partition_new(type, _fstype, s, end)
            if fstype == "raid":
                part.set_flag(parted.PARTITION_RAID, 1)
            elif fstype == "lvm":
                part.set_flag(parted.PARTITION_LVM, 1)
            constraint = self.ped_disk.dev.constraint_any()
            r = self.ped_disk.add_partition(part, constraint)
            if r:
                raise Exception, "Unable to create partition."
            if len(temp) > 0:
                for part in temp:
                    self.ped_disk.delete_partition(part)
            self.reload()
            return part.num
示例#9
0
class vmkCoreDumpFileSystem(FileSystemType):
    partedFileSystemType = parted.file_system_type_get("vmkcore")
    partedFileSystemName = "vmkcore"
    formattable = False
    checked = False
    vmwarefs = True
    linuxnativefs = True
    maxSizeMB = 100 + 10  # add in a fudge factor
    supported = True
    name = "vmkcore"

    partedPartitionFlags = []
    defaultOptions = "defaults"
    migratetofs = None

    def __init__(self):
        FileSystemType.__init__(self)

    def formatDevice(self, entry, progress=None, chroot='/'):
        pass
示例#10
0
class swapFileSystem(FileSystemType):
    partedFileSystemType = parted.file_system_type_get("linux-swap")
    partedFileSystemName = "linux-swap"
    formattable = True
    name = "swap"
    minSizeMB = 16
    maxSizeMB = 1024 * 1024
    linuxnativefs = True
    vmdkable = True
    supported = True

    # Format of the swap partition header.  Used anaconda's isys package as a
    # reference for this.
    headerFmt = "1024xIII16s"

    def __init__(self):
        FileSystemType.__init__(self)

    def mount(self, device, mountPoint, readOnly=False, bindMount=False):
        print "Swap On not implemented"

    def umount(self):
        print "Swap Off not implemented"

    def getUuid(self, devicePath):
        header = open(devicePath, 'r').read(struct.calcsize(self.headerFmt))
        (_version, _last_page, _nr_badpages, uuidBits) = \
                   struct.unpack(self.headerFmt, header)

        return util.uuidBitsToString(uuidBits)

    def formatDevice(self, devicePath=None, progress=None):
        args = ["/usr/sbin/mkswap", "-v1", devicePath]

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError("Could not format a linux swap partition.",
                                    e)

        workarounds.setSwapUUID(devicePath)
示例#11
0
class FATFileSystem(FileSystemType):
    partedFileSystemType = parted.file_system_type_get("fat32")
    partedFileSystemName = "fat32"
    formattable = True
    mountable = True
    maxSizeMB = 1024 * 1024
    name = "vfat"
    vmdkable = False
    supported = True

    def __init__(self):
        FileSystemType.__init__(self)

    def formatDevice(self, entry=None, progress=None, chroot='/'):
        raise RuntimeError, "Fat filesystem creation unimplemented."

        devicePath = "/tmp/foobar"
        args = ["/sbin/mkdosfs", devicePath]

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError("Could not format a DOS partition", e)
示例#12
0
               "%s != %s" % (err, conf['error'])
        return
    
    assert 'error' not in conf
    
    pd = device.partitions.partedDisk
    part = None
    for exp in conf['expected']:
        part = pd.next_partition(part)

        assert part.num == exp[0], \
               "%d: %d != %d" % (part.num, part.num, exp[0])
        assert part.type == exp[1], \
               "%d: %d != %d" % (part.num, part.type, exp[1])
        assert not exp[2] or \
               part.fs_type == parted.file_system_type_get(exp[2])
        assert part.geom.start == exp[3], \
               "%d: %d != %d" % (part.num, part.geom.start, exp[3])
        assert part.geom.end == exp[4], \
               "%d: %d != %d" % (part.num, part.geom.end, exp[4])
    
    assert pd.next_partition(part) == None, \
           "%s: more partitions that expected" % conf['desc']


def test_configs():
    '''Generator that returns a bunch of configurations to run through
    check_one_config.'''

    configs = [
示例#13
0
class FAT16FileSystem(FATFileSystem):
    partedFileSystemType = parted.file_system_type_get("fat16")
    partedFileSystemName = "fat16"
    maxSizeMB = 2 * 1024 * 1024
示例#14
0
class vmfs3FileSystem(FileSystemType):
    partedFileSystemType = parted.file_system_type_get("vmfs3")
    partedFileSystemName = "vmfs3"
    formattable = True
    checked = False
    vmwarefs = True
    linuxnativefs = False
    supported = True
    minSizeMB = 1200
    maxSizeMB = 2 * 1024 * 1024
    name = "vmfs3"
    blockSizeMB = 1

    maxLabelLength = 64  # From lvm_public.h
    maxFilenameLength = 127  # From statvfs of /vmfs

    @staticmethod
    def sanityCheckVolumeLabel(label):
        '''Return True if the given label is valid.

        XXX Not totally sure what all the constraints are for a label.

        >>> vmfs3FileSystem.sanityCheckVolumeLabel('hello')
        >>> vmfs3FileSystem.sanityCheckVolumeLabel('hello/world')
        Traceback (most recent call last):
        ...
        ValueError: vmfs volume label is invalid.
        >>> vmfs3FileSystem.sanityCheckVolumeLabel('hello' * 128)
        Traceback (most recent call last):
        ...
        ValueError: vmfs volume label must be less than 64 characters long.
        '''

        if not label:
            raise ValueError, \
                "Datastore names must contain at least one character."

        if len(label) > vmfs3FileSystem.maxLabelLength:
            raise ValueError, \
                  "Datastore names must be less than %d characters long." % \
                    (vmfs3FileSystem.maxLabelLength,)

        if label[0] in string.whitespace or label[-1] in string.whitespace:
            raise ValueError, "Datastore names must not start or end with " + \
                "spaces."

        if label[0] == '.':
            raise ValueError, "Datastore names must not begin with the '.' " + \
                "character."

        if not re.match('^(' + RegexLocator.vmfsvolume + ')$', label):
            raise ValueError, "Datastore names must not contain the '/' " + \
                "character."

    @classmethod
    def systemUniqueName(cls, prefix):
        '''Given a prefix return a filename that is unique for this installed
        system.'''
        import vmkctl

        uuid = vmkctl.SystemInfoImpl().GetSystemUuid()
        retval = "%s-%s" % (prefix, uuid.uuidStr)
        if len(retval) > cls.maxFilenameLength:
            raise ValueError("name is too long when prepended to UUID "
                             "(max %d chars) -- %s" %
                             (cls.maxFilenameLength, retval))
        return retval

    def __init__(self, volumeName=None):
        FileSystemType.__init__(self)
        self.volumeName = volumeName

    def mount(self,
              device,
              mountPoint,
              readOnly=False,
              bindMount=False,
              loopMount=False):
        pass

    def umount(self, mountPoint=None):
        pass

    def uuidDevice(self):
        pass

    def formatDevice(self, devicePath=None, progress=None):
        assert self.volumeName

        args = [
            "/usr/sbin/vmkfstools", "-C", self.name, "-b",
            "%dm" % self.blockSizeMB, "-S", self.volumeName, devicePath
        ]
        args.extend(self.extraFormatArgs)

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError("Could not format a vmfs volume.", e)
示例#15
0
 def __init__(self):
     self._fs_type = parted.file_system_type_get(self._name)
示例#16
0
 def __init__(self):
     self._fs_type = parted.file_system_type_get(self._name)
示例#17
0
                partsize = string.atoi(partinfo[1][:-1])
                partsect = int(
                    float(partsize) * 1024 * 1024 / parted.SECTOR_SIZE)
                partabssect = partabssect + partsect
            elif partsizetype != "%":
                raise RuntimeError, "invalid partition size specifier"
        partremsect = drvsectors - partabssect - curpartend

        for (partfs, partsizestr, partmount, parthints) in partcfg:
            print "Creating %s partition for %s..." % (partfs, partmount)
            partsizetype = string.upper(partsizestr[-1])
            partsize = string.atoi(partsizestr[:-1])

            if partfs == "swap":
                partfs = "linux-swap"
            partfstype = parted.file_system_type_get(partfs)

            if partsizetype == "%":
                partsect = int(partremsect * (float(partsize) / 100))
            else:
                partsect = int(
                    float(partsize) * 1024 * 1024 / parted.SECTOR_SIZE)

            partdevice = drvobj.create_partition(curpartend,
                                                 curpartend + partsect - 1,
                                                 partfstype, parthints)
            mountlist.append([partdevice, partmount, partfs])
            curpartend = curpartend + partsect

        drvobj.commit_changes()
示例#18
0
    def __init__(self):
        self.readSupportedFilesystems()

        self._fs_type = parted.file_system_type_get(self._name)
示例#19
0
	    if partsizetype == "M":
		partsize = string.atoi(partinfo[1][:-1])
		partsect = int(float(partsize) * 1024 * 1024 / parted.SECTOR_SIZE)
		partabssect = partabssect + partsect
	    elif partsizetype != "%":
		raise RuntimeError, "invalid partition size specifier"
	partremsect = drvsectors - partabssect - curpartend

	for (partfs, partsizestr, partmount, parthints) in partcfg:
	    print "Creating %s partition for %s..." % (partfs, partmount)
	    partsizetype = string.upper(partsizestr[-1])
	    partsize = string.atoi(partsizestr[:-1])
	    
	    if partfs == "swap":
		partfs = "linux-swap"
	    partfstype = parted.file_system_type_get(partfs)

	    if partsizetype == "%":
		partsect = int(partremsect * (float(partsize) / 100))
	    else:
		partsect = int(float(partsize) * 1024 * 1024 / parted.SECTOR_SIZE)

	    partdevice = drvobj.create_partition(curpartend,
						 curpartend + partsect - 1,
						 partfstype, parthints)
	    mountlist.append([partdevice, partmount, partfs])
	    curpartend = curpartend + partsect

	drvobj.commit_changes()

	drvdisk = drv.disk_open()