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)
Initializes this class.
source code
list
_BuildSshOptions(self, batch, ask_key, use_cluster_key, strict_host_check, private_key=None, quiet=True, port=None)
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, port=None)
Build an ssh command to execute a command on a remote node.
source code
utils.process.RunResult
Run(self, *args, **kwargs)
Runs a command on a remote node.
source code
boolean
CopyFileToNode(self, node, port, filename)
Copy a file to another node with scp.
source code
 
VerifyNodeHostname(self, node, ssh_port)
Verify hostname consistency via SSH.
source code
Method Details [hide private]

__init__(self, cluster_name)
(Constructor)

source code 

Initializes this class.

Parameters:
  • cluster_name (str) - name of the cluster

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

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
  • port - the SSH port to use, or None to use the default
Returns: list
the list of options ready to use in utils.process.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, port=None)

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
  • port - the SSH port on which the node's daemon is running
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.process.RunResult
the result as from utils.process.RunCmd()

CopyFileToNode(self, node, port, 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, ssh_port)

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
  • ssh_port - the port of a SSH daemon running on the node
Returns:
(success, detail), where:
  • success: True/False
  • detail: string with details