1package managednetwork 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// GroupsClient is the the Microsoft Azure Managed Network management API provides a RESTful set of web services that 30// interact with Microsoft Azure Networks service to programmatically view, control, change, and monitor your entire 31// Azure network centrally and with ease. 32type GroupsClient struct { 33 BaseClient 34} 35 36// NewGroupsClient creates an instance of the GroupsClient client. 37func NewGroupsClient(subscriptionID string) GroupsClient { 38 return NewGroupsClientWithBaseURI(DefaultBaseURI, subscriptionID) 39} 40 41// NewGroupsClientWithBaseURI creates an instance of the GroupsClient client. 42func NewGroupsClientWithBaseURI(baseURI string, subscriptionID string) GroupsClient { 43 return GroupsClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// CreateOrUpdate the Put ManagedNetworkGroups operation creates or updates a Managed Network Group resource 47// Parameters: 48// managedNetworkGroup - parameters supplied to the create/update a Managed Network Group resource 49// resourceGroupName - the name of the resource group. 50// managedNetworkName - the name of the Managed Network. 51// managedNetworkGroupName - the name of the Managed Network Group. 52func (client GroupsClient) CreateOrUpdate(ctx context.Context, managedNetworkGroup Group, resourceGroupName string, managedNetworkName string, managedNetworkGroupName string) (result GroupsCreateOrUpdateFuture, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/GroupsClient.CreateOrUpdate") 55 defer func() { 56 sc := -1 57 if result.Response() != nil { 58 sc = result.Response().StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 req, err := client.CreateOrUpdatePreparer(ctx, managedNetworkGroup, resourceGroupName, managedNetworkName, managedNetworkGroupName) 64 if err != nil { 65 err = autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "CreateOrUpdate", nil, "Failure preparing request") 66 return 67 } 68 69 result, err = client.CreateOrUpdateSender(req) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "CreateOrUpdate", result.Response(), "Failure sending request") 72 return 73 } 74 75 return 76} 77 78// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 79func (client GroupsClient) CreateOrUpdatePreparer(ctx context.Context, managedNetworkGroup Group, resourceGroupName string, managedNetworkName string, managedNetworkGroupName string) (*http.Request, error) { 80 pathParameters := map[string]interface{}{ 81 "managedNetworkGroupName": autorest.Encode("path", managedNetworkGroupName), 82 "managedNetworkName": autorest.Encode("path", managedNetworkName), 83 "resourceGroupName": autorest.Encode("path", resourceGroupName), 84 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 85 } 86 87 const APIVersion = "2019-06-01-preview" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 92 preparer := autorest.CreatePreparer( 93 autorest.AsContentType("application/json; charset=utf-8"), 94 autorest.AsPut(), 95 autorest.WithBaseURL(client.BaseURI), 96 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedNetwork/managedNetworks/{managedNetworkName}/managedNetworkGroups/{managedNetworkGroupName}", pathParameters), 97 autorest.WithJSON(managedNetworkGroup), 98 autorest.WithQueryParameters(queryParameters)) 99 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 100} 101 102// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 103// http.Response Body if it receives an error. 104func (client GroupsClient) CreateOrUpdateSender(req *http.Request) (future GroupsCreateOrUpdateFuture, err error) { 105 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 106 var resp *http.Response 107 resp, err = autorest.SendWithSender(client, req, sd...) 108 if err != nil { 109 return 110 } 111 future.Future, err = azure.NewFutureFromResponse(resp) 112 return 113} 114 115// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 116// closes the http.Response Body. 117func (client GroupsClient) CreateOrUpdateResponder(resp *http.Response) (result Group, err error) { 118 err = autorest.Respond( 119 resp, 120 client.ByInspecting(), 121 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 122 autorest.ByUnmarshallingJSON(&result), 123 autorest.ByClosing()) 124 result.Response = autorest.Response{Response: resp} 125 return 126} 127 128// Delete the Delete ManagedNetworkGroups operation deletes a Managed Network Group specified by the resource group, 129// Managed Network name, and group name 130// Parameters: 131// resourceGroupName - the name of the resource group. 132// managedNetworkName - the name of the Managed Network. 133// managedNetworkGroupName - the name of the Managed Network Group. 134func (client GroupsClient) Delete(ctx context.Context, resourceGroupName string, managedNetworkName string, managedNetworkGroupName string) (result GroupsDeleteFuture, err error) { 135 if tracing.IsEnabled() { 136 ctx = tracing.StartSpan(ctx, fqdn+"/GroupsClient.Delete") 137 defer func() { 138 sc := -1 139 if result.Response() != nil { 140 sc = result.Response().StatusCode 141 } 142 tracing.EndSpan(ctx, sc, err) 143 }() 144 } 145 req, err := client.DeletePreparer(ctx, resourceGroupName, managedNetworkName, managedNetworkGroupName) 146 if err != nil { 147 err = autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "Delete", nil, "Failure preparing request") 148 return 149 } 150 151 result, err = client.DeleteSender(req) 152 if err != nil { 153 err = autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "Delete", result.Response(), "Failure sending request") 154 return 155 } 156 157 return 158} 159 160// DeletePreparer prepares the Delete request. 161func (client GroupsClient) DeletePreparer(ctx context.Context, resourceGroupName string, managedNetworkName string, managedNetworkGroupName string) (*http.Request, error) { 162 pathParameters := map[string]interface{}{ 163 "managedNetworkGroupName": autorest.Encode("path", managedNetworkGroupName), 164 "managedNetworkName": autorest.Encode("path", managedNetworkName), 165 "resourceGroupName": autorest.Encode("path", resourceGroupName), 166 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 167 } 168 169 const APIVersion = "2019-06-01-preview" 170 queryParameters := map[string]interface{}{ 171 "api-version": APIVersion, 172 } 173 174 preparer := autorest.CreatePreparer( 175 autorest.AsDelete(), 176 autorest.WithBaseURL(client.BaseURI), 177 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedNetwork/managedNetworks/{managedNetworkName}/managedNetworkGroups/{managedNetworkGroupName}", pathParameters), 178 autorest.WithQueryParameters(queryParameters)) 179 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 180} 181 182// DeleteSender sends the Delete request. The method will close the 183// http.Response Body if it receives an error. 184func (client GroupsClient) DeleteSender(req *http.Request) (future GroupsDeleteFuture, err error) { 185 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 186 var resp *http.Response 187 resp, err = autorest.SendWithSender(client, req, sd...) 188 if err != nil { 189 return 190 } 191 future.Future, err = azure.NewFutureFromResponse(resp) 192 return 193} 194 195// DeleteResponder handles the response to the Delete request. The method always 196// closes the http.Response Body. 197func (client GroupsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 198 err = autorest.Respond( 199 resp, 200 client.ByInspecting(), 201 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 202 autorest.ByClosing()) 203 result.Response = resp 204 return 205} 206 207// Get the Get ManagedNetworkGroups operation gets a Managed Network Group specified by the resource group, Managed 208// Network name, and group name 209// Parameters: 210// resourceGroupName - the name of the resource group. 211// managedNetworkName - the name of the Managed Network. 212// managedNetworkGroupName - the name of the Managed Network Group. 213func (client GroupsClient) Get(ctx context.Context, resourceGroupName string, managedNetworkName string, managedNetworkGroupName string) (result Group, err error) { 214 if tracing.IsEnabled() { 215 ctx = tracing.StartSpan(ctx, fqdn+"/GroupsClient.Get") 216 defer func() { 217 sc := -1 218 if result.Response.Response != nil { 219 sc = result.Response.Response.StatusCode 220 } 221 tracing.EndSpan(ctx, sc, err) 222 }() 223 } 224 req, err := client.GetPreparer(ctx, resourceGroupName, managedNetworkName, managedNetworkGroupName) 225 if err != nil { 226 err = autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "Get", nil, "Failure preparing request") 227 return 228 } 229 230 resp, err := client.GetSender(req) 231 if err != nil { 232 result.Response = autorest.Response{Response: resp} 233 err = autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "Get", resp, "Failure sending request") 234 return 235 } 236 237 result, err = client.GetResponder(resp) 238 if err != nil { 239 err = autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "Get", resp, "Failure responding to request") 240 } 241 242 return 243} 244 245// GetPreparer prepares the Get request. 246func (client GroupsClient) GetPreparer(ctx context.Context, resourceGroupName string, managedNetworkName string, managedNetworkGroupName string) (*http.Request, error) { 247 pathParameters := map[string]interface{}{ 248 "managedNetworkGroupName": autorest.Encode("path", managedNetworkGroupName), 249 "managedNetworkName": autorest.Encode("path", managedNetworkName), 250 "resourceGroupName": autorest.Encode("path", resourceGroupName), 251 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 252 } 253 254 const APIVersion = "2019-06-01-preview" 255 queryParameters := map[string]interface{}{ 256 "api-version": APIVersion, 257 } 258 259 preparer := autorest.CreatePreparer( 260 autorest.AsGet(), 261 autorest.WithBaseURL(client.BaseURI), 262 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedNetwork/managedNetworks/{managedNetworkName}/managedNetworkGroups/{managedNetworkGroupName}", pathParameters), 263 autorest.WithQueryParameters(queryParameters)) 264 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 265} 266 267// GetSender sends the Get request. The method will close the 268// http.Response Body if it receives an error. 269func (client GroupsClient) GetSender(req *http.Request) (*http.Response, error) { 270 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 271 return autorest.SendWithSender(client, req, sd...) 272} 273 274// GetResponder handles the response to the Get request. The method always 275// closes the http.Response Body. 276func (client GroupsClient) GetResponder(resp *http.Response) (result Group, err error) { 277 err = autorest.Respond( 278 resp, 279 client.ByInspecting(), 280 azure.WithErrorUnlessStatusCode(http.StatusOK), 281 autorest.ByUnmarshallingJSON(&result), 282 autorest.ByClosing()) 283 result.Response = autorest.Response{Response: resp} 284 return 285} 286 287// ListByManagedNetwork the ListByManagedNetwork ManagedNetworkGroup operation retrieves all the Managed Network Groups 288// in a specified Managed Networks in a paginated format. 289// Parameters: 290// resourceGroupName - the name of the resource group. 291// managedNetworkName - the name of the Managed Network. 292// top - may be used to limit the number of results in a page for list queries. 293// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response 294// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that 295// specifies a starting point to use for subsequent calls. 296func (client GroupsClient) ListByManagedNetwork(ctx context.Context, resourceGroupName string, managedNetworkName string, top *int32, skiptoken string) (result GroupListResultPage, err error) { 297 if tracing.IsEnabled() { 298 ctx = tracing.StartSpan(ctx, fqdn+"/GroupsClient.ListByManagedNetwork") 299 defer func() { 300 sc := -1 301 if result.glr.Response.Response != nil { 302 sc = result.glr.Response.Response.StatusCode 303 } 304 tracing.EndSpan(ctx, sc, err) 305 }() 306 } 307 if err := validation.Validate([]validation.Validation{ 308 {TargetValue: top, 309 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 310 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(20), Chain: nil}, 311 {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, 312 }}}}}); err != nil { 313 return result, validation.NewError("managednetwork.GroupsClient", "ListByManagedNetwork", err.Error()) 314 } 315 316 result.fn = client.listByManagedNetworkNextResults 317 req, err := client.ListByManagedNetworkPreparer(ctx, resourceGroupName, managedNetworkName, top, skiptoken) 318 if err != nil { 319 err = autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "ListByManagedNetwork", nil, "Failure preparing request") 320 return 321 } 322 323 resp, err := client.ListByManagedNetworkSender(req) 324 if err != nil { 325 result.glr.Response = autorest.Response{Response: resp} 326 err = autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "ListByManagedNetwork", resp, "Failure sending request") 327 return 328 } 329 330 result.glr, err = client.ListByManagedNetworkResponder(resp) 331 if err != nil { 332 err = autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "ListByManagedNetwork", resp, "Failure responding to request") 333 } 334 335 return 336} 337 338// ListByManagedNetworkPreparer prepares the ListByManagedNetwork request. 339func (client GroupsClient) ListByManagedNetworkPreparer(ctx context.Context, resourceGroupName string, managedNetworkName string, top *int32, skiptoken string) (*http.Request, error) { 340 pathParameters := map[string]interface{}{ 341 "managedNetworkName": autorest.Encode("path", managedNetworkName), 342 "resourceGroupName": autorest.Encode("path", resourceGroupName), 343 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 344 } 345 346 const APIVersion = "2019-06-01-preview" 347 queryParameters := map[string]interface{}{ 348 "api-version": APIVersion, 349 } 350 if top != nil { 351 queryParameters["$top"] = autorest.Encode("query", *top) 352 } 353 if len(skiptoken) > 0 { 354 queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) 355 } 356 357 preparer := autorest.CreatePreparer( 358 autorest.AsGet(), 359 autorest.WithBaseURL(client.BaseURI), 360 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedNetwork/managedNetworks/{managedNetworkName}/managedNetworkGroups", pathParameters), 361 autorest.WithQueryParameters(queryParameters)) 362 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 363} 364 365// ListByManagedNetworkSender sends the ListByManagedNetwork request. The method will close the 366// http.Response Body if it receives an error. 367func (client GroupsClient) ListByManagedNetworkSender(req *http.Request) (*http.Response, error) { 368 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 369 return autorest.SendWithSender(client, req, sd...) 370} 371 372// ListByManagedNetworkResponder handles the response to the ListByManagedNetwork request. The method always 373// closes the http.Response Body. 374func (client GroupsClient) ListByManagedNetworkResponder(resp *http.Response) (result GroupListResult, err error) { 375 err = autorest.Respond( 376 resp, 377 client.ByInspecting(), 378 azure.WithErrorUnlessStatusCode(http.StatusOK), 379 autorest.ByUnmarshallingJSON(&result), 380 autorest.ByClosing()) 381 result.Response = autorest.Response{Response: resp} 382 return 383} 384 385// listByManagedNetworkNextResults retrieves the next set of results, if any. 386func (client GroupsClient) listByManagedNetworkNextResults(ctx context.Context, lastResults GroupListResult) (result GroupListResult, err error) { 387 req, err := lastResults.groupListResultPreparer(ctx) 388 if err != nil { 389 return result, autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "listByManagedNetworkNextResults", nil, "Failure preparing next results request") 390 } 391 if req == nil { 392 return 393 } 394 resp, err := client.ListByManagedNetworkSender(req) 395 if err != nil { 396 result.Response = autorest.Response{Response: resp} 397 return result, autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "listByManagedNetworkNextResults", resp, "Failure sending next results request") 398 } 399 result, err = client.ListByManagedNetworkResponder(resp) 400 if err != nil { 401 err = autorest.NewErrorWithError(err, "managednetwork.GroupsClient", "listByManagedNetworkNextResults", resp, "Failure responding to next results request") 402 } 403 return 404} 405 406// ListByManagedNetworkComplete enumerates all values, automatically crossing page boundaries as required. 407func (client GroupsClient) ListByManagedNetworkComplete(ctx context.Context, resourceGroupName string, managedNetworkName string, top *int32, skiptoken string) (result GroupListResultIterator, err error) { 408 if tracing.IsEnabled() { 409 ctx = tracing.StartSpan(ctx, fqdn+"/GroupsClient.ListByManagedNetwork") 410 defer func() { 411 sc := -1 412 if result.Response().Response.Response != nil { 413 sc = result.page.Response().Response.Response.StatusCode 414 } 415 tracing.EndSpan(ctx, sc, err) 416 }() 417 } 418 result.page, err = client.ListByManagedNetwork(ctx, resourceGroupName, managedNetworkName, top, skiptoken) 419 return 420} 421