Script setup_ssh
[hide private]
[frames] | no frames]

Script setup_ssh

Tool to setup the SSH configuration on a remote node.

This is needed before we can join the node into the cluster.

Classes [hide private]
  RemoteCommandError
Exception if remote command was not successful.
  JoinCheckError
Exception raised if join check fails.
  HostKeyVerificationError
Exception if host key do not match.
  AuthError
Exception for authentication errors to hosts.
Functions [hide private]
 
_CheckJoin(transport)
Checks if a join is safe or dangerous.
 
_RunRemoteCommand(transport, command)
Invokes and wait for the command over SSH.
 
_InvokeDaemonUtil(transport, command)
Invokes daemon-util on the remote side.
 
_ReadSftpFile(sftp, filename)
Reads a file over sftp.
 
_WriteSftpFile(sftp, name, perm, data)
SFTPs data to a remote file.
 
SetupSSH(transport)
Sets the SSH up on the other side.
 
ParseOptions()
Parses options passed to program.
 
SetupLogging(options)
Sets up the logging.
list
LoadPrivateKeys(options)
Load the list of available private keys.
 
_FormatFingerprint(fpr)
Formats a paramiko.PKey.get_fingerprint() human readable.
boolean
LoginViaKeys(transport, username, keys)
Try to login on the given transport via a list of keys.
 
LoadKnownHosts()
Load the known hosts.
 
_VerifyServerKey(transport, host, host_keys)
Verify the server keys.
 
main()
Main routine.

Imports: getpass, logging, paramiko, os, optparse, sys, cli, constants, errors, netutils, ssconf, ssh, utils


Function Details [hide private]

_CheckJoin(transport)

 

Checks if a join is safe or dangerous.

Note: This function relies on the fact, that all hosts have the same configuration at compile time of Ganeti. So that the constants do not mismatch.

Parameters:
  • transport - The paramiko transport instance
Returns:
True if the join is safe; False otherwise

_RunRemoteCommand(transport, command)

 

Invokes and wait for the command over SSH.

Parameters:
  • transport - The paramiko transport instance
  • command - The command to be executed

_InvokeDaemonUtil(transport, command)

 

Invokes daemon-util on the remote side.

Parameters:
  • transport - The paramiko transport instance
  • command - The daemon-util command to be run

_ReadSftpFile(sftp, filename)

 

Reads a file over sftp.

Parameters:
  • sftp - An open paramiko SFTP client
  • filename - The filename of the file to read
Returns:
The content of the file

_WriteSftpFile(sftp, name, perm, data)

 

SFTPs data to a remote file.

Parameters:
  • sftp - A open paramiko SFTP client
  • name - The remote file name
  • perm - The remote file permission
  • data - The data to write

SetupSSH(transport)

 

Sets the SSH up on the other side.

Parameters:
  • transport - The paramiko transport instance

SetupLogging(options)

 

Sets up the logging.

Parameters:
  • options - Parsed options

LoadPrivateKeys(options)

 

Load the list of available private keys.

It loads the standard ssh key from disk and then tries to connect to the ssh agent too.

Returns: list
a list of paramiko.PKey

_FormatFingerprint(fpr)

 

Formats a paramiko.PKey.get_fingerprint() human readable.

Parameters:
  • fpr - The fingerprint to be formatted
Returns:
A human readable fingerprint

LoginViaKeys(transport, username, keys)

 

Try to login on the given transport via a list of keys.

Parameters:
  • transport - the transport to use
  • username - the username to login as
  • keys (list) - list of paramiko.PKey to use for authentication
Returns: boolean
True or False depending on whether the login was successfull or not

LoadKnownHosts()

 

Load the known hosts.

Returns:
paramiko.util.load_host_keys dict

_VerifyServerKey(transport, host, host_keys)

 

Verify the server keys.

Parameters:
  • transport - A paramiko.transport instance
  • host - Name of the host we verify
  • host_keys - Loaded host keys
Raises:
  • HostkeyVerificationError - When the host identify couldn't be verified