start_script.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:fuel-ccp-entrypoint 作者: openstack 项目源码 文件源码
def execute_cmd(cmd, user=None):
    LOG.debug("Executing cmd:\n%s", cmd_str(cmd))
    kwargs = {
        "shell": True,
        "stdin": sys.stdin,
        "stdout": sys.stdout,
        "stderr": sys.stderr}
    # If openstackclient command is being executed, appropriate environment
    # variables will be set
    for prefix in ["openstack ", "neutron ", "murano "]:
        if cmd.startswith(prefix):
            kwargs['preexec_fn'] = openstackclient_preexec_fn()
            break
    # Execute as user if `user` param is provided, execute as current user
    # otherwise
    else:
        if user:
            LOG.debug('Executing as user %s', user)
            pw_record = pwd.getpwnam(user)
            user_uid = pw_record.pw_uid
            user_gid = pw_record.pw_gid
            user_home = pw_record.pw_dir
            kwargs['preexec_fn'] = preexec_fn(user_uid, user_gid, user_home)
    return subprocess.Popen(cmd_str(cmd), **kwargs)
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号