• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python commands.execCmd函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __enter__

    def __enter__(self):
        rc, out, err = execCmd([_SSH_AGENT.cmd], raw=True)
        if rc != 0:
            raise V2VError('Error init ssh-agent, exit code: %r'
                           ', out: %r, err: %r' %
                           (rc, out, err))

        m = self._ssh_auth_re.match(out)
        # looking for: SSH_AUTH_SOCK=/tmp/ssh-VEE74ObhTWBT/agent.29917
        self._auth = {m.group(1): m.group(2)}
        self._agent_pid = m.group(3)

        try:
            rc, out, err = execCmd([_SSH_ADD.cmd], env=self._auth)
        except:
            self._kill_agent()
            raise

        if rc != 0:
            # 1 = general fail
            # 2 = no agnet
            if rc != 2:
                self._kill_agent()
            raise V2VError('Error init ssh-add, exit code: %r'
                           ', out: %r, err: %r' %
                           (rc, out, err))
开发者ID:nirs,项目名称:vdsm,代码行数:26,代码来源:v2v.py


示例2: 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 = commands.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.assertEqual(p.stdout.read(len(data)), data)
开发者ID:oVirt,项目名称:vdsm,代码行数:27,代码来源:misc_test.py


示例3: testExec

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

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


示例4: cleanup_transient_repository

def cleanup_transient_repository(*args):
    """
    cleanup-transient-repository
    Cleanup the unused transient disks present in the repository.
    (NOTE: it is recommended to NOT execute this command when the vdsm
    daemon is running)
    """
    if len(args) > 1:
        raise ExtraArgsError()

    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:nirs,项目名称:vdsm,代码行数:32,代码来源:transient.py


示例5: testV2VOutput

    def testV2VOutput(self):
        cmd = [FAKE_VIRT_V2V.cmd,
               '-v',
               '-x',
               '-ic', self.vpx_url,
               '-o', 'vdsm',
               '-of', 'raw',
               '-oa', 'sparse',
               '--vdsm-image-uuid', self.image_id_a,
               '--vdsm-vol-uuid', self.volume_id_a,
               '--vdsm-image-uuid', self.image_id_b,
               '--vdsm-vol-uuid', self.volume_id_b,
               '--password-file', '/tmp/mypass',
               '--vdsm-vm-uuid', self.job_id,
               '--vdsm-ovf-output', '/usr/local/var/run/vdsm/v2v',
               '--machine-readable',
               '-os', '/rhev/data-center/%s/%s' % (self.pool_id,
                                                   self.domain_id),
               self.vm_name]

        rc, output, error = execCmd(cmd, raw=True)
        self.assertEqual(rc, 0)

        with io.open('fake-virt-v2v.out', 'rb') as f:
            self.assertEqual(output, f.read())

        with io.open('fake-virt-v2v.err', 'rb') as f:
            self.assertEqual(error, f.read())
开发者ID:nirs,项目名称:vdsm,代码行数:28,代码来源:v2v_test.py


示例6: run_dd

 def run_dd(self, args):
     cmd = [constants.EXT_DD]
     cmd.extend(args)
     rc, out, err = commands.execCmd(cmd, raw=True, data=self.data)
     assert rc == 0, "Process failed: rc={} err={}".format(rc, err)
     assert err != '', "No data from stderr"
     return out
开发者ID:nirs,项目名称:vdsm,代码行数:7,代码来源:commands_test.py


示例7: snapshotScheduleDisable

def snapshotScheduleDisable():
    command = [_snapSchedulerPath.cmd, "disable_force"]
    rc, out, err = commands.execCmd(command)
    if rc not in [0, SNAP_SCHEDULER_ALREADY_DISABLED_RC]:
        raise ge.GlusterDisableSnapshotScheduleFailedException(
            rc)
    return True
开发者ID:oVirt,项目名称:vdsm,代码行数:7,代码来源:api.py


示例8: _kill_agent

 def _kill_agent(self):
     rc, out, err = execCmd([_SSH_AGENT.cmd, '-k'],
                            env={'SSH_AGENT_PID': self._agent_pid})
     if rc != 0:
         logging.error('Error killing ssh-agent (PID=%r), exit code: %r'
                       ', out: %r, err: %r' %
                       (self._agent_pid, rc, out, err))
开发者ID:nirs,项目名称:vdsm,代码行数:7,代码来源:v2v.py


示例9: volumeStatvfs

def volumeStatvfs(volumeName, host=GLUSTER_VOL_HOST,
                  port=GLUSTER_VOL_PORT,
                  protocol=GLUSTER_VOL_PROTOCOL):
    module = "vdsm.gluster.gfapi"
    command = [sys.executable, '-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 = commands.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:nirs,项目名称:vdsm,代码行数:28,代码来源:gfapi.py


示例10: removeEphemeralBridge

def removeEphemeralBridge(bridgeName):
    rc, out, err = commands.execCmd([
        EXT_IP, 'link', 'del', bridgeName, 'type', 'bridge'])
    if rc != 0:
        raise EnvironmentError(
            'Failed to remove ephemeral dummy bridge. Err: %s' % err
        )
开发者ID:nirs,项目名称:vdsm,代码行数:7,代码来源:dummybr.py


示例11: upload

def upload(url, path, headers={}):
    cmd = [constants.EXT_CURL_IMG_WRAP, "--upload"]
    cmd.extend(_headersToOptions(headers) + [path, url])

    rc, out, err = commands.execCmd(cmd)

    if rc != 0:
        raise CurlError(rc, out, err)
开发者ID:nirs,项目名称:vdsm,代码行数:8,代码来源:curlImgWrap.py


示例12: __exit__

    def __exit__(self, *args):
        rc, out, err = execCmd([_SSH_ADD.cmd, '-d'], env=self._auth)
        if rc != 0:
            logging.error('Error deleting ssh-add, exit code: %r'
                          ', out: %r, err: %r' %
                          (rc, out, err))

        self._kill_agent()
开发者ID:nirs,项目名称:vdsm,代码行数:8,代码来源:v2v.py


示例13: test_limit_rss

def test_limit_rss():
    # This should fail to allocate about 100 MiB.
    script = "s = 100 * 1024**2 * 'x'"
    cmd = ["python", "-c", script]
    cmd = cmdutils.prlimit(cmd, address_space=100 * 1024**2)
    rc, out, err = commands.execCmd(cmd, raw=True)
    assert rc == 1
    assert b"MemoryError" in err
开发者ID:nirs,项目名称:vdsm,代码行数:8,代码来源:prlimit_test.py


示例14: _validate_module

def _validate_module(name):
    if not os.path.exists('/sys/module/' + name):
        cmd_modprobe = [modprobe.cmd, name]
        rc, out, err = commands.execCmd(cmd_modprobe, sudo=True)
        if rc != 0:
            raise SkipTest("This test requires %s module "
                           "(failed to load module: rc=%s, out=%s, err=%s)" %
                           (name, rc, out, err))
开发者ID:nirs,项目名称:vdsm,代码行数:8,代码来源:modprobe.py


示例15: testStdErr

 def testStdErr(self):
     """
     Tests that execCmd correctly returns the standard error of the prog it
     executes.
     """
     cmd = ["sh", "-c", "echo it works! >&2"]
     ret, stdout, stderr = commands.execCmd(cmd)
     self.assertEqual(stderr[0].decode("ascii"), "it works!")
开发者ID:oVirt,项目名称:vdsm,代码行数:8,代码来源:misc_test.py


示例16: testWaitCond

 def testWaitCond(self):
     p = commands.execCmd([EXT_SLEEP, str(EXECCMD_TIMEOUT + 1)], sync=False)
     startTime = time.time()
     p.wait(cond=lambda: time.time() - startTime > TIMEOUT)
     duration = time.time() - startTime
     self.assertLess(duration, EXECCMD_TIMEOUT + TIMEOUT)
     self.assertGreater(duration, EXECCMD_TIMEOUT)
     p.kill()
开发者ID:oVirt,项目名称:vdsm,代码行数:8,代码来源:misc_test.py


示例17: attach

 def attach(self):
     if self._path is not None:
         raise AssertionError("Device is attached: %s" % self)
     cmd = ["losetup", "--find", "--show", self._backing_file]
     rc, out, err = commands.execCmd(cmd, raw=True)
     if rc != 0:
         raise cmdutils.Error(cmd, rc, out, err)
     self._path = out.strip().decode("ascii")
开发者ID:nirs,项目名称:vdsm,代码行数:8,代码来源:loopback.py


示例18: testSudo

 def testSudo(self):
     """
     Tests that when running with sudo the user really is root (or other
     desired user).
     """
     cmd = [EXT_WHOAMI]
     checkSudo(cmd)
     ret, stdout, stderr = commands.execCmd(cmd, sudo=True)
     self.assertEqual(stdout[0].decode("ascii"), SUDO_USER)
开发者ID:oVirt,项目名称:vdsm,代码行数:9,代码来源:misc_test.py


示例19: physicalVolumeList

def physicalVolumeList():
    rc, out, err = commands.execCmd([_pvsCommandPath.cmd,
                                     "--reportformat", "json",
                                     "--units", "b",
                                     "--nosuffix",
                                     "-o", "pv_name,vg_name"])
    if rc:
        raise ge.GlusterCmdExecFailedException(rc, out, err)
    return json.loads("".join(out))["report"][0]["pv"]
开发者ID:nirs,项目名称:vdsm,代码行数:9,代码来源:thinstorage.py


示例20: copyFromImage

def copyFromImage(dstImgPath, methodArgs):
    fileObj = methodArgs['fileObj']
    bytes_left = total_size = methodArgs['length']
    cmd = [constants.EXT_DD, "if=%s" % dstImgPath, "bs=%s" % constants.MEGAB,
           "count=%s" % (total_size // constants.MEGAB + 1)]

    p = commands.execCmd(cmd, sync=False)
    p.blocking = True
    with commands.terminating(p):
        _copyData(p.stdout, fileObj, bytes_left)
开发者ID:nirs,项目名称:vdsm,代码行数:10,代码来源:imageSharing.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python response.error函数代码示例发布时间:2022-05-26
下一篇:
Python commands.execCmd函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap