session

Module for session object representing all connection to remote hosts.

class lmi.scripts.common.session.Session(app, hosts, credentials=None, same_credentials=False)[source]

Session object keeps connection objects to remote hosts. Their are associated with particular hostnames. It also caches credentials for them. Connections are made as they are needed. When credentials are missing for connection to be made, the user is asked to supply them from standard input.

Parameters:
  • app – Instance of main application.
  • hosts (list) – List of hostname strings.
  • credentials (dictionary) – Mapping assigning a pair (user, password) to each hostname.
  • same_credentials (boolean) – Use the same credentials for all hosts in session. The first credentials given will be used.
get_credentials(hostname)[source]
Parameters:hostname (string) – Name of host to get credentials for.
Returns:Pair of (username, password) for given hostname. If no credentials were given for this host, ('', '') is returned.
Return type:tuple
get_unconnected()[source]
Returns:List of hostnames, which do not have associated connection yet.
Return type:list
hostnames[source]

List of hostnames in session.

Return type:list
class lmi.scripts.common.session.SessionProxy(session, uris)[source]

Behaves like a session. But it just encapsulates other session object and provides access to a subset of its items.

Parameters:
  • session – Session object or even another session proxy.
  • uris (list) – Subset of uris in encapsulated session object.