Skip to content
Snippets Groups Projects
Commit 3a906b3b authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

export ParseSchema

parent 8a11ab6e
Branches
Tags
3 merge requests!95path traversal library,!91"Overhaul Architecture",!90Develop
......@@ -2,20 +2,17 @@ package main
import (
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util"
schema "code.fbi.h-da.de/cocsn/yang-models/generated/arista"
"code.fbi.h-da.de/cocsn/yang-models/generated/arista"
)
func main() {
tree := schema.SchemaTree
schema,_ := arista.Schema()
paths := util.NewPaths()
for _,v := range tree {
if v.Parent != nil {
if v.Parent.Name == "device" {
pathElement := paths.ProcessEntry(v)
pathElement.Print()
}
}
paths.ParseSchema(schema, "device")
for _,v := range paths {
v.Print()
}
}
......@@ -3,6 +3,7 @@ package util
import (
"fmt"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/ytypes"
)
type PathElement struct {
......@@ -32,7 +33,7 @@ func NewPaths() Paths {
type Paths map[string]*PathElement
func (p Paths)ProcessEntry(e *yang.Entry) *PathElement {
func (p Paths) processEntry(e *yang.Entry) *PathElement {
if e.Dir != nil {
elem := &PathElement{
Children: make([]*PathElement, len(e.Dir)),
......@@ -40,7 +41,7 @@ func (p Paths)ProcessEntry(e *yang.Entry) *PathElement {
}
i := 0
for _,v := range e.Dir {
elem.Children[i] = p.ProcessEntry(v)
elem.Children[i] = p.processEntry(v)
i++
}
p[e.Name] = elem
......@@ -50,4 +51,16 @@ func (p Paths)ProcessEntry(e *yang.Entry) *PathElement {
Name: e.Name,
}
return leaf
}
func (p Paths) ParseSchema(schema *ytypes.Schema, root string) error {
tree := schema.SchemaTree
for _,v := range tree {
if v.Parent != nil {
if v.Parent.Name == root {
p.processEntry(v)
}
}
}
return nil
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment