Example #1
0
def sudo(cmd):
    """Runs a nicely niced sudo command, or prints it if DEBUG is on."""
    cmd = 'nice -n 19 %s' % cmd
    if DEBUG == False:
        return fab_sudo(cmd)
    else:
        print "sudo: %s" % cmd
Example #2
0
    def run(self, cmd, **kwargs):
        abort_exception = None
        if not self.ignore_errors:
            abort_exception = RemoteExecutionError

        if kwargs:
            cmd = cmd.format(**kwargs)

        ssh_attempts = cfglib.CONF.migrate.ssh_connection_attempts

        with settings(warn_only=self.ignore_errors,
                      host_string=self.host,
                      user=self.user,
                      password=self.password,
                      abort_exception=abort_exception,
                      reject_unkown_hosts=False,
                      combine_stderr=False,
                      connection_attempts=ssh_attempts):
            with forward_agent(self.key):
                LOG.debug("running '%s' on '%s' host as user '%s'",
                          cmd, self.host, self.user)
                if self.sudo and self.user != 'root':
                    return fab_sudo(cmd)
                else:
                    return run(cmd)
Example #3
0
def sudo_local(command, shell=True, pty=True, combine_stderr=True, user=None, capture=False, warn_only=False):
    """ sudo/local function based on host """
    if env.user == user:
        return run_local(command, shell=shell, pty=pty, combine_stderr=combine_stderr, capture=capture, warn_only=warn_only)
    else:
        if is_local():
            return fab_local("sudo %s" % command, capture=capture)
        else:
            return fab_sudo(command, shell=shell, pty=pty, combine_stderr=combine_stderr, user=user, warn_only=warn_only)
Example #4
0
def sudo(args):
    """
    Helper pour exécuter sur le serveur une commande en tant que le user git
    """
    fab_sudo("%s" % args, pty=True, user=GIT_USER)
Example #5
0
 def __execute_command(self, command, sudo=False, user=None):
     if sudo or (user is not None):
         return fab_sudo(command, user=user)
     return run(command)
Example #6
0
 def __execute_command(self, command, sudo=False, user=None):
     if sudo or (user is not None):
         return fab_sudo(command, user=user)
     return run(command)