Open mjoshiNetElastic opened 6 years ago
Hi,
Could you clarify the question a little bit please? At the moment, we do not store the YANG module's namespace
statement in the tags for struct fields - we do store the module's name since this is required for rendering to JSON).
I'm not sure what the XMLName xml.name
field is - do you have a reference?
If you are planning to expand ygot
to marshal and unmarshal to and from XML, then I'm happy to discuss how the design for this might look. I think that it would need a few steps:
namespace
for each struct field needs to be stored somewhere, this could either be in the compressed JSON schema (preferable), or as struct tags.ygot/render.go
to handle a GoStruct
and return the relevant XML.ytypes
to handle XML input.Thanks, r.
Hi Rob, what I am trying to get at here is to be able to use the generated go structs as a base for for constructing xml marshal calls so as to generate netconf edit-config requests.
type editConfig struct { XMLName xml.Name
xml:"edit-config" Target string
xml:"target" Config interface{} } type Config struct { XMLName xml.Name
xml:"config"`
Config interface{}
}
type IETFRouting_Router struct {
XMLName xml.Name xml:"urn:ietf:params:xml:ns:yang:ietf-routing router"
Config interface{}
}`
Need this -
**// IETFRouting_Router_Bgp represents the /ietf-routing/router/bgp YANG schema element. type IETFRouting_Router_Bgp struct { _XMLName xml.Name
xml:"bgp-config bgp"_ LocalAs uint32
xml:"local-as" }**
generated by ygot:
**// IETFRouting_Router_Bgp represents the /ietf-routing/router/bgp YANG schema element. type IETFRouting_Router_Bgp struct { LocalAs *uint32
path:"local-as" module:"bgp-config"`
}**
bgp := &IETFRouting_Router_Bgp{LocalAs: 1233}
rtr := IETFRouting_Router{Config: bgp}
ed := &editConfig{Target: "
the end result is to generate a xml string looking like this:
`
<config>
<router xmlns="urn:ietf:params:xml:ns:yang:ietf-routing">
<bgp xmlns="bgp-config">
<local-as>888</local-as>
</bgp>
</router>
</config>
</edit-config>`
This isn't something that is implemented today in ygot. The current recommended approach to get data instances to a device is to use RFC7951 JSON (a number of platforms already support this, and I believe that they do this via NETCONF, although we'd encourage you to look at gNMI).
Alternatively, a marshalling approach needs to be written for XML. You could look at how the JSON marshalling is done in ygot/render.go to give a view as to how to this -- since the layout of the structs will need some wrangling to serialise to XML, and can't just be done directly. As a part of this implementation, you'd need to look into the way to have the namespace available as per my previous comment.
Hi, Is there any way I can generate xml namespace tags and XMLName xml.name field as a part of the auto-generated go structs?
Thanks.