Bases: jnpr.junos.factory.table.Table
Retrieve configuration data for this table. By default only the keys of the table is loaded. This behavior can be overriden by either requesting a sepcifc table item, or by calling with kvargs[‘values’]=True
Vargs: | [0] identifies a unique item in the table, same as calling with :kvargs[‘key’]: value |
---|
‘values’ - True/False*, when set to True will cause all data item values to be retrieved, not just the name-keys.
‘key’ - used to retrieve the contents of the table record, and not just the list of keys (default) [when namesonly=True]
Fields: | dictionary of fields, structure of which is ~internal~ and should not be defined explicitly. use the RunstatMaker.Fields() mechanism to create theserather than hardcoding the dictionary structures; since they might change over time. |
---|---|
Kvargs: | ‘view_name’ to name the class. this could be useful for debug or eventual callback mechanisms. ‘groups’ is a dict of name/xpath assocaited to fields this technique would be used to extract fields from node-set elements like port <if-device-flags>. ‘extends’ names the base View class to extend. using this technique you can add to existing defined Views. |
This file contains the FactoryLoader class that is used to dynamically create Runstat Table and View objects from a <dict> of data. The <dict> can originate from any kind of source: YAML, JSON, program. For examples of YAML refer to the .yml files in this jnpr.junos.op directory.
Bases: object
Used to load a <dict> of data that contains Table and View definitions.
The primary method is :load(): which will return a <dict> of item-name and item-class definitions.
If you want to import these definitions directly into your namespace, (like a module) you would do the following:
loader = FactoryLoader() catalog = loader.load( <catalog_dict> ) globals().update( catalog )
If you did not want to do this, you can access the items as the catalog. For example, if your <catalog_dict> contained a Table called MyTable, then you could do something like:
MyTable = catalog[‘MyTable’] table = MyTable(dev) table.get() ...
Bases: jnpr.junos.factory.table.Table
Retrieve the XML table data from the Device instance and returns back the Table instance - for call-chaining purposes.
If the Table was created with a :path: rather than a Device, then this method will load the XML from that file. In this case, the *vargs, and **kvargs are not used.
ALIAS: __call__
Vargs: | [0] is the table :arg_key: value. This is used so that the caller can retrieve just one item from the table without having to know the Junos RPC argument. |
---|---|
Kvargs: | these are the name/value pairs relating to the specific Junos XML command attached to the table. For example, if the RPC is ‘get-route-information’, there are parameters such as ‘table’ and ‘destination’. Any valid RPC argument can be passed to :kvargs: to further filter the results of the :get(): operation. neato! |
Bases: object
Dev: | Device instance |
---|---|
Xml: | lxml Element instance |
Path: | file path to XML, to be used rather than :dev: |
True if this table does not have records, but is a container of fields False otherwise
Save a copy of the table XML data to a local file. The name of the output file (:path:) can include the name of the Device host, the timestamp of this action, as well as any user-defined appended value. These ‘add-ons’ will be added to the :path: value prior to the file extension in the order (hostname,timestamp,append), separated by underscore (_).
For example, if both hostname=True and append=’BAZ1’, then when :path: = ‘/var/tmp/foo.xml’ and the Device.hostname is “srx123”, the final file-path will be “/var/tmp/foo_srx123_BAZ1.xml”
Path: | file-path to write the XML file on the local filesystem |
---|---|
Hostname: | if True, will append the hostname to the :path: |
Timestamp: |
|
Append: | any <str> value that you’d like appended to the :path: value preceding the filename extension. |
Bases: object
View is the base-class that makes extracting values from XML data appear as objects with attributes.
Table: | instance of the RunstatTable |
---|---|
View_xml: | this should be an lxml etree Elemenet object. This constructor also accepts a list with a single item/XML |
return the name of view item
~~~ EXPERIMENTAL ~~~ refresh the data from the Junos device. this only works if the table provides an “args_key”, does not update the original table, just this specific view/item
Bases: object
Used to dynamically create a field dictionary used with the RunstatView class
field string value will be passed to function :astype:
This is typically used to do simple type conversions, but also works really well if you set :astype: to a function that does a basic converstion like look at the value and change it to a True/False. For example:
astype=lambda x: True if x == ‘enabled’ else False
Load a YAML file at :path: that contains Table and View definitions. Returns a <dict> of item-name anditem-class definition.
If you want to import these definitions directly into your namespace, (like a module) you would do the following:
globals().update( loadyaml( <path-to-yaml-file> ))
If you did not want to do this, you can access the items as the <dict>. For example, if your YAML file contained a Table called MyTable, then you could do something like:
catalog = loadyaml( <path-to-yaml-file> ) MyTable = catalog[‘MyTable’]
table = MyTable(dev) table.get() ...
Bases: object
Used to load a <dict> of data that contains Table and View definitions.
The primary method is :load(): which will return a <dict> of item-name and item-class definitions.
If you want to import these definitions directly into your namespace, (like a module) you would do the following:
loader = FactoryLoader() catalog = loader.load( <catalog_dict> ) globals().update( catalog )
If you did not want to do this, you can access the items as the catalog. For example, if your <catalog_dict> contained a Table called MyTable, then you could do something like:
MyTable = catalog[‘MyTable’] table = MyTable(dev) table.get() ...