def unmount(self, mountpoint): args = ['/bin/umount'] args.append(mountpoint) cmdstr = ' '.join(args) out,err,res = execWithCaptureErrorStatus("/bin/umount", args) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("umount",cmdstr, err)) # unmount all with mountpoint while res == 0: out,err,res = execWithCaptureErrorStatus("/bin/umount", args)
def move_pv(self, pv, extents_from, data, background=False): args = list() args.append(PVMOVE_BIN_PATH) args.append("--config") args.append("'log{command_names=0}'") # policy if data[1] != None: if data[1] == 0: args.append('--alloc inherit') elif data[1] == 1: args.append('--alloc normal') elif data[1] == 2: args.append('--alloc contiguous') elif data[1] == 3: args.append('--alloc anywhere') # lv to migrate from if data[2] != None: args.append('--name ' + data[2]) # pv to migrate from pv_from = pv.strip() for (start, size) in extents_from: pv_from = pv_from + ':' + str(start) + '-' + str(start + size - 1) args.append(pv_from) # pv to migrate to if data[0] != None: args.append(data[0]) if background: args.append('--background') out, err, res = execWithCaptureErrorStatus(PVMOVE_BIN_PATH, args) else: out, err, res = execWithCaptureErrorStatusProgress(PVMOVE_BIN_PATH, args, _("Migrating Extents")) if res != 0: cmdstr = ' '.join(args) raise CommandError('FATAL', COMMAND_FAILURE % ("pvmove",cmdstr, err))
def remove_vg(self, vgname): args = list() args.append(VGCHANGE_BIN_PATH) args.append("--config") args.append("'log{command_names=0}'") args.append("-a") args.append("n") args.append(vgname.strip()) cmdstr = ' '.join(args) out,err,res = execWithCaptureErrorStatus(VGCHANGE_BIN_PATH,args) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("vgchange",cmdstr,err)) return commandstring = VGREMOVE_BIN_PATH + " " + vgname args_list = list() args_list.append(VGREMOVE_BIN_PATH) args_list.append("--config") args_list.append("'log{command_names=0}'") args_list.append(vgname) cmdstring = ' '.join(args) outs,errs,result = execWithCaptureErrorStatusProgress(VGREMOVE_BIN_PATH,args_list, _("Removing Volume Group")) if result != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("vgremove",cmdstring,errs))
def reread_partition_table(self, devpath): BLOCKDEV_BIN = '/sbin/blockdev' args = [BLOCKDEV_BIN, '--rereadpt', devpath] out, err, status = execWithCaptureErrorStatus(BLOCKDEV_BIN, args) if status != 0: return False execWithCaptureProgress('sleep', ['sleep', '1'], _('Rereading partition table')) return True
def running(self): if self.get_name() == None: return False try: # try magma_tool args = ['/sbin/magma_tool', 'quorum'] o, e, s = execWithCaptureErrorStatus('/sbin/magma_tool', args) if s == 0: if o.find('Quorate') != -1: return True except: pass try: # try cman_tool cman_tool_path = '/sbin/cman_tool' if os.access(cman_tool_path, os.X_OK) == False: cman_tool_path = '/usr/sbin/cman_tool' args = [cman_tool_path, 'status'] o, e, s = execWithCaptureErrorStatus(cman_tool_path, args) if s != 0: return False quorum = -1 votes = -1 lines = o.splitlines() for line in lines: words = line.split() if len(words) < 2: continue if words[0] == 'Quorum:': quorum = int(words[1]) elif words[0] == 'Total_votes:': votes = int(words[1]) if len(words) < 3: continue if words[0] == 'Total' and words[1] == 'votes:': votes = int(words[2]) if quorum <= 0 or votes < 0: raise 'Unable to retrieve cluster quorum info' return votes >= quorum except: return False
def activate_lv(self, lvpath): cmd_args = list() cmd_args.append(LVCHANGE_BIN_PATH) cmd_args.append("--config") cmd_args.append("'log{command_names=0}'") cmd_args.append('-ay') cmd_args.append(lvpath) cmdstr = ' '.join(cmd_args) out,err,res = execWithCaptureErrorStatus(LVCHANGE_BIN_PATH, cmd_args) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("lvchange",cmdstr,err))
def mount(self, dev_path, mnt_point, fstype): cmd_args = list() cmd_args.append("/bin/mount") cmd_args.append('-t') cmd_args.append(fstype) cmd_args.append(dev_path) cmd_args.append(mnt_point) cmdstr = ' '.join(cmd_args) out,err,res = execWithCaptureErrorStatus("/bin/mount",cmd_args) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("mount",cmdstr,err))
def is_snapshot(self, lvpath): arglist = list() arglist = [LVM_BIN_PATH, 'lvs', '--config', "'log{command_names=0}'", "-o", "attr", "--noheadings", lvpath] out, err, status = execWithCaptureErrorStatus(LVM_BIN_PATH, arglist) if status != 0: return False if out.lstrip().startswith("s") == True: return True else: return False
def complete_pvmove(self, background=False): args = [PVMOVE_BIN_PATH] args.append("--config") args.append("'log{command_names=0}'") if background: args.append('--background') out, err, res = execWithCaptureErrorStatus(PVMOVE_BIN_PATH, args) else: out, err, res = execWithCaptureErrorStatusProgress(PVMOVE_BIN_PATH, args, _("Completing Extent Migration")) if res != 0: cmdstr = ' '.join(args) raise CommandError('FATAL', COMMAND_FAILURE % ("pvmove",cmdstr, err))
def __get_gfs_fstype(self, path): if self.check_path('/sbin/gfs_tool'): args = ['/sbin/gfs_tool'] args.append('sb') args.append(path) args.append('ondisk') cmdstr = ' '.join(args) o, e, r = execWithCaptureErrorStatus('/sbin/gfs_tool', args) if r == 0: for k, v in gfs_types.iteritems(): if k in o: return v return None
def __get_gfs_table_name(self, path): if self.check_path('/sbin/gfs_tool'): args = ['/sbin/gfs_tool'] args.append('sb') args.append(path) args.append('table') cmdstr = ' '.join(args) o, e, r = execWithCaptureErrorStatus('/sbin/gfs_tool', args) if r == 0: words = o.strip().split() if len(words) == 6: return words[5].strip('\"').split(':') return (None, None)
def __get_gfs_lock_type(self, path): if self.check_path('/sbin/gfs2_tool'): args = ['/sbin/gfs2_tool'] args.append('sb') args.append(path) args.append('proto') cmdstr = ' '.join(args) o, e, r = execWithCaptureErrorStatus('/sbin/gfs2_tool', args) if r == 0: if 'lock_dlm' in o: return 'dlm' elif 'lock_gulm' in o: return 'gulm' elif 'nolock' in o: return 'nolock' return None
def extend_lv(self, lvpath, new_size_extents, test=False): cmd_args = list() cmd_args.append(LVEXTEND_BIN_PATH) cmd_args.append("--config") cmd_args.append("'log{command_names=0}'") if test: cmd_args.append('--test') cmd_args.append('-l') cmd_args.append(str(new_size_extents)) cmd_args.append(lvpath) cmdstr = ' '.join(cmd_args) if test: out,err,res = execWithCaptureErrorStatus(LVEXTEND_BIN_PATH, cmd_args) return (res == 0) out,err,res = execWithCaptureErrorStatusProgress(LVEXTEND_BIN_PATH, cmd_args, _("Resizing Logical Volume")) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("lvresize",cmdstr,err))
def __get_data_for_PV(self, pv, pvs_output): # anything that is in, place to the end end = pv.get_properties() text_list = list() if pv.get_type() == UNINITIALIZED_TYPE: # size size_string = pv.get_size_total_string() text_list.append(UV_SIZE) text_list.append(size_string) # partition type part = pv.getPartition()[1] partition_type = PARTITION_IDs[part.id] if part.id != ID_EMPTY and part.id != ID_UNKNOWN: partition_type = partition_type + ' (' + str(hex( part.id)) + ')' text_list.append(UV_PARTITION_TYPE) text_list.append(partition_type) # mount point mountPoints = [] for path in pv.get_paths(): mountPoint = self.getMountPoint(path) if mountPoint != None: if mountPoint == '/': mountPoint = _("/ Root Filesystem") mountPoints.append(mountPoint) if len(mountPoints) == 0: mountPoints = UNMOUNTED else: mount_list = mountPoints mountPoints = mount_list[0] for mountPoint in mount_list[1:]: mountPoints = mountPoints + ', ' + mountPoint text_list.append(UV_MOUNT_POINT) text_list.append(mountPoints) fstabMountPoints = [] for path in pv.get_paths(): mountPoint = Fstab.get_mountpoint(path) if mountPoint != None: if mountPoint == '/': mountPoint = _("/ Root Filesystem") fstabMountPoints.append(mountPoint) if len(fstabMountPoints) == 0: fstabMountPoints = _("None") else: mount_list = fstabMountPoints fstabMountPoints = mount_list[0] for mountPoint in mount_list[1:]: fstabMountPoints = fstabMountPoints + ', ' + mountPoint text_list.append(UV_MOUNTPOINT_AT_REBOOT) text_list.append(fstabMountPoints) # filesystem text_list.append(UV_FILESYSTEM) text_list.append(self.__getFS(path)) else: # UNALLOCATED_TYPE || PHYS_TYPE lines = pvs_output.splitlines() for line in lines: words = line.strip().split(',') if words[PV_NAME_IDX] in pv.get_paths(): break text_list.append(PV_NAME) text_list.append(words[PV_NAME_IDX]) if words[PV_VG_NAME_IDX] == "": text_list.append(VG_NAME) text_list.append("---") else: text_list.append(VG_NAME) text_list.append(words[PV_VG_NAME_IDX]) text_list.append(PV_SIZE) text_list.append(words[PV_SIZE_IDX]) text_list.append(PV_USED) text_list.append(words[PV_USED_IDX]) text_list.append(PV_FREE) text_list.append(words[PV_FREE_IDX]) text_list.append(PV_PE_COUNT) text_list.append(words[PV_PE_COUNT_IDX]) text_list.append(PV_PE_ALLOC_COUNT) text_list.append(words[PV_PE_ALLOC_COUNT_IDX]) text_list.append(PV_ATTR) text_list.append(words[PV_ATTR_IDX]) text_list.append(PV_UUID) text_list.append(words[PV_UUID_IDX]) # append old props for prop in end: text_list.append(prop) try: # add scsi dev info device = pv.getDevnames()[0] devname = pv.extract_name(device) SCSI_ID_BIN = '/sbin/scsi_id' args = [SCSI_ID_BIN, '-g', '-i', '-u', '-s', '/block/' + devname] o, e, s = execWithCaptureErrorStatus(SCSI_ID_BIN, args) if s == 0: scsi_addr, scsi_id = o.strip().split() scsi_addr = scsi_addr.strip(':') text_list.append(_("SCSI Address: ")) text_list.append(scsi_addr) text_list.append(_("SCSI ID: ")) text_list.append(scsi_id) except: pass return text_list
def get_multipath_data(self): multipath_data = {} dmsetup_lines = None if os.access(DMSETUP_BIN, os.F_OK): args = list() args.append(DMSETUP_BIN) args.append('table') cmdstr = ' '.join(args) o,e,r = execWithCaptureErrorStatus(DMSETUP_BIN, args) if r != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("dmsetup",cmdstr, e)) dmtable_lines = o.splitlines() else: return multipath_data args = list() args.append(LS_BIN) args.append('-l') args.append('/dev/') cmdstr = ' '.join(args) o,e,r = execWithCaptureErrorStatus(LS_BIN, args) if r != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("ls",cmdstr, e)) ls_lines = o.splitlines() # get block devices block_devices = [] for line in ls_lines: words = line.split() if len(words) == 0: continue if words[0][0] == 'b': # [name, major, minor] block_devices.append(['/dev/' + words[9], words[4].rstrip(','), words[5]]) # process dmsetup table for line in dmtable_lines: if len(line) == 0: continue words = line.split() if 'multipath' not in words: continue # get origin args = list() args.append(DMSETUP_BIN) args.append('ls') cmdstr = ' '.join(args) o,e,r = execWithCaptureErrorStatus(DMSETUP_BIN, args) if r != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("dmsetup",cmdstr, e)) origin = None origin_name = words[0].rstrip(':') for or_line in o.splitlines(): or_words = or_line.split() if or_words[0] == origin_name: major = or_words[1].strip('(').strip(',') minor = or_words[2].strip(')') for l in block_devices: if l[1] == major and l[2] == minor: origin = l[0] break break if origin == None: origin = '/dev/mapper/' + origin_name devices = [] for word in words[1:]: if ':' in word: idx = word.find(':') major = word[:idx] minor = word[idx+1:] for bd in block_devices: if bd[1] == major and bd[2] == minor: devices.append(bd[0]) if len(devices) == 0: print 'multipath error: ' + origin + str(devices) continue multipath_data[origin] = devices return multipath_data
def __get_data_for_PV(self, pv, pvs_output): # anything that is in, place to the end end = pv.get_properties() text_list = list() if pv.get_type() == UNINITIALIZED_TYPE: # size size_string = pv.get_size_total_string() text_list.append(UV_SIZE) text_list.append(size_string) # partition type part = pv.getPartition()[1] partition_type = PARTITION_IDs[part.id] if part.id != ID_EMPTY and part.id != ID_UNKNOWN: partition_type = partition_type + ' (' + str(hex(part.id)) + ')' text_list.append(UV_PARTITION_TYPE) text_list.append(partition_type) # mount point mountPoints = [] for path in pv.get_paths(): mountPoint = self.getMountPoint(path) if mountPoint != None: if mountPoint == '/': mountPoint = _("/ Root Filesystem") mountPoints.append(mountPoint) if len(mountPoints) == 0: mountPoints = UNMOUNTED else: mount_list = mountPoints mountPoints = mount_list[0] for mountPoint in mount_list[1:]: mountPoints = mountPoints + ', ' + mountPoint text_list.append(UV_MOUNT_POINT) text_list.append(mountPoints) fstabMountPoints = [] for path in pv.get_paths(): mountPoint = Fstab.get_mountpoint(path) if mountPoint != None: if mountPoint == '/': mountPoint = _("/ Root Filesystem") fstabMountPoints.append(mountPoint) if len(fstabMountPoints) == 0: fstabMountPoints = _("None") else: mount_list = fstabMountPoints fstabMountPoints = mount_list[0] for mountPoint in mount_list[1:]: fstabMountPoints = fstabMountPoints + ', ' + mountPoint text_list.append(UV_MOUNTPOINT_AT_REBOOT) text_list.append(fstabMountPoints) # filesystem text_list.append(UV_FILESYSTEM) text_list.append(self.__getFS(path)) else: # UNALLOCATED_TYPE || PHYS_TYPE lines = pvs_output.splitlines() for line in lines: words = line.strip().split(',') if words[PV_NAME_IDX] in pv.get_paths(): break text_list.append(PV_NAME) text_list.append(words[PV_NAME_IDX]) if words[PV_VG_NAME_IDX] == "": text_list.append(VG_NAME) text_list.append("---") else: text_list.append(VG_NAME) text_list.append(words[PV_VG_NAME_IDX]) text_list.append(PV_SIZE) text_list.append(words[PV_SIZE_IDX]) text_list.append(PV_USED) text_list.append(words[PV_USED_IDX]) text_list.append(PV_FREE) text_list.append(words[PV_FREE_IDX]) text_list.append(PV_PE_COUNT) text_list.append(words[PV_PE_COUNT_IDX]) text_list.append(PV_PE_ALLOC_COUNT) text_list.append(words[PV_PE_ALLOC_COUNT_IDX]) text_list.append(PV_ATTR) text_list.append(words[PV_ATTR_IDX]) text_list.append(PV_UUID) text_list.append(words[PV_UUID_IDX]) # append old props for prop in end: text_list.append(prop) try: # add scsi dev info device = pv.getDevnames()[0] devname = pv.extract_name(device) SCSI_ID_BIN = '/sbin/scsi_id' args = [SCSI_ID_BIN, '-g', '-i', '-u', '-s', '/block/' + devname] o, e, s = execWithCaptureErrorStatus(SCSI_ID_BIN, args) if s == 0: scsi_addr, scsi_id = o.strip().split() scsi_addr = scsi_addr.strip(':') text_list.append(_("SCSI Address: ")) text_list.append(scsi_addr) text_list.append(_("SCSI ID: ")) text_list.append(scsi_id) except: pass return text_list