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	}
80
81	return
82}
83
84// GetPreparer prepares the Get request.
85func (client PeerExpressRouteCircuitConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (*http.Request, error) {
86	pathParameters := map[string]interface{}{
87		"circuitName":       autorest.Encode("path", circuitName),
88		"connectionName":    autorest.Encode("path", connectionName),
89		"peeringName":       autorest.Encode("path", peeringName),
90		"resourceGroupName": autorest.Encode("path", resourceGroupName),
91		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
92	}
93
94	const APIVersion = "2020-05-01"
95	queryParameters := map[string]interface{}{
96		"api-version": APIVersion,
97	}
98
99	preparer := autorest.CreatePreparer(
100		autorest.AsGet(),
101		autorest.WithBaseURL(client.BaseURI),
102		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/peerConnections/{connectionName}", pathParameters),
103		autorest.WithQueryParameters(queryParameters))
104	return preparer.Prepare((&http.Request{}).WithContext(ctx))
105}
106
107// GetSender sends the Get request. The method will close the
108// http.Response Body if it receives an error.
109func (client PeerExpressRouteCircuitConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
110	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
111}
112
113// GetResponder handles the response to the Get request. The method always
114// closes the http.Response Body.
115func (client PeerExpressRouteCircuitConnectionsClient) GetResponder(resp *http.Response) (result PeerExpressRouteCircuitConnection, err error) {
116	err = autorest.Respond(
117		resp,
118		client.ByInspecting(),
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	}
160
161	return
162}
163
164// ListPreparer prepares the List request.
165func (client PeerExpressRouteCircuitConnectionsClient) ListPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (*http.Request, error) {
166	pathParameters := map[string]interface{}{
167		"circuitName":       autorest.Encode("path", circuitName),
168		"peeringName":       autorest.Encode("path", peeringName),
169		"resourceGroupName": autorest.Encode("path", resourceGroupName),
170		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
171	}
172
173	const APIVersion = "2020-05-01"
174	queryParameters := map[string]interface{}{
175		"api-version": APIVersion,
176	}
177
178	preparer := autorest.CreatePreparer(
179		autorest.AsGet(),
180		autorest.WithBaseURL(client.BaseURI),
181		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/peerConnections", pathParameters),
182		autorest.WithQueryParameters(queryParameters))
183	return preparer.Prepare((&http.Request{}).WithContext(ctx))
184}
185
186// ListSender sends the List request. The method will close the
187// http.Response Body if it receives an error.
188func (client PeerExpressRouteCircuitConnectionsClient) ListSender(req *http.Request) (*http.Response, error) {
189	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
190}
191
192// ListResponder handles the response to the List request. The method always
193// closes the http.Response Body.
194func (client PeerExpressRouteCircuitConnectionsClient) ListResponder(resp *http.Response) (result PeerExpressRouteCircuitConnectionListResult, err error) {
195	err = autorest.Respond(
196		resp,
197		client.ByInspecting(),
198		azure.WithErrorUnlessStatusCode(http.StatusOK),
199		autorest.ByUnmarshallingJSON(&result),
200		autorest.ByClosing())
201	result.Response = autorest.Response{Response: resp}
202	return
203}
204
205// listNextResults retrieves the next set of results, if any.
206func (client PeerExpressRouteCircuitConnectionsClient) listNextResults(ctx context.Context, lastResults PeerExpressRouteCircuitConnectionListResult) (result PeerExpressRouteCircuitConnectionListResult, err error) {
207	req, err := lastResults.peerExpressRouteCircuitConnectionListResultPreparer(ctx)
208	if err != nil {
209		return result, autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "listNextResults", nil, "Failure preparing next results request")
210	}
211	if req == nil {
212		return
213	}
214	resp, err := client.ListSender(req)
215	if err != nil {
216		result.Response = autorest.Response{Response: resp}
217		return result, autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "listNextResults", resp, "Failure sending next results request")
218	}
219	result, err = client.ListResponder(resp)
220	if err != nil {
221		err = autorest.NewErrorWithError(err, "network.PeerExpressRouteCircuitConnectionsClient", "listNextResults", resp, "Failure responding to next results request")
222	}
223	return
224}
225
226// ListComplete enumerates all values, automatically crossing page boundaries as required.
227func (client PeerExpressRouteCircuitConnectionsClient) ListComplete(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result PeerExpressRouteCircuitConnectionListResultIterator, err error) {
228	if tracing.IsEnabled() {
229		ctx = tracing.StartSpan(ctx, fqdn+"/PeerExpressRouteCircuitConnectionsClient.List")
230		defer func() {
231			sc := -1
232			if result.Response().Response.Response != nil {
233				sc = result.page.Response().Response.Response.StatusCode
234			}
235			tracing.EndSpan(ctx, sc, err)
236		}()
237	}
238	result.page, err = client.List(ctx, resourceGroupName, circuitName, peeringName)
239	return
240}
241