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


Python utils.execCmd函数代码示例

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


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

示例1: chown

def chown(vendorid, productid):

    # remove the 0x from the vendor and product id
    devid = vendorid[2:] + ':' + productid[2:]
    command = ['lsusb', '-d', devid]
    retcode, out, err = utils.execCmd(command, sudo=False, raw=True)
    if retcode != 0:
        sys.stderr.write('hostusb: cannot find usb device: %s\n' % devid)
        sys.exit(2)

    # find the device path:
    # /dev/bus/usb/xxx/xxx
    devpath = '/dev/bus/usb/' + out[4:7] + '/' + out[15:18]
    stat = os.stat(devpath)

    group = grp.getgrnam('qemu')
    gid = group.gr_gid
    user = pwd.getpwnam('qemu')
    uid = user.pw_uid

    # we don't use os.chown because we need sudo
    owner = str(uid) + ':' + str(gid)
    command = ['/bin/chown', owner, devpath]
    retcode, out, err = utils.execCmd(command, sudo=True, raw=True)
    if retcode != 0:
        sys.stderr.write('hostusb: error chown %s to %s, err = %s\n' % (devpath, owner, err))
        sys.exit(2)

    log_dev_owner(devpath, stat.st_uid, stat.st_gid)
开发者ID:ekohl,项目名称:vdsm,代码行数:29,代码来源:before_vm_start.py

示例2: check_brctl

def check_brctl():
    try:
        execCmd([EXT_BRCTL, "show"])
    except OSError as e:
        if e.errno == errno.ENOENT:
            raise SkipTest("Cannot run %r: %s\nDo you have bridge-utils "
                           "installed?" % (EXT_BRCTL, e))
        raise
开发者ID:germanovm,项目名称:vdsm,代码行数:8,代码来源:nettestlib.py

示例3: _removeFile

    def _removeFile(filename):
        """Remove file, umounting ovirt config files if needed."""

        mounts = open('/proc/mounts').read()
        if ' /config ext3' in mounts and ' %s ext3' % filename in mounts:
            utils.execCmd([constants.EXT_UMOUNT, '-n', filename])
        utils.rmFile(filename)
        logging.debug("Removed file %s", filename)
开发者ID:therealmik,项目名称:vdsm,代码行数:8,代码来源:ifcfg.py

示例4: removeBridge

 def removeBridge(self, bridge):
     DynamicSourceRoute.addInterfaceTracking(bridge)
     ifdown(bridge.name)
     self._removeSourceRoute(bridge, StaticSourceRoute)
     utils.execCmd([constants.EXT_BRCTL, 'delbr', bridge.name])
     self.configApplier.removeBridge(bridge.name)
     if bridge.port:
         bridge.port.remove()
开发者ID:germanovm,项目名称:vdsm,代码行数:8,代码来源:ifcfg.py

示例5: configureNic

    def configureNic(self, nic, **opts):
        self.configApplier.setIfaceConfigAndUp(nic)

        ethtool_opts = getEthtoolOpts(nic.name)
        if ethtool_opts:
            # We ignore ethtool's return code to maintain initscripts'
            # behaviour.
            execCmd(
                [_ETHTOOL_BINARY.cmd, '-K', nic.name] + ethtool_opts.split())
开发者ID:int64ago-public,项目名称:vdsm,代码行数:9,代码来源:iproute2.py

示例6: configureNic

    def configureNic(self, nic, **opts):
        DynamicSourceRoute.addInterfaceTracking(nic)
        self.configApplier.setIfaceConfigAndUp(nic)
        self._addSourceRoute(nic)

        ethtool_opts = getEthtoolOpts(nic.name)
        if ethtool_opts:
            # We ignore ethtool's return code to maintain initscripts'
            # behaviour.
            execCmd([_ETHTOOL_BINARY.cmd, "-K", nic.name] + ethtool_opts.split())
开发者ID:nickxiao,项目名称:vdsm,代码行数:10,代码来源:iproute2.py

示例7: adjust

    def adjust(self):
        """adjust ksm state according to configuration and current memory stress
        return whether ksm is running"""

        self._lock.acquire()
        try:
            utils.execCmd([constants.EXT_SERVICE, 'ksmtuned', 'retune'], sudo=True)
            self.state, self.pages = self.readState()
        finally:
            self._lock.release()
        return self.state
开发者ID:ekohl,项目名称:vdsm,代码行数:11,代码来源:ksm.py

示例8: adjust

    def adjust(self):
        """Adjust ksm's vigor

        Recalculate how hard should ksm work, according to configuration and
        current memory stress.
        Return whether ksm is running"""

        with self._lock:
            utils.execCmd([constants.EXT_SERVICE, 'ksmtuned', 'retune'],
                          sudo=True)
        return running()
开发者ID:futurice,项目名称:vdsm,代码行数:11,代码来源:ksm.py

示例9: adjust

    def adjust(self):
        """Adjust ksm's vigor

        Recalculate how hard should ksm work, according to configuration and
        current memory stress.
        Return whether ksm is running"""

        self._lock.acquire()
        try:
            utils.execCmd([constants.EXT_SERVICE, "ksmtuned", "retune"], sudo=True)
        finally:
            self._lock.release()
        return running()
开发者ID:edwardbadboy,项目名称:vdsm-ubuntu,代码行数:13,代码来源:ksm.py

示例10: setUp

    def setUp(self):
        self.assertFalse(self.tempFilePath and self.devPath)

        tempFd, self.tempFilePath = tempfile.mkstemp()
        os.close(tempFd)

        cmd = ['dd', 'if=/dev/zero', 'of=%s' % self.tempFilePath,
               'bs=%sM' % FILE_SIZE_MB, 'count=1']
        rc, out, err = utils.execCmd(cmd)
        self.assertEquals(rc, 0)
        cmd = ['losetup', '-f', '--show', self.tempFilePath]
        rc, out, err = utils.execCmd(cmd)
        self.assertEquals(rc, 0)
        self.devPath = out[0].strip()
开发者ID:Caez83,项目名称:vdsm,代码行数:14,代码来源:parted_utils_tests.py

示例11: cleanup_transient_repository

def cleanup_transient_repository(*args):
    """
    Cleanup the unused transient disks present in the repository.
    (NOTE: it is recommended to NOT execute this command when the vdsm
    daemon is running)
    """
    transient_images = set(glob.glob(os.path.join(TRANSIENT_DISKS_REPO, "*")))

    if len(transient_images) == 0:
        return  # Nothing to do

    cmd_ret, cmd_out, cmd_err = execCmd([_fuser.cmd] + list(transient_images))
    # According to: "fuser returns a non-zero return code if none of the
    # specified files is accessed or in case of a fatal error. If at least
    # one access has been found, fuser returns zero." we can discard the
    # return code.
    # NOTE: the list of open files is printed to cmd_err with an extra ":"
    # character appended (removed by [:-1]).
    open_transient_images = set(x[:-1] for x in cmd_err)

    for image_path in transient_images - open_transient_images:
        # NOTE: This could cause a race with the creation of a virtual
        # machine with a transient disk (if vdsm is running).
        try:
            os.unlink(image_path)
        except OSError as e:
            if e.errno != os.errno.ENOENT:
                raise
开发者ID:mydaisy2,项目名称:vdsm,代码行数:28,代码来源:transient.py

示例12: volumeStatvfs

def volumeStatvfs(volumeName, host=GLUSTER_VOL_HOST,
                  port=GLUSTER_VOL_PORT,
                  protocol=GLUSTER_VOL_PROTOCOL):
    module = "gluster.gfapi"
    command = [constants.EXT_PYTHON, '-m', module, '-v', volumeName,
               '-p', str(port), '-H', host, '-t', protocol, '-c', 'statvfs']

    # to include /usr/share/vdsm in python path
    env = os.environ.copy()
    env['PYTHONPATH'] = "%s:%s" % (
        env.get("PYTHONPATH", ""), constants.P_VDSM)
    env['PYTHONPATH'] = ":".join(map(os.path.abspath,
                                     env['PYTHONPATH'].split(":")))

    rc, out, err = utils.execCmd(command, raw=True, env=env)
    if rc != 0:
        raise ge.GlfsStatvfsException(rc, [out], [err])
    res = json.loads(out)
    return os.statvfs_result((res['f_bsize'],
                              res['f_frsize'],
                              res['f_blocks'],
                              res['f_bfree'],
                              res['f_bavail'],
                              res['f_files'],
                              res['f_ffree'],
                              res['f_favail'],
                              res['f_flag'],
                              res['f_namemax']))
开发者ID:nickxiao,项目名称:vdsm,代码行数:28,代码来源:gfapi.py

示例13: testExec

    def testExec(self):
        """
        Tests that execCmd execs and returns the correct ret code
        """
        ret, out, err = utils.execCmd([EXT_ECHO])

        self.assertEquals(ret, 0)
开发者ID:Caez83,项目名称:vdsm,代码行数:7,代码来源:miscTests.py

示例14: getCpuTopology

def getCpuTopology(capabilities):
    topology = {}

    if capabilities is None:
        retcode, out, err = utils.execCmd(['lscpu'], raw=True)
        capabilities = out

    corePS = None
    threadsPC = None
    sockets = None

    for line in capabilities.splitlines():
        if line.strip() == '':
            continue
        key, value = map(str.strip, line.split(':', 1))

        if key == 'Socket(s)':
            sockets = int(value)
        elif key == 'Thread(s) per core':
            threadsPC = int(value)
        elif key == 'Core(s) per socket':
            corePS = int(value)

    if corePS and threadsPC and sockets:
        topology['sockets'] = sockets
        topology['cores'] = corePS * sockets
        topology['threads'] = threadsPC * corePS * sockets
    else:
        raise RuntimeError('Undefined topology')

    return topology
开发者ID:aiminickwong,项目名称:vdsm,代码行数:31,代码来源:ppc64HardwareInfo.py

示例15: testWriteLargeData

    def testWriteLargeData(self):
        data = """The Doctor: Davros, if you had created a virus in your
                              laboratory, something contagious and infectious
                              that killed on contact, a virus that would
                              destroy all other forms of life; would you allow
                              its use?
                  Davros: It is an interesting conjecture.
                  The Doctor: Would you do it?
                  Davros: The only living thing... The microscopic organism...
                          reigning supreme... A fascinating idea.
                  The Doctor: But would you do it?
                  Davros: Yes; yes. To hold in my hand, a capsule that
                          contained such power. To know that life and death on
                          such a scale was my choice. To know that the tiny
                          pressure on my thumb, enough to break the glass,
                          would end everything. Yes! I would do it! That power
                          would set me up above the gods! And through the
                          Daleks, I shall have that power! """
        # (C) BBC - Doctor Who

        data = data * 100
        p = utils.execCmd([EXT_CAT], sync=False)
        self.log.info("Writing data to std out")
        p.stdin.write(data)
        p.stdin.flush()
        self.log.info("Written data reading")
        self.assertEquals(p.stdout.read(len(data)), data)
开发者ID:Caez83,项目名称:vdsm,代码行数:27,代码来源:miscTests.py


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