1package network
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// ExpressRouteCircuitPeeringsClient is the network Client
19type ExpressRouteCircuitPeeringsClient struct {
20	BaseClient
21}
22
23// NewExpressRouteCircuitPeeringsClient creates an instance of the ExpressRouteCircuitPeeringsClient client.
24func NewExpressRouteCircuitPeeringsClient(subscriptionID string) ExpressRouteCircuitPeeringsClient {
25	return NewExpressRouteCircuitPeeringsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewExpressRouteCircuitPeeringsClientWithBaseURI creates an instance of the ExpressRouteCircuitPeeringsClient client
29// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
30// clouds, Azure stack).
31func NewExpressRouteCircuitPeeringsClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteCircuitPeeringsClient {
32	return ExpressRouteCircuitPeeringsClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// CreateOrUpdate creates or updates a peering in the specified express route circuits.
36// Parameters:
37// resourceGroupName - the name of the resource group.
38// circuitName - the name of the express route circuit.
39// peeringName - the name of the peering.
40// peeringParameters - parameters supplied to the create or update express route circuit peering operation.
41func (client ExpressRouteCircuitPeeringsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, peeringParameters ExpressRouteCircuitPeering) (result ExpressRouteCircuitPeeringsCreateOrUpdateFuture, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.CreateOrUpdate")
44		defer func() {
45			sc := -1
46			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
47				sc = result.FutureAPI.Response().StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: peeringParameters,
54			Constraints: []validation.Constraint{{Target: "peeringParameters.ExpressRouteCircuitPeeringPropertiesFormat", Name: validation.Null, Rule: false,
55				Chain: []validation.Constraint{{Target: "peeringParameters.ExpressRouteCircuitPeeringPropertiesFormat.PeerASN", Name: validation.Null, Rule: false,
56					Chain: []validation.Constraint{{Target: "peeringParameters.ExpressRouteCircuitPeeringPropertiesFormat.PeerASN", Name: validation.InclusiveMaximum, Rule: int64(4294967295), Chain: nil},
57						{Target: "peeringParameters.ExpressRouteCircuitPeeringPropertiesFormat.PeerASN", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
58					}},
59				}}}}}); err != nil {
60		return result, validation.NewError("network.ExpressRouteCircuitPeeringsClient", "CreateOrUpdate", err.Error())
61	}
62
63	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, circuitName, peeringName, peeringParameters)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "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.ExpressRouteCircuitPeeringsClient", "CreateOrUpdate", nil, "Failure sending request")
72		return
73	}
74
75	return
76}
77
78// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
79func (client ExpressRouteCircuitPeeringsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, peeringParameters ExpressRouteCircuitPeering) (*http.Request, error) {
80	pathParameters := map[string]interface{}{
81		"circuitName":       autorest.Encode("path", circuitName),
82		"peeringName":       autorest.Encode("path", peeringName),
83		"resourceGroupName": autorest.Encode("path", resourceGroupName),
84		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
85	}
86
87	const APIVersion = "2017-10-01"
88	queryParameters := map[string]interface{}{
89		"api-version": APIVersion,
90	}
91
92	peeringParameters.Etag = nil
93	preparer := autorest.CreatePreparer(
94		autorest.AsContentType("application/json; charset=utf-8"),
95		autorest.AsPut(),
96		autorest.WithBaseURL(client.BaseURI),
97		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}", pathParameters),
98		autorest.WithJSON(peeringParameters),
99		autorest.WithQueryParameters(queryParameters))
100	return preparer.Prepare((&http.Request{}).WithContext(ctx))
101}
102
103// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
104// http.Response Body if it receives an error.
105func (client ExpressRouteCircuitPeeringsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteCircuitPeeringsCreateOrUpdateFuture, err error) {
106	var resp *http.Response
107	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
108	if err != nil {
109		return
110	}
111	var azf azure.Future
112	azf, err = azure.NewFutureFromResponse(resp)
113	future.FutureAPI = &azf
114	future.Result = future.result
115	return
116}
117
118// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
119// closes the http.Response Body.
120func (client ExpressRouteCircuitPeeringsClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteCircuitPeering, err error) {
121	err = autorest.Respond(
122		resp,
123		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
124		autorest.ByUnmarshallingJSON(&result),
125		autorest.ByClosing())
126	result.Response = autorest.Response{Response: resp}
127	return
128}
129
130// Delete deletes the specified peering from the specified express route circuit.
131// Parameters:
132// resourceGroupName - the name of the resource group.
133// circuitName - the name of the express route circuit.
134// peeringName - the name of the peering.
135func (client ExpressRouteCircuitPeeringsClient) Delete(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result ExpressRouteCircuitPeeringsDeleteFuture, err error) {
136	if tracing.IsEnabled() {
137		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.Delete")
138		defer func() {
139			sc := -1
140			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
141				sc = result.FutureAPI.Response().StatusCode
142			}
143			tracing.EndSpan(ctx, sc, err)
144		}()
145	}
146	req, err := client.DeletePreparer(ctx, resourceGroupName, circuitName, peeringName)
147	if err != nil {
148		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Delete", nil, "Failure preparing request")
149		return
150	}
151
152	result, err = client.DeleteSender(req)
153	if err != nil {
154		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Delete", nil, "Failure sending request")
155		return
156	}
157
158	return
159}
160
161// DeletePreparer prepares the Delete request.
162func (client ExpressRouteCircuitPeeringsClient) DeletePreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (*http.Request, error) {
163	pathParameters := map[string]interface{}{
164		"circuitName":       autorest.Encode("path", circuitName),
165		"peeringName":       autorest.Encode("path", peeringName),
166		"resourceGroupName": autorest.Encode("path", resourceGroupName),
167		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
168	}
169
170	const APIVersion = "2017-10-01"
171	queryParameters := map[string]interface{}{
172		"api-version": APIVersion,
173	}
174
175	preparer := autorest.CreatePreparer(
176		autorest.AsDelete(),
177		autorest.WithBaseURL(client.BaseURI),
178		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}", pathParameters),
179		autorest.WithQueryParameters(queryParameters))
180	return preparer.Prepare((&http.Request{}).WithContext(ctx))
181}
182
183// DeleteSender sends the Delete request. The method will close the
184// http.Response Body if it receives an error.
185func (client ExpressRouteCircuitPeeringsClient) DeleteSender(req *http.Request) (future ExpressRouteCircuitPeeringsDeleteFuture, err error) {
186	var resp *http.Response
187	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
188	if err != nil {
189		return
190	}
191	var azf azure.Future
192	azf, err = azure.NewFutureFromResponse(resp)
193	future.FutureAPI = &azf
194	future.Result = future.result
195	return
196}
197
198// DeleteResponder handles the response to the Delete request. The method always
199// closes the http.Response Body.
200func (client ExpressRouteCircuitPeeringsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
201	err = autorest.Respond(
202		resp,
203		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
204		autorest.ByClosing())
205	result.Response = resp
206	return
207}
208
209// Get gets the specified authorization from the specified express route circuit.
210// Parameters:
211// resourceGroupName - the name of the resource group.
212// circuitName - the name of the express route circuit.
213// peeringName - the name of the peering.
214func (client ExpressRouteCircuitPeeringsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result ExpressRouteCircuitPeering, err error) {
215	if tracing.IsEnabled() {
216		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.Get")
217		defer func() {
218			sc := -1
219			if result.Response.Response != nil {
220				sc = result.Response.Response.StatusCode
221			}
222			tracing.EndSpan(ctx, sc, err)
223		}()
224	}
225	req, err := client.GetPreparer(ctx, resourceGroupName, circuitName, peeringName)
226	if err != nil {
227		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Get", nil, "Failure preparing request")
228		return
229	}
230
231	resp, err := client.GetSender(req)
232	if err != nil {
233		result.Response = autorest.Response{Response: resp}
234		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Get", resp, "Failure sending request")
235		return
236	}
237
238	result, err = client.GetResponder(resp)
239	if err != nil {
240		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Get", resp, "Failure responding to request")
241		return
242	}
243
244	return
245}
246
247// GetPreparer prepares the Get request.
248func (client ExpressRouteCircuitPeeringsClient) GetPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (*http.Request, error) {
249	pathParameters := map[string]interface{}{
250		"circuitName":       autorest.Encode("path", circuitName),
251		"peeringName":       autorest.Encode("path", peeringName),
252		"resourceGroupName": autorest.Encode("path", resourceGroupName),
253		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
254	}
255
256	const APIVersion = "2017-10-01"
257	queryParameters := map[string]interface{}{
258		"api-version": APIVersion,
259	}
260
261	preparer := autorest.CreatePreparer(
262		autorest.AsGet(),
263		autorest.WithBaseURL(client.BaseURI),
264		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}", pathParameters),
265		autorest.WithQueryParameters(queryParameters))
266	return preparer.Prepare((&http.Request{}).WithContext(ctx))
267}
268
269// GetSender sends the Get request. The method will close the
270// http.Response Body if it receives an error.
271func (client ExpressRouteCircuitPeeringsClient) GetSender(req *http.Request) (*http.Response, error) {
272	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
273}
274
275// GetResponder handles the response to the Get request. The method always
276// closes the http.Response Body.
277func (client ExpressRouteCircuitPeeringsClient) GetResponder(resp *http.Response) (result ExpressRouteCircuitPeering, err error) {
278	err = autorest.Respond(
279		resp,
280		azure.WithErrorUnlessStatusCode(http.StatusOK),
281		autorest.ByUnmarshallingJSON(&result),
282		autorest.ByClosing())
283	result.Response = autorest.Response{Response: resp}
284	return
285}
286
287// List gets all peerings in a specified express route circuit.
288// Parameters:
289// resourceGroupName - the name of the resource group.
290// circuitName - the name of the express route circuit.
291func (client ExpressRouteCircuitPeeringsClient) List(ctx context.Context, resourceGroupName string, circuitName string) (result ExpressRouteCircuitPeeringListResultPage, err error) {
292	if tracing.IsEnabled() {
293		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.List")
294		defer func() {
295			sc := -1
296			if result.ercplr.Response.Response != nil {
297				sc = result.ercplr.Response.Response.StatusCode
298			}
299			tracing.EndSpan(ctx, sc, err)
300		}()
301	}
302	result.fn = client.listNextResults
303	req, err := client.ListPreparer(ctx, resourceGroupName, circuitName)
304	if err != nil {
305		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", nil, "Failure preparing request")
306		return
307	}
308
309	resp, err := client.ListSender(req)
310	if err != nil {
311		result.ercplr.Response = autorest.Response{Response: resp}
312		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", resp, "Failure sending request")
313		return
314	}
315
316	result.ercplr, err = client.ListResponder(resp)
317	if err != nil {
318		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", resp, "Failure responding to request")
319		return
320	}
321	if result.ercplr.hasNextLink() && result.ercplr.IsEmpty() {
322		err = result.NextWithContext(ctx)
323		return
324	}
325
326	return
327}
328
329// ListPreparer prepares the List request.
330func (client ExpressRouteCircuitPeeringsClient) ListPreparer(ctx context.Context, resourceGroupName string, circuitName string) (*http.Request, error) {
331	pathParameters := map[string]interface{}{
332		"circuitName":       autorest.Encode("path", circuitName),
333		"resourceGroupName": autorest.Encode("path", resourceGroupName),
334		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
335	}
336
337	const APIVersion = "2017-10-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", 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 ExpressRouteCircuitPeeringsClient) 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 ExpressRouteCircuitPeeringsClient) ListResponder(resp *http.Response) (result ExpressRouteCircuitPeeringListResult, err error) {
359	err = autorest.Respond(
360		resp,
361		azure.WithErrorUnlessStatusCode(http.StatusOK),
362		autorest.ByUnmarshallingJSON(&result),
363		autorest.ByClosing())
364	result.Response = autorest.Response{Response: resp}
365	return
366}
367
368// listNextResults retrieves the next set of results, if any.
369func (client ExpressRouteCircuitPeeringsClient) listNextResults(ctx context.Context, lastResults ExpressRouteCircuitPeeringListResult) (result ExpressRouteCircuitPeeringListResult, err error) {
370	req, err := lastResults.expressRouteCircuitPeeringListResultPreparer(ctx)
371	if err != nil {
372		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "listNextResults", nil, "Failure preparing next results request")
373	}
374	if req == nil {
375		return
376	}
377	resp, err := client.ListSender(req)
378	if err != nil {
379		result.Response = autorest.Response{Response: resp}
380		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "listNextResults", resp, "Failure sending next results request")
381	}
382	result, err = client.ListResponder(resp)
383	if err != nil {
384		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "listNextResults", resp, "Failure responding to next results request")
385	}
386	return
387}
388
389// ListComplete enumerates all values, automatically crossing page boundaries as required.
390func (client ExpressRouteCircuitPeeringsClient) ListComplete(ctx context.Context, resourceGroupName string, circuitName string) (result ExpressRouteCircuitPeeringListResultIterator, err error) {
391	if tracing.IsEnabled() {
392		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.List")
393		defer func() {
394			sc := -1
395			if result.Response().Response.Response != nil {
396				sc = result.page.Response().Response.Response.StatusCode
397			}
398			tracing.EndSpan(ctx, sc, err)
399		}()
400	}
401	result.page, err = client.List(ctx, resourceGroupName, circuitName)
402	return
403}
404