-
Notifications
You must be signed in to change notification settings - Fork 344
UMLOutput
In some circumstances it is useful to be able to visualize YANG models as UML diagrams. Pyang supports two different ways of doing this:
- Render png using PlantUML:
pyang -f uml
- Generate AppleScript that renders a OmniGraffle UML document
OmniGraffle :
pyang -f omni
If you have OmniGraffle installed you can use this plugin to render a UML kind-of diagram in OmniGraffle. The good thing here is that you can modify the layout, remove parts of the diagram etc to make it more good looking.
Use this in the following way:
- Start OmniGraffle
- Generate the AppleScript file from the YANG module
- Run the AppleScript, this will open a OmniGraffle doc and render the UML diagram
$ pyang -f omni ietf-interfaces.yang -o ietf-interfaces.scpt
$ osascript ietf-interfaces.scpt
![https://raw.githubusercontent.com/mbj4668/pyang/master/doc/img/ietf-interfaces.png] (https://raw.githubusercontent.com/mbj4668/pyang/master/doc/img/ietf-interfaces.png)
The uml plugin to pyang generates a file that can be read by plantuml r7997 (http://sourceforge.net/projects/plantuml/files/plantuml.7997.jar/download).
The following example converts the ietf-netconf-monitoring module into a UML diagram:
$ pyang -f uml ietf-netconf-monitoring.yang -o ietf-netconf-monitoring.uml
$ java -jar plantuml.jar ietf-netconf-monitoring.uml
$ open img/ietf-netconf-monitoring.png
On some platforms Java might spit out "java.lang.OutOfMemoryError: Java heap space"
Pass the -Xmx<SIZE>m
to java like:
$ java -Xmx1024m -jar plantuml.jar ietf-netconf-monitoring.uml
Please note that the uml output has numerous options to tweak and simplify the layout. To skip details try the --uml-no=
parameter. In many cases you like to inline augments and groupings, use the --uml-inline
parameters.
You can also pass several YANG files to the UML output format, but the files must be given in dependency order. (Multi-file does not work for module/sub-module dependancies)
Another example with some parts suppressed:
$ pyang -f uml --uml-no=circles,stereotypes,annotation ietf-netconf-monitoring.yang -o ietf-netconf-monitoring.uml
A multi-file example from the ongoing YANG modeling in Metro Ethernet Forum
A complex example based on the Configuration Data Model for IPFIX and PSAMP
There is also a python script to generate a UML package structure for all yangs in a folder.
uml-utilities/uml-pkg
Use it in the following way:
$ ls *.yang | xargs -n1 pyang -f depend > packages.txt
$ uml-pkg --title=TITLE --inputfile=packages.txt > packages.uml
$ java -jar plantuml.jar packages.uml
$ open img/packages.png