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

export ParseSchema

parent 8a11ab6e
No related branches found
No related tags found
3 merge requests!95path traversal library,!91"Overhaul Architecture",!90Develop
This commit is part of merge request !91. Comments created here will be created in the context of that merge request.
...@@ -2,20 +2,17 @@ package main ...@@ -2,20 +2,17 @@ package main
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util" "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() { func main() {
tree := schema.SchemaTree schema,_ := arista.Schema()
paths := util.NewPaths() paths := util.NewPaths()
for _,v := range tree { paths.ParseSchema(schema, "device")
if v.Parent != nil {
if v.Parent.Name == "device" { for _,v := range paths {
pathElement := paths.ProcessEntry(v) v.Print()
pathElement.Print()
}
}
} }
} }
...@@ -3,6 +3,7 @@ package util ...@@ -3,6 +3,7 @@ package util
import ( import (
"fmt" "fmt"
"github.com/openconfig/goyang/pkg/yang" "github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/ytypes"
) )
type PathElement struct { type PathElement struct {
...@@ -32,7 +33,7 @@ func NewPaths() Paths { ...@@ -32,7 +33,7 @@ func NewPaths() Paths {
type Paths map[string]*PathElement 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 { if e.Dir != nil {
elem := &PathElement{ elem := &PathElement{
Children: make([]*PathElement, len(e.Dir)), Children: make([]*PathElement, len(e.Dir)),
...@@ -40,7 +41,7 @@ func (p Paths)ProcessEntry(e *yang.Entry) *PathElement { ...@@ -40,7 +41,7 @@ func (p Paths)ProcessEntry(e *yang.Entry) *PathElement {
} }
i := 0 i := 0
for _,v := range e.Dir { for _,v := range e.Dir {
elem.Children[i] = p.ProcessEntry(v) elem.Children[i] = p.processEntry(v)
i++ i++
} }
p[e.Name] = elem p[e.Name] = elem
...@@ -50,4 +51,16 @@ func (p Paths)ProcessEntry(e *yang.Entry) *PathElement { ...@@ -50,4 +51,16 @@ func (p Paths)ProcessEntry(e *yang.Entry) *PathElement {
Name: e.Name, Name: e.Name,
} }
return leaf 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