1package network 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/tracing" 25 "net/http" 26) 27 28// PeerExpressRouteCircuitConnectionsClient is the network Client 29type PeerExpressRouteCircuitConnectionsClient struct { 30 BaseClient 31} 32 33// NewPeerExpressRouteCircuitConnectionsClient creates an instance of the PeerExpressRouteCircuitConnectionsClient 34// client. 35func NewPeerExpressRouteCircuitConnectionsClient(subscriptionID string) PeerExpressRouteCircuitConnectionsClient { 36 return NewPeerExpressRouteCircuitConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewPeerExpressRouteCircuitConnectionsClientWithBaseURI creates an instance of the 40// PeerExpressRouteCircuitConnectionsClient client using a custom endpoint. Use this when interacting with an Azure 41// cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 42func NewPeerExpressRouteCircuitConnectionsClientWithBaseURI(baseURI string, subscriptionID string) PeerExpressRouteCircuitConnectionsClient { 43 return PeerExpressRouteCircuitConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// Get gets the specified Peer Express Route Circuit Connection from the specified express route circuit. 47// Parameters: 48// resourceGroupName - the name of the resource group. 49// circuitName - the name of the express route circuit. 50// peeringName - the name of the peering. 51// connectionName - the name of the peer express route circuit connection. 52func (client PeerExpressRouteCircuitConnectionsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (result PeerExpressRouteCircuitConnection, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/PeerExpressRouteCircuitConnectionsClient.Get") 55 defer func() { 56 sc := -1 57 if result.Response.Response != nil { 58 sc = result.Response.Response.StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 req, err := client.GetPreparer(ctx, resourceGroupName, circuitName, peeringName, connectionName) 64 if err != nil { 65 err = autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "Get", nil, "Failure preparing request") 66 return 67 } 68 69 resp, err := client.GetSender(req) 70 if err != nil { 71 result.Response = autorest.Response{Response: resp} 72 err = autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "Get", resp, "Failure sending request") 73 return 74 } 75 76 result, err = client.GetResponder(resp) 77 if err != nil { 78 err = autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "Get", resp, "Failure responding to request") 79 return 80 } 81 82 return 83} 84 85// GetPreparer prepares the Get request. 86func (client PeerExpressRouteCircuitConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (*http.Request, error) { 87 pathParameters := map[string]interface{}{ 88 "circuitName": autorest.Encode("path", circuitName), 89 "connectionName": autorest.Encode("path", connectionName), 90 "peeringName": autorest.Encode("path", peeringName), 91 "resourceGroupName": autorest.Encode("path", resourceGroupName), 92 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 93 } 94 95 const APIVersion = "2019-06-01" 96 queryParameters := map[string]interface{}{ 97 "api-version": APIVersion, 98 } 99 100 preparer := autorest.CreatePreparer( 101 autorest.AsGet(), 102 autorest.WithBaseURL(client.BaseURI), 103 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/peerConnections/{connectionName}", pathParameters), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// GetSender sends the Get request. The method will close the 109// http.Response Body if it receives an error. 110func (client PeerExpressRouteCircuitConnectionsClient) GetSender(req *http.Request) (*http.Response, error) { 111 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 112} 113 114// GetResponder handles the response to the Get request. The method always 115// closes the http.Response Body. 116func (client PeerExpressRouteCircuitConnectionsClient) GetResponder(resp *http.Response) (result PeerExpressRouteCircuitConnection, err error) { 117 err = autorest.Respond( 118 resp, 119 azure.WithErrorUnlessStatusCode(http.StatusOK), 120 autorest.ByUnmarshallingJSON(&result), 121 autorest.ByClosing()) 122 result.Response = autorest.Response{Response: resp} 123 return 124} 125 126// List gets all global reach peer connections associated with a private peering in an express route circuit. 127// Parameters: 128// resourceGroupName - the name of the resource group. 129// circuitName - the name of the circuit. 130// peeringName - the name of the peering. 131func (client PeerExpressRouteCircuitConnectionsClient) List(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result PeerExpressRouteCircuitConnectionListResultPage, err error) { 132 if tracing.IsEnabled() { 133 ctx = tracing.StartSpan(ctx, fqdn+"/PeerExpressRouteCircuitConnectionsClient.List") 134 defer func() { 135 sc := -1 136 if result.percclr.Response.Response != nil { 137 sc = result.percclr.Response.Response.StatusCode 138 } 139 tracing.EndSpan(ctx, sc, err) 140 }() 141 } 142 result.fn = client.listNextResults 143 req, err := client.ListPreparer(ctx, resourceGroupName, circuitName, peeringName) 144 if err != nil { 145 err = autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "List", nil, "Failure preparing request") 146 return 147 } 148 149 resp, err := client.ListSender(req) 150 if err != nil { 151 result.percclr.Response = autorest.Response{Response: resp} 152 err = autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "List", resp, "Failure sending request") 153 return 154 } 155 156 result.percclr, err = client.ListResponder(resp) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "List", resp, "Failure responding to request") 159 return 160 } 161 if result.percclr.hasNextLink() && result.percclr.IsEmpty() { 162 err = result.NextWithContext(ctx) 163 return 164 } 165 166 return 167} 168 169// ListPreparer prepares the List request. 170func (client PeerExpressRouteCircuitConnectionsClient) ListPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (*http.Request, error) { 171 pathParameters := map[string]interface{}{ 172 "circuitName": autorest.Encode("path", circuitName), 173 "peeringName": autorest.Encode("path", peeringName), 174 "resourceGroupName": autorest.Encode("path", resourceGroupName), 175 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 176 } 177 178 const APIVersion = "2019-06-01" 179 queryParameters := map[string]interface{}{ 180 "api-version": APIVersion, 181 } 182 183 preparer := autorest.CreatePreparer( 184 autorest.AsGet(), 185 autorest.WithBaseURL(client.BaseURI), 186 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/peerConnections", pathParameters), 187 autorest.WithQueryParameters(queryParameters)) 188 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 189} 190 191// ListSender sends the List request. The method will close the 192// http.Response Body if it receives an error. 193func (client PeerExpressRouteCircuitConnectionsClient) ListSender(req *http.Request) (*http.Response, error) { 194 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 195} 196 197// ListResponder handles the response to the List request. The method always 198// closes the http.Response Body. 199func (client PeerExpressRouteCircuitConnectionsClient) ListResponder(resp *http.Response) (result PeerExpressRouteCircuitConnectionListResult, err error) { 200 err = autorest.Respond( 201 resp, 202 azure.WithErrorUnlessStatusCode(http.StatusOK), 203 autorest.ByUnmarshallingJSON(&result), 204 autorest.ByClosing()) 205 result.Response = autorest.Response{Response: resp} 206 return 207} 208 209// listNextResults retrieves the next set of results, if any. 210func (client PeerExpressRouteCircuitConnectionsClient) listNextResults(ctx context.Context, lastResults PeerExpressRouteCircuitConnectionListResult) (result PeerExpressRouteCircuitConnectionListResult, err error) { 211 req, err := lastResults.peerExpressRouteCircuitConnectionListResultPreparer(ctx) 212 if err != nil { 213 return result, autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "listNextResults", nil, "Failure preparing next results request") 214 } 215 if req == nil { 216 return 217 } 218 resp, err := client.ListSender(req) 219 if err != nil { 220 result.Response = autorest.Response{Response: resp} 221 return result, autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "listNextResults", resp, "Failure sending next results request") 222 } 223 result, err = client.ListResponder(resp) 224 if err != nil { 225 err = autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "listNextResults", resp, "Failure responding to next results request") 226 } 227 return 228} 229 230// ListComplete enumerates all values, automatically crossing page boundaries as required. 231func (client PeerExpressRouteCircuitConnectionsClient) ListComplete(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result PeerExpressRouteCircuitConnectionListResultIterator, err error) { 232 if tracing.IsEnabled() { 233 ctx = tracing.StartSpan(ctx, fqdn+"/PeerExpressRouteCircuitConnectionsClient.List") 234 defer func() { 235 sc := -1 236 if result.Response().Response.Response != nil { 237 sc = result.page.Response().Response.Response.StatusCode 238 } 239 tracing.EndSpan(ctx, sc, err) 240 }() 241 } 242 result.page, err = client.List(ctx, resourceGroupName, circuitName, peeringName) 243 return 244} 245