drivers

class ntc_rosetta.drivers.base.Driver

Parent class used to operate on models and native datastructures

The class has a few class attributes that need to be overriden by classes inheriting from this class.

parser

Class attribute to defines which yangify.parser.RootParser to use when parsing native data

translator

Class attribute to defines which yangify.translator.RootParser to use when translating YANG models to native data

datamodel

Class attribute that defines which yangson.datamodel.DataModel the parser and translator can operate on.

datamodel_name = ''
classmethod get_datamodel() → yangson.datamodel.DataModel
merge(candidate: Dict[str, Any], running: Dict[str, Any], replace: bool = False) → Any

Given two objects conforming to a data model compute the needed native commands to converge the configurations.

Parameters:
  • candidate – Desired configuration (must conform to the datamodel of the driver)
  • running – Original configuration (must conform to the datamodel of the driver)
  • replace – Whether to return a list of commands that reinitializes blocks (i.e. defaulting an interface)
parse(native: Optional[Dict[str, Any]] = None, validate: bool = True, include: Optional[List[str]] = None, exclude: Optional[List[str]] = None) → ntc_rosetta.drivers.base.ParseResult

Parser native data and maps it into an object conforming to the datamodel.

Parameters:
  • native – native data extracted from a device
  • validate – whether to validate the model or not
  • include – if specified only return data matching the YANG paths here
  • excldue – if specify exclude data matching the YANG paths here
parser

alias of yangify.parser.RootParser

translate(candidate: Dict[str, Any], replace: bool = False) → Any

Translates data conforming to the model into native configuration the device understands.

Parameters:
  • candidate – Data to translate (must conform to the datamodel of the driver)
  • replace – Whether to return a list of commands that reinitializes blocks (i.e. defaulting an interface)
translator

alias of yangify.translator.RootTranslator

class ntc_rosetta.drivers.base.ParseResult(root: yangson.instance.RootNode, datamodel: yangson.datamodel.DataModel)

Result of parsing a configuration

root

Root of the response

datamodel

Datamodel related to the parsed object

peek(path: str) → Union[int, decimal.Decimal, str, Tuple[None], ArrayValue, ObjectValue, None]

Return the value in the given path (YANG)

raw_value() → Union[bool, int, str, List[None], Dict[str, Union[bool, int, str, List[None], Dict[str, RawValue], List[Dict[str, RawValue]], List[Union[bool, int, str, List[None]]]]], List[Dict[str, Union[bool, int, str, List[None], Dict[str, RawValue], List[Dict[str, RawValue]], List[Union[bool, int, str, List[None]]]]]], List[Union[bool, int, str, List[None]]]]

Parsed data in python’s native datastructures (dicts, lists, strings, etc)