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


Python utils.exec_cmd函数代码示例

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


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

示例1: chown_file

def chown_file(filepath, logger):
    """touch a file and setting the chown
    """
    if os.path.exists(filepath):
        os.remove(filepath)

    touch_cmd = "touch %s" % filepath
    logger.info(touch_cmd)
    ret, out = utils.exec_cmd(touch_cmd, shell=True)
    if ret:
        logger.error("failed to touch a new file")
        logger.error(out[0])
        return 1

    logger.info("set chown of %s as 107:107" % filepath)
    chown_cmd = "chown 107:107 %s" % filepath
    ret, out = utils.exec_cmd(chown_cmd, shell=True)
    if ret:
        logger.error("failed to set the ownership of %s" % filepath)
        return 1

    logger.info("set %s mode as 664" % filepath)
    cmd = "chmod 664 %s" % filepath
    ret, out = utils.exec_cmd(cmd, shell=True)
    if ret:
        logger.error("failed to set the mode of %s" % filepath)
        return 1

    return 0
开发者ID:libvirt,项目名称:libvirt-test-API,代码行数:29,代码来源:ownership_test.py

示例2: vcpupin_check

def vcpupin_check(guestname, vcpu, cpulist):
    """check vcpu subprocess status of the running virtual machine
       grep Cpus_allowed_list /proc/PID/task/*/status
    """
    cmd_pid = "cat /var/run/libvirt/qemu/%s.pid" % guestname
    status, pid = utils.exec_cmd(cmd_pid, shell=True)
    if status:
        logger.error("failed to get the pid of domain %s" % guestname)
        return 1

    cmd_vcpu_task_id = "virsh qemu-monitor-command %s --hmp info cpus|grep '#%s'|cut -d '=' -f3"\
        % (guestname, vcpu)
    status, vcpu_task_id = utils.exec_cmd(cmd_vcpu_task_id, shell=True)
    if status:
        logger.error("failed to get the threadid of domain %s" % guestname)
        return 1

    logger.debug("vcpu id %s:" % vcpu_task_id[0])
    cmd_cpus_allowed_list = "grep Cpus_allowed_list /proc/%s/task/%s/status" % (pid[
                                                                                0], vcpu_task_id[0])
    status, output = utils.exec_cmd(cmd_cpus_allowed_list, shell=True)
    if status:
        logger.error("failed to get the cpu_allowed_list of vcpu %s")
        return 1

    logger.debug("the output of command 'grep Cpus_allowed_list \
                          /proc/%s/task/%s/status' is %s" % (pid[0], vcpu_task_id[0], output))

    if output[0].split('\t')[1] == cpulist:
        logger.info("vcpu process cpus allowed list is expected")
        return 0
    else:
        logger.error("vcpu process cpus allowed list is not expected")
        return 1
开发者ID:libvirt,项目名称:libvirt-test-API,代码行数:34,代码来源:vcpupin_live.py

示例3: CA_setting_up

def CA_setting_up(logger):
    """ setting up a Certificate Authority """
    # Create a private key for CA
    logger.info("generate CA certificates")

    cakey_fd = open(CAKEY, "w")
    ret, out = utils.exec_cmd([CERTTOOL, "--generate-privkey"], outfile=cakey_fd)
    cakey_fd.close()
    if ret != 0:
        logger.error("failed to create CA private key")
        return 1

    # ca.info file
    cainfo = os.path.join(TEMP_TLS_FOLDER, "ca.info")
    cainfo_fd = open(cainfo, "w")
    cainfo_str = "cn = Libvirt_test_API\n" + "ca\n" + "cert_signing_key\n"

    cainfo_fd.write(cainfo_str)
    cainfo_fd.close()

    # Generate cacert.pem
    cacert_args = [CERTTOOL, "--generate-self-signed", "--load-privkey", CAKEY, "--template", cainfo]
    cacert_fd = open(CACERT, "w")
    ret, out = utils.exec_cmd(cacert_args, outfile=cacert_fd)
    cacert_fd.close()
    if ret != 0:
        logger.error("failed to create cacert.pem")
        return 1

    logger.info("done the CA certificates job")
    return 0
开发者ID:rbian,项目名称:libvirt-test-API,代码行数:31,代码来源:tls_setup.py

示例4: get_security_driver

def get_security_driver(logger):
    """get security driver from /etc/libvirt/qemu.conf"""

    cmds = "grep \"^security_driver\" /etc/libvirt/qemu.conf"
    (ret, conf) = utils.exec_cmd(cmds, shell=True)
    if ret:
        cmds = "getenforce"
        (ret, policy) = utils.exec_cmd(cmds, shell=True)

        if policy[0] == "Disabled":
            return "none"
        else:
            return "selinux"

    tmp = conf[0].split(' = ')
    if len(tmp[1].split(', ')) > 1:
        driver = tmp[1].split(', ')
        return (filter(str.isalpha, driver[0]))
    else:
        cmds = "echo '%s' | awk -F '\"' '{print $2}'" % conf[0]
        (ret, driver) = utils.exec_cmd(cmds, shell=True)

        if driver[0] == "selinux":
            return "selinux"
        elif driver[0] == "none":
            return "none"
        elif driver[0] == "apparmor":
            return "apparmor"
        elif driver[0] == "stack":
            return "stack"
        else:
            return ""
开发者ID:libvirt,项目名称:libvirt-test-API,代码行数:32,代码来源:connection_security_model.py

示例5: check_numa_params

def check_numa_params(guestname, mode, node_tuple):
    """dump domain live xml description to check numa params and
       check memory allowed list of domain pid
    """
    cmd = "cat /var/run/libvirt/qemu/%s.pid" % guestname
    status, pid = utils.exec_cmd(cmd, shell=True)
    if status:
        logger.error("failed to get the pid of domain %s" % guestname)
        return 1

    cmd = "grep Mems_allowed_list /proc/%s/status" % pid[0]
    status, output = utils.exec_cmd(cmd, shell=True)
    nodeval = output[0].split('\t')[1]
    ret = utils.param_to_tuple(nodeval, node_num)
    logger.info("Mems_allowed_list in domain pid status is: %s" % nodeval)
    logger.debug("parse nodeset to tuple is:")
    logger.debug(ret)
    if not ret:
        logger.error("fail to parse nodeset to tuple")
        return 1

    # TODO: add check for mode

    if ret == node_tuple:
        return 0
    else:
        return 1
开发者ID:libvirt,项目名称:libvirt-test-API,代码行数:27,代码来源:numa_param_live.py

示例6: nfs_setup

def nfs_setup(root_squash, logger):
    """setup nfs on localhost
    """
    logger.info("set nfs service")
    if root_squash == "yes":
        option = "root_squash"
    elif root_squash == "no":
        option = "no_root_squash"
    else:
        logger.error("wrong root_squash value")
        return 1

    cmd = "echo /tmp *\(rw,%s\) >> /etc/exports" % option
    ret, out = utils.exec_cmd(cmd, shell=True)
    if ret:
        logger.error("failed to config nfs export")
        return 1

    logger.info("restart nfs service")
    cmd = "service nfs restart"
    ret, out = utils.exec_cmd(cmd, shell=True)
    if ret:
        logger.error("failed to restart nfs service")
        return 1
    else:
        for i in range(len(out)):
            logger.info(out[i])

    return 0
开发者ID:carriercomm,项目名称:libvirt-test-API,代码行数:29,代码来源:domain_nfs_start.py

示例7: check_pinemulator

def check_pinemulator(guestname, maxcpu, pininfo_after):
    """check emulator status of the running virtual machine
    """

    cmd = "cat /var/run/libvirt/qemu/%s.pid" % guestname
    status, pid = utils.exec_cmd(cmd, shell=True)
    if status:
        logger.error("failed to get the pid of domain %s" % guestname)
        return 1

    cmd = "grep Cpus_allowed_list /proc/%s/task/%s/status" % (pid[0], pid[0])
    status, output = utils.exec_cmd(cmd, shell=True)
    if status:
        logger.error("failed to get Cpus_allowed_list")
        return 1

    cpu_allowed_list = output[0]
    cpulistcheck = cpu_allowed_list.split('\t')[1]
    pininfo_in_process = str(utils.param_to_tuple(cpulistcheck, maxcpu))

    if cmp(pininfo_in_process, pininfo_after):
        logger.error("domain emulator pin failed")
        return 1
    else:
        logger.info("domain emulator pin successed")
        return 0
开发者ID:libvirt,项目名称:libvirt-test-API,代码行数:26,代码来源:pinemulator.py

示例8: deliver_cert

def deliver_cert(target_machine, username, password, pkipath, logger):
    """ deliver CA, server and client certificates """
    # transmit cacert.pem to remote host
    logger.info("deliver CA, server and client certificates to both local and remote server")
    ret = utils.scp_file(target_machine, username, password, CA_FOLDER, CACERT)
    if ret:
        logger.error("scp cacert.pem to %s error" % target_machine)
        return 1

    # copy cacert.pem to local CA folder
    cacert_cp = [CP, "-f", CACERT, (pkipath and pkipath) or CA_FOLDER]
    ret, out = utils.exec_cmd(cacert_cp)
    if ret:
        logger.error("copying cacert.pem to %s error" % CA_FOLDER)
        return 1

    # mkdir /etc/pki/libvirt/private on remote host
    libvirt_priv_cmd = "mkdir -p %s" % PRIVATE_KEY_FOLDER
    ret, output = utils.remote_exec_pexpect(target_machine, username, password, libvirt_priv_cmd)
    if ret:
        logger.error("failed to make /etc/pki/libvirt/private on %s" % target_machine)
        return 1

    # transmit serverkey.pem to remote host
    ret = utils.scp_file(target_machine, username, password, PRIVATE_KEY_FOLDER, SERVERKEY)
    if ret:
        logger.error("failed to scp serverkey.pem to %s" % target_machine)
        return 1

    # transmit servercert.pem to remote host
    ret = utils.scp_file(target_machine, username, password, CERTIFICATE_FOLDER, SERVERCERT)
    if ret:
        logger.error("failed to scp servercert.pem to %s" % target_machine)
        return 1

    libvirt_priv_cmd_local = [MKDIR, "-p", PRIVATE_KEY_FOLDER]
    ret, out = utils.exec_cmd(libvirt_priv_cmd_local)
    if ret:
        logger.error("failed to make %s on local" % PRIVATE_KEY_FOLDER)
        return 1

    # copy clientkey.pem to local folder
    clientkey_cp = [CP, "-f", CLIENTKEY, (pkipath and pkipath) or PRIVATE_KEY_FOLDER]
    ret, out = utils.exec_cmd(clientkey_cp)
    if ret:
        logger.error("failed to copy clientkey.pem to %s" % PRIVATE_KEY_FOLDER)
        return 1

    # copy clientcert.pem to local folder
    clientcert_cp = [CP, "-f", CLIENTCERT, (pkipath and pkipath) or CERTIFICATE_FOLDER]
    ret, out = utils.exec_cmd(clientcert_cp)
    if ret:
        logger.error("failed to copy clientcert.pem to %s" % CERTIFICATE_FOLDER)
        return 1

    logger.info("done to delivery")
    return 0
开发者ID:rbian,项目名称:libvirt-test-API,代码行数:57,代码来源:tls_setup.py

示例9: tls_client_cert

def tls_client_cert(local_machine, logger):
    """ generating client certificates """
    # Create tls client key
    logger.info("generate client certificates")

    clientkey_fd = open(CLIENTKEY, "w")
    ret, out = utils.exec_cmd([CERTTOOL, "--generate-privkey"], outfile=clientkey_fd)
    clientkey_fd.close()
    if ret != 0:
        logger.error("failed to create client key")
        return 1

    # client.info
    clientinfo = os.path.join(TEMP_TLS_FOLDER, "client.info")
    clientinfo_fd = open(clientinfo, "w")
    clientinfo_str = (
        "country = xxx\n"
        + "state = xxx\n"
        + "locality = xxx\n"
        + "organization = Libvirt_test_API\n"
        + "cn = %s\n" % local_machine
        + "tls_www_client\n"
        + "encryption_key\n"
        + "signing_key\n"
    )

    clientinfo_fd.write(clientinfo_str)
    clientinfo_fd.close()

    # Generate clientcert.pem
    clientcert_args = [
        CERTTOOL,
        "--generate-certificate",
        "--load-privkey",
        CLIENTKEY,
        "--load-ca-certificate",
        CACERT,
        "--load-ca-privkey",
        CAKEY,
        "--template",
        clientinfo,
    ]

    clientcert_fd = open(CLIENTCERT, "w")
    ret, out = utils.exec_cmd(clientcert_args, outfile=clientcert_fd)
    clientcert_fd.close()
    if ret != 0:
        logger.error("failed to create client certificates")
        return 1

    logger.info("done the client certificates job")
    return 0
开发者ID:rbian,项目名称:libvirt-test-API,代码行数:52,代码来源:tls_setup.py

示例10: tls_server_cert

def tls_server_cert(target_machine, logger):
    """ generating server certificates """
    # Create tls server key
    logger.info("generate server certificates")

    serverkey_fd = open(SERVERKEY, "w")
    ret, out = utils.exec_cmd([CERTTOOL, "--generate-privkey"], outfile=serverkey_fd)
    serverkey_fd.close()
    if ret != 0:
        logger.error("failed to create server key")
        return 1

    # server.info
    serverinfo = os.path.join(TEMP_TLS_FOLDER, "server.info")
    serverinfo_fd = open(serverinfo, "w")
    serverinfo_str = (
        "organization = Libvirt_test_API\n"
        + "cn = %s\n" % target_machine
        + "tls_www_server\n"
        + "encryption_key\n"
        + "signing_key\n"
    )

    serverinfo_fd.write(serverinfo_str)
    serverinfo_fd.close()

    # Generate servercert.pem
    servercert_args = [
        CERTTOOL,
        "--generate-certificate",
        "--load-privkey",
        SERVERKEY,
        "--load-ca-certificate",
        CACERT,
        "--load-ca-privkey",
        CAKEY,
        "--template",
        serverinfo,
    ]
    servercert_fd = open(SERVERCERT, "w")
    ret, out = utils.exec_cmd(servercert_args, outfile=servercert_fd)
    servercert_fd.close()
    if ret != 0:
        logger.error("failed to create servercert.pem")
        return 1

    logger.info("done the server certificates job")
    return 0
开发者ID:rbian,项目名称:libvirt-test-API,代码行数:48,代码来源:tls_setup.py

示例11: validate_caps_from_hv

def validate_caps_from_hv(emulatorbin, logger):
    """
        Validate the relative caps between libvirt and qemu-kvm
    """
    F1 = '%s -h| grep "\-drive"'
    F2 = '%s -h| grep "format="'
    F3 = '%s -h| grep "readonly="'
    F4 = '%s -h| grep "^\\-device"'
    l = [F1, F2, F3, F4]
    flags = []
    for item in l:
        status, temp = utils.exec_cmd(item % emulatorbin, shell=True)
        if not status:
            flags.append(True)
            logger.debug("Got: %s from vh" % temp)
        else:
            flags.append(False)
            logger.debug("Got: %s from vh" % temp)
    if get_hypervisor_ver(emulatorbin, logger) >= 11000:
        flags.append(True)
    else:
        flags.append(False)
    libvirt_f = [drive, drive_forma, drive_readonly, device, blk_sg_io]
    if flags == libvirt_f:
        return True
    else:
        return False
开发者ID:rbian,项目名称:libvirt-test-API,代码行数:27,代码来源:connection_getDomainCapabilities.py

示例12: qemu_hang

def qemu_hang(params):
    """Hang qemu process, check libvirtd status"""
    logger = params['logger']
    guestname = params['guestname']

    conn = sharedmod.libvirtobj['conn']

    logger.info("check the domain state")
    ret = check_domain_running(conn, guestname, logger)
    if ret:
        return 1

    logger.info("check the libvirtd status:")
    ret = libvirtd_check(logger)
    if ret:
        return 1

    ret, pid = get_domain_pid(logger, guestname)
    if ret:
        return 1

    cmd = "kill -STOP %s" % pid
    logger.info(cmd)
    ret, out = utils.exec_cmd(cmd, shell=True)
    if ret:
        logger.error("failed to stop qemu process of %s" % guestname)
        return 1

    logger.info("recheck libvirtd status:")
    ret = libvirtd_check(logger)
    if ret:
        return 1

    return 0
开发者ID:carriercomm,项目名称:libvirt-test-API,代码行数:34,代码来源:qemu_hang.py

示例13: get_cpu_list

def get_cpu_list(state_type, logger):
    """ get all cpu in the same type state
    """
    ret = list()

    if state_type == "online":
        match = '1'
        ret.append(0)
    elif state_type == "offline":
        match = '0'
    else:
        logger.error("Unidentified cpu state type %s" % state_type)
        return ret

    cpu_num = get_cpu_num(logger)
    if cpu_num < 0:
        return ret

    for i in range(1, cpu_num):
        cmd = CPUSTATE % i
        status, out = utils.exec_cmd(cmd, shell=True)
        if status != 0:
            logger.error("Exec %s fails" % cmd)
            return ret
        logger.debug("Exec outputs %s" % out[0])

        if out[0] == match:
            ret.append(i)

    return ret
开发者ID:ryanmiao,项目名称:libvirt-test-API,代码行数:30,代码来源:cpu_map.py

示例14: check_pool_sources

def check_pool_sources(host, xmlstr):
    """check the netfs sources with command:
       showmount --no-headers -e HOSTNAME
    """
    source_val = []

    doc = minidom.parseString(xmlstr)
    for diskTag in doc.getElementsByTagName("source"):
        device_element = diskTag.getElementsByTagName("dir")[0]
        attr = device_element.getAttributeNode('path')
        path_val = attr.nodeValue

        source_val.append(path_val)

    logger.debug("pool source info list is: %s" % source_val)

    cmd = "showmount --no-headers -e %s | awk -F' ' '{print $1}'" % host
    ret, path_list = utils.exec_cmd(cmd, shell=True)

    logger.debug("showmount command output list is: %s" % path_list)

    if source_val == path_list:
        logger.info("source list matched with showmount command output")
        return 0
    else:
        logger.error("source list did not match with showmount command output")
        return 1
开发者ID:carriercomm,项目名称:libvirt-test-API,代码行数:27,代码来源:find_netfs_pool_sources.py

示例15: check_pool_sources

def check_pool_sources(host, xmlstr):
    """check the iscsi sources with command:
       iscsiadm --mode discovery --type sendtargets --portal
    """
    source_val = []

    doc = minidom.parseString(xmlstr)
    for diskTag in doc.getElementsByTagName("source"):
        device_element = diskTag.getElementsByTagName("device")[0]
        attr = device_element.getAttributeNode('path')
        path_val = attr.nodeValue

        source_val.append(path_val)

    logger.debug("pool source info list is: %s" % source_val)

    cmd = "iscsiadm --mode discovery --type sendtargets --portal %s:3260,1 |\
           awk -F' ' '{print $2}'" % host
    ret, path_list = utils.exec_cmd(cmd, shell=True)

    logger.debug("iscsiadm command output list is: %s" % path_list)

    if source_val == path_list:
        logger.info("source list matched with iscsiadm command output")
        return 0
    else:
        logger.error("source list did not match with iscsiadm command output")
        return 1
开发者ID:libvirt,项目名称:libvirt-test-API,代码行数:28,代码来源:find_iscsi_pool_sources.py


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