pynml.manager
¶
topology manager module.
Classes¶
NMLManager
: NML namespace manager.ExtendedNMLManager
: Extended NMLManager object.
-
class
pynml.manager.
NMLManager
(name=u'NML Namespace', **kwargs)¶ NML namespace manager.
Parameters: name (str) – Name of this namespace.
Variables: - namespace –
OrderedDict
with all NML objects registered. Useregister_object()
to register new objects. - metadata – Store all kwargs passed to the constructor.
Inheritance
-
export_graphviz
()¶ Export current namespace as a Graphviz graph.
Return type: str Returns: The current NML namespace in Graphviz graph notation.
-
export_nml
(pretty=True)¶ Export current namespace as a NML XML format.
Parameters: pretty – Pretty print the output XML. Return type: str Returns: The current NML namespace in NML XML format.
-
get_object
(identifier)¶ Get an object from this namespace by it’s unique identifier.
Parameters: identifier (str) – Object unique identifier. Return type: NMLObject Returns: The object with given identifier, or None if not found.
-
register_object
(obj)¶ Register a NML object into the namespace managed by this Manager.
Parameters: obj (NetworkObject) – Object to register into the namespace. Raises: Exception – If object already in namespace.
-
save_graphviz
(path, keep_gv=False)¶ Plot this namespace using Graphviz.
To use this function the following must be considered:
- The path must be a path to a filename in the format expected, for example, if a .svg file is expected the path must end with a .svg. If no format is provided an exception is raised.
- The output file will be overriden. If case of permissions or IO error and exception is raised.
- This function will call the dot binary by itself if found (using py:func:distutils.spawn.find_executable); if not, an exception is raised.
- If the output parent directories does not exists this function will try to create them using py:func:os.makedirs.
Parameters: Return type: str o None
Returns: Path to .gv file is keep_gv is True, else None.
-
save_nml
(path, pretty=True)¶ Write NML XML file of the current namespace.
To use this function the following must be considered:
- The output file will be overriden. If case of permissions or IO error and exception is raised.
- If the output parent directories does not exists this function will try to create them using py:func:os.makedirs.
Parameters:
- namespace –
-
class
pynml.manager.
ExtendedNMLManager
(**kwargs)¶ Extended NMLManager object.
This object provides a additional helper interface that allow to easily create common objects in a topology, their relations and iterate over them. In particular, this object does the following assumptions that are not part of the NML specification:
- A
pynml.nml.BidirectionalPort
is related to a singlepynml.nml.Node
. - A
pynml.nml.BidirectionalLink
is related to a singlepynml.nml.BidirectionalPort
.
If the above assumptions aren’t true for your topologies please use the standard
NMLManager
or implement your own subclass.The original proposed name for this class was
NMLManagerWithCommonHelpersThatMakeSeveralAssumptions
, but it was too long.Inheritance
-
bilinks
()¶ Iterate over all registered
pynml.nml.BidirectionalLink
s in the namespace.This iterates the bilinks in the order as they were added into the namespace.
Returns: An iterator to all bilinks in the namespace. The iterator is a tuple of the form: (( pynml.nml.Node
A,pynml.nml.BidirectionalPort
A), (pynml.nml.Node
B,pynml.nml.BidirectionalPort
B),pynml.nml.BidirectionalLink
).
-
biports
()¶ Iterate over all registered
pynml.nml.BidirectionalPort
s in the namespace.This iterates the biports in the order as they were added into the namespace.
Returns: An iterator to all biports in the namespace. The iterator is a tuple ( pynml.nml.Node
,pynml.nml.BidirectionalPort
).
-
create_bilink
(biport_a, biport_b, **kwargs)¶ Helper to create and register a
pynml.nml.BidirectionalLink
.All keyword arguments are passed as is to the
pynml.nml.BidirectionalLink
constructor. This helper also creates all intermediate directed sink and source sublinks and relates them to the inbound and outbound subports.Return type: pynml.nml.BidirectionalLink
Returns: A new pynml.nml.BidirectionalLink
already registered into the namespace and with sublinks already related.
-
create_biport
(node, **kwargs)¶ Helper to create and register a
pynml.nml.BidirectionalPort
.All keyword arguments are passed as is to the
pynml.nml.BidirectionalPort
constructor. This helper also creates all intermediate directed inbound and outbound subports and relates them to the node. The node argument is related to those subports too.Return type: pynml.nml.BidirectionalPort
Returns: A new pynml.nml.BidirectionalPort
already registered into the namespace and with subports already related.
-
create_environment
(**kwargs)¶ Helper to create and register a
pynml.nml.Environment
.All keyword arguments are passed as is to the
pynml.nml.Environment
constructor.Return type: pynml.nml.Environment
Returns: A new pynml.nml.Environment
already registered into the namespace.
-
create_node
(**kwargs)¶ Helper to create and register a
pynml.nml.Node
.All keyword arguments are passed as is to the
pynml.nml.Node
constructor.Return type: pynml.nml.Node
Returns: A new pynml.nml.Node
already registered into the namespace.
-
environment
¶ Returns the environment :class: pynml.nml.Environment
-
export_graphviz
()¶ Graphiz export override. See
NMLManager.export_graphviz()
.
-
nodes
()¶ Iterate over all registered
pynml.nml.Node
s in the namespace.This iterates the nodes in the order as they were added into the namespace.
Returns: An iterator to all nodes in the namespace.
- A