Package ganeti :: Module ssh :: Class SshRunner
[hide private]
[frames] | no frames]

Class SshRunner

source code

Wrapper for SSH commands.

Instance Methods [hide private]
 
__init__(self, cluster_name, ipv6=False)
Initializes this class.
source code
list
_BuildSshOptions(self, batch, ask_key, use_cluster_key, strict_host_check, private_key=None, quiet=True)
Builds a list with needed SSH options.
source code
 
BuildCmd(self, hostname, user, command, batch=True, ask_key=False, tty=False, use_cluster_key=True, strict_host_check=True, private_key=None, quiet=True)
Build an ssh command to execute a command on a remote node.
source code
utils.RunResult
Run(self, *args, **kwargs)
Runs a command on a remote node.
source code
boolean
CopyFileToNode(self, node, filename)
Copy a file to another node with scp.
source code
 
VerifyNodeHostname(self, node)
Verify hostname consistency via SSH.
source code
Method Details [hide private]

__init__(self, cluster_name, ipv6=False)
(Constructor)

source code 

Initializes this class.

Parameters:
  • cluster_name (str) - name of the cluster
  • ipv6 (bool) - If true, force ssh to use IPv6 addresses only

_BuildSshOptions(self, batch, ask_key, use_cluster_key, strict_host_check, private_key=None, quiet=True)

source code 

Builds a list with needed SSH options.

Parameters:
  • batch - same as ssh's batch option
  • ask_key - allows ssh to ask for key confirmation; this parameter conflicts with the batch one
  • use_cluster_key - if True, use the cluster name as the HostKeyAlias name
  • strict_host_check - this makes the host key checking strict
  • private_key - use this private key instead of the default
  • quiet - whether to enable -q to ssh
Returns: list
the list of options ready to use in utils.RunCmd

BuildCmd(self, hostname, user, command, batch=True, ask_key=False, tty=False, use_cluster_key=True, strict_host_check=True, private_key=None, quiet=True)

source code 

Build an ssh command to execute a command on a remote node.

Parameters:
  • hostname - the target host, string
  • user - user to auth as
  • command - the command
  • batch - if true, ssh will run in batch mode with no prompting
  • ask_key - if true, ssh will run with StrictHostKeyChecking=ask, so that we can connect to an unknown host (not valid in batch mode)
  • use_cluster_key - whether to expect and use the cluster-global SSH key
  • strict_host_check - whether to check the host's SSH key at all
  • private_key - use this private key instead of the default
  • quiet - whether to enable -q to ssh
Returns:
the ssh call to run 'command' on the remote host.

Run(self, *args, **kwargs)

source code 

Runs a command on a remote node.

This method has the same return value as `utils.RunCmd()`, which it uses to launch ssh.

Args: see SshRunner.BuildCmd.

Returns: utils.RunResult
the result as from utils.RunCmd()

CopyFileToNode(self, node, filename)

source code 

Copy a file to another node with scp.

Parameters:
  • node - node in the cluster
  • filename - absolute pathname of a local file
Returns: boolean
the success of the operation

VerifyNodeHostname(self, node)

source code 

Verify hostname consistency via SSH.

This functions connects via ssh to a node and compares the hostname reported by the node to the name with have (the one that we connected to).

This is used to detect problems in ssh known_hosts files (conflicting known hosts) and inconsistencies between dns/hosts entries and local machine names

Parameters:
  • node - nodename of a host to check; can be short or full qualified hostname
Returns:
(success, detail), where:
  • success: True/False
  • detail: string with details