diff --git a/resource-manager/operationalinsights/2020-08-01/clusters/README.md b/resource-manager/operationalinsights/2020-08-01/clusters/README.md index 93ed14342a4..0ede8797baf 100644 --- a/resource-manager/operationalinsights/2020-08-01/clusters/README.md +++ b/resource-manager/operationalinsights/2020-08-01/clusters/README.md @@ -111,11 +111,7 @@ payload := clusters.ClusterPatch{ } -read, err := client.Update(ctx, id, payload) -if err != nil { +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { // handle the error } -if model := read.Model; model != nil { - // do something with the model/response object -} ``` diff --git a/resource-manager/operationalinsights/2020-08-01/clusters/method_update.go b/resource-manager/operationalinsights/2020-08-01/clusters/method_update.go index 80edce4b64f..55fe3507602 100644 --- a/resource-manager/operationalinsights/2020-08-01/clusters/method_update.go +++ b/resource-manager/operationalinsights/2020-08-01/clusters/method_update.go @@ -2,9 +2,12 @@ package clusters import ( "context" + "fmt" "net/http" "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" "github.com/hashicorp/go-azure-sdk/sdk/odata" ) @@ -12,6 +15,7 @@ import ( // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type UpdateOperationResponse struct { + Poller pollers.Poller HttpResponse *http.Response OData *odata.OData Model *Cluster @@ -22,6 +26,7 @@ func (c ClustersClient) Update(ctx context.Context, id ClusterId, input ClusterP opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ + http.StatusAccepted, http.StatusOK, }, HttpMethod: http.MethodPatch, @@ -47,12 +52,24 @@ func (c ClustersClient) Update(ctx context.Context, id ClusterId, input ClusterP return } - var model Cluster - result.Model = &model - - if err = resp.Unmarshal(result.Model); err != nil { + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { return } return } + +// UpdateThenPoll performs Update then polls until it's completed +func (c ClustersClient) UpdateThenPoll(ctx context.Context, id ClusterId, input ClusterPatch) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +}