Developer Docs¶
Running tests¶
Setup a virtual env
mkvirtualenv inmanta-test -p python3
pip install -r requirements.dev.txt
pip install -r requirements.txt
mkdir /tmp/env
export INMANTA_TEST_ENV=/tmp/env
export INMANTA_MODULE_REPO=git@github.com:inmanta/
# Optional value to set in environments with large config files. 60 seconds is used if not specified.
export N5K_NETCONF_TIMEOUT="60"
Run tests
pytest tests
Design¶
This handler uses netconf
to send cli commands to the switch. netconf
is also used to fetch
the full configuration from the device.
The module consists of multiple entities:
A Resource for which one or more can be generated per device. This entity contains a desired state configuration commands that come from ManagedObjects in the configuration model.
ManagedObjects which are the entities that represent the desired state. Each managed object generates configuration commands. This module should be able to “partially” manage a switch. This means that all attributes that generate configuration lines should be nullable. null then means, do not manage the attribute and ignore it. As a consequence each managed object has a list of attributes that should be removed (e.g. no description). For flags, which are modelled as booleans this is not required (e.g. shutdown=false becomes no shutdown)
The handler uses a schema definition to generate an NX-OS edit script that can transform the current state into the desired state. This schema defines the tree structure that the IOS-like configuration of NX-OS is. It has a similar function what a yang schema does for xml based configuration.
Schema documentation¶
The schema file contains a list of components
that match with lines in the configuration. Each component
can have
a list of children. These lines and the parent/child relation is translated into a set of internal Component
model objects.
There are two schemas for Nexus 5500/5600:
nx-os
nx-osv
nx-os
is a schema used by a real device whereas nx-osv
is used by a virtual device
An object can have the following attributes:
name
: Thename
of the component as it is seen in the config of the Nexustype
: This determines the type of configuration line. Currently the following types have been defined:value
: A line in which everything aftername
is considered as the value of the parameter (strippped of leading and trailing whitespaces).flag
: A flag parameter, can have True/False value. For example shutdown/no shutdown.switch
: A list of values to choose from a given set of valuescontainer
: An object that holds other objects with a common nameattribute_range_list
: List ofrange
objects which can have attributes. Attributes are presented in the config as values printed right after therange
before the new line character.field_range_list
: List ofrange
objects which can have fields. Fields are presented in the config as values / components which are printed with an indentation, each in a new line.scripted_range_list
: List ofrange
objects without attributes nor fields. The list supports adding and removing items from it’s range withscript
syntax, i. e.add
andremove
keywords.
Example:
- name: interface
type: container
creatable: false
children:
- name: switchport
type: flag
default: true
- name: switchport mode
type: switch
Each schema component can have certain fields defined, which are:
name
type
creatable
(no all components)default
(only children ofcontainer
or fields offield_range_list
)
There are also spefic fields for each component:
attributes
fields
value
Config object representation:
Config objects are represented according to the provided schema as object instances such as
Container
,ScriptedRangeList
etc. The class hierarchy of the module is:
Notes:
Cisco ranges are expanded using http://www.pennington.net/py/ciscoconfparse/api_ccp_util.html#ciscoconfparse.ccp_util.CiscoRange