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// ExpressRouteCrossConnectionPeeringsClient is the network Client
19type ExpressRouteCrossConnectionPeeringsClient struct {
20	BaseClient
21}
22
23// NewExpressRouteCrossConnectionPeeringsClient creates an instance of the ExpressRouteCrossConnectionPeeringsClient
24// client.
25func NewExpressRouteCrossConnectionPeeringsClient(subscriptionID string) ExpressRouteCrossConnectionPeeringsClient {
26	return NewExpressRouteCrossConnectionPeeringsClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewExpressRouteCrossConnectionPeeringsClientWithBaseURI creates an instance of the
30// ExpressRouteCrossConnectionPeeringsClient client using a custom endpoint.  Use this when interacting with an Azure
31// cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
32func NewExpressRouteCrossConnectionPeeringsClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteCrossConnectionPeeringsClient {
33	return ExpressRouteCrossConnectionPeeringsClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// CreateOrUpdate creates or updates a peering in the specified ExpressRouteCrossConnection.
37// Parameters:
38// resourceGroupName - the name of the resource group.
39// crossConnectionName - the name of the ExpressRouteCrossConnection.
40// peeringName - the name of the peering.
41// peeringParameters - parameters supplied to the create or update ExpressRouteCrossConnection peering
42// operation.
43func (client ExpressRouteCrossConnectionPeeringsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, peeringParameters ExpressRouteCrossConnectionPeering) (result ExpressRouteCrossConnectionPeeringsCreateOrUpdateFuture, err error) {
44	if tracing.IsEnabled() {
45		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCrossConnectionPeeringsClient.CreateOrUpdate")
46		defer func() {
47			sc := -1
48			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
49				sc = result.FutureAPI.Response().StatusCode
50			}
51			tracing.EndSpan(ctx, sc, err)
52		}()
53	}
54	if err := validation.Validate([]validation.Validation{
55		{TargetValue: peeringParameters,
56			Constraints: []validation.Constraint{{Target: "peeringParameters.ExpressRouteCrossConnectionPeeringProperties", Name: validation.Null, Rule: false,
57				Chain: []validation.Constraint{{Target: "peeringParameters.ExpressRouteCrossConnectionPeeringProperties.PeerASN", Name: validation.Null, Rule: false,
58					Chain: []validation.Constraint{{Target: "peeringParameters.ExpressRouteCrossConnectionPeeringProperties.PeerASN", Name: validation.InclusiveMaximum, Rule: int64(4294967295), Chain: nil},
59						{Target: "peeringParameters.ExpressRouteCrossConnectionPeeringProperties.PeerASN", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
60					}},
61				}}}}}); err != nil {
62		return result, validation.NewError("network.ExpressRouteCrossConnectionPeeringsClient", "CreateOrUpdate", err.Error())
63	}
64
65	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, crossConnectionName, peeringName, peeringParameters)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "network.ExpressRouteCrossConnectionPeeringsClient", "CreateOrUpdate", nil, "Failure preparing request")
68		return
69	}
70
71	result, err = client.CreateOrUpdateSender(req)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "network.ExpressRouteCrossConnectionPeeringsClient", "CreateOrUpdate", nil, "Failure sending request")
74		return
75	}
76
77	return
78}
79
80// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
81func (client ExpressRouteCrossConnectionPeeringsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, peeringParameters ExpressRouteCrossConnectionPeering) (*http.Request, error) {
82	pathParameters := map[string]interface{}{
83		"crossConnectionName": autorest.Encode("path", crossConnectionName),
84		"peeringName":         autorest.Encode("path", peeringName),
85		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
86		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
87	}
88
89	const APIVersion = "2019-12-01"
90	queryParameters := map[string]interface{}{
91		"api-version": APIVersion,
92	}
93
94	peeringParameters.Etag = 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/expressRouteCrossConnections/{crossConnectionName}/peerings/{peeringName}", pathParameters),
100		autorest.WithJSON(peeringParameters),
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 ExpressRouteCrossConnectionPeeringsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteCrossConnectionPeeringsCreateOrUpdateFuture, err error) {
108	var resp *http.Response
109	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
110	if err != nil {
111		return
112	}
113	var azf azure.Future
114	azf, err = azure.NewFutureFromResponse(resp)
115	future.FutureAPI = &azf
116	future.Result = future.result
117	return
118}
119
120// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
121// closes the http.Response Body.
122func (client ExpressRouteCrossConnectionPeeringsClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteCrossConnectionPeering, err error) {
123	err = autorest.Respond(
124		resp,
125		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
126		autorest.ByUnmarshallingJSON(&result),
127		autorest.ByClosing())
128	result.Response = autorest.Response{Response: resp}
129	return
130}
131
132// Delete deletes the specified peering from the ExpressRouteCrossConnection.
133// Parameters:
134// resourceGroupName - the name of the resource group.
135// crossConnectionName - the name of the ExpressRouteCrossConnection.
136// peeringName - the name of the peering.
137func (client ExpressRouteCrossConnectionPeeringsClient) Delete(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string) (result ExpressRouteCrossConnectionPeeringsDeleteFuture, err error) {
138	if tracing.IsEnabled() {
139		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCrossConnectionPeeringsClient.Delete")
140		defer func() {
141			sc := -1
142			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
143				sc = result.FutureAPI.Response().StatusCode
144			}
145			tracing.EndSpan(ctx, sc, err)
146		}()
147	}
148	req, err := client.DeletePreparer(ctx, resourceGroupName, crossConnectionName, peeringName)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "network.ExpressRouteCrossConnectionPeeringsClient", "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.ExpressRouteCrossConnectionPeeringsClient", "Delete", nil, "Failure sending request")
157		return
158	}
159
160	return
161}
162
163// DeletePreparer prepares the Delete request.
164func (client ExpressRouteCrossConnectionPeeringsClient) DeletePreparer(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string) (*http.Request, error) {
165	pathParameters := map[string]interface{}{
166		"crossConnectionName": autorest.Encode("path", crossConnectionName),
167		"peeringName":         autorest.Encode("path", peeringName),
168		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
169		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
170	}
171
172	const APIVersion = "2019-12-01"
173	queryParameters := map[string]interface{}{
174		"api-version": APIVersion,
175	}
176
177	preparer := autorest.CreatePreparer(
178		autorest.AsDelete(),
179		autorest.WithBaseURL(client.BaseURI),
180		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCrossConnections/{crossConnectionName}/peerings/{peeringName}", pathParameters),
181		autorest.WithQueryParameters(queryParameters))
182	return preparer.Prepare((&http.Request{}).WithContext(ctx))
183}
184
185// DeleteSender sends the Delete request. The method will close the
186// http.Response Body if it receives an error.
187func (client ExpressRouteCrossConnectionPeeringsClient) DeleteSender(req *http.Request) (future ExpressRouteCrossConnectionPeeringsDeleteFuture, err error) {
188	var resp *http.Response
189	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
190	if err != nil {
191		return
192	}
193	var azf azure.Future
194	azf, err = azure.NewFutureFromResponse(resp)
195	future.FutureAPI = &azf
196	future.Result = future.result
197	return
198}
199
200// DeleteResponder handles the response to the Delete request. The method always
201// closes the http.Response Body.
202func (client ExpressRouteCrossConnectionPeeringsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
203	err = autorest.Respond(
204		resp,
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 peering for the ExpressRouteCrossConnection.
212// Parameters:
213// resourceGroupName - the name of the resource group.
214// crossConnectionName - the name of the ExpressRouteCrossConnection.
215// peeringName - the name of the peering.
216func (client ExpressRouteCrossConnectionPeeringsClient) Get(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string) (result ExpressRouteCrossConnectionPeering, err error) {
217	if tracing.IsEnabled() {
218		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCrossConnectionPeeringsClient.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, crossConnectionName, peeringName)
228	if err != nil {
229		err = autorest.NewErrorWithError(err, "network.ExpressRouteCrossConnectionPeeringsClient", "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.ExpressRouteCrossConnectionPeeringsClient", "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.ExpressRouteCrossConnectionPeeringsClient", "Get", resp, "Failure responding to request")
243		return
244	}
245
246	return
247}
248
249// GetPreparer prepares the Get request.
250func (client ExpressRouteCrossConnectionPeeringsClient) GetPreparer(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string) (*http.Request, error) {
251	pathParameters := map[string]interface{}{
252		"crossConnectionName": autorest.Encode("path", crossConnectionName),
253		"peeringName":         autorest.Encode("path", peeringName),
254		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
255		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
256	}
257
258	const APIVersion = "2019-12-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/expressRouteCrossConnections/{crossConnectionName}/peerings/{peeringName}", 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 ExpressRouteCrossConnectionPeeringsClient) 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 ExpressRouteCrossConnectionPeeringsClient) GetResponder(resp *http.Response) (result ExpressRouteCrossConnectionPeering, err error) {
280	err = autorest.Respond(
281		resp,
282		azure.WithErrorUnlessStatusCode(http.StatusOK),
283		autorest.ByUnmarshallingJSON(&result),
284		autorest.ByClosing())
285	result.Response = autorest.Response{Response: resp}
286	return
287}
288
289// List gets all peerings in a specified ExpressRouteCrossConnection.
290// Parameters:
291// resourceGroupName - the name of the resource group.
292// crossConnectionName - the name of the ExpressRouteCrossConnection.
293func (client ExpressRouteCrossConnectionPeeringsClient) List(ctx context.Context, resourceGroupName string, crossConnectionName string) (result ExpressRouteCrossConnectionPeeringListPage, err error) {
294	if tracing.IsEnabled() {
295		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCrossConnectionPeeringsClient.List")
296		defer func() {
297			sc := -1
298			if result.erccpl.Response.Response != nil {
299				sc = result.erccpl.Response.Response.StatusCode
300			}
301			tracing.EndSpan(ctx, sc, err)
302		}()
303	}
304	result.fn = client.listNextResults
305	req, err := client.ListPreparer(ctx, resourceGroupName, crossConnectionName)
306	if err != nil {
307		err = autorest.NewErrorWithError(err, "network.ExpressRouteCrossConnectionPeeringsClient", "List", nil, "Failure preparing request")
308		return
309	}
310
311	resp, err := client.ListSender(req)
312	if err != nil {
313		result.erccpl.Response = autorest.Response{Response: resp}
314		err = autorest.NewErrorWithError(err, "network.ExpressRouteCrossConnectionPeeringsClient", "List", resp, "Failure sending request")
315		return
316	}
317
318	result.erccpl, err = client.ListResponder(resp)
319	if err != nil {
320		err = autorest.NewErrorWithError(err, "network.ExpressRouteCrossConnectionPeeringsClient", "List", resp, "Failure responding to request")
321		return
322	}
323	if result.erccpl.hasNextLink() && result.erccpl.IsEmpty() {
324		err = result.NextWithContext(ctx)
325		return
326	}
327
328	return
329}
330
331// ListPreparer prepares the List request.
332func (client ExpressRouteCrossConnectionPeeringsClient) ListPreparer(ctx context.Context, resourceGroupName string, crossConnectionName string) (*http.Request, error) {
333	pathParameters := map[string]interface{}{
334		"crossConnectionName": autorest.Encode("path", crossConnectionName),
335		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
336		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
337	}
338
339	const APIVersion = "2019-12-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/expressRouteCrossConnections/{crossConnectionName}/peerings", 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 ExpressRouteCrossConnectionPeeringsClient) ListSender(req *http.Request) (*http.Response, error) {
355	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
356}
357
358// ListResponder handles the response to the List request. The method always
359// closes the http.Response Body.
360func (client ExpressRouteCrossConnectionPeeringsClient) ListResponder(resp *http.Response) (result ExpressRouteCrossConnectionPeeringList, err error) {
361	err = autorest.Respond(
362		resp,
363		azure.WithErrorUnlessStatusCode(http.StatusOK),
364		autorest.ByUnmarshallingJSON(&result),
365		autorest.ByClosing())
366	result.Response = autorest.Response{Response: resp}
367	return
368}
369
370// listNextResults retrieves the next set of results, if any.
371func (client ExpressRouteCrossConnectionPeeringsClient) listNextResults(ctx context.Context, lastResults ExpressRouteCrossConnectionPeeringList) (result ExpressRouteCrossConnectionPeeringList, err error) {
372	req, err := lastResults.expressRouteCrossConnectionPeeringListPreparer(ctx)
373	if err != nil {
374		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCrossConnectionPeeringsClient", "listNextResults", nil, "Failure preparing next results request")
375	}
376	if req == nil {
377		return
378	}
379	resp, err := client.ListSender(req)
380	if err != nil {
381		result.Response = autorest.Response{Response: resp}
382		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCrossConnectionPeeringsClient", "listNextResults", resp, "Failure sending next results request")
383	}
384	result, err = client.ListResponder(resp)
385	if err != nil {
386		err = autorest.NewErrorWithError(err, "network.ExpressRouteCrossConnectionPeeringsClient", "listNextResults", resp, "Failure responding to next results request")
387	}
388	return
389}
390
391// ListComplete enumerates all values, automatically crossing page boundaries as required.
392func (client ExpressRouteCrossConnectionPeeringsClient) ListComplete(ctx context.Context, resourceGroupName string, crossConnectionName string) (result ExpressRouteCrossConnectionPeeringListIterator, err error) {
393	if tracing.IsEnabled() {
394		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCrossConnectionPeeringsClient.List")
395		defer func() {
396			sc := -1
397			if result.Response().Response.Response != nil {
398				sc = result.page.Response().Response.Response.StatusCode
399			}
400			tracing.EndSpan(ctx, sc, err)
401		}()
402	}
403	result.page, err = client.List(ctx, resourceGroupName, crossConnectionName)
404	return
405}
406