Bootstrap Client

class Node(server)[source]
Node object which can be used by actions via:
attributes.get(‘NODE’)
client

jsonrpclib.Server – jsonrpclib connect to Command API engine

api_config_cmds(cmds)[source]

Run CLI commands via Command API, starting from config mode.

Commands are ran in order.

Parameters:cmds (list) – List of CLI commands.
Returns:
List of Command API results corresponding to the
input commands.
Return type:list
api_enable_cmds(cmds, text_format=False)[source]

Run CLI commands via Command API, starting from enable mode.

Commands are ran in order.

Parameters:
  • cmds (list) – List of CLI commands.
  • text_format (bool, optional) – If true, Command API request will run in text mode (instead of JSON).
Returns:

List of Command API results corresponding to the

input commands.

Return type:

list

append_rc_eos_lines(lines)[source]

Add lines to rc.eos.

Parameters:lines (list) – List of bash commands
append_startup_config_lines(lines)[source]

Add lines to startup-config.

Parameters:lines (list) – List of CLI commands
classmethod bash_cmds(cmds)[source]

Executes bash commands in order - stops on first failure.

Parameters:cmds – list of bash commands
Returns:first failing command (None otherwise) code: exit code for first failing command (None otherwise) out: stdout for first failing command (None otherwise) err: stderr for first failing command (None otherwise)
Return type:cmd
create_user(user, group, passwd, root='/persist/local/', ssh_keys=None)[source]

Create a local user on the bootstrapped node. If ‘ssh_keys’ are provided, they will be copied to $HOME/.ssh/authorized_keys. Also, rc.eos will be modified to add this user on every boot. If the user provided already exists, the function will continue and install the ssh_keys (if necessary). The $HOME/.ssh directory will be assigned 0700 permissions and the $HOME/.ssh/authorized_keys file will be assigned 0600 permissions in accord with SSH best practices.

Parameters:
  • user (-) – the username
  • group (-) – the group assigned to the user
  • passwd (-) – cleartext password
  • root (-) – the path where the user’s home directory will reside
  • ssh_keys (-) – (optional) public keys that will be copied to ~$HOME/.ssh/authorized_keys
Raises:
  • ZtpError
  • - missing argument – user, group, passwd
    • useradd fails, return the error
    • ssh_keys cannot be written to ‘authorized_keys’
    • files cannot change ownership or permissions
Returns:

True if user created; False if otherwise

Return type:

bool

details()[source]

Get details.

Returns:System details

Format:

{'model':        <MODEL>,
 'version':      <EOS_VERSION>,
 'systemmac':    <SYSTEM_MAC>,
 'serialnumber': <SERIAL_NUMBER>,
 'neighbors':    <NEIGHBORS>        # see neighbors()
}
Return type:dict
flash()[source]

Get flash path.

Returns:flash path
Return type:string
has_startup_config()[source]

Check whether startup-config is configured or not.

Returns:True is startup-config is configured; false otherwise.
Return type:bool
log_msg(msg, error=False)[source]

Log message via configured syslog/XMPP.

Parameters:
  • msg (string) – Message
  • error (bool, optional) – True if msg is an error; false otherwise.
neighbors()[source]

Get neighbors.

Returns:LLDP neighbor

Format:

{'neighbors': {<LOCAL_PORT>:
 [{'device': <REMOTE_DEVICE>,
   'port': <REMOTE_PORT>}, ...],
...}}
Return type:dict
rc_eos()[source]

Get rc.eos path.

Returns:rc.eos path
Return type:string
retrieve_url(url, path)[source]

Download resource from server.

If ‘path’ is somewhere on flash and ‘url’ points back to SERVER, then the client will request the metadata for the resource from the server (in order to check whether there is enogh disk space available). If ‘url’ points to a different server, then the ‘content-length’ header will be used for the disk space checks.

Raises:ZtpError – resource cannot be retrieved: - metadata cannot be retrieved from server OR - metadata is inconsistent with request OR - disk space on flash is insufficient OR - file cannot be written to disk
Returns:startup-config path
Return type:string
classmethod server_address()[source]

Get ZTP Server URL.

Returns:ZTP Server URL.
Return type:string
startup_config()[source]

Get startup-config path.

Returns:startup-config path
Return type:string
classmethod substitute(template, substitutions, strict=True)[source]

Perform variable substitution on a config template.

Parameters:
  • template (string) – EOS configuration template
  • substitutions (dict) – set of substitutions for the template
  • strict (bool, optional) – If true, method will raise Exception when template variables are missing from ‘substitutions’.
Returns:

template string with variable substitution

Return type:

string

system()[source]

Get system information.

Returns:System information

Format:

{'model':        <MODEL>,
 'version':      <EOS_VERSION>,
 'systemmac':    <SYSTEM_MAC>,
 'serialnumber': <SERIAL_NUMBER>}
Return type:dict