jnpr.junos.factory.cfgtable.CfgTable(dev=None, xml=None, path=None)[source]¶Bases: jnpr.junos.factory.table.Table
get(*vargs, **kvargs)[source]¶Retrieve configuration data for this table. By default all child keys of the table are loaded. This behavior can be overridden by with kvargs[‘nameonly’]=True
| Parameters: |
|
|---|
keys_required¶True/False - if this Table requires keys
required_keys¶return a list of the keys required when invoking :get(): and :get_keys():
jnpr.junos.factory.factory_cls.FactoryOpTable(cmd, args=None, args_key=None, item=None, key='name', view=None, table_name=None)[source]¶jnpr.junos.factory.factory_cls.FactoryView(fields, **kvargs)[source]¶| 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.
jnpr.junos.factory.factory_loader.FactoryLoader[source]¶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() ...
jnpr.junos.factory.optable.OpTable(dev=None, xml=None, path=None)[source]¶Bases: jnpr.junos.factory.table.Table
get(*vargs, **kvargs)[source]¶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! |
jnpr.junos.factory.table.Table(dev=None, xml=None, path=None)[source]¶Bases: object
D¶the Device instance
ITEM_NAME_XPATH = 'name'¶ITEM_XPATH = None¶RPC¶the Device.rpc instance
VIEW = None¶__init__(dev=None, xml=None, path=None)[source]¶| Dev: | Device instance |
|---|---|
| Xml: | lxml Element instance |
| Path: | file path to XML, to be used rather than :dev: |
hostname¶is_container¶True if this table does not have records, but is a container of fields False otherwise
key_list¶the list of keys, as property for caching
savexml(path, hostname=False, timestamp=False, append=None)[source]¶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. |
view¶returns the current view assigned to this table
jnpr.junos.factory.view.View(table, view_xml)[source]¶Bases: object
View is the base-class that makes extracting values from XML data appear as objects with attributes.
D¶return the Device instance for this View
FIELDS = {}¶GROUPS = None¶ITEM_NAME_XPATH = 'name'¶T¶return the Table instance for the View
__init__(table, view_xml)[source]¶| 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 |
key¶return the name of view item
name¶return the name of view item
refresh()[source]¶~~~ 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
updater(*args, **kwds)[source]¶provide the ability for subclassing objects to extend the definitions of the fields. this is implemented as a context manager with the form called from the subclass constructor:
- with self.extend() as more:
- more.fields = <dict> more.groups = <dict> # optional
xml¶returns the XML associated to the item
jnpr.junos.factory.viewfields.ViewFields[source]¶Bases: object
Used to dynamically create a field dictionary used with the RunstatView class
astype(name, xpath=None, astype=<type 'int'>, **kvargs)[source]¶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
end¶flag(name, xpath=None, **kvargs)[source]¶field is a flag, results in True/False if the xpath element exists or not. Model this as a boolean type <bool>
jnpr.junos.factory.loadyaml(path)[source]¶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() ...
jnpr.junos.factory.FactoryLoader[source]¶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() ...