1package deploymentmanager 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// ServicesClient is the REST APIs for orchestrating deployments using the Azure Deployment Manager (ADM). See 19// https://docs.microsoft.com/en-us/azure/azure-resource-manager/deployment-manager-overview for more information. 20type ServicesClient struct { 21 BaseClient 22} 23 24// NewServicesClient creates an instance of the ServicesClient client. 25func NewServicesClient(subscriptionID string) ServicesClient { 26 return NewServicesClientWithBaseURI(DefaultBaseURI, subscriptionID) 27} 28 29// NewServicesClientWithBaseURI creates an instance of the ServicesClient client using a custom endpoint. Use this 30// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 31func NewServicesClientWithBaseURI(baseURI string, subscriptionID string) ServicesClient { 32 return ServicesClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// CreateOrUpdate synchronously creates a new service or updates an existing service. 36// Parameters: 37// resourceGroupName - the name of the resource group. The name is case insensitive. 38// serviceTopologyName - the name of the service topology . 39// serviceName - the name of the service resource. 40// serviceInfo - the service object 41func (client ServicesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceTopologyName string, serviceName string, serviceInfo ServiceResource) (result ServiceResource, err error) { 42 if tracing.IsEnabled() { 43 ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.CreateOrUpdate") 44 defer func() { 45 sc := -1 46 if result.Response.Response != nil { 47 sc = result.Response.Response.StatusCode 48 } 49 tracing.EndSpan(ctx, sc, err) 50 }() 51 } 52 if err := validation.Validate([]validation.Validation{ 53 {TargetValue: resourceGroupName, 54 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 55 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 56 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 57 {TargetValue: serviceInfo, 58 Constraints: []validation.Constraint{{Target: "serviceInfo.ServiceResourceProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 59 return result, validation.NewError("deploymentmanager.ServicesClient", "CreateOrUpdate", err.Error()) 60 } 61 62 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceTopologyName, serviceName, serviceInfo) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "deploymentmanager.ServicesClient", "CreateOrUpdate", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.CreateOrUpdateSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "deploymentmanager.ServicesClient", "CreateOrUpdate", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.CreateOrUpdateResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "deploymentmanager.ServicesClient", "CreateOrUpdate", resp, "Failure responding to request") 78 return 79 } 80 81 return 82} 83 84// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 85func (client ServicesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceTopologyName string, serviceName string, serviceInfo ServiceResource) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "resourceGroupName": autorest.Encode("path", resourceGroupName), 88 "serviceName": autorest.Encode("path", serviceName), 89 "serviceTopologyName": autorest.Encode("path", serviceTopologyName), 90 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 91 } 92 93 const APIVersion = "2018-09-01-preview" 94 queryParameters := map[string]interface{}{ 95 "api-version": APIVersion, 96 } 97 98 preparer := autorest.CreatePreparer( 99 autorest.AsContentType("application/json; charset=utf-8"), 100 autorest.AsPut(), 101 autorest.WithBaseURL(client.BaseURI), 102 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DeploymentManager/serviceTopologies/{serviceTopologyName}/services/{serviceName}", pathParameters), 103 autorest.WithJSON(serviceInfo), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 109// http.Response Body if it receives an error. 110func (client ServicesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 111 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 112} 113 114// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 115// closes the http.Response Body. 116func (client ServicesClient) CreateOrUpdateResponder(resp *http.Response) (result ServiceResource, err error) { 117 err = autorest.Respond( 118 resp, 119 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 120 autorest.ByUnmarshallingJSON(&result), 121 autorest.ByClosing()) 122 result.Response = autorest.Response{Response: resp} 123 return 124} 125 126// Delete sends the delete request. 127// Parameters: 128// resourceGroupName - the name of the resource group. The name is case insensitive. 129// serviceTopologyName - the name of the service topology . 130// serviceName - the name of the service resource. 131func (client ServicesClient) Delete(ctx context.Context, resourceGroupName string, serviceTopologyName string, serviceName string) (result autorest.Response, err error) { 132 if tracing.IsEnabled() { 133 ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Delete") 134 defer func() { 135 sc := -1 136 if result.Response != nil { 137 sc = result.Response.StatusCode 138 } 139 tracing.EndSpan(ctx, sc, err) 140 }() 141 } 142 if err := validation.Validate([]validation.Validation{ 143 {TargetValue: resourceGroupName, 144 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 145 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 146 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 147 return result, validation.NewError("deploymentmanager.ServicesClient", "Delete", err.Error()) 148 } 149 150 req, err := client.DeletePreparer(ctx, resourceGroupName, serviceTopologyName, serviceName) 151 if err != nil { 152 err = autorest.NewErrorWithError(err, "deploymentmanager.ServicesClient", "Delete", nil, "Failure preparing request") 153 return 154 } 155 156 resp, err := client.DeleteSender(req) 157 if err != nil { 158 result.Response = resp 159 err = autorest.NewErrorWithError(err, "deploymentmanager.ServicesClient", "Delete", resp, "Failure sending request") 160 return 161 } 162 163 result, err = client.DeleteResponder(resp) 164 if err != nil { 165 err = autorest.NewErrorWithError(err, "deploymentmanager.ServicesClient", "Delete", resp, "Failure responding to request") 166 return 167 } 168 169 return 170} 171 172// DeletePreparer prepares the Delete request. 173func (client ServicesClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceTopologyName string, serviceName string) (*http.Request, error) { 174 pathParameters := map[string]interface{}{ 175 "resourceGroupName": autorest.Encode("path", resourceGroupName), 176 "serviceName": autorest.Encode("path", serviceName), 177 "serviceTopologyName": autorest.Encode("path", serviceTopologyName), 178 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 179 } 180 181 const APIVersion = "2018-09-01-preview" 182 queryParameters := map[string]interface{}{ 183 "api-version": APIVersion, 184 } 185 186 preparer := autorest.CreatePreparer( 187 autorest.AsDelete(), 188 autorest.WithBaseURL(client.BaseURI), 189 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DeploymentManager/serviceTopologies/{serviceTopologyName}/services/{serviceName}", pathParameters), 190 autorest.WithQueryParameters(queryParameters)) 191 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 192} 193 194// DeleteSender sends the Delete request. The method will close the 195// http.Response Body if it receives an error. 196func (client ServicesClient) DeleteSender(req *http.Request) (*http.Response, error) { 197 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 198} 199 200// DeleteResponder handles the response to the Delete request. The method always 201// closes the http.Response Body. 202func (client ServicesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 203 err = autorest.Respond( 204 resp, 205 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 206 autorest.ByClosing()) 207 result.Response = resp 208 return 209} 210 211// Get sends the get request. 212// Parameters: 213// resourceGroupName - the name of the resource group. The name is case insensitive. 214// serviceTopologyName - the name of the service topology . 215// serviceName - the name of the service resource. 216func (client ServicesClient) Get(ctx context.Context, resourceGroupName string, serviceTopologyName string, serviceName string) (result ServiceResource, err error) { 217 if tracing.IsEnabled() { 218 ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Get") 219 defer func() { 220 sc := -1 221 if result.Response.Response != nil { 222 sc = result.Response.Response.StatusCode 223 } 224 tracing.EndSpan(ctx, sc, err) 225 }() 226 } 227 if err := validation.Validate([]validation.Validation{ 228 {TargetValue: resourceGroupName, 229 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 230 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 231 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 232 return result, validation.NewError("deploymentmanager.ServicesClient", "Get", err.Error()) 233 } 234 235 req, err := client.GetPreparer(ctx, resourceGroupName, serviceTopologyName, serviceName) 236 if err != nil { 237 err = autorest.NewErrorWithError(err, "deploymentmanager.ServicesClient", "Get", nil, "Failure preparing request") 238 return 239 } 240 241 resp, err := client.GetSender(req) 242 if err != nil { 243 result.Response = autorest.Response{Response: resp} 244 err = autorest.NewErrorWithError(err, "deploymentmanager.ServicesClient", "Get", resp, "Failure sending request") 245 return 246 } 247 248 result, err = client.GetResponder(resp) 249 if err != nil { 250 err = autorest.NewErrorWithError(err, "deploymentmanager.ServicesClient", "Get", resp, "Failure responding to request") 251 return 252 } 253 254 return 255} 256 257// GetPreparer prepares the Get request. 258func (client ServicesClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceTopologyName string, serviceName string) (*http.Request, error) { 259 pathParameters := map[string]interface{}{ 260 "resourceGroupName": autorest.Encode("path", resourceGroupName), 261 "serviceName": autorest.Encode("path", serviceName), 262 "serviceTopologyName": autorest.Encode("path", serviceTopologyName), 263 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 264 } 265 266 const APIVersion = "2018-09-01-preview" 267 queryParameters := map[string]interface{}{ 268 "api-version": APIVersion, 269 } 270 271 preparer := autorest.CreatePreparer( 272 autorest.AsGet(), 273 autorest.WithBaseURL(client.BaseURI), 274 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DeploymentManager/serviceTopologies/{serviceTopologyName}/services/{serviceName}", pathParameters), 275 autorest.WithQueryParameters(queryParameters)) 276 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 277} 278 279// GetSender sends the Get request. The method will close the 280// http.Response Body if it receives an error. 281func (client ServicesClient) GetSender(req *http.Request) (*http.Response, error) { 282 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 283} 284 285// GetResponder handles the response to the Get request. The method always 286// closes the http.Response Body. 287func (client ServicesClient) GetResponder(resp *http.Response) (result ServiceResource, err error) { 288 err = autorest.Respond( 289 resp, 290 azure.WithErrorUnlessStatusCode(http.StatusOK), 291 autorest.ByUnmarshallingJSON(&result), 292 autorest.ByClosing()) 293 result.Response = autorest.Response{Response: resp} 294 return 295} 296