def run(options, args): if len(args) < 1: raise cli.Error("Device name must be specified.") deviceName = args[0] snapshotSize = options.snapshot_size s = system.getSystem() with s.openProcessForInput("lsblk -nr -o MAJ:MIN,FSTYPE %s" % deviceName) as lsblk: line = lsblk.readline() if not line: raise cli.Error("Device '%s' doesn't exist or may not be a block device." % deviceName) splitted = line.split(" ") devNum = splitted[0] fstype = splitted[1].strip() if len(splitted) > 1 else None if fstype == "": fstype = None backupFunc = backupRaw if fstype is None else backupTar print >> sys.stderr, "Backup type:%s" % ("raw" if backupFunc == backupRaw else "tar") useSnapshot = (deviceName in (x.strip() for x in subprocess.check_output("lvs --noheadings -o lv_path --unquoted", shell=True, close_fds=True).split('\n') if x != "") and snapshotSize > 0) if useSnapshot: with s.openSnapshot(deviceName, snapshotSize) as snapshot: print >> sys.stderr, "Using snapshot:%s" % snapshot backupFunc(snapshot) else: backupFunc(deviceName) print >>sys.stderr, "Done."
def run(options, args): if len(args) < 2: raise cli.Error("Insufficient parameters.") source = args[0] target = args[1] bufsize = options.bufsize * 1024 exclude_from = options.exclude_from s = system.getSystem() if not s.isStreamSourceAvailable(source): raise cli.Error("Source file '%s' is not available." % source) if not os.path.isdir(target): raise cli.Error("Invalid target dir") extractor = generateExtractorBySuffix(source, target) if exclude_from != None: extractor.append("-X") extractor.append(exclude_from) i = 0 tar = subprocess.Popen(extractor, shell=False, stdin=subprocess.PIPE, close_fds=True) itstime = time.time() try: with s.openInputStream(source) as (src, size): buf = src.read(bufsize) i += len(buf) while buf != "": newtime = time.time() if newtime >= itstime + 0.01: print "%d/%d" % (i, size) sys.stdout.flush() itstime = newtime tar.stdin.write(buf) buf = src.read(bufsize) i += len(buf) print "%d/%d" % (size, size) sys.stdout.flush() except KeyboardInterrupt: tar.terminate() tar.stdin.close() tar.wait() exit(130) tar.stdin.close() tar.wait()
def run(options, args): if len(args) < 1: raise cli.Error("Insufficient parameters.") src = args[0] dest = None if len(args) < 2 else args[1] s = system.getSystem() if not s.isBlockSpecial(src): raise cli.Error("Source must be a block device") if s.isLogicalVolume(src): return src_lv(src, dest, options) #else return src_block(src, dest, options)
def run(options, args): if len(args) < 1: raise cli.Error("Insufficient parameters") cmd = ["/init"] if len(args) < 2 else args[1:] rootdir = args[0] #pid = os.fork() #if pid == 0: chroot_exec(rootdir, cmd, options.root_group)
def run(options, args): if len(args) < 2: raise cli.Error("Insufficient parameters.") src = args[0] dest = args[1] s = system.getSystem() if s.isBlockSpecial(src): if s.isLogicalVolume(src): return src_lv(src, dest, options) #else return src_block(src, dest, options) elif os.path.isdir(src): return src_dir(src, dest, options) #else raise cli.Error( "Invalid source specified(must be a directory or a mountable block device)" )
def run(options, args): if len(args) < 1: raise cli.Error("Insufficient parameters.") vgname = args[0] s = system.getSystem() device = s.createLogicalVolume(vgname, "_WBDISKBENCH_", 1) try: print "Testing sequential write..." sequential_write(device) print "Testing sequential read..." sequential_read(device) finally: s.removeLogicalVolume(device)
def execute(command, capture_output=True): cmd_encoding = locale.getpreferredencoding() if isinstance(command, list): result_command = [cmd.escape(arg).encode(cmd_encoding) for arg in command] else: result_command = command.encode(cmd_encoding) output_buffer = subprocess.PIPE if capture_output else None process = subprocess.Popen(result_command, stdout=output_buffer, stderr=output_buffer, shell=True) stdout, stderr = process.communicate() if process.returncode != 0 or capture_output and stderr: print_string(stderr.decode(locale.getpreferredencoding()), file=sys.stderr) raise cli.Error(u'Process execution error!') return stdout
def src_dir(src, dest, options): cmdline = ["rsync", "-ax"] if options.verbose: cmdline.append("-v") if options.delete: cmdline.append("--delete") cmdline.append(src if src.endswith('/') else src + '/') cmdline.append(dest) rsync = subprocess.Popen(cmdline) while True: try: rst = rsync.wait() if rst != 0: raise cli.Error("Rsync retuened error code:%d" % rst) return True except KeyboardInterrupt: pass # just to make sure subprocess is finished
def run(): parser = OptionParser(usage="usage: %prog [appname]", version="%prog 1.0") parser.add_option("-x", "--prefer-x11", dest="prefer_x11", action="store_true", help="Use X11 unless not compatible", default=False) (options, args) = parser.parse_args() device = None if len(args) > 0: appname = args[0] apps = system.get_apps() for app in apps: if app["name"] == appname: device = app["device"] break if device == None: raise cli.Error("Application %s doesn't exist" % (appname)) elif os.path.exists(system.runapp_link): mode = os.stat(system.runapp_link)[stat.ST_MODE] if not stat.S_ISBLK(mode): raise cli.Error("Symlink %s is not pointing a block device" % (system.runapp_link)) device = os.path.realpath(system.runapp_link) if device == None: raise cli.Error( "Appname must be specified unless %s symlink does exist." % (system.runapp_link)) with system.Mount(device) as tmpdir: metadata = system.get_metadata_from_cache(device) if metadata == None: metadata = system.get_app_metadata(device, tmpdir) run_app(tmpdir, metadata, options.prefer_x11)
def run(options, args): if len(args) < 1: raise cli.Error("Insufficient parameters.") domain = args[0] curses.setupterm() tput("sc") tput("cup", 24, 0) tput("setab", 6) tput("setaf", 4) print "[Walbrix]-------------------------------------------------------------" tput("sgr0") print string_cli_conn_console % unicode(domain) print string_cli_root_pass tput("setab", 7) tput("setaf", 1) print string_cli_console_disconnect tput("sgr0") tput("csr", 0, 23) tput("rc") print string_cli_desc os.execv("/usr/sbin/xl", ("/usr/sbin/xl", "console", domain))