@@ -61,6 +61,7 @@ type Client interface {
6161 Patch (ctx context.Context , conf ... Configurable ) error
6262 Update (ctx context.Context , conf ... Configurable ) error
6363 Delete (ctx context.Context , conf ... Configurable ) error
64+ Create (ctx context.Context , conf ... Configurable ) error
6465}
6566
6667// Client is a gNMI client offering convenience methods for device configuration
@@ -143,14 +144,18 @@ func (c *client) GetState(ctx context.Context, conf ...Configurable) error {
143144// If the current configuration equals the desired configuration, the operation is skipped.
144145// For partial updates that merge changes, use [Client.Patch] instead.
145146func (c * client ) Update (ctx context.Context , conf ... Configurable ) error {
146- return c .set (ctx , false , conf ... )
147+ return c .set (ctx , false , true , conf ... )
147148}
148149
149150// Patch merges the configuration for the given set of items.
150151// If the current configuration equals the desired configuration, the operation is skipped.
151152// For full replacement of configuration, use [Client.Update] instead.
152153func (c * client ) Patch (ctx context.Context , conf ... Configurable ) error {
153- return c .set (ctx , true , conf ... )
154+ return c .set (ctx , true , true , conf ... )
155+ }
156+
157+ func (c * client ) Create (ctx context.Context , conf ... Configurable ) error {
158+ return c .set (ctx , false , false , conf ... )
154159}
155160
156161// Delete resets the configuration for the given set of items.
@@ -256,7 +261,7 @@ func (c *client) get(ctx context.Context, dt gpb.GetRequest_DataType, conf ...Co
256261// configuration. Otherwise, a full replacement is done.
257262// If the current configuration equals the desired configuration, the operation
258263// is skipped.
259- func (c * client ) set (ctx context.Context , patch bool , conf ... Configurable ) error {
264+ func (c * client ) set (ctx context.Context , patch bool , retrieve bool , conf ... Configurable ) error {
260265 if len (conf ) == 0 {
261266 return nil
262267 }
@@ -267,16 +272,20 @@ func (c *client) set(ctx context.Context, patch bool, conf ...Configurable) erro
267272 return err
268273 }
269274 got := cp .Deep (cf )
270- err = c .GetConfig (ctx , got )
271- if err != nil && ! errors .Is (err , ErrNil ) {
272- return fmt .Errorf ("gnmiext: failed to retrieve current config for %s: %w" , cf .XPath (), err )
273- }
274- // If the current configuration is equal to the desired configuration, skip the update.
275- // This avoids unnecessary updates and potential disruptions.
276- if err == nil && reflect .DeepEqual (cf , got ) {
277- c .logger .V (1 ).Info ("Configuration is already up-to-date" , "path" , cf .XPath ())
278- continue
275+
276+ if retrieve {
277+ err = c .GetConfig (ctx , got )
278+ if err != nil && ! errors .Is (err , ErrNil ) {
279+ return fmt .Errorf ("gnmiext: failed to retrieve current config for %s: %w" , cf .XPath (), err )
280+ }
281+ // If the current configuration is equal to the desired configuration, skip the update.
282+ // This avoids unnecessary updates and potential disruptions.
283+ if err == nil && reflect .DeepEqual (cf , got ) {
284+ c .logger .V (1 ).Info ("Configuration is already up-to-date" , "path" , cf .XPath ())
285+ continue
286+ }
279287 }
288+
280289 b , err := c .Marshal (cf )
281290 if err != nil {
282291 return err
0 commit comments