Documentation
¶
Index ¶
- Constants
- func GNMIFieldGenerator(pathStructName, _ string, compressBehaviour genutil.CompressBehaviour, ...) (string, error)
- func GNMIGenerator(pathStructName, fakeRootName string, ...) (string, error)
- func GNMIGeneratorUncompressed(pathStructName, fakeRootName string, ...) (string, error)
- func GNMIInitGenerator(pathStructName, fakeRootName string, ...) (string, error)
- func GetOrderedNodeDataNames(nodeDataMap NodeDataMap) []string
- type CompressionInfo
- type ExtraGenerators
- type GenConfig
- type GeneratedPathCode
- type Generator
- type GoImports
- type GoPathStructCodeSnippet
- type NodeData
- type NodeDataMap
Constants ¶
const ( // WildcardSuffix is the suffix given to the wildcard versions of each // node as well as a list's wildcard child constructor methods that // distinguishes each from its non-wildcard counterpart. WildcardSuffix = "Any" // BuilderCtorSuffix is the suffix applied to the list builder // constructor method's name in order to indicate itself to the user. BuilderCtorSuffix = "Any" // WholeKeyedListSuffix is the suffix applied to a keyed list's // constructor method name in order to indicate itself to the user. WholeKeyedListSuffix = "Map" // BuilderKeyPrefix is the prefix applied to the key-modifying builder // method for a list PathStruct that uses the builder API. // NOTE: This cannot be "", as the builder method name would conflict // with the child constructor method for the keys. BuilderKeyPrefix = "With" )
Static default configuration values that differ from the zero value for their types.
Variables ¶
This section is empty.
Functions ¶
func GNMIFieldGenerator ¶ added in v0.8.2
func GNMIFieldGenerator(pathStructName, _ string, compressBehaviour genutil.CompressBehaviour, _ *ygen.ParsedDirectory, node *NodeData, wildcard bool) (string, error)
GNMIFieldGenerator generates an embedded query field for a PathStruct.
This is meant to be used for uncompressed generation, where there is no need to distinguish between config and state queries.
func GNMIGenerator ¶
func GNMIGenerator(pathStructName, fakeRootName string, compressBehaviour genutil.CompressBehaviour, dir *ygen.ParsedDirectory, node *NodeData, _ bool) (string, error)
GNMIGenerator is a plugin generator for generating ygnmi query objects for compressed structs.
- pathStructName is the name of the PathStruct of the node. - node contains information of the node. - dir is the containing directory of the node. For leaves this is the parent.
Note: GNMIGenerator requires that PreferOperationalState be true when generating PathStructs. TODO(DanG100): pass schema from parent to child.
func GNMIGeneratorUncompressed ¶ added in v0.8.2
func GNMIGeneratorUncompressed(pathStructName, fakeRootName string, compressBehaviour genutil.CompressBehaviour, dir *ygen.ParsedDirectory, node *NodeData, _ bool) (string, error)
GNMIGeneratorUncompressed is a plugin generator for generating ygnmi query objects for uncompressed structs.
func GNMIInitGenerator ¶ added in v0.8.2
func GNMIInitGenerator(pathStructName, fakeRootName string, compressBehaviour genutil.CompressBehaviour, _ *ygen.ParsedDirectory, node *NodeData, wildcard bool) (string, error)
GNMIInitGenerator generates the initialization for an embedded query field for a PathStruct.
This is meant to be used for uncompressed generation, where there is no need to distinguish between config and state queries.
func GetOrderedNodeDataNames ¶
func GetOrderedNodeDataNames(nodeDataMap NodeDataMap) []string
GetOrderedNodeDataNames returns the alphabetically-sorted slice of keys (path struct names) for a given NodeDataMap.
Types ¶
type CompressionInfo ¶ added in v0.8.0
type CompressionInfo struct {
// PreRelPath is the list of strings of qualified path elements prior
// to the compressed-out node in Go list syntax.
//
// e.g. "openconfig-withlistval:atomic-lists", "openconfig-withlistval:atomic-lists-again"
PreRelPathList string
// PreRelPath is the list of strings of qualified path elements after
// the compressed-out node in Go list syntax.
PostRelPathList string
}
CompressionInfo contains information about a compressed path element for a node which points to a path element that's compressed out.
e.g. for OpenConfig's /interfaces/interface, if a path points to /interfaces, then CompressionInfo will be populated with the following: - PreRelPath: []{"openconfig-interfaces:interfaces"} - PostRelPath: []{"openconfig-interfaces:interface"}
type ExtraGenerators ¶ added in v0.8.2
type ExtraGenerators struct {
// StructFields are extra PathStruct fields to be generated.
StructFields []Generator
// StructInits are extra PathStruct initializers to be generated when
// the PathStruct is created.
StructInits []Generator
// Extras are other free-form extra generated code to accompany a
// particular PathStruct.
Extras []Generator
}
ExtraGenerators is the set of all generators for a generation invocation.
type GenConfig ¶
type GenConfig struct {
// CompressBehaviour determines whether the direct children of some
// entries are omitted in the generated code for brevity. It also uses
// a shortened naming convention for type names, including
// enumeration/identityref names.
//
// Compress options are recommended when using OpenConfig-styled YANG,
// and Uncompress* options otherwise.
CompressBehaviour genutil.CompressBehaviour
// PackageName is the name that should be used for the generating package.
PackageName string
// GoImports contains package import options.
GoImports GoImports
// ParseOptions specifies the options for how the YANG schema is
// produced.
ParseOptions ygen.ParseOpts
// FakeRootName specifies the name of the struct that should be generated
// representing the root.
FakeRootName string
// PathStructSuffix is the suffix to be appended to generated
// PathStructs to distinguish them from the generated GoStructs, which
// assume a similar name.
PathStructSuffix string
// SkipEnumDeduplication specifies whether leaves of type 'enumeration' that
// are used in multiple places in the schema should share a common type within
// the generated code that is output by ygen. By default (false), a common type
// is used.
// This is the same flag used by ygen: they must match for pathgen's
// generated code to be compatible with it.
SkipEnumDeduplication bool
// ShortenEnumLeafNames removes the module name from the name of
// enumeration leaves.
// This is the same flag used by ygen: they must match for pathgen's
// generated code to be compatible with it.
ShortenEnumLeafNames bool
// EnumOrgPrefixesToTrim trims the organization name from the module
// part of the name of enumeration leaves if there is a match.
EnumOrgPrefixesToTrim []string
// UseDefiningModuleForTypedefEnumNames uses the defining module name
// to prefix typedef enumerated types instead of the module where the
// typedef enumerated value is used.
// This is the same flag used by ygen: they must match for pathgen's
// generated code to be compatible with it.
UseDefiningModuleForTypedefEnumNames bool
// AppendEnumSuffixForSimpleUnionEnums appends an "Enum" suffix to the
// enumeration name for simple (i.e. non-typedef) leaves which are
// unions with an enumeration inside. This makes all inlined
// enumerations within unions, whether typedef or not, have this
// suffix, achieving consistency. Since this flag is planned to be a
// v1 compatibility flag along with
// UseDefiningModuleForTypedefEnumNames, and will be removed in v1, it
// only applies when useDefiningModuleForTypedefEnumNames is also set
// to true.
AppendEnumSuffixForSimpleUnionEnums bool
// GeneratingBinary is the name of the binary calling the generator library, it is
// included in the header of output files for debugging purposes. If a
// string is not specified, the location of the library is utilised.
GeneratingBinary string
// GenerateWildcardPaths means to generate wildcard nodes and paths.
GenerateWildcardPaths bool
// SplitByModule controls whether to generate a go package for each yang module.
SplitByModule bool
// TrimPackageModulePrefix is the prefix to trim from generated go package names.
TrimPackageModulePrefix string
// BasePackagePath is used to create to full import path of the generated go packages.
BasePackagePath string
// PackageString is the string to apppend to the generated Go package names.
PackageSuffix string
// UnifyPathStructs controls whether to generate both config and states in the same package.
UnifyPathStructs bool
// ExtraGenerators are custom funcs that are used to extend the path struct generation.
ExtraGenerators ExtraGenerators
// IgnoreAtomicLists disables the following default behaviours:
// - All compressed lists will have a new accessor <ListName>Map() that
// retrieves the whole list.
// - Any child underneath lists whose compressed-out parent container
// is marked "telemetry-atomic" are no longer reachable.
// - lists marked `ordered-by user` will be represented using built-in Go maps
// instead of an ordered map Go structure.
IgnoreAtomicLists bool
// IgnoreAtomic avoids generating any descendants where a
// non-compressed-out list or container is marked "telemetry-atomic".
IgnoreAtomic bool
// SplitPackagePaths specifies the prefix paths at or below which symbols will
// reside in the provided package. The mapped string is the custom name for
// the package (optional).
SplitPackagePaths map[string]string
//UseModuleNameAsPathOrigin uses the YANG module name to the origin for generated gNMI paths.
UseModuleNameAsPathOrigin bool
//PathOriginName specifies the origin name for generated gNMI paths.
PathOriginName string
}
GenConfig stores code generation configuration.
func NewDefaultConfig ¶
NewDefaultConfig creates a GenConfig with default configuration. schemaStructPkgPath is a required configuration parameter. It should be set to "" when the generated PathStruct package is to be the same package as the GoStructs package.
func (*GenConfig) GeneratePathCode ¶
func (cg *GenConfig) GeneratePathCode(yangFiles, includePaths []string) (map[string]*GeneratedPathCode, NodeDataMap, util.Errors)
GeneratePathCode takes a slice of strings containing the path to a set of YANG files which contain YANG modules, and a second slice of strings which specifies the set of paths that are to be searched for associated models (e.g., modules that are included by the specified set of modules, or submodules of those modules). It extracts the set of modules that are to be generated, and returns a map of package names to GeneratedPathCode structs. Each struct contains all the generated code of that package needed support the path-creation API. The important components of the generated code are listed below:
- Struct definitions for each container, list, or leaf schema node, as well as the fakeroot.
- Next-level methods for the fakeroot and each non-leaf schema node, which instantiate and return the next-level structs corresponding to its child schema nodes.
With these components, the generated API is able to support absolute path creation of any node of the input schema. Also returned is the NodeDataMap of the schema, i.e. information about each node in the generated code, which may help callers add customized augmentations to the basic generated path code. If errors are encountered during code generation, they are returned.
type GeneratedPathCode ¶
type GeneratedPathCode struct {
Structs []GoPathStructCodeSnippet // Structs is the generated set of structs representing containers or lists in the input YANG models.
CommonHeader string // CommonHeader is the header that should be used for all output Go files.
Deps map[string]bool // Deps is the list of packages that this package depends on.
}
GeneratedPathCode contains generated code snippets that can be processed by the calling application. The generated code is divided into two types of objects - both represented as a slice of strings: Structs contains a set of Go structures that have been generated, and Enums contains the code for generated enumerated types (corresponding to identities, or enumerated values within the YANG models for which code is being generated). Additionally the header with package comment of the generated code is returned in Header, along with the a slice of strings containing the packages that are required for the generated Go code to be compiled is returned.
For schemas that contain enumerated types (identities, or enumerations), a code snippet is returned as the EnumMap field that allows the string values from the YANG schema to be resolved. The keys of the map are strings corresponding to the name of the generated type, with the map values being maps of the int64 identifier for each value of the enumeration to the name of the element, as used in the YANG schema.
func (GeneratedPathCode) SplitFiles ¶
func (genCode GeneratedPathCode) SplitFiles(fileN int) ([]string, error)
SplitFiles returns a slice of strings, each representing a file that together contains the entire generated code. fileN specifies the number of files to split the code into, and has to be between 1 and the total number of directory entries in the input schema. By splitting, the size of the output files can be roughly controlled.
func (GeneratedPathCode) String ¶
func (genCode GeneratedPathCode) String() string
String method for GeneratedPathCode, which can be used to write all the generated code into a single file.
type Generator ¶
type Generator func(string, string, genutil.CompressBehaviour, *ygen.ParsedDirectory, *NodeData, bool) (string, error)
Generator is func to returns extra generated code for a given node.
type GoImports ¶
type GoImports struct {
// SchemaStructPkgPath specifies the path to the ygen-generated structs, which
// is used to get the enum and union type names used as the list key
// for calling a list path accessor.
SchemaStructPkgPath string
// YgotImportPath specifies the path to the ygot library that should be used
// in the generated code.
YgotImportPath string
// YtypesImportPath specifies the path to the ytypes library that should be used
// in the generated code.
YtypesImportPath string
// YgnmiImportPath is the import path to the ygnmi library that should be used
// in the generated code.
YgnmiImportPath string
}
GoImports contains package import options.
type GoPathStructCodeSnippet ¶
type GoPathStructCodeSnippet struct {
// PathStructName is the name of the struct that is contained within the snippet.
// It is stored such that callers can identify the struct to control where it
// is output.
PathStructName string
// StructBase stores the basic code snippet that represents the struct that is
// the input when code generation is performed, which includes its definition.
StructBase string
// ChildConstructors contains the method code snippets with the input struct as a
// receiver, that is used to get the child path struct.
ChildConstructors string
// Package is the name of the package that this snippet belongs to.
Package string
// Deps are any packages that this snippet depends on.
Deps []string
// ExtraGeneration is the output of any extra generators passed into GenConfig.
ExtraGeneration string
}
GoPathStructCodeSnippet is used to store the generated code snippets associated with a particular Go struct entity (corresponding to a container, list, or leaf in the schema).
func (*GoPathStructCodeSnippet) String ¶
func (g *GoPathStructCodeSnippet) String() string
String returns the contents of a GoPathStructCodeSnippet as a string by simply writing out all of its generated code.
type NodeData ¶
type NodeData struct {
// GoTypeName is the generated Go type name of a schema node. It is
// qualified by the SchemaStructPkgAlias if necessary. It could be a
// GoStruct or a leaf type.
GoTypeName string
// LocalGoTypeName is the generated Go type name of a schema node, but
// always with the SchemaStructPkgAlias stripped. It could be a
// GoStruct or a leaf type.
LocalGoTypeName string
// GoFieldName is the field name of the node under its parent struct.
GoFieldName string
// SubsumingGoStructName is the GoStruct type name corresponding to the node. If
// the node is a leaf, then it is the parent GoStruct's name.
SubsumingGoStructName string
// IsLeaf indicates whether this child is a leaf node.
IsLeaf bool
// IsScalarField indicates a leaf that is stored as a pointer in its
// parent struct.
IsScalarField bool
// IsListContainer indicates that the node represents the container
// surrounding a list.
IsListContainer bool
// HasDefault indicates whether this node has a default value
// associated with it. This is only relevant to leaf or leaf-list
// nodes.
HasDefault bool
// YANGTypeName is the type of the leaf given in the YANG file (without
// the module prefix, if any, per goyang behaviour). If the node is not
// a leaf this will be empty. Note that the current purpose for this is
// to allow callers to handle certain types as special cases, but since
// the name of the node is a very basic piece of information which
// excludes the defining module, this is somewhat hacky, so it may be
// removed or modified in the future.
YANGTypeName string
// YANGPath is the schema path of the YANG node.
YANGPath string
// GoPathPackageName is the Go package name containing the generated PathStruct for the schema node.
GoPathPackageName string
// YANGFieldName is the name of the field entry for this node, only set for leaves.
YANGFieldName string
// Directory is the name of the directory used to create this node. For leaves, it's the parent directory.
DirectoryName string
// CompressInfo contains information about a compressed path element for a node
// which points to a path element that's compressed out.
CompressInfo *CompressionInfo
// ConfigFalse indicates whether the node is "config false" or "config
// true" in its YANG schema definition.
ConfigFalse bool
// PathOriginName is the name of the origin for this node.
PathOriginName string
}
NodeData contains information about the ygen-generated code of a YANG schema node.
type NodeDataMap ¶
NodeDataMap is a map from the path struct type name of a schema node to its NodeData.