Exemplo n.º 1
0
def RunCommand(cfg, host, cmd):
    key = Path(cfg.configpath).joinpath(cfg.keypath)
    key = Path(key).joinpath(cfg.keyname)
    if cfg.log_level == "DEBUG":
        with settings(show('everything'),
                      user='******',
                      host_string=host,
                      key_filename=key.as_posix(),
                      warn_only=True):
            results = fabric_run(cmd)
    else:
        with settings(hide('everything'),
                      user='******',
                      host_string=host,
                      key_filename=key.as_posix(),
                      warn_only=True):
            results = fabric_run(cmd)
    return results
Exemplo n.º 2
0
def run(cmd, user=None, capture=None, *args, **kwargs):
    """
    :param cmd: command to execute
    :param user: user mode will be ignore when we deploy on local machine.
    :param capture: in local machine, it will be True by default.
    :param args:
    :param kwargs:
    :return:
    """
    if env.hosts:
        if user:
            return fabric_run("su - %s -c '%s'" % (user, cmd))
        else:
            return fabric_run(cmd, *args, **kwargs)
    else:
        capture = True if capture is None else capture
        return fabric_local(cmd, capture=capture, *args, **kwargs)
    pass
Exemplo n.º 3
0
def run(*args, **kwargs):
    if env.use_sudo:
        return sudo(user=env.sudo_user, *args, **kwargs)
    else:
        return fabric_run(*args, **kwargs)