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// circuit 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 = "2018-10-01"
89	queryParameters := map[string]interface{}{
90		"api-version": APIVersion,
91	}
92
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}/connections/{connectionName}", pathParameters),
98		autorest.WithJSON(expressRouteCircuitConnectionParameters),
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 ExpressRouteCircuitConnectionsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteCircuitConnectionsCreateOrUpdateFuture, err error) {
106	var resp *http.Response
107	resp, err = autorest.SendWithSender(client, req,
108		azure.DoRetryWithRegistration(client.Client))
109	if err != nil {
110		return
111	}
112	future.Future, err = azure.NewFutureFromResponse(resp)
113	return
114}
115
116// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
117// closes the http.Response Body.
118func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteCircuitConnection, err error) {
119	err = autorest.Respond(
120		resp,
121		client.ByInspecting(),
122		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
123		autorest.ByUnmarshallingJSON(&result),
124		autorest.ByClosing())
125	result.Response = autorest.Response{Response: resp}
126	return
127}
128
129// Delete deletes the specified Express Route Circuit Connection from the specified express route circuit.
130// Parameters:
131// resourceGroupName - the name of the resource group.
132// circuitName - the name of the express route circuit.
133// peeringName - the name of the peering.
134// connectionName - the name of the express route circuit connection.
135func (client ExpressRouteCircuitConnectionsClient) Delete(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (result ExpressRouteCircuitConnectionsDeleteFuture, err error) {
136	if tracing.IsEnabled() {
137		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitConnectionsClient.Delete")
138		defer func() {
139			sc := -1
140			if result.Response() != nil {
141				sc = result.Response().StatusCode
142			}
143			tracing.EndSpan(ctx, sc, err)
144		}()
145	}
146	req, err := client.DeletePreparer(ctx, resourceGroupName, circuitName, peeringName, connectionName)
147	if err != nil {
148		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "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.ExpressRouteCircuitConnectionsClient", "Delete", result.Response(), "Failure sending request")
155		return
156	}
157
158	return
159}
160
161// DeletePreparer prepares the Delete request.
162func (client ExpressRouteCircuitConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (*http.Request, error) {
163	pathParameters := map[string]interface{}{
164		"circuitName":       autorest.Encode("path", circuitName),
165		"connectionName":    autorest.Encode("path", connectionName),
166		"peeringName":       autorest.Encode("path", peeringName),
167		"resourceGroupName": autorest.Encode("path", resourceGroupName),
168		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
169	}
170
171	const APIVersion = "2018-10-01"
172	queryParameters := map[string]interface{}{
173		"api-version": APIVersion,
174	}
175
176	preparer := autorest.CreatePreparer(
177		autorest.AsDelete(),
178		autorest.WithBaseURL(client.BaseURI),
179		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}", pathParameters),
180		autorest.WithQueryParameters(queryParameters))
181	return preparer.Prepare((&http.Request{}).WithContext(ctx))
182}
183
184// DeleteSender sends the Delete request. The method will close the
185// http.Response Body if it receives an error.
186func (client ExpressRouteCircuitConnectionsClient) DeleteSender(req *http.Request) (future ExpressRouteCircuitConnectionsDeleteFuture, err error) {
187	var resp *http.Response
188	resp, err = autorest.SendWithSender(client, req,
189		azure.DoRetryWithRegistration(client.Client))
190	if err != nil {
191		return
192	}
193	future.Future, err = azure.NewFutureFromResponse(resp)
194	return
195}
196
197// DeleteResponder handles the response to the Delete request. The method always
198// closes the http.Response Body.
199func (client ExpressRouteCircuitConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
200	err = autorest.Respond(
201		resp,
202		client.ByInspecting(),
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 Express Route Circuit Connection 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.
214// connectionName - the name of the express route circuit connection.
215func (client ExpressRouteCircuitConnectionsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (result ExpressRouteCircuitConnection, err error) {
216	if tracing.IsEnabled() {
217		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitConnectionsClient.Get")
218		defer func() {
219			sc := -1
220			if result.Response.Response != nil {
221				sc = result.Response.Response.StatusCode
222			}
223			tracing.EndSpan(ctx, sc, err)
224		}()
225	}
226	req, err := client.GetPreparer(ctx, resourceGroupName, circuitName, peeringName, connectionName)
227	if err != nil {
228		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", nil, "Failure preparing request")
229		return
230	}
231
232	resp, err := client.GetSender(req)
233	if err != nil {
234		result.Response = autorest.Response{Response: resp}
235		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", resp, "Failure sending request")
236		return
237	}
238
239	result, err = client.GetResponder(resp)
240	if err != nil {
241		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", resp, "Failure responding to request")
242	}
243
244	return
245}
246
247// GetPreparer prepares the Get request.
248func (client ExpressRouteCircuitConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (*http.Request, error) {
249	pathParameters := map[string]interface{}{
250		"circuitName":       autorest.Encode("path", circuitName),
251		"connectionName":    autorest.Encode("path", connectionName),
252		"peeringName":       autorest.Encode("path", peeringName),
253		"resourceGroupName": autorest.Encode("path", resourceGroupName),
254		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
255	}
256
257	const APIVersion = "2018-10-01"
258	queryParameters := map[string]interface{}{
259		"api-version": APIVersion,
260	}
261
262	preparer := autorest.CreatePreparer(
263		autorest.AsGet(),
264		autorest.WithBaseURL(client.BaseURI),
265		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}", pathParameters),
266		autorest.WithQueryParameters(queryParameters))
267	return preparer.Prepare((&http.Request{}).WithContext(ctx))
268}
269
270// GetSender sends the Get request. The method will close the
271// http.Response Body if it receives an error.
272func (client ExpressRouteCircuitConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
273	return autorest.SendWithSender(client, req,
274		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