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 create_new_vg(self, name, max_phys, max_log, extent_size, is_unit_megs, pv, clustered=False): if is_unit_megs: units_arg = 'm' else: units_arg = 'k' size_arg = extent_size + units_arg args = list() args.append(VGCREATE_BIN_PATH) args.append("-M2") args.append("-l") args.append(max_log) args.append("-p") args.append(max_phys) args.append("-s") args.append(size_arg) args.append('-c') if clustered: args.append('y') else: args.append('n') args.append(name.strip()) args.append(pv.strip()) cmdstr = ' '.join(args) out,err,res = execWithCaptureErrorStatusProgress(VGCREATE_BIN_PATH, args, _("Creating Volume Group")) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("vgcreate",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 extend_online(self, dev_path): cmd = '/usr/sbin/xfs_growfs' args = [cmd, dev_path] cmdstr = ' '.join(args) msg = RESIZING_FS % (self.name) o, e, s = execWithCaptureErrorStatusProgress(cmd, args, msg) if s != 0: raise CommandError('FATAL', FSRESIZE_FAILURE % (cmdstr, e))
def create(self, path): if not self.creatable: raise "not creatable" try: valid = False while not valid: rc = self.dlg.run() if rc == gtk.RESPONSE_OK: valid = True msg = '' illegal_chars = ';:\'"/?.>,<]}[{ =+)(*&^%$#@!`~' c_name = self.clustername_entry.get_text().strip() g_name = self.gfsname_entry.get_text().strip() for c in illegal_chars: if c in c_name: msg = _( "Cluster name contains illegal character " + c) valid = False if c in g_name: msg = _("GFS name contains illegal character " + c) valid = False if len(c_name) == 0: msg = _("Missing Cluster Name") valid = False elif len(g_name) == 0: msg = _("Missing GFS Name") valid = False if not valid: self.__errorMessage(msg) else: j_num = self.journals_spin.get_value_as_int() table = c_name + ':' + g_name locking_type = 'lock_' if self.lock_dlm_butt.get_active(): locking_type += 'dlm' elif self.lock_gulm_butt.get_active(): locking_type += 'gulm' except: self.dlg.hide() raise self.dlg.hide() MKFS_GFS_BIN = '/sbin/gfs_mkfs' args = [MKFS_GFS_BIN] args.append('-j') args.append(str(j_num)) args.append('-p') args.append(locking_type) args.append('-t') args.append(table) args.append('-O') args.append(path) cmdstr = ' '.join(args) msg = CREATING_FS % (self.name) o, e, r = execWithCaptureErrorStatusProgress(MKFS_GFS_BIN, args, msg) if r != 0: raise CommandError('FATAL', FSCREATE_FAILURE % (cmdstr, e))
def extend_online(self, dev_path): args = ['/sbin/gfs2_grow'] args.append(dev_path) cmdstr = ' '.join(args) msg = RESIZING_FS % (self.name) o, e, r = execWithCaptureErrorStatusProgress('/sbin/gfs2_grow', args, msg) if r != 0: raise CommandError('FATAL', FSRESIZE_FAILURE % (cmdstr, e))
def upgrade(self, dev_path): args = ['/sbin/tune2fs'] args.append('-j') args.append(dev_path) cmdstr = ' '.join(args) msg = UPGRADING_FS % (self.name, ext3().name) o, e, r = execWithCaptureErrorStatusProgress('/sbin/tune2fs', args, msg) if r != 0: raise CommandError('FATAL', FSUPGRADE_FAILURE % (cmdstr, e))
def remove_pv(self, pvname): args = list() args.append(PVREMOVE_BIN_PATH) args.append("--config") args.append("'log{command_names=0}'") args.append(pvname.strip()) cmdstr = ' '.join(args) out,err,res = execWithCaptureErrorStatusProgress(PVREMOVE_BIN_PATH,args, _("Removing Physical Volume")) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("pvremove",cmdstr,err))
def create(self, path): args = list() args.append("/sbin/mkfs") args.append("-t") args.append('xfs') args.append(path) cmdstr = ' '.join(args) msg = CREATING_FS % (self.name) o, e, r = execWithCaptureErrorStatusProgress("/sbin/mkfs", args, msg) if r != 0: raise CommandError('FATAL', FSCREATE_FAILURE % (cmdstr, e))
def add_unalloc_to_vg(self, pv, vg): args = list() args.append(VGEXTEND_BIN_PATH) args.append("--config") args.append("'log{command_names=0}'") args.append(vg.strip()) args.append(pv.strip()) cmdstr = ' '.join(args) out,err,res = execWithCaptureErrorStatusProgress(VGEXTEND_BIN_PATH, args, _("Adding Physical Volume to Volume Group")) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("vgextend",cmdstr,err))
def remove_mirroring(self, lvpath): cmd_args = list() cmd_args.append(LVCONVERT_BIN_PATH) cmd_args.append("--config") cmd_args.append("'log{command_names=0}'") cmd_args.append('-m0') cmd_args.append(lvpath) cmdstr = ' '.join(cmd_args) out,err,res = execWithCaptureErrorStatusProgress(LVCONVERT_BIN_PATH, cmd_args, _("Removing Mirror from Logical Volume")) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("lvconvert",cmdstr,err))
def reduce_vg(self, vg, pv): args = list() args.append(VGREDUCE_BIN_PATH) args.append("--config") args.append("'log{command_names=0}'") args.append(vg.strip()) args.append(pv.strip()) cmdstr = ' '.join(args) out,err,res = execWithCaptureErrorStatusProgress(VGREDUCE_BIN_PATH,args, _("Removing Physical Volume from Volume Group")) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("vgreduce",cmdstr,err))
def initialize_entity(self, ent): entity = ent.strip() command_args = list() command_args.append(PVCREATE_BIN_PATH) command_args.append("-M") command_args.append("2") command_args.append(entity) commandstring = ' '.join(command_args) out,err,res = execWithCaptureErrorStatusProgress(PVCREATE_BIN_PATH,command_args, _("Initializing Physical Volume")) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("pvcreate",commandstring,err))
def extend_offline(self, dev_path): # first check fs (resize2fs requirement) args = list() args.append('/sbin/e2fsck') args.append('-f') args.append('-p') # repair fs args.append(dev_path) cmdstr = ' '.join(args) msg = CHECKING_FS % self.name o, e, r = execWithCaptureErrorStatusProgress('/sbin/e2fsck', args, msg) if not (r == 0 or r == 1): raise CommandError('FATAL', FSCHECK_FAILURE % (cmdstr, e)) args = list() args.append('/sbin/resize2fs') args.append(dev_path) cmdstr = ' '.join(args) msg = RESIZING_FS % (self.name) o, e, r = execWithCaptureErrorStatusProgress('/sbin/resize2fs', args, msg) if r != 0: raise CommandError('FATAL', FSRESIZE_FAILURE % (cmdstr, e))
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 rename_lv(self, vgname, lvname_old, lvname_new): args = list() args.append(LVRENAME_BIN_PATH) args.append("--config") args.append("'log{command_names=0}'") args.append(vgname) args.append(lvname_old) args.append(lvname_new) cmdstr = ' '.join(args) out,err,res = execWithCaptureErrorStatusProgress(LVRENAME_BIN_PATH,args, _("Renaming Logical Volume")) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("lvrename",cmdstr,err))
def create(self, path): MKFS_GFS_BIN = '/sbin/gfs2_mkfs' args = [MKFS_GFS_BIN] args.append('-j') args.append('1') args.append('-p') args.append('lock_nolock') args.append('-O') args.append(path) cmdstr = ' '.join(args) msg = CREATING_FS % (self.name) o, e, r = execWithCaptureErrorStatusProgress(MKFS_GFS_BIN, args, msg) if r != 0: raise CommandError('FATAL', FSCREATE_FAILURE % (cmdstr, e))
def add_mirroring(self, lvpath, pvlist=[]): cmd_args = list() cmd_args.append(LVCONVERT_BIN_PATH) cmd_args.append("--config") cmd_args.append("'log{command_names=0}'") cmd_args.append('-m1') cmd_args.append(lvpath) for pv in pvlist: cmd_args.append(pv.get_path()) cmdstr = ' '.join(cmd_args) out,err,res = execWithCaptureErrorStatusProgress(LVCONVERT_BIN_PATH, cmd_args, _("Adding Mirror to Logical Volume")) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("lvconvert",cmdstr,err))
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 remove_lv(self, lvpath): if self.is_snapshot(lvpath) == False: self.deactivate_lv(lvpath) try: args = list() args.append(LVREMOVE_BIN_PATH) args.append("--config") args.append("'log{command_names=0}'") args.append("--force") args.append(lvpath.strip()) cmdstr = ' '.join(args) out,err,res = execWithCaptureErrorStatusProgress(LVREMOVE_BIN_PATH,args, _("Removing Logical Volume")) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("lvremove",cmdstr,err)) except CommandError, e: self.activate_lv(lvpath) raise e
def new_lv(self, cmd_args_dict, pvlist=[]): #first set up lvcreate args arglist = list() arglist.append(LVCREATE_BIN_PATH) arglist.append("-n") lvname = cmd_args_dict[NEW_LV_NAME_ARG] arglist.append(lvname) if cmd_args_dict[NEW_LV_UNIT_ARG] == EXTENT_IDX: arglist.append("-l") arglist.append(str(cmd_args_dict[NEW_LV_SIZE_ARG])) else: arglist.append("-L") if cmd_args_dict[NEW_LV_UNIT_ARG] == KILOBYTE_IDX: arglist.append(str(cmd_args_dict[NEW_LV_SIZE_ARG]) + "k") elif cmd_args_dict[NEW_LV_UNIT_ARG] == MEGABYTE_IDX: arglist.append(str(cmd_args_dict[NEW_LV_SIZE_ARG]) + "m") elif cmd_args_dict[NEW_LV_UNIT_ARG] == GIGABYTE_IDX: arglist.append(str(cmd_args_dict[NEW_LV_SIZE_ARG]) + "g") if cmd_args_dict[NEW_LV_SNAPSHOT]: arglist.append("-s") arglist.append(cmd_args_dict[NEW_LV_SNAPSHOT_ORIGIN]) else: if cmd_args_dict[NEW_LV_MIRRORING]: arglist.append("-m1") if cmd_args_dict[NEW_LV_IS_STRIPED_ARG] == True: arglist.append("-i") arglist.append(str(cmd_args_dict[NEW_LV_NUM_STRIPES_ARG])) arglist.append("-I") arglist.append(str(cmd_args_dict[NEW_LV_STRIPE_SIZE_ARG])) vgname = cmd_args_dict[NEW_LV_VGNAME_ARG] arglist.append(vgname) for pv in pvlist: arglist.append(pv.get_path()) cmd_str = ' '.join(arglist) result_string,err,res = execWithCaptureErrorStatusProgress(LVCREATE_BIN_PATH, arglist, _("Creating Logical Volume")) if res != 0: raise CommandError('FATAL', COMMAND_FAILURE % ("lvcreate",cmd_str,err))