ygot
Overview
ygot is a collection of Go utilities that can generate Go structures based off of YANG modules. In the demo we are going to generate go code based off of the openconfig-system model using ygot.
Demo Actions
- Import the necessary YANG files for openconfig-system to create a hostname.
- The hostname will be printed out and stored within the system.json file.
- Using the Arista gNMI binary we will configure a device with the ceos1 hostname.
Clone this repo
Install ygot
Check to see if all of the current YANG files are accurate
Reveal output
├── yang/openconfig-aaa-radius.yang
├── yang/openconfig-aaa-tacacs.yang
├── yang/openconfig-aaa-types.yang
├── yang/openconfig-aaa.yang
├── yang/openconfig-alarms.yang
├── yang/openconfig-alarm-types.yang
├── yang/openconfig-extensions.yang
├── yang/openconfig-inet-types.yang
├── yang/openconfig-license.yang
├── yang/openconfig-messages.yang
├── yang/openconfig-platform-types.yang
├── yang/openconfig-platform.yang
├── yang/openconfig-procmon.yang
├── yang/openconfig-system-logging.yang
├── yang/openconfig-system-management.yang
├── yang/openconfig-system-terminal.yang
├── yang/openconfig-system.yang
├── yang/openconfig-types.yang
└── yang/openconfig-yang-types.yang
Run ygot
go run $GOPATH/src/github.com/openconfig/ygot/generator/generator.go \
-path=yang -output_file=pkg/oc.go -package_name=oc -generate_fakeroot \
-fakeroot_name=device -compress_paths=true yang/openconfig-system.yang
Check the contents of pkg/oc.go
oc.go
is the necessary go import / package for openconfig-system. Looking at the Device struct within pkg/oc.go
type Device struct {
Component map[string]*Component `path:"components/component" module:"openconfig-platform"`
Messages *Messages `path:"messages" module:"openconfig-messages"`
System *System `path:"system" module:"openconfig-system"`
}
Looking at the System
struct we can see the Hostname
field.
We need to fill in the Hostname field and pass it through the EmitJSON
function so we can render this model with the correct
information which can be found in main.go
.
Run the go code
Output:
Reveal output
The output is also within `config/hostname.json` which is the same as the printed version.
Change the hostname on a device
The device should now have the ceos1 hostname.