Skip to content

Commit

Permalink
Merge pull request #136 from openconfig/allow-prefer-config
Browse files Browse the repository at this point in the history
Allow prefer config
  • Loading branch information
wenovus authored Nov 9, 2023
2 parents 975fbce + 99b05c1 commit af2a64f
Show file tree
Hide file tree
Showing 41 changed files with 15,471 additions and 415 deletions.
20 changes: 11 additions & 9 deletions app/ygnmi/cmd/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func New() *cobra.Command {
generator.Flags().String("fakeroot_name", "root", "Change the name of the ygot-generated fake root entity (ygot's default is \"device\").")
generator.Flags().Bool("shorten_enum_leaf_names", true, "If also set to true when compress_paths=true, all leaves of type enumeration will by default not be prefixed with the name of its residing module.")
generator.Flags().Bool("annotations", false, "If set to true, metadata annotations are added within the ygot-generated structs.")
generator.Flags().Bool("prefer_operational_state", true, "If set to true, state (config false) fields in the YANG schema are preferred over intended config leaves in the generated Go code with compressed schema paths. This flag is only valid for compress_paths=true.")

// TODO(wenovus): Delete these hidden flags before or on v1 release.
generator.Flags().Bool("typedef_enum_with_defmod", true, "If set to true, all typedefs of type enumeration or identity will be prefixed with the name of its module of definition instead of its residing module.")
Expand Down Expand Up @@ -110,7 +111,13 @@ func generate(cmd *cobra.Command, args []string) error {
}
compressBehaviour := genutil.Uncompressed
if viper.GetBool("compress_paths") {
compressBehaviour = genutil.PreferOperationalState
if viper.GetBool("prefer_operational_state") {
compressBehaviour = genutil.PreferOperationalState
} else {
compressBehaviour = genutil.PreferIntendedConfig
}
}
if compressBehaviour.CompressEnabled() {
extraGenerators = pathgen.ExtraGenerators{
Extras: []pathgen.Generator{pathgen.GNMIGenerator},
}
Expand Down Expand Up @@ -204,15 +211,10 @@ func generate(cmd *cobra.Command, args []string) error {
}
}

return generateStructs(args, schemaStructPath, version, fakeRootName)
return generateStructs(args, schemaStructPath, version, fakeRootName, compressBehaviour)
}

func generateStructs(modules []string, schemaPath, version, fakeRootName string) error {
cmp := genutil.Uncompressed
if viper.GetBool("compress_paths") {
cmp = genutil.PreferOperationalState
}

func generateStructs(modules []string, schemaPath, version, fakeRootName string, compressBehaviour genutil.CompressBehaviour) error {
// Perform the code generation.
cg := gogen.New(
version,
Expand All @@ -228,7 +230,7 @@ func generateStructs(modules []string, schemaPath, version, fakeRootName string)
},
},
TransformationOptions: ygen.TransformationOpts{
CompressBehaviour: cmp,
CompressBehaviour: compressBehaviour,
SkipEnumDeduplication: false,
GenerateFakeRoot: true,
FakeRootName: fakeRootName,
Expand Down
28 changes: 28 additions & 0 deletions exampleoc/a/a-0.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (n *Model_SingleKey_CounterPath) State() ygnmi.SingletonQuery[float32] {
return ygnmi.NewSingletonQuery[float32](
"Model_SingleKey",
true,
false,
true,
false,
true,
Expand Down Expand Up @@ -93,6 +94,7 @@ func (n *Model_SingleKey_CounterPathAny) State() ygnmi.WildcardQuery[float32] {
return ygnmi.NewWildcardQuery[float32](
"Model_SingleKey",
true,
false,
true,
false,
true,
Expand Down Expand Up @@ -141,6 +143,7 @@ func (n *Model_SingleKey_CountersPath) State() ygnmi.SingletonQuery[[]float32] {
return ygnmi.NewSingletonQuery[[]float32](
"Model_SingleKey",
true,
false,
true,
false,
true,
Expand Down Expand Up @@ -177,6 +180,7 @@ func (n *Model_SingleKey_CountersPathAny) State() ygnmi.WildcardQuery[[]float32]
return ygnmi.NewWildcardQuery[[]float32](
"Model_SingleKey",
true,
false,
true,
false,
true,
Expand Down Expand Up @@ -225,6 +229,7 @@ func (n *Model_SingleKey_KeyPath) State() ygnmi.SingletonQuery[string] {
return ygnmi.NewSingletonQuery[string](
"Model_SingleKey",
true,
false,
true,
true,
true,
Expand Down Expand Up @@ -265,6 +270,7 @@ func (n *Model_SingleKey_KeyPathAny) State() ygnmi.WildcardQuery[string] {
return ygnmi.NewWildcardQuery[string](
"Model_SingleKey",
true,
false,
true,
true,
true,
Expand Down Expand Up @@ -308,6 +314,7 @@ func (n *Model_SingleKey_KeyPath) Config() ygnmi.ConfigQuery[string] {
true,
true,
true,
true,
false,
ygnmi.NewNodePath(
[]string{"config", "key"},
Expand Down Expand Up @@ -348,6 +355,7 @@ func (n *Model_SingleKey_KeyPathAny) Config() ygnmi.WildcardQuery[string] {
true,
true,
true,
true,
false,
ygnmi.NewNodePath(
[]string{"config", "key"},
Expand Down Expand Up @@ -397,6 +405,7 @@ func (n *Model_SingleKey_ValuePath) State() ygnmi.SingletonQuery[int64] {
return ygnmi.NewSingletonQuery[int64](
"Model_SingleKey",
true,
false,
true,
true,
true,
Expand Down Expand Up @@ -437,6 +446,7 @@ func (n *Model_SingleKey_ValuePathAny) State() ygnmi.WildcardQuery[int64] {
return ygnmi.NewWildcardQuery[int64](
"Model_SingleKey",
true,
false,
true,
true,
true,
Expand Down Expand Up @@ -480,6 +490,7 @@ func (n *Model_SingleKey_ValuePath) Config() ygnmi.ConfigQuery[int64] {
true,
true,
true,
true,
false,
ygnmi.NewNodePath(
[]string{"config", "value"},
Expand Down Expand Up @@ -520,6 +531,7 @@ func (n *Model_SingleKey_ValuePathAny) Config() ygnmi.WildcardQuery[int64] {
true,
true,
true,
true,
false,
ygnmi.NewNodePath(
[]string{"config", "value"},
Expand Down Expand Up @@ -794,6 +806,7 @@ func (n *Model_SingleKeyPath) State() ygnmi.SingletonQuery[*oc.Model_SingleKey]
true,
false,
false,
false,
true,
false,
n,
Expand All @@ -818,6 +831,7 @@ func (n *Model_SingleKeyPathAny) State() ygnmi.WildcardQuery[*oc.Model_SingleKey
true,
false,
false,
false,
true,
false,
n,
Expand All @@ -840,6 +854,7 @@ func (n *Model_SingleKeyPath) Config() ygnmi.ConfigQuery[*oc.Model_SingleKey] {
return ygnmi.NewConfigQuery[*oc.Model_SingleKey](
"Model_SingleKey",
false,
true,
false,
false,
true,
Expand All @@ -864,6 +879,7 @@ func (n *Model_SingleKeyPathAny) Config() ygnmi.WildcardQuery[*oc.Model_SingleKe
return ygnmi.NewWildcardQuery[*oc.Model_SingleKey](
"Model_SingleKey",
false,
true,
false,
false,
true,
Expand All @@ -890,6 +906,7 @@ func (n *Model_SingleKeyPathMap) State() ygnmi.SingletonQuery[map[string]*oc.Mod
true,
false,
false,
false,
true,
true,
n,
Expand Down Expand Up @@ -920,6 +937,7 @@ func (n *Model_SingleKeyPathMapAny) State() ygnmi.WildcardQuery[map[string]*oc.M
true,
false,
false,
false,
true,
true,
n,
Expand Down Expand Up @@ -948,6 +966,7 @@ func (n *Model_SingleKeyPathMap) Config() ygnmi.ConfigQuery[map[string]*oc.Model
return ygnmi.NewConfigQuery[map[string]*oc.Model_SingleKey](
"Model",
false,
true,
false,
false,
true,
Expand Down Expand Up @@ -978,6 +997,7 @@ func (n *Model_SingleKeyPathMapAny) Config() ygnmi.WildcardQuery[map[string]*oc.
return ygnmi.NewWildcardQuery[map[string]*oc.Model_SingleKey](
"Model",
false,
true,
false,
false,
true,
Expand Down Expand Up @@ -1030,6 +1050,7 @@ func (n *Model_SingleKey_OrderedListPathMap) State() ygnmi.SingletonQuery[*oc.Mo
true,
false,
false,
false,
true,
true,
n,
Expand Down Expand Up @@ -1060,6 +1081,7 @@ func (n *Model_SingleKey_OrderedListPathMapAny) State() ygnmi.WildcardQuery[*oc.
true,
false,
false,
false,
true,
true,
n,
Expand Down Expand Up @@ -1088,6 +1110,7 @@ func (n *Model_SingleKey_OrderedListPathMap) Config() ygnmi.ConfigQuery[*oc.Mode
return ygnmi.NewConfigQuery[*oc.Model_SingleKey_OrderedList_OrderedMap](
"Model_SingleKey",
false,
true,
false,
false,
true,
Expand Down Expand Up @@ -1118,6 +1141,7 @@ func (n *Model_SingleKey_OrderedListPathMapAny) Config() ygnmi.WildcardQuery[*oc
return ygnmi.NewWildcardQuery[*oc.Model_SingleKey_OrderedList_OrderedMap](
"Model_SingleKey",
false,
true,
false,
false,
true,
Expand Down Expand Up @@ -1170,6 +1194,7 @@ func (n *Model_SingleKey_SingleKeyPathMap) State() ygnmi.SingletonQuery[map[stri
true,
false,
false,
false,
true,
true,
n,
Expand Down Expand Up @@ -1200,6 +1225,7 @@ func (n *Model_SingleKey_SingleKeyPathMapAny) State() ygnmi.WildcardQuery[map[st
true,
false,
false,
false,
true,
true,
n,
Expand Down Expand Up @@ -1228,6 +1254,7 @@ func (n *Model_SingleKey_SingleKeyPathMap) Config() ygnmi.ConfigQuery[map[string
return ygnmi.NewConfigQuery[map[string]*oc.Model_SingleKey_SingleKey](
"Model_SingleKey",
false,
true,
false,
false,
true,
Expand Down Expand Up @@ -1258,6 +1285,7 @@ func (n *Model_SingleKey_SingleKeyPathMapAny) Config() ygnmi.WildcardQuery[map[s
return ygnmi.NewWildcardQuery[map[string]*oc.Model_SingleKey_SingleKey](
"Model_SingleKey",
false,
true,
false,
false,
true,
Expand Down
Loading

0 comments on commit af2a64f

Please sign in to comment.