github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/expressroutecircuitconnections_client.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // Licensed under the MIT License. See License.txt in the project root for license information. 6 // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 package armnetwork 10 11 import ( 12 "context" 13 "errors" 14 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 18 "net/http" 19 "net/url" 20 "strings" 21 ) 22 23 // ExpressRouteCircuitConnectionsClient contains the methods for the ExpressRouteCircuitConnections group. 24 // Don't use this type directly, use NewExpressRouteCircuitConnectionsClient() instead. 25 type ExpressRouteCircuitConnectionsClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewExpressRouteCircuitConnectionsClient creates a new instance of ExpressRouteCircuitConnectionsClient with the specified values. 31 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 32 // ID forms part of the URI for every service call. 33 // - credential - used to authorize requests. Usually a credential from azidentity. 34 // - options - pass nil to accept the default values. 35 func NewExpressRouteCircuitConnectionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ExpressRouteCircuitConnectionsClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &ExpressRouteCircuitConnectionsClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreateOrUpdate - Creates or updates a Express Route Circuit Connection in the specified express route circuits. 48 // If the operation fails it returns an *azcore.ResponseError type. 49 // 50 // Generated from API version 2024-05-01 51 // - resourceGroupName - The name of the resource group. 52 // - circuitName - The name of the express route circuit. 53 // - peeringName - The name of the peering. 54 // - connectionName - The name of the express route circuit connection. 55 // - expressRouteCircuitConnectionParameters - Parameters supplied to the create or update express route circuit connection 56 // operation. 57 // - options - ExpressRouteCircuitConnectionsClientBeginCreateOrUpdateOptions contains the optional parameters for the ExpressRouteCircuitConnectionsClient.BeginCreateOrUpdate 58 // method. 59 func (client *ExpressRouteCircuitConnectionsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, expressRouteCircuitConnectionParameters ExpressRouteCircuitConnection, options *ExpressRouteCircuitConnectionsClientBeginCreateOrUpdateOptions) (*runtime.Poller[ExpressRouteCircuitConnectionsClientCreateOrUpdateResponse], error) { 60 if options == nil || options.ResumeToken == "" { 61 resp, err := client.createOrUpdate(ctx, resourceGroupName, circuitName, peeringName, connectionName, expressRouteCircuitConnectionParameters, options) 62 if err != nil { 63 return nil, err 64 } 65 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitConnectionsClientCreateOrUpdateResponse]{ 66 FinalStateVia: runtime.FinalStateViaAzureAsyncOp, 67 Tracer: client.internal.Tracer(), 68 }) 69 return poller, err 70 } else { 71 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ExpressRouteCircuitConnectionsClientCreateOrUpdateResponse]{ 72 Tracer: client.internal.Tracer(), 73 }) 74 } 75 } 76 77 // CreateOrUpdate - Creates or updates a Express Route Circuit Connection in the specified express route circuits. 78 // If the operation fails it returns an *azcore.ResponseError type. 79 // 80 // Generated from API version 2024-05-01 81 func (client *ExpressRouteCircuitConnectionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, expressRouteCircuitConnectionParameters ExpressRouteCircuitConnection, options *ExpressRouteCircuitConnectionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { 82 var err error 83 const operationName = "ExpressRouteCircuitConnectionsClient.BeginCreateOrUpdate" 84 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 85 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 86 defer func() { endSpan(err) }() 87 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, circuitName, peeringName, connectionName, expressRouteCircuitConnectionParameters, options) 88 if err != nil { 89 return nil, err 90 } 91 httpResp, err := client.internal.Pipeline().Do(req) 92 if err != nil { 93 return nil, err 94 } 95 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 96 err = runtime.NewResponseError(httpResp) 97 return nil, err 98 } 99 return httpResp, nil 100 } 101 102 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 103 func (client *ExpressRouteCircuitConnectionsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, expressRouteCircuitConnectionParameters ExpressRouteCircuitConnection, options *ExpressRouteCircuitConnectionsClientBeginCreateOrUpdateOptions) (*policy.Request, error) { 104 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}" 105 if resourceGroupName == "" { 106 return nil, errors.New("parameter resourceGroupName cannot be empty") 107 } 108 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 109 if circuitName == "" { 110 return nil, errors.New("parameter circuitName cannot be empty") 111 } 112 urlPath = strings.ReplaceAll(urlPath, "{circuitName}", url.PathEscape(circuitName)) 113 if peeringName == "" { 114 return nil, errors.New("parameter peeringName cannot be empty") 115 } 116 urlPath = strings.ReplaceAll(urlPath, "{peeringName}", url.PathEscape(peeringName)) 117 if connectionName == "" { 118 return nil, errors.New("parameter connectionName cannot be empty") 119 } 120 urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName)) 121 if client.subscriptionID == "" { 122 return nil, errors.New("parameter client.subscriptionID cannot be empty") 123 } 124 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 125 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 126 if err != nil { 127 return nil, err 128 } 129 reqQP := req.Raw().URL.Query() 130 reqQP.Set("api-version", "2024-05-01") 131 req.Raw().URL.RawQuery = reqQP.Encode() 132 req.Raw().Header["Accept"] = []string{"application/json"} 133 if err := runtime.MarshalAsJSON(req, expressRouteCircuitConnectionParameters); err != nil { 134 return nil, err 135 } 136 return req, nil 137 } 138 139 // BeginDelete - Deletes the specified Express Route Circuit Connection from the specified express route circuit. 140 // If the operation fails it returns an *azcore.ResponseError type. 141 // 142 // Generated from API version 2024-05-01 143 // - resourceGroupName - The name of the resource group. 144 // - circuitName - The name of the express route circuit. 145 // - peeringName - The name of the peering. 146 // - connectionName - The name of the express route circuit connection. 147 // - options - ExpressRouteCircuitConnectionsClientBeginDeleteOptions contains the optional parameters for the ExpressRouteCircuitConnectionsClient.BeginDelete 148 // method. 149 func (client *ExpressRouteCircuitConnectionsClient) BeginDelete(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *ExpressRouteCircuitConnectionsClientBeginDeleteOptions) (*runtime.Poller[ExpressRouteCircuitConnectionsClientDeleteResponse], error) { 150 if options == nil || options.ResumeToken == "" { 151 resp, err := client.deleteOperation(ctx, resourceGroupName, circuitName, peeringName, connectionName, options) 152 if err != nil { 153 return nil, err 154 } 155 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitConnectionsClientDeleteResponse]{ 156 FinalStateVia: runtime.FinalStateViaLocation, 157 Tracer: client.internal.Tracer(), 158 }) 159 return poller, err 160 } else { 161 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ExpressRouteCircuitConnectionsClientDeleteResponse]{ 162 Tracer: client.internal.Tracer(), 163 }) 164 } 165 } 166 167 // Delete - Deletes the specified Express Route Circuit Connection from the specified express route circuit. 168 // If the operation fails it returns an *azcore.ResponseError type. 169 // 170 // Generated from API version 2024-05-01 171 func (client *ExpressRouteCircuitConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *ExpressRouteCircuitConnectionsClientBeginDeleteOptions) (*http.Response, error) { 172 var err error 173 const operationName = "ExpressRouteCircuitConnectionsClient.BeginDelete" 174 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 175 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 176 defer func() { endSpan(err) }() 177 req, err := client.deleteCreateRequest(ctx, resourceGroupName, circuitName, peeringName, connectionName, options) 178 if err != nil { 179 return nil, err 180 } 181 httpResp, err := client.internal.Pipeline().Do(req) 182 if err != nil { 183 return nil, err 184 } 185 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 186 err = runtime.NewResponseError(httpResp) 187 return nil, err 188 } 189 return httpResp, nil 190 } 191 192 // deleteCreateRequest creates the Delete request. 193 func (client *ExpressRouteCircuitConnectionsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *ExpressRouteCircuitConnectionsClientBeginDeleteOptions) (*policy.Request, error) { 194 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}" 195 if resourceGroupName == "" { 196 return nil, errors.New("parameter resourceGroupName cannot be empty") 197 } 198 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 199 if circuitName == "" { 200 return nil, errors.New("parameter circuitName cannot be empty") 201 } 202 urlPath = strings.ReplaceAll(urlPath, "{circuitName}", url.PathEscape(circuitName)) 203 if peeringName == "" { 204 return nil, errors.New("parameter peeringName cannot be empty") 205 } 206 urlPath = strings.ReplaceAll(urlPath, "{peeringName}", url.PathEscape(peeringName)) 207 if connectionName == "" { 208 return nil, errors.New("parameter connectionName cannot be empty") 209 } 210 urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName)) 211 if client.subscriptionID == "" { 212 return nil, errors.New("parameter client.subscriptionID cannot be empty") 213 } 214 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 215 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 216 if err != nil { 217 return nil, err 218 } 219 reqQP := req.Raw().URL.Query() 220 reqQP.Set("api-version", "2024-05-01") 221 req.Raw().URL.RawQuery = reqQP.Encode() 222 req.Raw().Header["Accept"] = []string{"application/json"} 223 return req, nil 224 } 225 226 // Get - Gets the specified Express Route Circuit Connection from the specified express route circuit. 227 // If the operation fails it returns an *azcore.ResponseError type. 228 // 229 // Generated from API version 2024-05-01 230 // - resourceGroupName - The name of the resource group. 231 // - circuitName - The name of the express route circuit. 232 // - peeringName - The name of the peering. 233 // - connectionName - The name of the express route circuit connection. 234 // - options - ExpressRouteCircuitConnectionsClientGetOptions contains the optional parameters for the ExpressRouteCircuitConnectionsClient.Get 235 // method. 236 func (client *ExpressRouteCircuitConnectionsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *ExpressRouteCircuitConnectionsClientGetOptions) (ExpressRouteCircuitConnectionsClientGetResponse, error) { 237 var err error 238 const operationName = "ExpressRouteCircuitConnectionsClient.Get" 239 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 240 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 241 defer func() { endSpan(err) }() 242 req, err := client.getCreateRequest(ctx, resourceGroupName, circuitName, peeringName, connectionName, options) 243 if err != nil { 244 return ExpressRouteCircuitConnectionsClientGetResponse{}, err 245 } 246 httpResp, err := client.internal.Pipeline().Do(req) 247 if err != nil { 248 return ExpressRouteCircuitConnectionsClientGetResponse{}, err 249 } 250 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 251 err = runtime.NewResponseError(httpResp) 252 return ExpressRouteCircuitConnectionsClientGetResponse{}, err 253 } 254 resp, err := client.getHandleResponse(httpResp) 255 return resp, err 256 } 257 258 // getCreateRequest creates the Get request. 259 func (client *ExpressRouteCircuitConnectionsClient) getCreateRequest(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *ExpressRouteCircuitConnectionsClientGetOptions) (*policy.Request, error) { 260 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}" 261 if resourceGroupName == "" { 262 return nil, errors.New("parameter resourceGroupName cannot be empty") 263 } 264 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 265 if circuitName == "" { 266 return nil, errors.New("parameter circuitName cannot be empty") 267 } 268 urlPath = strings.ReplaceAll(urlPath, "{circuitName}", url.PathEscape(circuitName)) 269 if peeringName == "" { 270 return nil, errors.New("parameter peeringName cannot be empty") 271 } 272 urlPath = strings.ReplaceAll(urlPath, "{peeringName}", url.PathEscape(peeringName)) 273 if connectionName == "" { 274 return nil, errors.New("parameter connectionName cannot be empty") 275 } 276 urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName)) 277 if client.subscriptionID == "" { 278 return nil, errors.New("parameter client.subscriptionID cannot be empty") 279 } 280 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 281 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 282 if err != nil { 283 return nil, err 284 } 285 reqQP := req.Raw().URL.Query() 286 reqQP.Set("api-version", "2024-05-01") 287 req.Raw().URL.RawQuery = reqQP.Encode() 288 req.Raw().Header["Accept"] = []string{"application/json"} 289 return req, nil 290 } 291 292 // getHandleResponse handles the Get response. 293 func (client *ExpressRouteCircuitConnectionsClient) getHandleResponse(resp *http.Response) (ExpressRouteCircuitConnectionsClientGetResponse, error) { 294 result := ExpressRouteCircuitConnectionsClientGetResponse{} 295 if err := runtime.UnmarshalAsJSON(resp, &result.ExpressRouteCircuitConnection); err != nil { 296 return ExpressRouteCircuitConnectionsClientGetResponse{}, err 297 } 298 return result, nil 299 } 300 301 // NewListPager - Gets all global reach connections associated with a private peering in an express route circuit. 302 // 303 // Generated from API version 2024-05-01 304 // - resourceGroupName - The name of the resource group. 305 // - circuitName - The name of the circuit. 306 // - peeringName - The name of the peering. 307 // - options - ExpressRouteCircuitConnectionsClientListOptions contains the optional parameters for the ExpressRouteCircuitConnectionsClient.NewListPager 308 // method. 309 func (client *ExpressRouteCircuitConnectionsClient) NewListPager(resourceGroupName string, circuitName string, peeringName string, options *ExpressRouteCircuitConnectionsClientListOptions) *runtime.Pager[ExpressRouteCircuitConnectionsClientListResponse] { 310 return runtime.NewPager(runtime.PagingHandler[ExpressRouteCircuitConnectionsClientListResponse]{ 311 More: func(page ExpressRouteCircuitConnectionsClientListResponse) bool { 312 return page.NextLink != nil && len(*page.NextLink) > 0 313 }, 314 Fetcher: func(ctx context.Context, page *ExpressRouteCircuitConnectionsClientListResponse) (ExpressRouteCircuitConnectionsClientListResponse, error) { 315 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteCircuitConnectionsClient.NewListPager") 316 nextLink := "" 317 if page != nil { 318 nextLink = *page.NextLink 319 } 320 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 321 return client.listCreateRequest(ctx, resourceGroupName, circuitName, peeringName, options) 322 }, nil) 323 if err != nil { 324 return ExpressRouteCircuitConnectionsClientListResponse{}, err 325 } 326 return client.listHandleResponse(resp) 327 }, 328 Tracer: client.internal.Tracer(), 329 }) 330 } 331 332 // listCreateRequest creates the List request. 333 func (client *ExpressRouteCircuitConnectionsClient) listCreateRequest(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, options *ExpressRouteCircuitConnectionsClientListOptions) (*policy.Request, error) { 334 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections" 335 if resourceGroupName == "" { 336 return nil, errors.New("parameter resourceGroupName cannot be empty") 337 } 338 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 339 if circuitName == "" { 340 return nil, errors.New("parameter circuitName cannot be empty") 341 } 342 urlPath = strings.ReplaceAll(urlPath, "{circuitName}", url.PathEscape(circuitName)) 343 if peeringName == "" { 344 return nil, errors.New("parameter peeringName cannot be empty") 345 } 346 urlPath = strings.ReplaceAll(urlPath, "{peeringName}", url.PathEscape(peeringName)) 347 if client.subscriptionID == "" { 348 return nil, errors.New("parameter client.subscriptionID cannot be empty") 349 } 350 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 351 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 352 if err != nil { 353 return nil, err 354 } 355 reqQP := req.Raw().URL.Query() 356 reqQP.Set("api-version", "2024-05-01") 357 req.Raw().URL.RawQuery = reqQP.Encode() 358 req.Raw().Header["Accept"] = []string{"application/json"} 359 return req, nil 360 } 361 362 // listHandleResponse handles the List response. 363 func (client *ExpressRouteCircuitConnectionsClient) listHandleResponse(resp *http.Response) (ExpressRouteCircuitConnectionsClientListResponse, error) { 364 result := ExpressRouteCircuitConnectionsClientListResponse{} 365 if err := runtime.UnmarshalAsJSON(resp, &result.ExpressRouteCircuitConnectionListResult); err != nil { 366 return ExpressRouteCircuitConnectionsClientListResponse{}, err 367 } 368 return result, nil 369 }