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.
40func NewExpressRouteCircuitConnectionsClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteCircuitConnectionsClient {
41	return ExpressRouteCircuitConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate creates or updates a Express Route Circuit Connection in the specified express route circuits.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// circuitName - the name of the express route circuit.
48// peeringName - the name of the peering.
49// connectionName - the name of the express route circuit connection.
50// expressRouteCircuitConnectionParameters - parameters supplied to the create or update express route circuit
51// connection operation.
52func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, expressRouteCircuitConnectionParameters ExpressRouteCircuitConnection) (result ExpressRouteCircuitConnectionsCreateOrUpdateFuture, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitConnectionsClient.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, resourceGroupName, circuitName, peeringName, connectionName, expressRouteCircuitConnectionParameters)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
66		return
67	}
68
69	result, err = client.CreateOrUpdateSender(req)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
72		return
73	}
74
75	return
76}
77
78// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
79func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, expressRouteCircuitConnectionParameters ExpressRouteCircuitConnection) (*http.Request, error) {
80	pathParameters := map[string]interface{}{
81		"circuitName":       autorest.Encode("path", circuitName),
82		"connectionName":    autorest.Encode("path", connectionName),
83		"peeringName":       autorest.Encode("path", peeringName),
84		"resourceGroupName": autorest.Encode("path", resourceGroupName),
85		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
86	}
87
88	const APIVersion = "2019-07-01"
89	queryParameters := map[string]interface{}{
90		"api-version": APIVersion,
91	}
92
93	expressRouteCircuitConnectionParameters.Etag = nil
94	expressRouteCircuitConnectionParameters.Type = nil
95	preparer := autorest.CreatePreparer(
96		autorest.AsContentType("application/json; charset=utf-8"),
97		autorest.AsPut(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}", pathParameters),
100		autorest.WithJSON(expressRouteCircuitConnectionParameters),
101		autorest.WithQueryParameters(queryParameters))
102	return preparer.Prepare((&http.Request{}).WithContext(ctx))
103}
104
105// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
106// http.Response Body if it receives an error.
107func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteCircuitConnectionsCreateOrUpdateFuture, err error) {
108	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
109	var resp *http.Response
110	resp, err = autorest.SendWithSender(client, req, sd...)
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 = "2019-07-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	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
190	var resp *http.Response
191	resp, err = autorest.SendWithSender(client, req, sd...)
192	if err != nil {
193		return
194	}
195	future.Future, err = azure.NewFutureFromResponse(resp)
196	return
197}
198
199// DeleteResponder handles the response to the Delete request. The method always
200// closes the http.Response Body.
201func (client ExpressRouteCircuitConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
202	err = autorest.Respond(
203		resp,
204		client.ByInspecting(),
205		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
206		autorest.ByClosing())
207	result.Response = resp
208	return
209}
210
211// Get gets the specified Express Route Circuit Connection from the specified express route circuit.
212// Parameters:
213// resourceGroupName - the name of the resource group.
214// circuitName - the name of the express route circuit.
215// peeringName - the name of the peering.
216// connectionName - the name of the express route circuit connection.
217func (client ExpressRouteCircuitConnectionsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (result ExpressRouteCircuitConnection, err error) {
218	if tracing.IsEnabled() {
219		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitConnectionsClient.Get")
220		defer func() {
221			sc := -1
222			if result.Response.Response != nil {
223				sc = result.Response.Response.StatusCode
224			}
225			tracing.EndSpan(ctx, sc, err)
226		}()
227	}
228	req, err := client.GetPreparer(ctx, resourceGroupName, circuitName, peeringName, connectionName)
229	if err != nil {
230		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", nil, "Failure preparing request")
231		return
232	}
233
234	resp, err := client.GetSender(req)
235	if err != nil {
236		result.Response = autorest.Response{Response: resp}
237		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", resp, "Failure sending request")
238		return
239	}
240
241	result, err = client.GetResponder(resp)
242	if err != nil {
243		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", resp, "Failure responding to request")
244	}
245
246	return
247}
248
249// GetPreparer prepares the Get request.
250func (client ExpressRouteCircuitConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (*http.Request, error) {
251	pathParameters := map[string]interface{}{
252		"circuitName":       autorest.Encode("path", circuitName),
253		"connectionName":    autorest.Encode("path", connectionName),
254		"peeringName":       autorest.Encode("path", peeringName),
255		"resourceGroupName": autorest.Encode("path", resourceGroupName),
256		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
257	}
258
259	const APIVersion = "2019-07-01"
260	queryParameters := map[string]interface{}{
261		"api-version": APIVersion,
262	}
263
264	preparer := autorest.CreatePreparer(
265		autorest.AsGet(),
266		autorest.WithBaseURL(client.BaseURI),
267		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}", pathParameters),
268		autorest.WithQueryParameters(queryParameters))
269	return preparer.Prepare((&http.Request{}).WithContext(ctx))
270}
271
272// GetSender sends the Get request. The method will close the
273// http.Response Body if it receives an error.
274func (client ExpressRouteCircuitConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
275	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
276	return autorest.SendWithSender(client, req, sd...)
277}
278
279// GetResponder handles the response to the Get request. The method always
280// closes the http.Response Body.
281func (client ExpressRouteCircuitConnectionsClient) GetResponder(resp *http.Response) (result ExpressRouteCircuitConnection, err error) {
282	err = autorest.Respond(
283		resp,
284		client.ByInspecting(),
285		azure.WithErrorUnlessStatusCode(http.StatusOK),
286		autorest.ByUnmarshallingJSON(&result),
287		autorest.ByClosing())
288	result.Response = autorest.Response{Response: resp}
289	return
290}
291
292// List gets all global reach connections associated with a private peering in an express route circuit.
293// Parameters:
294// resourceGroupName - the name of the resource group.
295// circuitName - the name of the circuit.
296// peeringName - the name of the peering.
297func (client ExpressRouteCircuitConnectionsClient) List(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result ExpressRouteCircuitConnectionListResultPage, err error) {
298	if tracing.IsEnabled() {
299		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitConnectionsClient.List")
300		defer func() {
301			sc := -1
302			if result.ercclr.Response.Response != nil {
303				sc = result.ercclr.Response.Response.StatusCode
304			}
305			tracing.EndSpan(ctx, sc, err)
306		}()
307	}
308	result.fn = client.listNextResults
309	req, err := client.ListPreparer(ctx, resourceGroupName, circuitName, peeringName)
310	if err != nil {
311		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "List", nil, "Failure preparing request")
312		return
313	}
314
315	resp, err := client.ListSender(req)
316	if err != nil {
317		result.ercclr.Response = autorest.Response{Response: resp}
318		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "List", resp, "Failure sending request")
319		return
320	}
321
322	result.ercclr, err = client.ListResponder(resp)
323	if err != nil {
324		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "List", resp, "Failure responding to request")
325	}
326
327	return
328}
329
330// ListPreparer prepares the List request.
331func (client ExpressRouteCircuitConnectionsClient) ListPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (*http.Request, error) {
332	pathParameters := map[string]interface{}{
333		"circuitName":       autorest.Encode("path", circuitName),
334		"peeringName":       autorest.Encode("path", peeringName),
335		"resourceGroupName": autorest.Encode("path", resourceGroupName),
336		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
337	}
338
339	const APIVersion = "2019-07-01"
340	queryParameters := map[string]interface{}{
341		"api-version": APIVersion,
342	}
343
344	preparer := autorest.CreatePreparer(
345		autorest.AsGet(),
346		autorest.WithBaseURL(client.BaseURI),
347		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections", pathParameters),
348		autorest.WithQueryParameters(queryParameters))
349	return preparer.Prepare((&http.Request{}).WithContext(ctx))
350}
351
352// ListSender sends the List request. The method will close the
353// http.Response Body if it receives an error.
354func (client ExpressRouteCircuitConnectionsClient) ListSender(req *http.Request) (*http.Response, error) {
355	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
356	return autorest.SendWithSender(client, req, sd...)
357}
358
359// ListResponder handles the response to the List request. The method always
360// closes the http.Response Body.
361func (client ExpressRouteCircuitConnectionsClient) ListResponder(resp *http.Response) (result ExpressRouteCircuitConnectionListResult, err error) {
362	err = autorest.Respond(
363		resp,
364		client.ByInspecting(),
365		azure.WithErrorUnlessStatusCode(http.StatusOK),
366		autorest.ByUnmarshallingJSON(&result),
367		autorest.ByClosing())
368	result.Response = autorest.Response{Response: resp}
369	return
370}
371
372// listNextResults retrieves the next set of results, if any.
373func (client ExpressRouteCircuitConnectionsClient) listNextResults(ctx context.Context, lastResults ExpressRouteCircuitConnectionListResult) (result ExpressRouteCircuitConnectionListResult, err error) {
374	req, err := lastResults.expressRouteCircuitConnectionListResultPreparer(ctx)
375	if err != nil {
376		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "listNextResults", nil, "Failure preparing next results request")
377	}
378	if req == nil {
379		return
380	}
381	resp, err := client.ListSender(req)
382	if err != nil {
383		result.Response = autorest.Response{Response: resp}
384		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "listNextResults", resp, "Failure sending next results request")
385	}
386	result, err = client.ListResponder(resp)
387	if err != nil {
388		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "listNextResults", resp, "Failure responding to next results request")
389	}
390	return
391}
392
393// ListComplete enumerates all values, automatically crossing page boundaries as required.
394func (client ExpressRouteCircuitConnectionsClient) ListComplete(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result ExpressRouteCircuitConnectionListResultIterator, err error) {
395	if tracing.IsEnabled() {
396		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitConnectionsClient.List")
397		defer func() {
398			sc := -1
399			if result.Response().Response.Response != nil {
400				sc = result.page.Response().Response.Response.StatusCode
401			}
402			tracing.EndSpan(ctx, sc, err)
403		}()
404	}
405	result.page, err = client.List(ctx, resourceGroupName, circuitName, peeringName)
406	return
407}
408