remote_multicommand package¶
Submodules¶
remote_multicommand.remote_multicommand module¶
-
class
remote_multicommand.remote_multicommand.
RemoteMultiCommand
(ssh_key, **kwargs)¶ Bases:
loggers.loggers.Loggers
Execute commands in parallel in remote servers
- Provides a layer of abstraction for executing multiple commands in multiple servers
- with multiple processes in parallel
Parameters: - key_ssh (
str
) – path of the ssh private key to connect (must be None if using user and pasword to connect) - log_folder (
str
, optional , default =None) – folder where the log files of this class will be generated - username (
str
, optional , default =root) – username using the connection - password (
str
,optional, default =None) – password for connection if using user and password instead of key - ssh_port (
str
, optional, default =22) – ssh tcp port - server_has_dns (
bool
, optional, default =True) – if the server is not registered in a DNS domain and/or has not its DNS name equals to its hostname, this flag must de set to False, otherwise this condition will be checked to certify we are trully connected to the right server.
-
execute_command
(server)¶ Execute a command in a remote server
Issues a command in the server and updates the dictionary self.servers_cmd_dict, which maintains the state of all commands executed in this object
Parameters: server ( str
) – server where the command will be executedReturns: dictionary containing the server, the command executed, the result of the connection attempt and the result of the command issued
-
launch_list_of_commands
(script_cmds, num_of_process, servers_list, ssh_log_level='CRITICAL')¶ Launch a list of parallel commands
Launches several processes that execute a sequence of commands in a list of servers For each server, the next commands will only be executed if the preceding command was successfull.
Parameters: - script_cmds (
str
orlist
) – list or string containing the commands (interprets ”;”, new line character and comments) - num_of_process – (
int
) number of separated process launched in each iteration - servers_list (
list
) – servers list - ssh_log_level (
str
, default = ‘CRITICAL’) – log level of the ssh connection. Could be ‘DEBUG’, ‘INFO’, ‘ERROR’ or ‘CRITICAL’
Returns: - dictionary containing the servers and the result of
the command
Return type: servers_cmd_dict (
dict
)- script_cmds (
-
launch_multicommand
(cmd, num_of_process, servers_list, ssh_log_level='CRITICAL')¶ Launches several processes that execute the command in a list of servers
Parameters: - cmd (
str
) – command to be executed in each server of the list - num_of_process (
int
) – number of separated process launched in each iteration - servers_list (
list
) – servers list - ssh_log_level (
str
, default = ‘CRITICAL’) – log level of the ssh connection. Could be ‘DEBUG’, ‘INFO’, ‘ERROR’ or ‘CRITICAL’
Returns: - dictionary containing the servers and the result of
the command
Return type: servers_cmd_dict (
dict
)- cmd (