go mod init yang.to.cue
go get github.com/openconfig/ygot/generator
git clone --depth=1 https://github.com/YangModels/yang.git
git clone https://github.com/openconfig/public openconfig
curl -o yang/arista.yang https://raw.githubusercontent.com/aristanetworks/yang/master/EOS-4.25.1F/release/openconfig/models/interfaces/arista-intf-augments.yang
mkdir pkg
go run github.com/openconfig/ygot/generator \
-path=openconfig \
-generate_fakeroot \
-fakeroot_name=device \
-output_file=pkg/yang.go \
-compress_paths=false \
-exclude_modules=ietf-interfaces,openconfig-mpls,openconfig-isis,openconfig-evpn \
-include_descriptions=false \
-include_model_data=false \
-package_name=yang \
-exclude_state \
openconfig/release/models/interfaces/openconfig-if-ip.yang \
openconfig/release/models/bgp/openconfig-bgp.yang \
openconfig/release/models/network-instance/openconfig-network-instance.yang \
yang/arista.yang
go run main.go
This generates the ./go.json
file
# replace 'path' tags with 'json'
sed -i -E 's/path:"(\S+)"/json:"\1"/' pkg/yang.go
# replace Go maps with slices
sed -i -E 's/map\[.*\]\*(\S+)/\[\]\*\1/' pkg/yang.go
cue mod init yang.cue
cue get go yang.to.cue/pkg/...
The generated file is located in cue.mod/gen/yang.to.cue/pkg/yang_go_gen.cue
# regenerate ygot package
go run github.com/openconfig/ygot/generator \
-path=openconfig \
-generate_fakeroot \
-fakeroot_name=device \
-output_file=pkg/yang.go \
-compress_paths=false \
-exclude_modules=ietf-interfaces,openconfig-mpls,openconfig-isis,openconfig-evpn \
-include_descriptions=false \
-include_model_data=false \
-package_name=yang \
-exclude_state \
openconfig/release/models/interfaces/openconfig-if-ip.yang \
openconfig/release/models/bgp/openconfig-bgp.yang \
openconfig/release/models/network-instance/openconfig-network-instance.yang \
yang/arista.yang
go run post-import.go
From here on, you work exclusively with CUE definitions and can safely delete
./openconfig
and./yang
directories with YANG models and./pkg
containing ygot types.
cat values.cue
cue eval values.cue --out=json
# mismatch betweek YangList.key and YangList.Config.Key
cue eval bad/mismatch.cue --out=json
# duplicate entry in YangList
cue eval bad/duplicate.cue --out=json
# misspelled/incorrect entry
cue eval bad/undefined.cue --out=json
cat gnmi_tool.cue
cue apply