当前位置: 首页>>代码示例>>Python>>正文


Python util.doexec函数代码示例

本文整理汇总了Python中util.doexec函数的典型用法代码示例。如果您正苦于以下问题:Python doexec函数的具体用法?Python doexec怎么用?Python doexec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了doexec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: diff

def diff(vhd_fn1, vhd_fn2):
    cmd = "vhd-util check -n %s" % (vhd_fn1)
    util.doexec(cmd, 0)
    cmd = "vhd-util check -n %s" % (vhd_fn2)
    util.doexec(cmd, 0)
    cmd = LIBVHDIO_CMD + "diff %s %s" % (vhd_fn1, vhd_fn2)
    return util.doexec(cmd, 0)
开发者ID:2xyo,项目名称:transfervm,代码行数:7,代码来源:vhd.py

示例2: zeroReferenceFile

def zeroReferenceFile(reference_fn, size_mb):
    if os.path.isfile(reference_fn):
         cmdrm = "rm %s" % (reference_fn)
         util.doexec(cmdrm,0)

    cmd = "dd if=/dev/zero of=%s bs=1M count=%d" % (reference_fn, size_mb)
    util.doexec(cmd, 0)
    return
开发者ID:2xyo,项目名称:transfervm,代码行数:8,代码来源:vhd.py

示例3: _fill_range

def _fill_range(vhd_fn, reference_fn, pattern_fn, off, len, pattern_len, pattern_off):
    if pattern_off < off:
        raise Exception("invalid usage of _fill_range")

 #   _zero(reference_fn, off, pattern_off - off)
    cmd = "dd conv=notrunc if=%s of=%s bs=1 seek=%d" % (pattern_fn, reference_fn, pattern_off)
    util.doexec(cmd, 0)
  #  _zero(reference_fn, pattern_off + pattern_len, len - pattern_len - (pattern_off - off))

    cmd = LIBVHDIO_CMD + "dd if=%s of=%s bs=1 seek=%d" % (pattern_fn, vhd_fn, pattern_off)
    util.doexec(cmd, 0)
开发者ID:2xyo,项目名称:transfervm,代码行数:11,代码来源:vhd.py

示例4: sg_readcap

def sg_readcap(device):
    device = os.path.join('/dev', getdev(device))
    readcapcommand = ['/usr/bin/sg_readcap', '-b', device]
    (rc,stdout,stderr) = util.doexec(readcapcommand)
    if rc == 6:
        # retry one time for "Capacity data has changed"
        (rc,stdout,stderr) = util.doexec(readcapcommand)
    if rc != 0:
        raise util.SMException("util.sg_readcap(%s) failed" % (device))
    (blockcount,blocksize) = stdout.split()
    return (int(blockcount, 0) * int(blocksize, 0))
开发者ID:BobBall,项目名称:sm,代码行数:11,代码来源:scsiutil.py

示例5: sg_readcap

def sg_readcap(device):
    device = os.path.join('/dev', getdev(device))
    readcapcommand = ['/usr/bin/sg_readcap', '-b', device]
    (rc,stdout,stderr) = util.doexec(readcapcommand)
    if rc == 6:
        # retry one time for "Capacity data has changed"
        (rc,stdout,stderr) = util.doexec(readcapcommand)
    if rc != 0:
        raise util.SMException("scsiutil.sg_readcap(%s) failed" % (device))
    match = re.search('(^|.*\n)(0x[0-9a-fA-F]+) (0x[0-9a-fA-F]+)\n$', stdout)
    if not match:
        raise util.SMException("scsiutil.sg_readcap(%s) failed to parse: %s"
                               % (device, stdout))
    (blockcount, blocksize) = match.group(2, 3)
    return (int(blockcount, 0) * int(blocksize, 0))
开发者ID:geosharath,项目名称:sm,代码行数:15,代码来源:scsiutil.py

示例6: check_conf_file

def check_conf_file():
    (rc,stdout,stderr) = util.doexec(['/sbin/multipath','-h'])
    # Ugly way to check for malformed conf file
    if len(stdout):
        util.SMlog("Malformed multipath conf file")
        return 1
    return 0
开发者ID:chandrikas,项目名称:sm,代码行数:7,代码来源:wwid_conf.py

示例7: fill

def fill(vhd_fn, reference_fn, size_mb, pattern):
    zeroReferenceFile(reference_fn, size_mb) #writing zeroes to reference file to avoid WAW propblem
    size = size_mb * 1024 * 1024
    fraction = 100
    if pattern == PATTERN_EMPTY:
        cmd = "dd if=/dev/zero of=%s bs=1M count=%d" % (reference_fn, size_mb)
        util.doexec(cmd, 0)
        return

    pattern_string = "Random bits here >>%s<< end of random bits" % random.getrandbits(100)
    pattern_len = len(pattern_string)
    f = open(PATTERN_FILE, 'w')
    f.write(pattern_string)
    f.close()

    if pattern == PATTERN_SHORT_STRING_BEGINNING:
        _fill_range(vhd_fn, reference_fn, PATTERN_FILE, 0, size, pattern_len, 0)
    elif pattern == PATTERN_SHORT_STRING_MIDDLE:
        _fill_range(vhd_fn, reference_fn, PATTERN_FILE, 0, size, pattern_len, size / 2)
    elif pattern == PATTERN_SHORT_STRING_END:
        _fill_range(vhd_fn, reference_fn, PATTERN_FILE, 0, size, pattern_len, size - pattern_len)
    elif pattern == PATTERN_BLOCKS_SEQUENTIAL:
        for i in range(size / VHD_BLOCK_SIZE):
            _fill_range(vhd_fn, reference_fn, PATTERN_FILE,
                    i * VHD_BLOCK_SIZE, VHD_BLOCK_SIZE, pattern_len, i * VHD_BLOCK_SIZE + 1000)
    elif pattern == PATTERN_BLOCKS_REVERSE:
        for i in range(size / VHD_BLOCK_SIZE - 1, -1, -1):
            _fill_range(vhd_fn, reference_fn, PATTERN_FILE,
                    i * VHD_BLOCK_SIZE, VHD_BLOCK_SIZE, pattern_len, i * VHD_BLOCK_SIZE + 1000)
    elif pattern == PATTERN_BLOCKS_RANDOM:
        block_seq = range(size / VHD_BLOCK_SIZE)
        random.shuffle(block_seq)
        for i in block_seq:
            print "Populating block %d" % i
            _fill_block(vhd_fn, reference_fn, i, PATTERN_FILE, pattern_len)
    elif pattern == PATTERN_BLOCKS_RANDOM_FRACTION:
        block_seq = range(1, (size / VHD_BLOCK_SIZE), fraction)
        random.shuffle(block_seq)
        for i in block_seq:
            print "Populating block %d" % i
            _fill_block(vhd_fn, reference_fn, i, PATTERN_FILE, pattern_len)
    else:
        raise Exception("Invalid pattern number: %d" % pattern)

    os.unlink(PATTERN_FILE)
开发者ID:2xyo,项目名称:transfervm,代码行数:45,代码来源:vhd.py

示例8: do_get_topology

def do_get_topology(cmd):
    util.SMlog("mpath cmd: %s" % cmd)
    (rc,stdout,stderr) = util.doexec(mpathcmd,cmd)
    util.SMlog("mpath output: %s" % stdout)
    lines = stdout.split('\n')[:-1]
    if len(lines):
	    m=regex2.search(lines[0])
	    lines[0]=str(m.group(2))
    return lines
开发者ID:BobBall,项目名称:sm,代码行数:9,代码来源:mpath_cli.py

示例9: exn_on_failure

def exn_on_failure(cmd, message):
    '''Executes via util.doexec the command specified. If the return code is 
    non-zero, raises an ISCSIError with the given message'''
    (rc,stdout,stderr) = util.doexec(cmd)
    if rc==0:
        return (stdout,stderr)
    else:
        msg = 'rc: %d, stdout: %s, stderr: %s' % (rc,stdout,stderr)
        raise xs_errors.XenError('SMGeneral', opterr=msg)
开发者ID:redivy,项目名称:xe-storage-plugins,代码行数:9,代码来源:iscsilib.py

示例10: parse_config

def parse_config(vendor, product):
    try:
        retVal = True
        cmd = "show config"
        XenCertPrint("mpath cmd: %s" % cmd)
        (rc, stdout, stderr) = util.doexec(mpath_cli.mpathcmd, cmd)
        XenCertPrint("mpath output: %s" % stdout)
        stdout = stdout.rstrip("}\nmultipaths {\n}\nmultipathd> ") + "\t"
        XenCertPrint("mpath output after stripping: %s" % stdout)
        list = stdout.split("device {")
        skipThis = True
        for para in list:
            returnmap = {}
            XenCertPrint("The para is: %s" % para)
            if not skipThis:
                para = para.lstrip()
                para = para.rstrip("\n\t}\n\t")
                listParams = para.split("\n\t\t")
                XenCertPrint("ListParams: %s" % listParams)
                for paramPair in listParams:
                    key = ""
                    value = ""
                    params = paramPair.split(" ")
                    firstParam = True
                    for param in params:
                        if firstParam:
                            key = param
                            firstParam = False
                            continue
                        else:
                            value += param
                            value += " "
                    value = value.strip()
                    returnmap[key] = value
                returnmap["vendor"] = returnmap["vendor"].replace('"', "")
                returnmap["product"] = returnmap["product"].replace('"', "")
                if returnmap["product"].find("*") != -1:
                    if returnmap["product"] != "*":
                        regexproduct = re.compile(returnmap["product"])
                        if returnmap["vendor"] == vendor and regexproduct.search(product):
                            break
                    else:
                        if returnmap["vendor"] == vendor:
                            break
                else:
                    if returnmap["vendor"] == vendor and returnmap["product"] == product:
                        break
            else:
                skipThis = False
    except Exception, e:
        XenCertPrint(
            "Failed to get multipath config for vendor: %s and product: %s. Exception: %s" % (vendor, product, str(e))
        )
        retVal = False
开发者ID:robertbreker,项目名称:xencert,代码行数:54,代码来源:StorageHandlerUtil.py

示例11: doexec_locked

def doexec_locked(cmd):
    '''Executes via util.doexec the command specified whilst holding lock'''
    _lock = None
    if os.path.basename(cmd[0]) == 'iscsiadm':
        _lock = lock.Lock(LOCK_TYPE_RUNNING, 'iscsiadm')
        _lock.acquire()
    #util.SMlog("%s" % (cmd))
    (rc,stdout,stderr) = util.doexec(cmd)
    if _lock <> None and _lock.held():
        _lock.release()
    return (rc, stdout, stderr)
开发者ID:chandrikas,项目名称:sm,代码行数:11,代码来源:iscsilib.py

示例12: _zero

def _zero(fn, off, len):
     
    if len == 0:
      return

    partial_block = BLOCK_SIZE - (off % BLOCK_SIZE)
    if partial_block % BLOCK_SIZE:
        if partial_block > len:
            partial_block = len
        cmd = "dd conv=notrunc if=/dev/zero of=%s bs=1 seek=%d count=%d" % (fn, off, partial_block)
        util.doexec(cmd, 0)
        off += partial_block
        len -= partial_block

    if len == 0:
        return

    whole_blocks = len / BLOCK_SIZE
    if whole_blocks:
        cmd = "dd conv=notrunc if=/dev/zero of=%s bs=%d seek=%d count=%d" % \
                (fn, BLOCK_SIZE, off / BLOCK_SIZE, whole_blocks)
        util.doexec(cmd, 0)
        off += whole_blocks * BLOCK_SIZE
        len -= whole_blocks * BLOCK_SIZE

    if len == 0:
        return

    cmd = "dd conv=notrunc if=/dev/zero of=%s bs=1 seek=%d count=%d" % (fn, off, len)
    util.doexec(cmd, 0)
开发者ID:2xyo,项目名称:transfervm,代码行数:30,代码来源:vhd.py

示例13: is_working

def is_working():
    cmd="help"
    util.SMlog("mpath cmd: %s" % cmd)
    try:
        (rc,stdout,stderr) = util.doexec(mpathcmd,cmd)
	util.SMlog("mpath output: %s" % stdout)
	m=regex3.search(stdout)
	if m:
	    return True
	else:
            return False
    except:
        return False
开发者ID:BobBall,项目名称:sm,代码行数:13,代码来源:mpath_cli.py

示例14: parse_config

def parse_config(vendor, product):
    try:
	retVal = True
    	cmd="show config"		
	XenCertPrint("mpath cmd: %s" % cmd)
        (rc,stdout,stderr) = util.doexec(mpath_cli.mpathcmd,cmd)
        XenCertPrint("mpath output: %s" % stdout)
        stdout = stdout.rstrip('}\nmultipaths {\n}\nmultipathd> ') + '\t'
        XenCertPrint("mpath output after stripping: %s" % stdout)
        list = stdout.split("device {")
        skipThis = True
        for para in list:
            returnmap = {}
            XenCertPrint("The para is: %s" % para)
            if not skipThis:
	        para = para.lstrip()
                para = para.rstrip('\n\t}\n\t')
                listParams = para.split('\n\t\t')
                XenCertPrint("ListParams: %s" % listParams)
                for paramPair in listParams:
		    key = ''
		    value = ''
		    params = paramPair.split(' ')
		    firstParam = True
		    for param in params:
			if firstParam:
			    key = param
			    firstParam = False
			    continue
			else:
			    value += param
			    value += ' '
		    value = value.strip()	    
		    returnmap[key] = value
            
		if returnmap['product'].find('*') != -1:
		    if returnmap['product'] != '*':
			regexproduct = re.compile(returnmap['product'])
			if returnmap['vendor'] == vendor and regexproduct.search(product):
			    break
		    else:
			if returnmap['vendor'] == vendor:
			    break
		else:
		    if returnmap['vendor'] == vendor and returnmap['product'] == product:
			break
            else:
    	        skipThis = False 
    except Exception, e:
        XenCertPrint("Failed to get multipath config for vendor: %s and product: %s. Exception: %s" % (vendor, product, str(e)))
        retVal = False
开发者ID:JohnGarbutt,项目名称:xcp-storage-managers,代码行数:51,代码来源:StorageHandlerUtil.py

示例15: FindTimeToWriteData

def FindTimeToWriteData(devicename, sizeInMiB):
    ddOutFile = 'of=' + devicename
    XenCertPrint("Now copy %dMiB data from /dev/zero to this device and record the time taken to copy it." % sizeInMiB)
    cmd = ['dd', 'if=/dev/zero', ddOutFile, 'bs=4096', 'count=%d' % (sizeInMiB * 256)]
    try:
	(rc, stdout, stderr) = util.doexec(cmd,'')
	list = stderr.split('\n')
	timeTaken = list[2].split(',')[1]
	dataCopyTime = int(float(timeTaken.split()[0]))
	XenCertPrint("The IO test returned rc: %s stdout: %s, stderr: %s" % (rc, stdout, stderr))
	XenCertPrint("Time taken to copy %dMiB to the device %s is %d" % (sizeInMiB, devicename, dataCopyTime))
	return dataCopyTime
    except Exception, e:
	raise Exception(str(e))
开发者ID:chandrikas,项目名称:xencert,代码行数:14,代码来源:StorageHandlerUtil.py


注:本文中的util.doexec函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。