def logPartitioningScheme(): """ Logs all disks state @rtype: tuple @returns: (status, output) of command """ return getstatusoutput(CMD_LIST_ALL)
def detectPowerKVMInstalledDisk(self, boot_parts=None): """Detect the partition where PowerKVM is installed. @rtype: String @return: The disk PowerKVM is installed or None if none found""" if boot_parts == None: self.__logger.debug("detectPowerKVMInstalledDisk(): boot_parts == None") return None # We need to run pvscan and try to find any of boot_parts in # its output. If matched, it's the disk to be used during # reinstall. # # For example: # # bash-4.2# pvscan # No matching physical volumes found # # bash-4.2# pvscan # PV /dev/sda6 VG ibmpkvm_vg_log lvm2 [10.00 GiB / 0 free] # PV /dev/sda5 VG ibmpkvm_vg_root lvm2 [20.00 GiB / 0 free] # PV /dev/sda8 VG ibmpkvm_vg_data lvm2 [41.48 GiB / 0 free] # PV /dev/sda7 VG ibmpkvm_vg_swap lvm2 [8.00 GiB / 0 free] # Total: 4 [79.47 GiB] / in use: 4 [79.47 GiB] / in no VG: 0 [0 ] ret, output = getstatusoutput("pvscan") self.__logger.debug("detectPowerKVMInstalledDisk(): pvscan return: {0}".format(ret)) self.__logger.debug("detectPowerKVMInstalledDisk(): pvscan output:\n{0}".format(output)) if NO_PHYSICAL_VOLUMES_FOUND in output: self.__logger.debug("detectPowerKVMInstalledDisk(): no physical volumes found") return None # remove numbers from boot_parts, thus we'll have a list of disk names disks = [''.join([c for c in part if not c.isdigit()]) for part in boot_parts] pkvm_installed_disk = None # parse pvscan output for line in output.split('\n'): if VGROOT in line: root_part = line.split()[1] pv_name = ''.join([c for c in root_part if not c.isdigit()]) self.__logger.debug("detectPowerKVMInstalledDisk(): pv_name = {0}".format(pv_name)) for disk in disks: self.__logger.debug("detectPowerKVMInstalledDisk(): disk = {0}".format(disk)) if disk == pv_name: self.__logger.debug("detectPowerKVMInstalledDisk(): disk == pv_name") pkvm_installed_disk = pv_name return pkvm_installed_disk
def _runPartedCommand(partedCommand, disk, errorMessage, hasMultipath=False, tolerant=False): """ Runs a parted command and re-read disk partition table. @type partedCommand: basestring @param partedCommand: parted command to run @type disk: basestring @param disk: disk path @type errorMessage: basestring @param errorMessage: error message to user in case of a failure @type hasMultipath: bool @param hasMultipath: flag that informs if system has multipath @type tolerant: bool @param tolerant: True to not exit if error found, False otherwise @rtype: None @returns: nothing """ # runs command (status, output) = getstatusoutput(partedCommand) # log command line llecho("Running: %s" % partedCommand) # log exit status and output llecho("Status: %d" % status) llecho("Output:\n%s\n" % output) if hasMultipath: return # FIXME: use a safer check here, i.e., a regular expression to match the # desired output. # partition table needs to be re-read: do it if 're-read' in output: # partition table was successfully re-read: change status accordingly if _reReadPartitionTable(disk, hasMultipath): status = 0 # command failed: log and exit if status != 0: llecho(errorMessage) if not tolerant: sys.exit(1)
def _hasValidDiskLabel(disk): """ Informs if the disk has a valid disk label. @type disk: basestring @param disk: disk path @rtype: bool @returns: True if the disk has a valid label, False otherwise """ # get disk label through blkid (status, output) = getstatusoutput(CMD_CHECK_PARTITION % {'disk': disk}) # could not get disk label or it is invalid: return False if status != 0 or output.strip() != 'dos': return False # valid disk label: return True return True