Skip to content

Commit

Permalink
added option to forward ssh agent
Browse files Browse the repository at this point in the history
  • Loading branch information
cancan101 committed Nov 5, 2014
1 parent eb7ada2 commit e840896
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions starcluster/sshutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,14 @@ def execute_async(self, command, source_profile=True):
def get_last_status(self):
return self.__last_status

def get_status(self, command, source_profile=True):
def get_status(self, command, source_profile=True, forward_ssh_agent=False):
"""
Execute a remote command and return the exit status
"""
channel = self.transport.open_session()
if forward_ssh_agent:
paramiko.agent.AgentRequestHandler(channel)

if source_profile:
command = "source /etc/profile && %s" % command
channel.exec_command(command)
Expand Down Expand Up @@ -529,7 +532,8 @@ def _get_output(self, channel, silent=True, only_printable=False):

def execute(self, command, silent=True, only_printable=False,
ignore_exit_status=False, log_output=True, detach=False,
source_profile=True, raise_on_failure=True):
source_profile=True, raise_on_failure=True,
forward_ssh_agent=False):
"""
Execute a remote command and return stdout/stderr
Expand All @@ -546,9 +550,15 @@ def execute(self, command, silent=True, only_printable=False,
check for non-zero exit status if detach=True)
source_profile - if True prefix the command with "source /etc/profile"
raise_on_failure - raise exception.SSHError if command fails
forward_ssh_agent- Turn on SSH agent forwarding
equivalent to `ssh -A` from the `ssh` command line utility.
Defaults to False if not set.
returns List of output lines
"""
channel = self.transport.open_session()
if forward_ssh_agent:
paramiko.agent.AgentRequestHandler(channel)

if detach:
command = "nohup %s &" % command
if source_profile:
Expand Down

0 comments on commit e840896

Please sign in to comment.