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// ExpressRouteConnectionsClient is the network Client
19type ExpressRouteConnectionsClient struct {
20	BaseClient
21}
22
23// NewExpressRouteConnectionsClient creates an instance of the ExpressRouteConnectionsClient client.
24func NewExpressRouteConnectionsClient(subscriptionID string) ExpressRouteConnectionsClient {
25	return NewExpressRouteConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewExpressRouteConnectionsClientWithBaseURI creates an instance of the ExpressRouteConnectionsClient client using a
29// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
30// Azure stack).
31func NewExpressRouteConnectionsClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteConnectionsClient {
32	return ExpressRouteConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// CreateOrUpdate creates a connection between an ExpressRoute gateway and an ExpressRoute circuit.
36// Parameters:
37// resourceGroupName - the name of the resource group.
38// expressRouteGatewayName - the name of the ExpressRoute gateway.
39// connectionName - the name of the connection subresource.
40// putExpressRouteConnectionParameters - parameters required in an ExpressRouteConnection PUT operation.
41func (client ExpressRouteConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, putExpressRouteConnectionParameters ExpressRouteConnection) (result ExpressRouteConnectionsCreateOrUpdateFuture, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteConnectionsClient.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: putExpressRouteConnectionParameters,
54			Constraints: []validation.Constraint{{Target: "putExpressRouteConnectionParameters.ExpressRouteConnectionProperties", Name: validation.Null, Rule: false,
55				Chain: []validation.Constraint{{Target: "putExpressRouteConnectionParameters.ExpressRouteConnectionProperties.ExpressRouteCircuitPeering", Name: validation.Null, Rule: true, Chain: nil}}},
56				{Target: "putExpressRouteConnectionParameters.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
57		return result, validation.NewError("network.ExpressRouteConnectionsClient", "CreateOrUpdate", err.Error())
58	}
59
60	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, expressRouteGatewayName, connectionName, putExpressRouteConnectionParameters)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
63		return
64	}
65
66	result, err = client.CreateOrUpdateSender(req)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "CreateOrUpdate", nil, "Failure sending request")
69		return
70	}
71
72	return
73}
74
75// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
76func (client ExpressRouteConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, putExpressRouteConnectionParameters ExpressRouteConnection) (*http.Request, error) {
77	pathParameters := map[string]interface{}{
78		"connectionName":          autorest.Encode("path", connectionName),
79		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
80		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
81		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
82	}
83
84	const APIVersion = "2020-06-01"
85	queryParameters := map[string]interface{}{
86		"api-version": APIVersion,
87	}
88
89	preparer := autorest.CreatePreparer(
90		autorest.AsContentType("application/json; charset=utf-8"),
91		autorest.AsPut(),
92		autorest.WithBaseURL(client.BaseURI),
93		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections/{connectionName}", pathParameters),
94		autorest.WithJSON(putExpressRouteConnectionParameters),
95		autorest.WithQueryParameters(queryParameters))
96	return preparer.Prepare((&http.Request{}).WithContext(ctx))
97}
98
99// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
100// http.Response Body if it receives an error.
101func (client ExpressRouteConnectionsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteConnectionsCreateOrUpdateFuture, err error) {
102	var resp *http.Response
103	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
104	if err != nil {
105		return
106	}
107	var azf azure.Future
108	azf, err = azure.NewFutureFromResponse(resp)
109	future.FutureAPI = &azf
110	future.Result = future.result
111	return
112}
113
114// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
115// closes the http.Response Body.
116func (client ExpressRouteConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteConnection, err error) {
117	err = autorest.Respond(
118		resp,
119		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
120		autorest.ByUnmarshallingJSON(&result),
121		autorest.ByClosing())
122	result.Response = autorest.Response{Response: resp}
123	return
124}
125
126// Delete deletes a connection to a ExpressRoute circuit.
127// Parameters:
128// resourceGroupName - the name of the resource group.
129// expressRouteGatewayName - the name of the ExpressRoute gateway.
130// connectionName - the name of the connection subresource.
131func (client ExpressRouteConnectionsClient) Delete(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string) (result ExpressRouteConnectionsDeleteFuture, err error) {
132	if tracing.IsEnabled() {
133		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteConnectionsClient.Delete")
134		defer func() {
135			sc := -1
136			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
137				sc = result.FutureAPI.Response().StatusCode
138			}
139			tracing.EndSpan(ctx, sc, err)
140		}()
141	}
142	req, err := client.DeletePreparer(ctx, resourceGroupName, expressRouteGatewayName, connectionName)
143	if err != nil {
144		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "Delete", nil, "Failure preparing request")
145		return
146	}
147
148	result, err = client.DeleteSender(req)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "Delete", nil, "Failure sending request")
151		return
152	}
153
154	return
155}
156
157// DeletePreparer prepares the Delete request.
158func (client ExpressRouteConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string) (*http.Request, error) {
159	pathParameters := map[string]interface{}{
160		"connectionName":          autorest.Encode("path", connectionName),
161		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
162		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
163		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
164	}
165
166	const APIVersion = "2020-06-01"
167	queryParameters := map[string]interface{}{
168		"api-version": APIVersion,
169	}
170
171	preparer := autorest.CreatePreparer(
172		autorest.AsDelete(),
173		autorest.WithBaseURL(client.BaseURI),
174		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections/{connectionName}", pathParameters),
175		autorest.WithQueryParameters(queryParameters))
176	return preparer.Prepare((&http.Request{}).WithContext(ctx))
177}
178
179// DeleteSender sends the Delete request. The method will close the
180// http.Response Body if it receives an error.
181func (client ExpressRouteConnectionsClient) DeleteSender(req *http.Request) (future ExpressRouteConnectionsDeleteFuture, err error) {
182	var resp *http.Response
183	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
184	if err != nil {
185		return
186	}
187	var azf azure.Future
188	azf, err = azure.NewFutureFromResponse(resp)
189	future.FutureAPI = &azf
190	future.Result = future.result
191	return
192}
193
194// DeleteResponder handles the response to the Delete request. The method always
195// closes the http.Response Body.
196func (client ExpressRouteConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
197	err = autorest.Respond(
198		resp,
199		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
200		autorest.ByClosing())
201	result.Response = resp
202	return
203}
204
205// Get gets the specified ExpressRouteConnection.
206// Parameters:
207// resourceGroupName - the name of the resource group.
208// expressRouteGatewayName - the name of the ExpressRoute gateway.
209// connectionName - the name of the ExpressRoute connection.
210func (client ExpressRouteConnectionsClient) Get(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string) (result ExpressRouteConnection, err error) {
211	if tracing.IsEnabled() {
212		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteConnectionsClient.Get")
213		defer func() {
214			sc := -1
215			if result.Response.Response != nil {
216				sc = result.Response.Response.StatusCode
217			}
218			tracing.EndSpan(ctx, sc, err)
219		}()
220	}
221	req, err := client.GetPreparer(ctx, resourceGroupName, expressRouteGatewayName, connectionName)
222	if err != nil {
223		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "Get", nil, "Failure preparing request")
224		return
225	}
226
227	resp, err := client.GetSender(req)
228	if err != nil {
229		result.Response = autorest.Response{Response: resp}
230		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "Get", resp, "Failure sending request")
231		return
232	}
233
234	result, err = client.GetResponder(resp)
235	if err != nil {
236		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "Get", resp, "Failure responding to request")
237		return
238	}
239
240	return
241}
242
243// GetPreparer prepares the Get request.
244func (client ExpressRouteConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string) (*http.Request, error) {
245	pathParameters := map[string]interface{}{
246		"connectionName":          autorest.Encode("path", connectionName),
247		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
248		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
249		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
250	}
251
252	const APIVersion = "2020-06-01"
253	queryParameters := map[string]interface{}{
254		"api-version": APIVersion,
255	}
256
257	preparer := autorest.CreatePreparer(
258		autorest.AsGet(),
259		autorest.WithBaseURL(client.BaseURI),
260		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections/{connectionName}", pathParameters),
261		autorest.WithQueryParameters(queryParameters))
262	return preparer.Prepare((&http.Request{}).WithContext(ctx))
263}
264
265// GetSender sends the Get request. The method will close the
266// http.Response Body if it receives an error.
267func (client ExpressRouteConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
268	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
269}
270
271// GetResponder handles the response to the Get request. The method always
272// closes the http.Response Body.
273func (client ExpressRouteConnectionsClient) GetResponder(resp *http.Response) (result ExpressRouteConnection, err error) {
274	err = autorest.Respond(
275		resp,
276		azure.WithErrorUnlessStatusCode(http.StatusOK),
277		autorest.ByUnmarshallingJSON(&result),
278		autorest.ByClosing())
279	result.Response = autorest.Response{Response: resp}
280	return
281}
282
283// List lists ExpressRouteConnections.
284// Parameters:
285// resourceGroupName - the name of the resource group.
286// expressRouteGatewayName - the name of the ExpressRoute gateway.
287func (client ExpressRouteConnectionsClient) List(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (result ExpressRouteConnectionList, err error) {
288	if tracing.IsEnabled() {
289		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteConnectionsClient.List")
290		defer func() {
291			sc := -1
292			if result.Response.Response != nil {
293				sc = result.Response.Response.StatusCode
294			}
295			tracing.EndSpan(ctx, sc, err)
296		}()
297	}
298	req, err := client.ListPreparer(ctx, resourceGroupName, expressRouteGatewayName)
299	if err != nil {
300		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "List", nil, "Failure preparing request")
301		return
302	}
303
304	resp, err := client.ListSender(req)
305	if err != nil {
306		result.Response = autorest.Response{Response: resp}
307		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "List", resp, "Failure sending request")
308		return
309	}
310
311	result, err = client.ListResponder(resp)
312	if err != nil {
313		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "List", resp, "Failure responding to request")
314		return
315	}
316
317	return
318}
319
320// ListPreparer prepares the List request.
321func (client ExpressRouteConnectionsClient) ListPreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (*http.Request, error) {
322	pathParameters := map[string]interface{}{
323		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
324		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
325		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
326	}
327
328	const APIVersion = "2020-06-01"
329	queryParameters := map[string]interface{}{
330		"api-version": APIVersion,
331	}
332
333	preparer := autorest.CreatePreparer(
334		autorest.AsGet(),
335		autorest.WithBaseURL(client.BaseURI),
336		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections", pathParameters),
337		autorest.WithQueryParameters(queryParameters))
338	return preparer.Prepare((&http.Request{}).WithContext(ctx))
339}
340
341// ListSender sends the List request. The method will close the
342// http.Response Body if it receives an error.
343func (client ExpressRouteConnectionsClient) ListSender(req *http.Request) (*http.Response, error) {
344	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
345}
346
347// ListResponder handles the response to the List request. The method always
348// closes the http.Response Body.
349func (client ExpressRouteConnectionsClient) ListResponder(resp *http.Response) (result ExpressRouteConnectionList, err error) {
350	err = autorest.Respond(
351		resp,
352		azure.WithErrorUnlessStatusCode(http.StatusOK),
353		autorest.ByUnmarshallingJSON(&result),
354		autorest.ByClosing())
355	result.Response = autorest.Response{Response: resp}
356	return
357}
358