@@ -63,6 +63,7 @@ type Client interface {
6363 Patch (ctx context.Context , conf ... Configurable ) error
6464 Update (ctx context.Context , conf ... Configurable ) error
6565 Delete (ctx context.Context , conf ... Configurable ) error
66+ Create (ctx context.Context , conf ... Configurable ) error
6667}
6768
6869// Client is a gNMI client offering convenience methods for device configuration
@@ -148,14 +149,18 @@ func (c *client) GetState(ctx context.Context, conf ...Configurable) error {
148149// If the current configuration equals the desired configuration, the operation is skipped.
149150// For partial updates that merge changes, use [Client.Patch] instead.
150151func (c * client ) Update (ctx context.Context , conf ... Configurable ) error {
151- return c .set (ctx , false , conf ... )
152+ return c .set (ctx , false , true , conf ... )
152153}
153154
154155// Patch merges the configuration for the given set of items.
155156// If the current configuration equals the desired configuration, the operation is skipped.
156157// For full replacement of configuration, use [Client.Update] instead.
157158func (c * client ) Patch (ctx context.Context , conf ... Configurable ) error {
158- return c .set (ctx , true , conf ... )
159+ return c .set (ctx , true , true , conf ... )
160+ }
161+
162+ func (c * client ) Create (ctx context.Context , conf ... Configurable ) error {
163+ return c .set (ctx , false , false , conf ... )
159164}
160165
161166// Delete resets the configuration for the given set of items.
@@ -261,7 +266,7 @@ func (c *client) get(ctx context.Context, dt gpb.GetRequest_DataType, conf ...Co
261266// configuration. Otherwise, a full replacement is done.
262267// If the current configuration equals the desired configuration, the operation
263268// is skipped.
264- func (c * client ) set (ctx context.Context , patch bool , conf ... Configurable ) error {
269+ func (c * client ) set (ctx context.Context , patch bool , retrieve bool , conf ... Configurable ) error {
265270 if len (conf ) == 0 {
266271 return nil
267272 }
@@ -272,16 +277,20 @@ func (c *client) set(ctx context.Context, patch bool, conf ...Configurable) erro
272277 return err
273278 }
274279 got := cp .Deep (cf )
275- err = c .GetConfig (ctx , got )
276- if err != nil && ! errors .Is (err , ErrNil ) {
277- return fmt .Errorf ("gnmiext: failed to retrieve current config for %s: %w" , cf .XPath (), err )
278- }
279- // If the current configuration is equal to the desired configuration, skip the update.
280- // This avoids unnecessary updates and potential disruptions.
281- if err == nil && reflect .DeepEqual (cf , got ) {
282- c .logger .V (1 ).Info ("Configuration is already up-to-date" , "path" , cf .XPath ())
283- continue
280+
281+ if retrieve {
282+ err = c .GetConfig (ctx , got )
283+ if err != nil && ! errors .Is (err , ErrNil ) {
284+ return fmt .Errorf ("gnmiext: failed to retrieve current config for %s: %w" , cf .XPath (), err )
285+ }
286+ // If the current configuration is equal to the desired configuration, skip the update.
287+ // This avoids unnecessary updates and potential disruptions.
288+ if err == nil && reflect .DeepEqual (cf , got ) {
289+ c .logger .V (1 ).Info ("Configuration is already up-to-date" , "path" , cf .XPath ())
290+ continue
291+ }
284292 }
293+
285294 b , err := c .Marshal (cf )
286295 if err != nil {
287296 return err
0 commit comments