connections

cec

class otto.connections.cec.Cec(shelf, iface, password=None, prompt=None)[source]

Connect via cec. This spawns a process running the installed cec client to interact with an appliance.

connect(timeout=10, expectation=True)[source]

Connect to and authenticate with host.

disconnect()[source]

Disconnect from host. This is mostly a formality.

run(cmd, wait=True, force=False, ans='y', timeout=60)[source]

This is the main command/only real operation. It runs a command and returns the result.

telnet

class otto.connections.telnet.Telnet(username, hostname, password, prompt, port=None)[source]

Connect via telnet. This spawns a process running the installed telnet client to interact with an appliance.

connect(timeout=60, skip_login=False)[source]

Connect to and authenticate with host.

timeout how long to wait for connect

run(cmd)[source]

This is the main command only real operation. It runs a command and returns the result.

ssh

class otto.connections.ssh.Client(host, user, password, port=22, compress=True)[source]

Connect to a host using paramiko, a Python interface to the SSH2 protocol. Transport compression is enabled by default now.

Client.environmentals is a dictionary of environment variables to be set. They can be manipulated on the fly with care or using the env context manager, otto.lib.contextmanager.env().

connect(timeout=10, key_file=None)[source]

Currently this method will return False if we can’t connect. If the script ignores this return and proceeds the traceback might not be obvious as to where the problem was.

disconnect()[source]

Disconnect from the host.

ls(path=None, expectation=True)[source]

return a list of files in path. If path is not specified cwd will be used. If path does not exist an exception will be raised unless expectation is False. Works in conjunction with the cd context manager.

open(fname, mode='r', bufsize=-1, expectation=True)[source]

return a file-like object of fname on the remote

reconnect(after=10, timeout=10, key_file=None, conn_attempts=10)[source]

This method will attempt to reconnect with the host, maybe after a reboot action.

The method will have a limit of 10 attempts to connect by default, for a total of 300 seconds before it gives up with the reconnection.

rm(path, expectation=True)[source]

remove a file named by a string

rmdir(dirname, expectation=True)[source]

remove a directory named by a string

run(cmd, timeout=None, bufsize=-1)[source]
Parameters:
  • cmd (str) – command to run on remote host
  • timeout (float) – timeout on blocking read/write operations when exceeded socket error will be raised
  • bufsize (int) – byte size of the buffer for the filehandle returned
Return type:

ReturnCode

stat(path)[source]

returns a namespace of:

{'size' : st.st_size,
 'uid': st.st_uid,
 'gid': st.st_gid,
 'mode': st.st_mode,
 'atime': st.st_atime,
 'mtime': st.st_mtime,
 }

this can accessesed like so:

fstat= init.stat('/etc/passwd')
fstat.flags
Parameters:path (str) –
Returns:
Return type:Namespace
class otto.connections.ssh.TunnelSocketCreator(host, user, port=22, key_filename=None, compress=True)[source]

a class for opening sockets remotely with ssh

connect(timeout=10)[source]

connect to proxy host :param timeout: :return:

get_sock(rhost, rport)[source]
Parameters:
  • rhost
  • rport
Returns:

a socket like object connected to rhost:rport

class otto.connections.ssh.parallelCmd(user, hostname, password, command, port=22)[source]

a non-blocking remote command running object

c = Cmd(init, params)
c.run()
# do other things
c.wait() # or use an 'if not c.done:' control struct
c.result.status
c.result.message

When the remote job has completed it will set:

.done to True
.message with the dict version of the fio output
.status with the exit code as a boolean

and try to store the json data as a dict in .dict .

done
Returns:whether or not the job is complete
Return type:bool
result

Return the result as a NamedTuple this means that result can be sliced or referenced by name:

status or 0: exitcode as int stdout or 1: stdout as str stderr or 2: stderr as str

so upon completion the following:

cmd.result[0] cmd.status

are equivilent. If the process is not complete this will block.

run()[source]

start the job on the remote host

wait()[source]

This is basicaly a join. It blocks untill the job is done. :return: a dictionary version of the json output :rtype: dict