ncdiff.Model class¶
-
class
ncdiff.Model(tree)[source]¶ Bases:
objectAbstraction of a YANG module. It supports str() which returns a string similar to the output of ‘pyang -f tree’.
-
name¶ Model name.
Type: str
-
prefix¶ Prefix of the model.
Type: str
-
prefixes¶ All prefixes used in the model. Dictionary keys are prefixes, and values are URLs.
Type: dict
-
url¶ URL of the model.
Type: str
-
urls¶ All URLs used in the model. Dictionary keys are URLs, and values are prefixes.
Type: dict
-
tree¶ The model tree as an Element object.
Type: Element
-
roots¶ All root nodes of the model. Each node is an Element object.
Type: list
-
width¶ This is used to facilitate pretty print of a model. Dictionary keys are nodes in the model tree, and values are indents.
Type: dict
__init__ instantiates a Model instance.
-
emit_tree(tree)[source]¶ High-level api: Emit a string presentation of the model.
Parameters: tree ( Element) – The model.Returns: A string presentation of the model that is very similar to the output of ‘pyang -f tree’ Return type: str
-
emit_children(tree, type='other')[source]¶ High-level api: Emit a string presentation of a part of the model.
Parameters: - tree (
Element) – The model. - type (
str) – Type of model content required. Its value can be ‘other’, ‘rpc’, or ‘notification’.
Returns: A string presentation of the model that is very similar to the output of ‘pyang -f tree’
Return type: str
- tree (
-
get_width(element)[source]¶ High-level api: Calculate how much indent is needed for a node.
Parameters: element ( Element) – A node in model tree.Returns: Start position from the left margin. Return type: int
-
static
get_depth_str(element, type='other')[source]¶ High-level api: Produce a string that represents tree hierarchy.
Parameters: - element (
Element) – A node in model tree. - type (
str) – Type of model content required. Its value can be ‘other’, ‘rpc’, or ‘notification’.
Returns: A string that represents tree hierarchy.
Return type: str
- element (
-
static
get_flags_str(element)[source]¶ High-level api: Produce a string that represents the type of a node.
Parameters: element ( Element) – A node in model tree.Returns: A string that represents the type of a node. Return type: str
-
get_name_str(element)[source]¶ High-level api: Produce a string that represents the name of a node.
Parameters: element ( Element) – A node in model tree.Returns: A string that represents the name of a node. Return type: str
-
get_datatype_str(element, length)[source]¶ High-level api: Produce a string that indicates the data type of a node.
Parameters: - element (
Element) – A node in model tree. - length (
int) – String length that has been consumed.
Returns: A string that indicates the data type of a node.
Return type: str
- element (
-
prefix_to_url(id)[source]¶ High-level api: Convert an identifier from
prefix:tagnamenotation to{namespace}tagnamenotation. If the identifier does not have a prefix, it is assumed that the whole identifier is a tag name.Parameters: id ( str) – Identifier inprefix:tagnamenotation.Returns: Identifier in {namespace}tagnamenotation.Return type: str
-
url_to_prefix(id)[source]¶ High-level api: Convert an identifier from
{namespace}tagnamenotation toprefix:tagnamenotation. If the identifier does not have a namespace, it is assumed that the whole identifier is a tag name.Parameters: id ( str) – Identifier in{namespace}tagnamenotation.Returns: Identifier in prefix:tagnamenotation.Return type: str
-
remove_model_prefix(id)[source]¶ High-level api: If prefix is the model prefix, return tagname without prefix. If prefix is not the model prefix, simply return the identifier without modification.
Parameters: id ( str) – Identifier inprefix:tagnamenotation.Returns: Identifier in prefix:tagnamenotation if prefix is not the model prefix. Or identifier intagnamenotation if prefix is the model prefix.Return type: str
-