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// ExpressRouteCircuitConnectionsClient is the network Client
29type ExpressRouteCircuitConnectionsClient struct {
30	BaseClient
31}
32
33// NewExpressRouteCircuitConnectionsClient creates an instance of the ExpressRouteCircuitConnectionsClient client.
34func NewExpressRouteCircuitConnectionsClient(subscriptionID string) ExpressRouteCircuitConnectionsClient {
35	return NewExpressRouteCircuitConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewExpressRouteCircuitConnectionsClientWithBaseURI creates an instance of the ExpressRouteCircuitConnectionsClient
39// client using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI
40// (sovereign clouds, Azure stack).
41func NewExpressRouteCircuitConnectionsClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteCircuitConnectionsClient {
42	return ExpressRouteCircuitConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// CreateOrUpdate creates or updates a Express Route Circuit Connection in the specified express route circuits.
46// Parameters:
47// resourceGroupName - the name of the resource group.
48// circuitName - the name of the express route circuit.
49// peeringName - the name of the peering.
50// connectionName - the name of the express route circuit connection.
51// expressRouteCircuitConnectionParameters - parameters supplied to the create or update express route circuit
52// connection operation.
53func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, expressRouteCircuitConnectionParameters ExpressRouteCircuitConnection) (result ExpressRouteCircuitConnectionsCreateOrUpdateFuture, err error) {
54	if tracing.IsEnabled() {
55		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitConnectionsClient.CreateOrUpdate")
56		defer func() {
57			sc := -1
58			if result.Response() != nil {
59				sc = result.Response().StatusCode
60			}
61			tracing.EndSpan(ctx, sc, err)
62		}()
63	}
64	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, circuitName, peeringName, connectionName, expressRouteCircuitConnectionParameters)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
67		return
68	}
69
70	result, err = client.CreateOrUpdateSender(req)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
73		return
74	}
75
76	return
77}
78
79// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
80func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, expressRouteCircuitConnectionParameters ExpressRouteCircuitConnection) (*http.Request, error) {
81	pathParameters := map[string]interface{}{
82		"circuitName":       autorest.Encode("path", circuitName),
83		"connectionName":    autorest.Encode("path", connectionName),
84		"peeringName":       autorest.Encode("path", peeringName),
85		"resourceGroupName": autorest.Encode("path", resourceGroupName),
86		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
87	}
88
89	const APIVersion = "2020-04-01"
90	queryParameters := map[string]interface{}{
91		"api-version": APIVersion,
92	}
93
94	expressRouteCircuitConnectionParameters.Etag = nil
95	expressRouteCircuitConnectionParameters.Type = nil
96	preparer := autorest.CreatePreparer(
97		autorest.AsContentType("application/json; charset=utf-8"),
98		autorest.AsPut(),
99		autorest.WithBaseURL(client.BaseURI),
100		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}", pathParameters),
101		autorest.WithJSON(expressRouteCircuitConnectionParameters),
102		autorest.WithQueryParameters(queryParameters))
103	return preparer.Prepare((&http.Request{}).WithContext(ctx))
104}
105
106// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
107// http.Response Body if it receives an error.
108func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteCircuitConnectionsCreateOrUpdateFuture, err error) {
109	var resp *http.Response
110	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
111	if err != nil {
112		return
113	}
114	future.Future, err = azure.NewFutureFromResponse(resp)
115	return
116}
117
118// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
119// closes the http.Response Body.
120func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteCircuitConnection, err error) {
121	err = autorest.Respond(
122		resp,
123		client.ByInspecting(),
124		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
125		autorest.ByUnmarshallingJSON(&result),
126		autorest.ByClosing())
127	result.Response = autorest.Response{Response: resp}
128	return
129}
130
131// Delete deletes the specified Express Route Circuit Connection from the specified express route circuit.
132// Parameters:
133// resourceGroupName - the name of the resource group.
134// circuitName - the name of the express route circuit.
135// peeringName - the name of the peering.
136// connectionName - the name of the express route circuit connection.
137func (client ExpressRouteCircuitConnectionsClient) Delete(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (result ExpressRouteCircuitConnectionsDeleteFuture, err error) {
138	if tracing.IsEnabled() {
139		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitConnectionsClient.Delete")
140		defer func() {
141			sc := -1
142			if result.Response() != nil {
143				sc = result.Response().StatusCode
144			}
145			tracing.EndSpan(ctx, sc, err)
146		}()
147	}
148	req, err := client.DeletePreparer(ctx, resourceGroupName, circuitName, peeringName, connectionName)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Delete", nil, "Failure preparing request")
151		return
152	}
153
154	result, err = client.DeleteSender(req)
155	if err != nil {
156		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Delete", result.Response(), "Failure sending request")
157		return
158	}
159
160	return
161}
162
163// DeletePreparer prepares the Delete request.
164func (client ExpressRouteCircuitConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (*http.Request, error) {
165	pathParameters := map[string]interface{}{
166		"circuitName":       autorest.Encode("path", circuitName),
167		"connectionName":    autorest.Encode("path", connectionName),
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-04-01"
174	queryParameters := map[string]interface{}{
175		"api-version": APIVersion,
176	}
177
178	preparer := autorest.CreatePreparer(
179		autorest.AsDelete(),
180		autorest.WithBaseURL(client.BaseURI),
181		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}", pathParameters),
182		autorest.WithQueryParameters(queryParameters))
183	return preparer.Prepare((&http.Request{}).WithContext(ctx))
184}
185
186// DeleteSender sends the Delete request. The method will close the
187// http.Response Body if it receives an error.
188func (client ExpressRouteCircuitConnectionsClient) DeleteSender(req *http.Request) (future ExpressRouteCircuitConnectionsDeleteFuture, err error) {
189	var resp *http.Response
190	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
191	if err != nil {
192		return
193	}
194	future.Future, err = azure.NewFutureFromResponse(resp)
195	return
196}
197
198// DeleteResponder handles the response to the Delete request. The method always
199// closes the http.Response Body.
200func (client ExpressRouteCircuitConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
201	err = autorest.Respond(
202		resp,
203		client.ByInspecting(),
204		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
205		autorest.ByClosing())
206	result.Response = resp
207	return
208}
209
210// Get gets the specified Express Route Circuit Connection from the specified express route circuit.
211// Parameters:
212// resourceGroupName - the name of the resource group.
213// circuitName - the name of the express route circuit.
214// peeringName - the name of the peering.
215// connectionName - the name of the express route circuit connection.
216func (client ExpressRouteCircuitConnectionsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (result ExpressRouteCircuitConnection, err error) {
217	if tracing.IsEnabled() {
218		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitConnectionsClient.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	req, err := client.GetPreparer(ctx, resourceGroupName, circuitName, peeringName, connectionName)
228	if err != nil {
229		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", nil, "Failure preparing request")
230		return
231	}
232
233	resp, err := client.GetSender(req)
234	if err != nil {
235		result.Response = autorest.Response{Response: resp}
236		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", resp, "Failure sending request")
237		return
238	}
239
240	result, err = client.GetResponder(resp)
241	if err != nil {
242		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", resp, "Failure responding to request")
243	}
244
245	return
246}
247
248// GetPreparer prepares the Get request.
249func (client ExpressRouteCircuitConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (*http.Request, error) {
250	pathParameters := map[string]interface{}{
251		"circuitName":       autorest.Encode("path", circuitName),
252		"connectionName":    autorest.Encode("path", connectionName),
253		"peeringName":       autorest.Encode("path", peeringName),
254		"resourceGroupName": autorest.Encode("path", resourceGroupName),
255		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
256	}
257
258	const APIVersion = "2020-04-01"
259	queryParameters := map[string]interface{}{
260		"api-version": APIVersion,
261	}
262
263	preparer := autorest.CreatePreparer(
264		autorest.AsGet(),
265		autorest.WithBaseURL(client.BaseURI),
266		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}", pathParameters),
267		autorest.WithQueryParameters(queryParameters))
268	return preparer.Prepare((&http.Request{}).WithContext(ctx))
269}
270
271// GetSender sends the Get request. The method will close the
272// http.Response Body if it receives an error.
273func (client ExpressRouteCircuitConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
274	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
275}
276
277// GetResponder handles the response to the Get request. The method always
278// closes the http.Response Body.
279func (client ExpressRouteCircuitConnectionsClient) GetResponder(resp *http.Response) (result ExpressRouteCircuitConnection, err error) {
280	err = autorest.Respond(
281		resp,
282		client.ByInspecting(),
283		azure.WithErrorUnlessStatusCode(http.StatusOK),
284		autorest.ByUnmarshallingJSON(&result),
285		autorest.ByClosing())
286	result.Response = autorest.Response{Response: resp}
287	return
288}
289
290// List gets all global reach connections associated with a private peering in an express route circuit.
291// Parameters:
292// resourceGroupName - the name of the resource group.
293// circuitName - the name of the circuit.
294// peeringName - the name of the peering.
295func (client ExpressRouteCircuitConnectionsClient) List(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result ExpressRouteCircuitConnectionListResultPage, err error) {
296	if tracing.IsEnabled() {
297		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitConnectionsClient.List")
298		defer func() {
299			sc := -1
300			if result.ercclr.Response.Response != nil {
301				sc = result.ercclr.Response.Response.StatusCode
302			}
303			tracing.EndSpan(ctx, sc, err)
304		}()
305	}
306	result.fn = client.listNextResults
307	req, err := client.ListPreparer(ctx, resourceGroupName, circuitName, peeringName)
308	if err != nil {
309		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "List", nil, "Failure preparing request")
310		return
311	}
312
313	resp, err := client.ListSender(req)
314	if err != nil {
315		result.ercclr.Response = autorest.Response{Response: resp}
316		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "List", resp, "Failure sending request")
317		return
318	}
319
320	result.ercclr, err = client.ListResponder(resp)
321	if err != nil {
322		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "List", resp, "Failure responding to request")
323	}
324
325	return
326}
327
328// ListPreparer prepares the List request.
329func (client ExpressRouteCircuitConnectionsClient) ListPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (*http.Request, error) {
330	pathParameters := map[string]interface{}{
331		"circuitName":       autorest.Encode("path", circuitName),
332		"peeringName":       autorest.Encode("path", peeringName),
333		"resourceGroupName": autorest.Encode("path", resourceGroupName),
334		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
335	}
336
337	const APIVersion = "2020-04-01"
338	queryParameters := map[string]interface{}{
339		"api-version": APIVersion,
340	}
341
342	preparer := autorest.CreatePreparer(
343		autorest.AsGet(),
344		autorest.WithBaseURL(client.BaseURI),
345		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections", pathParameters),
346		autorest.WithQueryParameters(queryParameters))
347	return preparer.Prepare((&http.Request{}).WithContext(ctx))
348}
349
350// ListSender sends the List request. The method will close the
351// http.Response Body if it receives an error.
352func (client ExpressRouteCircuitConnectionsClient) ListSender(req *http.Request) (*http.Response, error) {
353	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
354}
355
356// ListResponder handles the response to the List request. The method always
357// closes the http.Response Body.
358func (client ExpressRouteCircuitConnectionsClient) ListResponder(resp *http.Response) (result ExpressRouteCircuitConnectionListResult, err error) {
359	err = autorest.Respond(
360		resp,
361		client.ByInspecting(),
362		azure.WithErrorUnlessStatusCode(http.StatusOK),
363		autorest.ByUnmarshallingJSON(&result),
364		autorest.ByClosing())
365	result.Response = autorest.Response{Response: resp}
366	return
367}
368
369// listNextResults retrieves the next set of results, if any.
370func (client ExpressRouteCircuitConnectionsClient) listNextResults(ctx context.Context, lastResults ExpressRouteCircuitConnectionListResult) (result ExpressRouteCircuitConnectionListResult, err error) {
371	req, err := lastResults.expressRouteCircuitConnectionListResultPreparer(ctx)
372	if err != nil {
373		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "listNextResults", nil, "Failure preparing next results request")
374	}
375	if req == nil {
376		return
377	}
378	resp, err := client.ListSender(req)
379	if err != nil {
380		result.Response = autorest.Response{Response: resp}
381		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "listNextResults", resp, "Failure sending next results request")
382	}
383	result, err = client.ListResponder(resp)
384	if err != nil {
385		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "listNextResults", resp, "Failure responding to next results request")
386	}
387	return
388}
389
390// ListComplete enumerates all values, automatically crossing page boundaries as required.
391func (client ExpressRouteCircuitConnectionsClient) ListComplete(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result ExpressRouteCircuitConnectionListResultIterator, err error) {
392	if tracing.IsEnabled() {
393		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitConnectionsClient.List")
394		defer func() {
395			sc := -1
396			if result.Response().Response.Response != nil {
397				sc = result.page.Response().Response.Response.StatusCode
398			}
399			tracing.EndSpan(ctx, sc, err)
400		}()
401	}
402	result.page, err = client.List(ctx, resourceGroupName, circuitName, peeringName)
403	return
404}
405