jnpr.junos.cfg

jnpr.junos.cfg.resource

class jnpr.junos.cfg.resource.Resource(junos, namevar=None, **kvargs)[source]

Bases: object

D

returns the Device object bound to this resource/manager

M

returns the :Resource: manager associated to this resource

P

returns the parent of the associated Junos object

PROPERTIES = ['_exists', '_active']
R

returns the Device RPC meta object

__init__(junos, namevar=None, **kvargs)[source]

Resource or Resource-Manager constructor. All managed resources and resource-managers inherit from this class.

junos
Instance of Device, this is bound to the Resource for device access
namevar

If not None, identifies a specific resource by ‘name’. The format of the name is resource dependent. Most resources take a single string name, while others use tuples for compound names. refer to each resource for the ‘namevar’ definition

If namevar is None, then the instance is a Resource-Manager (RM). The RM is then used to select specific resources by name using the __getitem__ overload.

kvargs[‘P’] or kvargs[‘parent’]
Instance to the resource parent. This is set when resources have hierarchical relationships, like rules within rulesets
kvargs[‘M’]
Instance to the resource manager.
activate()[source]

activate resource in Junos config the same as the Junos config-mode “activate” command

active

is this resource configuration active on the Junos device?

RuntimeError:if invoked on a manager object
catalog

returns a dictionary of resources

catalog_refresh()[source]

reloads the resource catalog from the Junos device

classmethod copyifexists(klass, xml, ele_name, to_py, py_name=None)[source]
deactivate()[source]

activate resource in Junos config the same as the Junos config-mode “deactivate” command

delete()[source]

remove configuration from Junos device the same as the Junos config-mode “delete” command

classmethod diff_list(klass, has_list, should_list)[source]
exists

does this resource configuration exist on the Junos device?

RuntimError:if invoked on a manager
is_mgr

is this a resource manager?

is_new

is this a new resource? that is, it does not exist on the Junos device when it was initally retrieved

RuntimeError:if invoked on a manager
list

returns a list of named resources

list_refresh()[source]

reloads the managed resource list from the Junos device

manages

a resource may contain sub-managers for hierarchical oriented resources. this method will return a list of manager names attached to this resource, or :None: if there are not any

name

the name of the resource

RuntimeError:if invoked on a manager
propcopy(p_name)[source]

proptery from :has: to :should:

performs a ‘deepcopy’ of the property; used to make changes to list, dict type properties

read()[source]

read resource configuration from device

refresh()[source]
rename(new_name)[source]

rename resource in Junos configuration the same as the Junos config-mode “rename” command

reorder(**kvargs)[source]

move the configuration within the Junos hierarcy the same as the Junos config-mode “insert” command

Kvargs:after=”<name>” before=”<name>”
write(**kvargs)[source]

write resource configuration stored in :should: back to device

kvargs[‘touch’]
if True, then write() will skip the check to see if any items exist in :should:
xml

for debugging the resource XML configuration that was read from the Junos device

classmethod xml_set_or_delete(klass, xml, ele_name, value)[source]

HELPER function to either set a value or remove the element

classmethod xmltag_set_or_del(klass, ele_name, value)[source]

HELPER function creates an XML element tag read-only that includes the DEL attribute depending on :value:

jnpr.junos.cfg.user

class jnpr.junos.cfg.user.User(junos, namevar=None, **kvargs)[source]

Bases: jnpr.junos.cfg.resource.Resource

[edit system login user <name>]

Resource name: str
<name> is the user login name
Manages resources:
sshkey, UserSSHKey
MANAGES = {'sshkey': <class 'jnpr.junos.cfg.user_ssh_key.UserSSHKey'>}
PROPERTIES = ['uid', 'fullname', 'userclass', 'password', '$password', '$sshkeys']

jnpr.junos.cfg.user_ssh_key

class jnpr.junos.cfg.user_ssh_key.UserSSHKey(junos, namevar=None, **kvargs)[source]

Bases: jnpr.junos.cfg.resource.Resource

[edit system login user <name> authentication <key-type> <key-value> ]

Resource name: tuple(<key-type>, <key-value>)
<key-type> : [‘ssh-dsa’, ‘ssh-rsa’] <key-value> : SSH public key string (usually something very long)
Resource manager utilities:
load_key - allows you to load an ssh-key from a file or str
PROPERTIES = []
load_key(path=None, key_value=None)[source]

Adds a new ssh-key to the user authentication. You can provide either the path to the ssh-key file, or the contents of they key (useful for loading the same key on many devices)

Path:(optional) path to public ssh-key file on the local server,
Key_value:(optional) the contents of the ssh public key