class documentation

class SshRunner(object):

View In Hierarchy

Wrapper for SSH commands.

Method __init__ Initializes this class.
Method BuildCmd Build an ssh command to execute a command on a remote node.
Method CopyFileToNode Copy a file to another node with scp.
Method Run Runs a command on a remote node.
Method VerifyNodeHostname Verify hostname consistency via SSH.
Instance Variable cluster_name Undocumented
Instance Variable ipv6 Undocumented
Method _BuildSshOptions Builds a list with needed SSH options.
def __init__(self, cluster_name):

Initializes this class.

Parameters
cluster_name:strname of the cluster
def 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.

Parameters
hostnamethe target host, string
useruser to auth as
commandthe command
batchif true, ssh will run in batch mode with no prompting
ask_keyif true, ssh will run with StrictHostKeyChecking=ask, so that we can connect to an unknown host (not valid in batch mode)
ttyUndocumented
use_cluster_keywhether to expect and use the cluster-global SSH key
strict_host_checkwhether to check the host's SSH key at all
private_keyuse this private key instead of the default
quietwhether to enable -q to ssh
portthe SSH port on which the node's daemon is running
Returns
the ssh call to run 'command' on the remote host.
def CopyFileToNode(self, node, port, filename):

Copy a file to another node with scp.

Parameters
nodenode in the cluster
portUndocumented
filenameabsolute pathname of a local file
Returns
booleanthe success of the operation
def Run(self, *args, **kwargs):

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.RunResultthe result as from utils.process.RunCmd()
def VerifyNodeHostname(self, node, ssh_port):

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
nodenodename of a host to check; can be short or full qualified hostname
ssh_portthe port of a SSH daemon running on the node
Returns

(success, detail), where:

  • success: True/False
  • detail: string with details
cluster_name =

Undocumented

ipv6 =

Undocumented

def _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.

Parameters
batchsame as ssh's batch option
ask_keyallows ssh to ask for key confirmation; this parameter conflicts with the batch one
use_cluster_keyif True, use the cluster name as the HostKeyAlias name
strict_host_checkthis makes the host key checking strict
private_keyuse this private key instead of the default
quietwhether to enable -q to ssh
portthe SSH port to use, or None to use the default
Returns
listthe list of options ready to use in utils.process.RunCmd