Skip to content

Transformer phase1 #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 169 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
38d673d
load the yang to dynamically build in-memory metadata tree
redfish-api Jul 27, 2019
e28113b
add xslate code, yang extension etc.
redfish-api Jul 29, 2019
772be7e
Adding yang models as part of installer.
Jul 29, 2019
4390fe7
Merge branch 'master' into transformer-phase1
redfish-api Jul 29, 2019
6d08c82
Update yang files path on target, Defined yang path in transformer pa…
Jul 29, 2019
61205f4
Added code to dynamically create tranformer-spec-map having yang to d…
s-mari Jul 30, 2019
0ad30b0
Added infrastructure to populate xlate function map and invoke xfmr f…
Jul 31, 2019
2f0d1b1
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Jul 31, 2019
5476d95
Removed dbg print and renames the filename.
s-mari Jul 31, 2019
3da205e
Added check in XlateFuncBind function to avoid updating the existing …
Jul 31, 2019
486601b
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
Jul 31, 2019
de40ab9
Imported required packages and changed the package name.
s-mari Aug 1, 2019
bdaefcc
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Aug 1, 2019
9a2bce6
Addressed compilation error.
s-mari Aug 1, 2019
35728fa
Added sonic-extensions
amrutasali Aug 2, 2019
5b8ae1f
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
amrutasali Aug 2, 2019
af113fa
Added initial version of deviations for openconfig-acl covering Set c…
amrutasali Aug 5, 2019
64ad005
Moved openconfig-acl-annot.yang to annotations directory and added Ma…
amrutasali Aug 6, 2019
51f2528
Fixed issue in passing the yang files list to transformer LoadYangMod…
Aug 6, 2019
fe2bff1
Excluded annotations directory from ocbindings
amrutasali Aug 6, 2019
7f68823
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
amrutasali Aug 6, 2019
32bff76
Merge branch 'master' into transformer-phase1
Aug 9, 2019
0df904d
Initial commit - Common app registration
amrutasali Aug 9, 2019
23196f6
Transformer spec enhancement, oc yang & cvl yang incoming request han…
s-mari Aug 9, 2019
660fdd3
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Aug 9, 2019
5a8b43d
Extend goyang to generate template annotation file
ranjinidn Aug 9, 2019
56b6344
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
Aug 10, 2019
5d038f2
Changed the function names and file name
s-mari Aug 10, 2019
8fdaec0
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
Aug 11, 2019
c5b2665
Initial changes for transformer methods prototypes and ACL transforme…
Aug 11, 2019
64fc364
Build tool chain changes to generate :
amrutasali Aug 12, 2019
4ee1541
Corrected the src/cvl/schema/Makefile and fixed a commented out line
amrutasali Aug 12, 2019
025d306
Added support to get child table name and corrected the key gen from uri
s-mari Aug 12, 2019
fa0b4ac
Support for update, replace and delete request
s-mari Aug 12, 2019
11b497d
Updated xdbspec to include yang-xpath info and modified db-xpath crea…
s-mari Aug 13, 2019
3834a8d
Added PathInfo to Common App structure
amrutasali Aug 13, 2019
6a26fa6
Modified acl xfmr methods prefix Read_/Write_ to YangToDb_/DbToYang_
Aug 13, 2019
c1c19e5
In common app added support to generate Tables to Watch dynamically
amrutasali Aug 14, 2019
c8b0830
Updated details of nested child table in xspec map. Support to conver…
s-mari Aug 14, 2019
4c48246
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Aug 14, 2019
e3beda0
Added DbToYang_acl_port_bindings_xfmr method to handle db to OC conve…
Aug 14, 2019
b7376e0
part 1 - integrate translib with transformer
redfish-api Aug 14, 2019
d72f107
Integrate Translate yangpath to redisDB KeySpec (XlateUriToKeySpec)
ranjinidn Aug 14, 2019
f6ec091
modified common app translateGet and processGet signatures
amrutasali Aug 14, 2019
7fb10a4
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
amrutasali Aug 14, 2019
87ebf1b
corrected function siganature in common app for transformer.XlateUriT…
amrutasali Aug 14, 2019
8aad9cb
XlateUriToKeySpec: Use parent with empty table name and add children …
ranjinidn Aug 15, 2019
6f695ba
cvl yang get support from top-level container and added util functions
s-mari Aug 15, 2019
f8d8677
Fixed issue in handling interface binding if stage is not specified b…
Aug 15, 2019
7b8bc79
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
Aug 15, 2019
4af9076
XlateyangtoDB return sibilings as array of KeySpecs
ranjinidn Aug 15, 2019
df641e3
updated cvl-yang handling for create request
s-mari Aug 15, 2019
b888820
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Aug 15, 2019
7fd76e0
Add sonic-acl UT tests
Tejaswi-Goel Aug 15, 2019
85fd401
common app - Added support for basic level DB operations
amrutasali Aug 16, 2019
be4e4b3
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
amrutasali Aug 16, 2019
7a25984
Added support to pass in the operation type from apps to transformer
amrutasali Aug 16, 2019
8572760
Removed accidently added src/cvl/schema/allyangs_tree.html
amrutasali Aug 16, 2019
9042577
enabled oc yang to db map create creat request
s-mari Aug 16, 2019
b371fb1
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Aug 16, 2019
896bdc9
updated transformer function signature to include db, got and oper type.
s-mari Aug 16, 2019
8c65dc2
Added db pointer argument to transformer.XlateToDb()
amrutasali Aug 16, 2019
3de79fd
Modified Transformer method prototypes to pass operation type for xfm…
Aug 16, 2019
4a33754
call transformer.XlateUriToKeySpec() from processGet instead of
amrutasali Aug 16, 2019
cd5abe3
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
amrutasali Aug 16, 2019
c88231c
Enabled key, field and subtree overloaded-transformer-function exec f…
s-mari Aug 16, 2019
4ce0877
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Aug 16, 2019
289d53b
Modifed DB operations in common app :
amrutasali Aug 16, 2019
e17bc07
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
amrutasali Aug 16, 2019
3e6697b
Get handling: Send DB data to transformer to form json response
ranjinidn Aug 17, 2019
059ed1d
restructure acl_app.go
redfish-api Aug 17, 2019
35ec937
Initial support for leaf value retrieval in Get. Include only require…
ranjinidn Aug 17, 2019
122c0ea
fix xpath build from uri
redfish-api Aug 18, 2019
0dd9771
fixed crash in app transformer special handling code, added code to c…
s-mari Aug 18, 2019
8b03709
Add support for cvl yang db KeySpec creation and filter dbData for js…
ranjinidn Aug 18, 2019
92e77cb
Avoid using index values to identify the table and field names in cvl…
ranjinidn Aug 19, 2019
8ff8683
Goyang patch to introduce "ordered by insertion" list entry in yang.E…
ranjinidn Aug 19, 2019
47d4dfc
Handle DB Spec creation for CVL yang case
ranjinidn Aug 19, 2019
b5f9afe
Handle container level DbData creation for CVL yang to generate JSON …
ranjinidn Aug 19, 2019
d1e0464
Fix data being overwritten to JSON response. Include print to file
ranjinidn Aug 19, 2019
ac37709
changed the value parsing in xfmr handler funtions
s-mari Aug 20, 2019
86b0462
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Aug 20, 2019
cf254d8
Transformer Infra support to create a yang schema ordered DB table list
amrutasali Aug 20, 2019
cf83ec3
For CVL yang modified accessing yag entries to accessing them in yang
amrutasali Aug 20, 2019
c9094c4
Delete case:: Handle db request create for CVL yang
ranjinidn Aug 20, 2019
93d224f
Added support for table level delete in common app
amrutasali Aug 21, 2019
3a5ee1a
fixed crash in update request
s-mari Aug 21, 2019
6396138
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Aug 21, 2019
b57c2aa
xpath, tablename and key extraction for cvl yang
s-mari Aug 22, 2019
164ebcf
Send proper key formed for cvl yang delete case
ranjinidn Aug 22, 2019
8991985
Set case for Sonic yang - Added support for leaf-list handling in
amrutasali Aug 22, 2019
bd517be
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
amrutasali Aug 22, 2019
68b856e
Use "|" as delimited for CVL keys
ranjinidn Aug 22, 2019
e14f7f6
Fix get request for top level container
ranjinidn Aug 23, 2019
014c2fa
For delete case added support for deletion as per table ordering,
amrutasali Aug 26, 2019
9cd3339
Update the correct input json file name for create test case
ranjinidn Aug 26, 2019
c0ae3fb
fixed leaf level get for oc-yang
s-mari Aug 26, 2019
20170f5
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Aug 26, 2019
10d7f92
corrected the uri for field transformer
s-mari Aug 27, 2019
5301e41
Merge branch 'master' into transformer-phase1
amrutasali Aug 27, 2019
e530955
Added annotation for l2/config/ethertype attribute.
Aug 27, 2019
a4fad5f
support leaf value delete for oc yang
ranjinidn Aug 28, 2019
69d8471
Added transformer config file to specify list of yang models needs to…
Aug 28, 2019
72d86fb
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
Aug 28, 2019
913132b
Renamed file models to models_list
Aug 28, 2019
fe88df3
Really mv models models_list
Aug 28, 2019
287aca1
Handle delete for top level oc acl xpath request
ranjinidn Aug 28, 2019
cdbc35b
Populate Yang model list based on models_list manifest file and sonic…
Aug 28, 2019
648d7e0
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
Aug 28, 2019
7b6c2f9
Support to have common app registered as default/fallback app when no
amrutasali Aug 29, 2019
d869ce1
Addressed issue in passing data to field transformer method, addresed…
Aug 29, 2019
2e68e2f
Modify list of tables to watch to be the list of all tables in a
amrutasali Aug 29, 2019
e104fdc
Update DB ordered map for oc yang
ranjinidn Aug 30, 2019
7956a3f
Initial support for YANG extension to allow the Transformer to set th…
ranjinidn Aug 31, 2019
58ca40a
support to call transformer spl handler functions for get operation
s-mari Sep 4, 2019
ca5e593
Added API GetAndXlateFromDB() that clubs together genration of KeySpec
amrutasali Sep 4, 2019
ffde97a
Fix ygot issue in transformer by propagating ygRoot from app to trans…
amrutasali Sep 5, 2019
ca1250d
remove commented out code from transformer xfmrHandlerFunc
amrutasali Sep 5, 2019
bd42a11
In dbDataToYangJsonCreate() added support to fetch table order from
amrutasali Sep 6, 2019
e4dd5b1
removed commented put code for table order in xlate_from_db.go
amrutasali Sep 6, 2019
4cfd72f
Enhanced the xfmr functions, added flag for key leaf, updated get req…
s-mari Sep 7, 2019
f714c11
Resolved merge conflicts
s-mari Sep 7, 2019
c04c457
For Get case added support to retrieve attributes in config conatainers
amrutasali Sep 8, 2019
c809ad0
Added map-format output data for get-request
s-mari Sep 9, 2019
f770261
Addressed merge conflicts.
s-mari Sep 9, 2019
bffae5e
enhanced transformer to handle leaf level get-req
s-mari Sep 10, 2019
bd0d896
Initial Traverse multi DB support
ranjinidn Sep 10, 2019
0b38b71
Initial leaf-list support - common app modifications
amrutasali Sep 10, 2019
28a3656
removed mistakenly added CVL disabling in common_app.go
amrutasali Sep 10, 2019
3693d5d
Signature chnage for transformer functions
ranjinidn Sep 11, 2019
583c16c
modified acl-key xfmr to return integer and enhanced the get-req hand…
s-mari Sep 11, 2019
df0f7ff
make common-app as default to handle acl, add the field-xfmr for acl …
kwangsuk Sep 11, 2019
2eb5d98
Fix sonic get query failure
ranjinidn Sep 11, 2019
021c903
fix to exclude key-leaf data populating db-filed value and removed co…
s-mari Sep 11, 2019
359267c
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Sep 11, 2019
f2290f4
added unit8 yang data0type support for get-req
s-mari Sep 11, 2019
6ff960d
Fix crash for get leaf query
ranjinidn Sep 12, 2019
02b246d
cleanup code to showcase overloaded methods
kwangsuk Sep 12, 2019
3b2722c
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
kwangsuk Sep 12, 2019
cdb8731
fix the build error
redfish-api Sep 12, 2019
e8efc95
Fis get leaf crash, remove unsed annotations
ranjinidn Sep 12, 2019
71d0eeb
add get-validate to validate a YANG node durin data translation back …
redfish-api Sep 12, 2019
8d272a3
Fix crash during update request to leaflist
ranjinidn Sep 12, 2019
5bf7cc6
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
ranjinidn Sep 12, 2019
17787ff
Fix top level delete
ranjinidn Sep 13, 2019
e79b679
added yang annotations
s-mari Sep 13, 2019
1b5b715
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Sep 13, 2019
7acd5c8
Get case - leaf-list support in Transformer core for Sonic and OC yang.
amrutasali Sep 13, 2019
f569d66
add the field transformer for forwarding-action
kwangsuk Sep 13, 2019
237bc63
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
kwangsuk Sep 13, 2019
b7f3b33
Set case - leaf-list support in transformer core for OC yang
amrutasali Sep 13, 2019
f56a61e
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
amrutasali Sep 13, 2019
a3c4bbe
provision to get data for sibling container from the module level
s-mari Sep 13, 2019
30d7657
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Sep 13, 2019
fd1ca1a
Fixed variable scope issue while processing leaf data to redis DB
amrutasali Sep 14, 2019
2a6f718
Add validate callback function support for acl. Children will inherit…
ranjinidn Sep 18, 2019
3809d6f
move json creation for sonic-yang to map
s-mari Sep 18, 2019
d36eb73
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Sep 18, 2019
d50801c
error handling and code clean-up
s-mari Sep 18, 2019
b4ca046
Add error handling in xlate_utils.go
ranjinidn Sep 19, 2019
fdcdfc4
fix the uint64 encoding, fix the ygot bug in handling the union type of
kwangsuk Sep 19, 2019
9659b84
For a Get req on individual terminal node- Fix overloaded function pr…
amrutasali Sep 19, 2019
1ace0a0
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
amrutasali Sep 19, 2019
b6ebc29
table transformer support
s-mari Sep 19, 2019
7a722a2
Merge branch 'transformer-phase1' of https://github.com/project-arlo/…
s-mari Sep 19, 2019
b769aa9
Cleanup of unused code
ranjinidn Sep 19, 2019
2a6f01f
add the union type
kwangsuk Sep 20, 2019
428045f
sync from master into transformer-phase1 branch
s-mari Sep 20, 2019
feddf92
Add post transformer infra
ranjinidn Sep 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,26 @@ cp $(TOPDIR)/ygot-modified-files/schema.go $(BUILD_GOPATH)/src/github.com/openco
cp $(TOPDIR)/ygot-modified-files/unmarshal.go $(BUILD_GOPATH)/src/github.com/openconfig/ygot/ytypes/unmarshal.go; \
cp $(TOPDIR)/ygot-modified-files/validate.go $(BUILD_GOPATH)/src/github.com/openconfig/ygot/ytypes/validate.go; \
cp $(TOPDIR)/ygot-modified-files/reflect.go $(BUILD_GOPATH)/src/github.com/openconfig/ygot/ytypes/../util/reflect.go; \
$(GO) install -v -gcflags "-N -l" $(BUILD_GOPATH)/src/github.com/openconfig/ygot/ygot
cp $(TOPDIR)/goyang-modified-files/README.md $(BUILD_GOPATH)/src/github.com/openconfig/goyang/README.md; \
cp $(TOPDIR)/goyang-modified-files/yang.go $(BUILD_GOPATH)/src/github.com/openconfig/goyang/yang.go; \
cp $(TOPDIR)/goyang-modified-files/annotate.go $(BUILD_GOPATH)/src/github.com/openconfig/goyang/annotate.go; \
cp $(TOPDIR)/goyang-modified-files/entry.go $(BUILD_GOPATH)/src/github.com/openconfig/goyang/pkg/yang/entry.go; \
$(GO) install -v -gcflags "-N -l" $(BUILD_GOPATH)/src/github.com/openconfig/ygot/ygot; \
$(GO) install -v -gcflags "-N -l" $(BUILD_GOPATH)/src/github.com/openconfig/goyang

install:
$(INSTALL) -D $(REST_BIN) $(DESTDIR)/usr/sbin/rest_server
$(INSTALL) -D $(CERTGEN_BIN) $(DESTDIR)/usr/sbin/generate_cert
$(INSTALL) -d $(DESTDIR)/usr/sbin/schema/
$(INSTALL) -d $(DESTDIR)/usr/sbin/lib/
$(INSTALL) -d $(DESTDIR)/usr/models/yang/
$(INSTALL) -D $(TOPDIR)/src/cvl/schema/*.yin $(DESTDIR)/usr/sbin/schema/
$(INSTALL) -D $(TOPDIR)/src/cvl/testdata/schema/*.yin $(DESTDIR)/usr/sbin/schema/
$(INSTALL) -D $(TOPDIR)/src/cvl/schema/*.yang $(DESTDIR)/usr/models/yang/
$(INSTALL) -D $(TOPDIR)/models/yang/*.yang $(DESTDIR)/usr/models/yang/
$(INSTALL) -D $(TOPDIR)/config/transformer/models_list $(DESTDIR)/usr/models/yang/
$(INSTALL) -D $(TOPDIR)/models/yang/common/*.yang $(DESTDIR)/usr/models/yang/
$(INSTALL) -D $(TOPDIR)/models/yang/annotations/*.yang $(DESTDIR)/usr/models/yang/
cp -rf $(TOPDIR)/build/rest_server/dist/ui/ $(DESTDIR)/rest_ui/
cp -rf $(TOPDIR)/build/cli $(DESTDIR)/usr/sbin/
cp -rf $(TOPDIR)/build/swagger_client_py/ $(DESTDIR)/usr/sbin/lib/
Expand Down
4 changes: 4 additions & 0 deletions config/transformer/models_list
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#List yang models transformer need to load

openconfig-acl.yang
openconfig-acl-annot.yang
50 changes: 50 additions & 0 deletions goyang-modified-files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# goyang
YANG parser and compiler for Go programs.

The yang package (pkg/yang) is used to convert a YANG schema into either an
in memory abstract syntax trees (ast) or more fully resolved, in memory, "Entry"
trees. An Entry tree consists only of Entry structures and has had
augmentation, imports, and includes all applied.

goyang is a sample program that uses the yang (pkg/yang) package.

goyang uses the yang package to create an in-memory tree representation of
schemas defined in YANG and then dumps out the contents in several forms.
The forms include:

* tree - a simple tree representation
* types - list understood types extracted from the schema
* annotate - a template file to annotate the yang modules

The yang package, and the goyang program, are not complete and are a work in
progress.

For more complex output types, such as Go structs, and protobuf messages
please use the [openconfig/ygot](https://github.com/openconfig/ygot) package,
which uses this package as its backend.

### Getting started

To build goyang, ensure you have go language tools installed
(available at [golang.org](https://golang.org/dl)) and that the `GOPATH`
environment variable is set to your Go workspace.

1. `go get github.com/openconfig/goyang`
* This will download goyang code and dependencies into the src
subdirectory in your workspace.

2. `cd <workspace>/src/github.com/openconfig/goyang`

3. `go build`

* This will build the goyang binary and place it in the bin
subdirectory in your workspace.

### Contributing to goyang

goyang is still a work-in-progress and we welcome contributions. Please see
the `CONTRIBUTING` file for information about how to contribute to the codebase.

### Disclaimer

This is not an official Google product.
143 changes: 143 additions & 0 deletions goyang-modified-files/annotate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Copyright 2015 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"fmt"
"io"
"strings"

"github.com/openconfig/goyang/pkg/yang"
)

var allimports = make(map[string]string)
var modules = make(map[string]*yang.Module)

func init() {
register(&formatter{
name: "annotate",
f: genAnnotate,
utilf: getFile,
help: "generate template file for yang annotations",
})
}

// Get the modules for which annotation file needs to be generated
func getFile(files []string, mods map[string]*yang.Module) {
for _, name := range files {
slash := strings.Split(name, "/")
if strings.HasSuffix(name, ".yang") {
modname := slash[len(slash)-1]
modname = strings.TrimSuffix(modname, ".yang");
/* Save the yang.Module entries we are interested in */
modules[modname] = mods[modname]
}
}
}

func genAnnotate(w io.Writer, entries []*yang.Entry) {
/* Get all the imported modules in the entries */
GetAllImports(entries)
for _, e := range entries {
if _, ok := modules[e.Name]; ok {
var path string = ""
generate(w, e, path)
// { Add closing brace for each module
fmt.Fprintln(w, "}")
fmt.Fprintln(w)
}
}
}

// generate writes to stdoutput a template annotation file entry for the selected modules.
func generate(w io.Writer, e *yang.Entry, path string) {
if e.Parent == nil {
if e.Name != "" {
fmt.Fprintf(w, "module %s-annot {\n", e.Name) //}
fmt.Fprintln(w)
fmt.Fprintf(w, " yang-version \"%s\"\n", getYangVersion(e.Name, modules))
fmt.Fprintln(w)
fmt.Fprintf(w, " namespace \"http://openconfig.net/yang/annotation\";\n")
if e.Prefix != nil {
fmt.Fprintf(w, " prefix \"%s-annot\" \n", e.Prefix.Name)
}
fmt.Fprintln(w)

var imports = make(map[string]string)
imports = getImportModules(e.Name, modules)
for k := range imports {
if e.Name != k {
fmt.Fprintf(w, " import %s { prefix %s }\n", k, allimports[k])
}
}

fmt.Fprintln(w)
}
}

name := e.Name
if e.Prefix != nil {
name = e.Prefix.Name + ":" + name
}

delim := ""
if path != "" {
delim = "/"
}
path = path + delim + name

fmt.Fprintf(w, " deviation %s {\n", path)
fmt.Fprintf(w, " deviate add {\n")
fmt.Fprintf(w, " }\n")
fmt.Fprintf(w, " }\n")
fmt.Fprintln(w)

var names []string
for k := range e.Dir {
names = append(names, k)
}

for _, k := range names {
generate(w, e.Dir[k], path)
}

}

// Save to map all imported modules
func GetAllImports(entries []*yang.Entry) {
for _, e := range entries {
allimports[e.Name] = e.Prefix.Name
}
}

//Get Yang version from the yang.Modules
func getYangVersion(modname string, mods map[string]*yang.Module) string {
if (mods[modname].YangVersion != nil) {
return mods[modname].YangVersion.Name
}
return ""

}

// Get imported modules for a given module from yang.Module
func getImportModules(modname string, mods map[string]*yang.Module) map[string]string {
imports := map[string]string{}
if (mods[modname].Import != nil) {
for _, imp := range mods[modname].Import {
imports[imp.Name] = imp.Prefix.Name
}
}
return imports
}
Loading