diff --git a/profiles/preview/containerservice/mgmt/containerservice/models.go b/profiles/preview/containerservice/mgmt/containerservice/models.go index 9829e5f87d25..12747e0d2930 100644 --- a/profiles/preview/containerservice/mgmt/containerservice/models.go +++ b/profiles/preview/containerservice/mgmt/containerservice/models.go @@ -268,6 +268,7 @@ type ManagedClusterPoolUpgradeProfile = original.ManagedClusterPoolUpgradeProfil type ManagedClusterProperties = original.ManagedClusterProperties type ManagedClustersCreateOrUpdateFuture = original.ManagedClustersCreateOrUpdateFuture type ManagedClustersDeleteFuture = original.ManagedClustersDeleteFuture +type ManagedClustersUpdateTagsFuture = original.ManagedClustersUpdateTagsFuture type ManagedClusterUpgradeProfile = original.ManagedClusterUpgradeProfile type ManagedClusterUpgradeProfileProperties = original.ManagedClusterUpgradeProfileProperties type MasterProfile = original.MasterProfile @@ -285,6 +286,7 @@ type Resource = original.Resource type ServicePrincipalProfile = original.ServicePrincipalProfile type SSHConfiguration = original.SSHConfiguration type SSHPublicKey = original.SSHPublicKey +type TagsObject = original.TagsObject type VMDiagnostics = original.VMDiagnostics type WindowsProfile = original.WindowsProfile type OperationsClient = original.OperationsClient diff --git a/services/containerservice/mgmt/2018-03-31/containerservice/managedclusters.go b/services/containerservice/mgmt/2018-03-31/containerservice/managedclusters.go index 753471bfbf24..da59cf33e70f 100644 --- a/services/containerservice/mgmt/2018-03-31/containerservice/managedclusters.go +++ b/services/containerservice/mgmt/2018-03-31/containerservice/managedclusters.go @@ -609,3 +609,77 @@ func (client ManagedClustersClient) ListByResourceGroupComplete(ctx context.Cont result.page, err = client.ListByResourceGroup(ctx, resourceGroupName) return } + +// UpdateTags updates a managed cluster with the specified tags. +// Parameters: +// resourceGroupName - the name of the resource group. +// resourceName - the name of the managed cluster resource. +// parameters - parameters supplied to the Update Managed Cluster Tags operation. +func (client ManagedClustersClient) UpdateTags(ctx context.Context, resourceGroupName string, resourceName string, parameters TagsObject) (result ManagedClustersUpdateTagsFuture, err error) { + req, err := client.UpdateTagsPreparer(ctx, resourceGroupName, resourceName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "containerservice.ManagedClustersClient", "UpdateTags", nil, "Failure preparing request") + return + } + + result, err = client.UpdateTagsSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "containerservice.ManagedClustersClient", "UpdateTags", result.Response(), "Failure sending request") + return + } + + return +} + +// UpdateTagsPreparer prepares the UpdateTags request. +func (client ManagedClustersClient) UpdateTagsPreparer(ctx context.Context, resourceGroupName string, resourceName string, parameters TagsObject) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", resourceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateTagsSender sends the UpdateTags request. The method will close the +// http.Response Body if it receives an error. +func (client ManagedClustersClient) UpdateTagsSender(req *http.Request) (future ManagedClustersUpdateTagsFuture, err error) { + var resp *http.Response + resp, err = autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) + if err != nil { + return + } + err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// UpdateTagsResponder handles the response to the UpdateTags request. The method always +// closes the http.Response Body. +func (client ManagedClustersClient) UpdateTagsResponder(resp *http.Response) (result ManagedCluster, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/containerservice/mgmt/2018-03-31/containerservice/models.go b/services/containerservice/mgmt/2018-03-31/containerservice/models.go index f8b0bc6c3b8b..ba39aa50ca0c 100644 --- a/services/containerservice/mgmt/2018-03-31/containerservice/models.go +++ b/services/containerservice/mgmt/2018-03-31/containerservice/models.go @@ -1301,6 +1301,35 @@ func (future *ManagedClustersDeleteFuture) Result(client ManagedClustersClient) return } +// ManagedClustersUpdateTagsFuture an abstraction for monitoring and retrieving the results of a long-running +// operation. +type ManagedClustersUpdateTagsFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *ManagedClustersUpdateTagsFuture) Result(client ManagedClustersClient) (mc ManagedCluster, err error) { + var done bool + done, err = future.Done(client) + if err != nil { + err = autorest.NewErrorWithError(err, "containerservice.ManagedClustersUpdateTagsFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("containerservice.ManagedClustersUpdateTagsFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if mc.Response.Response, err = future.GetResult(sender); err == nil && mc.Response.Response.StatusCode != http.StatusNoContent { + mc, err = client.UpdateTagsResponder(mc.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "containerservice.ManagedClustersUpdateTagsFuture", "Result", mc.Response.Response, "Failure responding to request") + } + } + return +} + // ManagedClusterUpgradeProfile the list of available upgrades for compute pools. type ManagedClusterUpgradeProfile struct { autorest.Response `json:"-"` @@ -1709,6 +1738,21 @@ type SSHPublicKey struct { KeyData *string `json:"keyData,omitempty"` } +// TagsObject tags object for patch operations. +type TagsObject struct { + // Tags - Resource tags. + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for TagsObject. +func (toVar TagsObject) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if toVar.Tags != nil { + objectMap["tags"] = toVar.Tags + } + return json.Marshal(objectMap) +} + // VMDiagnostics profile for diagnostics on the container service VMs. type VMDiagnostics struct { // Enabled - Whether the VM diagnostic agent is provisioned on the VM.