ssh Package

cmdline Module

exception opennode.oms.endpoint.ssh.cmdline.ArgumentParsingError(status, message=None)[source]

Bases: exceptions.Exception

exception opennode.oms.endpoint.ssh.cmdline.ArgumentParsingInterrupted[source]

Bases: opennode.oms.endpoint.ssh.cmdline.ArgumentParsingError

class opennode.oms.endpoint.ssh.cmdline.GroupDictAction(group='group', is_path=False, base_path='', **kwargs)[source]

Bases: argparse.Action

Extends argparser with an action suited for key=value keyword arguments. Each arg declared with a KeywordAction, will be put inside a dictionary (by default called keywords) inside the resulting arg object.

This is particularly useful if you have a number of dynamically defined args which would otherwise end up in cluttering the resulting arg object without a clear way to enumerate them all.

You can override this grouping with the group parameter.

class opennode.oms.endpoint.ssh.cmdline.InstrumentableArgumentParser(file=None, *args, **kwargs)[source]

Bases: argparse.ArgumentParser

ArgumentParser subclass that raises an exception instead of exiting in case of errors, and allows all output to be redirected to a custom output stream.

error(message)[source]
exit(status=0, message=None)[source]
class opennode.oms.endpoint.ssh.cmdline.MergeListAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: argparse.Action

Custom argparse action which allows multiple occurrences of multivalued optional arguments, e.g. -x a b -x c d will yield [‘a’, ‘b’, ‘c’, ‘d’].

class opennode.oms.endpoint.ssh.cmdline.PartialVirtualConsoleArgumentParser(file=None, add_help=None, *args, **kwargs)[source]

Bases: opennode.oms.endpoint.ssh.cmdline.VirtualConsoleArgumentParser

Use this if you want to avoid printing error messages and retry on partial arglists.

parse_args(args=None, namespace=None)[source]
class opennode.oms.endpoint.ssh.cmdline.VirtualConsoleArgumentParser(add_help=None, *args, **kwargs)[source]

Bases: opennode.oms.endpoint.ssh.cmdline.InstrumentableArgumentParser

This parser avoids using the argparse help action, since it fires during the parsing, We want to pospone the handling of help until after the args are parsed.

declare_argument(dest, default=None)[source]

Declares the existence of an argument without adding a requirement and an option string for it.

It’s useful for GroupDictAction argument or other actions where multiple arguments store in the same value. The dest attribute for declared arguments will have its default value even if no argument was defined or matched.

parse_args(args=None, namespace=None)[source]
class opennode.oms.endpoint.ssh.cmdline.VirtualConsoleHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]

Bases: argparse.HelpFormatter

Takes care of presenting our special keyworded options in their canonical key = value form.

format_help()[source]

colored_columnize Module

Returns a compact set of columns as a string with newlines for an array of strings.

Adapted from the routine of the same name inside cmd.py

mmikulicic: taken from http://pypi.python.org/pypi/columnize and adapted for strings containing ANSI escapes (should work mostly for colors).

opennode.oms.endpoint.ssh.colored_columnize.bw(text)[source]

Plain black and white text.

opennode.oms.endpoint.ssh.colored_columnize.color_ljust(text, size)[source]
opennode.oms.endpoint.ssh.colored_columnize.color_rjust(text, size)[source]
opennode.oms.endpoint.ssh.colored_columnize.columnize(array, displaywidth=80, colsep=' ', arrange_vertical=True, ljust=True, lineprefix='')[source]
Return a list of strings as a compact set of columns arranged

horizontally or vertically.

For example, for a line width of 4 characters (arranged vertically):
[‘1’, ‘2,’, ‘3’, ‘4’] => ‘1 3

2 4 ‘

or arranged horizontally:
[‘1’, ‘2,’, ‘3’, ‘4’] => ‘1 2

3 4 ‘

Each column is only as wide as necessary. By default, columns are separated by two spaces - one was not legible enough. Set “colsep” to adjust the string separate columns. Set `displaywidth’ to set the line width.

Normally, consecutive items go down from the top to bottom from the left-most column to the right-most. If “arrange_vertical” is set false, consecutive items will go across, left to right, top to bottom.

detached Module

class opennode.oms.endpoint.ssh.detached.DetachedProtocol[source]

Bases: object

This represents a detached background protocol used to execute commands in background and redirect output to logs

write(*args, **kwargs)[source]

editable Module

class opennode.oms.endpoint.ssh.editable.EditableModelAdapter(context)[source]

Bases: grokcore.component.components.Adapter

toEditableString(descriptions=False)[source]

editor Module

class opennode.oms.endpoint.ssh.editor.Editor(parent)[source]

Bases: object

COMMENT_COLOR = '\x1b[0;31m'
MODELINE_HEIGHT = 2
abort()[source]
bol_pos(from_pos=None)[source]
char_at(pos)[source]
delete_character()[source]
draw_modeline(text)[source]
draw_status(text)[source]
enable_tracing()[source]
eol_pos()[source]
finalize_tracing()[source]
fixup_for_shorter_line(go_forward)[source]
goto_next_line()[source]
goto_prev_line()[source]
handle_BACKSPACE()[source]
handle_BEGIN_LINE()[source]
handle_DOWN()[source]
handle_DUMP_BUFFER()[source]
handle_END_LINE()[source]
handle_EOF()[source]
handle_EXIT()[source]
handle_KILL_LINE()[source]
handle_LEFT()[source]
handle_REDRAW()[source]
handle_RIGHT()[source]
handle_SAVE()[source]
handle_UP()[source]
handle_WHAT_CURSOR_POSITION()[source]
handle_YANK()[source]
insert_character(ch)[source]
keystrokeReceived(*args, **kwargs)[source]
redraw_buffer()[source]
refresh_modline()[source]
replay_recorded()[source]

Debug utility useful for repeating difficult to reproduce sessions that show some bug

reset_scrolling_region()[source]
show_keys(keys, prefix='C-')[source]
start(*args, **kwargs)[source]
trace_keystroke(keyID, mod)[source]
wait_for_exit()[source]
write(text)[source]

protocol Module

class opennode.oms.endpoint.ssh.protocol.CallbackExecutionSubProtocol[source]

Bases: object

keystrokeReceived(keyID, mod)[source]
class opennode.oms.endpoint.ssh.protocol.CommandExecutionSubProtocol(parent)[source]

Bases: object

handle_EOF()[source]
keystrokeReceived(keyID, mod)[source]
class opennode.oms.endpoint.ssh.protocol.OmsShellProtocol[source]

Bases: opennode.oms.endpoint.ssh.terminal.InteractiveTerminal

The OMS virtual console over SSH.

Accepts lines of input and writes them back to its connection. If a line consisting solely of “quit” is received, the connection is dropped.

close_connection()[source]
connectionMade()[source]
dataReceived(data)[source]
ensure_initialized(*args, **kwargs)[source]
exit_sub_protocol()[source]
expand(command, tokens)[source]
expand_token(command, token)[source]
get_command_class(name)[source]
handle_EOF()[source]
handle_TAB(*args, **kwargs)[source]
hist_file_name[source]
keystrokeReceived(keyID, modifier)[source]
lineReceived(*args, **kwargs)[source]
logged_in(principal)[source]

Invoked when the principal which opened this session is known

static make_path(path)[source]
parse_line(*args, **kwargs)[source]

Returns a command instance and parsed cmdline argument list.

TODO: Shell expansion should be handled here.

ps[source]
spawn_command(*args, **kwargs)[source]
spawn_commands(*args, **kwargs)[source]
class opennode.oms.endpoint.ssh.protocol.ProtocolContextExtractor(context)[source]

Bases: grokcore.component.components.Subscription

get_context()[source]
opennode.oms.endpoint.ssh.protocol.dataReceived(self, data)[source]
opennode.oms.endpoint.ssh.protocol.protocolInlineCallbacks(fun)[source]

Executes protocol async callbacks while buffering next keystrokes during the execution of the callback. After the callback finishes the buffered keystrokes will be replayed back, but currently only non-special characters are replayed, since special characters could trigger a reentrant here which would inject keystrokes out of order.

pubkey Module

class opennode.oms.endpoint.ssh.pubkey.InMemoryPublicKeyCheckerDontUse[source]

Bases: twisted.conch.checkers.SSHPublicKeyDatabase

Loads the public key from ~/.ssh/id_[rd]sa.pub at startup, and accepts logins for those keys Designed for testing, especially local testing.

checkKey(credentials)[source]

Accepts any user name

session Module

class opennode.oms.endpoint.ssh.session.BatchOmsShellProtocol[source]

Bases: opennode.oms.endpoint.ssh.protocol.OmsShellProtocol

batch = True
lineReceived(line)[source]

Ignore input, we are not a shell

class opennode.oms.endpoint.ssh.session.OmsSSHSession(*args, **kw)[source]

Bases: twisted.conch.ssh.session.SSHSession

request_agent(data)[source]
request_env(data)[source]
request_x11_req(data)[source]
class opennode.oms.endpoint.ssh.session.OmsTerminalRealm[source]

Bases: twisted.conch.manhole_ssh.TerminalRealm

class opennode.oms.endpoint.ssh.session.OmsTerminalSession(original)[source]

Bases: twisted.conch.manhole_ssh.TerminalSession

execCommand(proto, cmd)[source]
class opennode.oms.endpoint.ssh.session.OmsTerminalSessionTransport(proto, chainedProtocol, avatar, width, height)[source]

Bases: twisted.conch.manhole_ssh.TerminalSessionTransport

class opennode.oms.endpoint.ssh.session.OmsTerminalUser(original, avatarId)[source]

Bases: twisted.conch.manhole_ssh.TerminalUser

terminal Module

class opennode.oms.endpoint.ssh.terminal.InteractiveTerminal[source]

Bases: twisted.conch.recvline.HistoricRecvLine

Advanced interactive terminal. Handles history, line editing, killing/yanking, line movement.

Prompt handling is delegated to subclasses.

batch = False
close_connection()[source]

Closes the connection and saves history.

colorize(color, text)[source]
connectionMade()[source]
enter_full_screen()[source]

Switch to the full screen plane, used for editors.

exit_full_screen()[source]

Switch back to the normal plane.

handle_ABORT()[source]

Abort a search.

handle_BACKWARD_KILL_WORD()[source]

Provides the ALT-BACKSPACE behaviour like in emacs/bash.

handle_EOF()[source]

Exits the shell on CTRL-D

Exits search mode and edit the found history line.

handle_FF()[source]

Handles a ‘form feed’ byte - generally used to request a screen refresh/redraw.

handle_KILL_LINE()[source]

Deletes the rest of the line (from the cursor right), and keeps the content in the kill ring for future pastes.

handle_QUIT()[source]

Just copied from conch Manhole, no idea why it would be useful to differentiate it from CTRL-D, but I guess it’s here for a reason.

handle_SEARCH_NEXT()[source]
handle_SEARCH_RETURN()[source]
handle_TRANSPOSE()[source]

Provides the CTRL-T behaviour like on emacs/bash.

handle_YANK()[source]

Pastes the content of the kill ring.

hist_file_name[source]
initializeScreen()[source]
insert_buffer(buf)[source]

Inserts some chars in the buffer at the current cursor position.

insert_text(text)[source]

Inserts some text at the current cursor position and renders it.

keystrokeReceived(keyID, modifier)[source]
print_prompt()[source]
restore_history()[source]
save_history()[source]
search_ps[source]
set_terminal(terminal)[source]
terminalSize(width, height)[source]

Avoid clearing the whole screen

terminalSizeAfterLogin()[source]

Part of terminalSize executed after login

tokenizer Module

exception opennode.oms.endpoint.ssh.tokenizer.CommandLineSyntaxError(message)[source]

Bases: exceptions.Exception

The commandline has a syntax error and cannot be even tokenized correctly

class opennode.oms.endpoint.ssh.tokenizer.CommandLineTokenizer[source]

Bases: object

Tokenizer for the commandline, handling escaped space, quotes, escaped quotes and also special key=value syntax. It tries to provide user friendly error messages where possible.

tokenize(args)[source]