Skip to content
Snippets Groups Projects

path traversal library

Merged Ghost User requested to merge 67-1-path-traversal-get-all into 67-overhaul-architecture
Files
7
package main
import (
schema "code.fbi.h-da.de/cocsn/yang-models/generated/arista"
"fmt"
"github.com/openconfig/goyang/pkg/yang"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util"
"code.fbi.h-da.de/cocsn/yang-models/generated/arista"
log "github.com/sirupsen/logrus"
)
type PathElement struct {
Children []*PathElement
Name string
}
func (p *PathElement)Print() {
printPE(0, p)
}
func printPE(indent int, pe *PathElement) {
for i := 0; i < indent; i++ {
fmt.Print(" ")
}
fmt.Println(pe.Name)
if len(pe.Children) > 0 {
for _,p := range pe.Children {
printPE(indent+1, p)
}
}
}
func main() {
tree := schema.SchemaTree
paths := make(map[string]*PathElement)
log.SetLevel(log.DebugLevel)
schema, _ := arista.Schema()
paths := util.NewPaths()
paths.ParseSchema(schema, "device")
for k,v := range tree {
if v.Parent != nil {
if v.Parent.Name == "device" {
pathElement := processEntry(v)
pathElement.Print()
paths[k] = pathElement
}
}
for _, v := range paths {
v.Print()
}
}
func processEntry(e *yang.Entry) *PathElement {
if e.Dir != nil {
elem := &PathElement{
Children: make([]*PathElement, len(e.Dir)),
Name: e.Name,
}
i := 0
for _,v := range e.Dir {
elem.Children[i] = processEntry(v)
i++
}
return elem
}
leaf := &PathElement{
Name: e.Name,
}
return leaf
}
\ No newline at end of file
p := paths.StringBuilder()
log.Debug(p)
}
Loading