Example #1
0
def preserveDatastoreOnDrive(driveName):
    import userchoices

    diskSet = devices.DiskSet()
    datastoreSet = DatastoreSet()

    # find the /boot partition
    disk = diskSet[driveName]
    part = disk.findFirstPartitionMatching(
        fsTypes=('ext2', 'ext3'), minimumSize=partition.BOOT_MINIMUM_SIZE)

    assert part

    # wipe the partition
    part.mountPoint = "/boot"
    req = partition.PartitionRequest(mountPoint=part.mountPoint,
                                     minimumSize=part.getSizeInMegabytes(),
                                     fsType=part.fsType,
                                     consoleDevicePath=part.consoleDevicePath,
                                     clearContents=True)

    # get the datastores for a given drive
    datastores = datastoreSet.getEntriesByDriveName(driveName)

    userchoices.addPartitionMountRequest(req)
    userchoices.clearVirtualDevices()

    # XXX - assuming there is only one datastore on the drive
    partition.addDefaultVirtualDriveAndRequests(driveName,
                                                vmfsVolume=datastores[0].name)
Example #2
0
def preserveDatastoreOnDrive(driveName):
    import userchoices

    diskSet = devices.DiskSet()
    datastoreSet = DatastoreSet()

    # find the /boot partition
    disk = diskSet[driveName]
    part = disk.findFirstPartitionMatching(
        fsTypes=('ext2', 'ext3'),
        minimumSize=partition.BOOT_MINIMUM_SIZE)

    assert part

    # wipe the partition
    part.mountPoint = "/boot"
    req = partition.PartitionRequest(mountPoint=part.mountPoint,
        minimumSize=part.getSizeInMegabytes(),
        fsType=part.fsType,
        consoleDevicePath=part.consoleDevicePath,
        clearContents=True)

    # get the datastores for a given drive
    datastores = datastoreSet.getEntriesByDriveName(driveName)

    userchoices.addPartitionMountRequest(req)
    userchoices.clearVirtualDevices()

    # XXX - assuming there is only one datastore on the drive
    partition.addDefaultVirtualDriveAndRequests(driveName,
        vmfsVolume=datastores[0].name)
Example #3
0
    def commit(self):
        """Commit updates.  By the time we get here, we assume:
        * volume name has been sanity checked
        * requested size has been checked
        """

        assert self.deviceName, 'datastore device name not set'
        assert self.volumeName, 'datastore volume name not set'
        log.debug("DataStoreWindow.commit device %s volume %s" %
                  (self.deviceName, self.volumeName))

        # Check if drives to clear are in use; if so stop this madness.
        diskSet = devices.DiskSet()
        if self.deviceName == self.esxDeviceName:
            clearDrives = [self.deviceName]
        else:
            clearDrives = [self.deviceName, self.esxDeviceName]
            # presumably self.choseCreateNewDatastoreOnEsxDevice == False

        log.debug("Cleared drives = %s" % (', '.join(clearDrives)))
        volumePath = os.path.join('/vmfs/volumes', self.volumeName)

        if (os.path.exists(volumePath) or os.path.islink(volumePath)) \
           and not checkForClearedVolume(clearDrives, self.datastoreSet,
                                         self.volumeName):
            log.debug("Volume name in use")
            self.setSubstepEnv({'next': self.warnInUse})
            return

        # build partition requests, add to userchoices
        partition.addDefaultPartitionRequests(diskSet[self.esxDeviceName],
                                              False)

        if self.choseCreateNewDatastore:
            physicalRequests = [
                (None, 100, 0, True, fsset.vmfs3FileSystem(self.volumeName)),
            ]
            dev = diskSet[self.deviceName]
            userchoices.addPhysicalPartitionRequests(
                self.deviceName,
                partition.createPartitionRequestSet(dev, physicalRequests))

            userchoices.setClearPartitions(drives=clearDrives)

            userchoices.setEsxDatastoreDevice(dev.name)
            userchoices.setVmdkDatastore(self.volumeName)
        else:  # use existing datastore
            userchoices.setClearPartitions(drives=[self.esxDeviceName])

            userchoices.clearVirtualDevices()

            userchoices.setEsxDatastoreDevice(None)
            userchoices.setVmdkDatastore(self.volumeName)

        # size check
        size = partition.getRequestsSize(partition.getDefaultVirtualRequests())
        if size > devices.runtimeActionFindMaxVmdkSize():
            self.setSubstepEnv({'next': self.warnTooSmall})
            return
        self.setSubstepEnv({'next': self.stepForward})
Example #4
0
    def commit(self):
        """Commit updates.  By the time we get here, we assume:
        * volume name has been sanity checked
        * requested size has been checked
        """

        assert self.deviceName, 'datastore device name not set'
        assert self.volumeName, 'datastore volume name not set'
        log.debug("DataStoreWindow.commit device %s volume %s" %
                (self.deviceName, self.volumeName))

        # Check if drives to clear are in use; if so stop this madness.
        diskSet = devices.DiskSet()
        if self.deviceName == self.esxDeviceName:
            clearDrives = [self.deviceName]
        else:
            clearDrives = [self.deviceName, self.esxDeviceName]
            # presumably self.choseCreateNewDatastoreOnEsxDevice == False

        log.debug("Cleared drives = %s" % (', '.join(clearDrives)))
        volumePath = os.path.join('/vmfs/volumes', self.volumeName)

        if (os.path.exists(volumePath) or os.path.islink(volumePath)) \
           and not checkForClearedVolume(clearDrives, self.datastoreSet,
                                         self.volumeName):
            log.debug("Volume name in use")
            self.setSubstepEnv({'next': self.warnInUse})
            return

        # build partition requests, add to userchoices
        partition.addDefaultPartitionRequests(diskSet[self.esxDeviceName],
                                              False)

        if self.choseCreateNewDatastore:
            physicalRequests = [
                (None, 100, 0, True, fsset.vmfs3FileSystem(self.volumeName)),
            ]
            dev = diskSet[self.deviceName]
            userchoices.addPhysicalPartitionRequests(self.deviceName,
                partition.createPartitionRequestSet(dev, physicalRequests))

            userchoices.setClearPartitions(drives=clearDrives)

            userchoices.setEsxDatastoreDevice(dev.name)
            userchoices.setVmdkDatastore(self.volumeName)
        else:   # use existing datastore
            userchoices.setClearPartitions(drives=[self.esxDeviceName])

            userchoices.clearVirtualDevices()

            userchoices.setEsxDatastoreDevice(None)
            userchoices.setVmdkDatastore(self.volumeName)

        # size check
        size = partition.getRequestsSize(partition.getDefaultVirtualRequests())
        if size > devices.runtimeActionFindMaxVmdkSize():
            self.setSubstepEnv({'next': self.warnTooSmall})
            return
        self.setSubstepEnv({'next': self.stepForward})