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	"net/http"
25)
26
27// ExpressRouteCircuitConnectionsClient is the network Client
28type ExpressRouteCircuitConnectionsClient struct {
29	BaseClient
30}
31
32// NewExpressRouteCircuitConnectionsClient creates an instance of the ExpressRouteCircuitConnectionsClient client.
33func NewExpressRouteCircuitConnectionsClient(subscriptionID string) ExpressRouteCircuitConnectionsClient {
34	return NewExpressRouteCircuitConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
35}
36
37// NewExpressRouteCircuitConnectionsClientWithBaseURI creates an instance of the ExpressRouteCircuitConnectionsClient
38// client.
39func NewExpressRouteCircuitConnectionsClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteCircuitConnectionsClient {
40	return ExpressRouteCircuitConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// CreateOrUpdate creates or updates a Express Route Circuit Connection in the specified express route circuits.
44// Parameters:
45// resourceGroupName - the name of the resource group.
46// circuitName - the name of the express route circuit.
47// peeringName - the name of the peering.
48// connectionName - the name of the express route circuit connection.
49// expressRouteCircuitConnectionParameters - parameters supplied to the create or update express route circuit
50// circuit connection operation.
51func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, expressRouteCircuitConnectionParameters ExpressRouteCircuitConnection) (result ExpressRouteCircuitConnectionsCreateOrUpdateFuture, err error) {
52	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, circuitName, peeringName, connectionName, expressRouteCircuitConnectionParameters)
53	if err != nil {
54		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
55		return
56	}
57
58	result, err = client.CreateOrUpdateSender(req)
59	if err != nil {
60		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
61		return
62	}
63
64	return
65}
66
67// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
68func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, expressRouteCircuitConnectionParameters ExpressRouteCircuitConnection) (*http.Request, error) {
69	pathParameters := map[string]interface{}{
70		"circuitName":       autorest.Encode("path", circuitName),
71		"connectionName":    autorest.Encode("path", connectionName),
72		"peeringName":       autorest.Encode("path", peeringName),
73		"resourceGroupName": autorest.Encode("path", resourceGroupName),
74		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
75	}
76
77	const APIVersion = "2018-06-01"
78	queryParameters := map[string]interface{}{
79		"api-version": APIVersion,
80	}
81
82	preparer := autorest.CreatePreparer(
83		autorest.AsContentType("application/json; charset=utf-8"),
84		autorest.AsPut(),
85		autorest.WithBaseURL(client.BaseURI),
86		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}", pathParameters),
87		autorest.WithJSON(expressRouteCircuitConnectionParameters),
88		autorest.WithQueryParameters(queryParameters))
89	return preparer.Prepare((&http.Request{}).WithContext(ctx))
90}
91
92// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
93// http.Response Body if it receives an error.
94func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteCircuitConnectionsCreateOrUpdateFuture, err error) {
95	var resp *http.Response
96	resp, err = autorest.SendWithSender(client, req,
97		azure.DoRetryWithRegistration(client.Client))
98	if err != nil {
99		return
100	}
101	err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated))
102	if err != nil {
103		return
104	}
105	future.Future, err = azure.NewFutureFromResponse(resp)
106	return
107}
108
109// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
110// closes the http.Response Body.
111func (client ExpressRouteCircuitConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteCircuitConnection, err error) {
112	err = autorest.Respond(
113		resp,
114		client.ByInspecting(),
115		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
116		autorest.ByUnmarshallingJSON(&result),
117		autorest.ByClosing())
118	result.Response = autorest.Response{Response: resp}
119	return
120}
121
122// Delete deletes the specified Express Route Circuit Connection from the specified express route circuit.
123// Parameters:
124// resourceGroupName - the name of the resource group.
125// circuitName - the name of the express route circuit.
126// peeringName - the name of the peering.
127// connectionName - the name of the express route circuit connection.
128func (client ExpressRouteCircuitConnectionsClient) Delete(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (result ExpressRouteCircuitConnectionsDeleteFuture, err error) {
129	req, err := client.DeletePreparer(ctx, resourceGroupName, circuitName, peeringName, connectionName)
130	if err != nil {
131		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Delete", nil, "Failure preparing request")
132		return
133	}
134
135	result, err = client.DeleteSender(req)
136	if err != nil {
137		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Delete", result.Response(), "Failure sending request")
138		return
139	}
140
141	return
142}
143
144// DeletePreparer prepares the Delete request.
145func (client ExpressRouteCircuitConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (*http.Request, error) {
146	pathParameters := map[string]interface{}{
147		"circuitName":       autorest.Encode("path", circuitName),
148		"connectionName":    autorest.Encode("path", connectionName),
149		"peeringName":       autorest.Encode("path", peeringName),
150		"resourceGroupName": autorest.Encode("path", resourceGroupName),
151		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
152	}
153
154	const APIVersion = "2018-06-01"
155	queryParameters := map[string]interface{}{
156		"api-version": APIVersion,
157	}
158
159	preparer := autorest.CreatePreparer(
160		autorest.AsDelete(),
161		autorest.WithBaseURL(client.BaseURI),
162		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}", pathParameters),
163		autorest.WithQueryParameters(queryParameters))
164	return preparer.Prepare((&http.Request{}).WithContext(ctx))
165}
166
167// DeleteSender sends the Delete request. The method will close the
168// http.Response Body if it receives an error.
169func (client ExpressRouteCircuitConnectionsClient) DeleteSender(req *http.Request) (future ExpressRouteCircuitConnectionsDeleteFuture, err error) {
170	var resp *http.Response
171	resp, err = autorest.SendWithSender(client, req,
172		azure.DoRetryWithRegistration(client.Client))
173	if err != nil {
174		return
175	}
176	err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent))
177	if err != nil {
178		return
179	}
180	future.Future, err = azure.NewFutureFromResponse(resp)
181	return
182}
183
184// DeleteResponder handles the response to the Delete request. The method always
185// closes the http.Response Body.
186func (client ExpressRouteCircuitConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
187	err = autorest.Respond(
188		resp,
189		client.ByInspecting(),
190		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
191		autorest.ByClosing())
192	result.Response = resp
193	return
194}
195
196// Get gets the specified Express Route Circuit Connection from the specified express route circuit.
197// Parameters:
198// resourceGroupName - the name of the resource group.
199// circuitName - the name of the express route circuit.
200// peeringName - the name of the peering.
201// connectionName - the name of the express route circuit connection.
202func (client ExpressRouteCircuitConnectionsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (result ExpressRouteCircuitConnection, err error) {
203	req, err := client.GetPreparer(ctx, resourceGroupName, circuitName, peeringName, connectionName)
204	if err != nil {
205		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", nil, "Failure preparing request")
206		return
207	}
208
209	resp, err := client.GetSender(req)
210	if err != nil {
211		result.Response = autorest.Response{Response: resp}
212		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", resp, "Failure sending request")
213		return
214	}
215
216	result, err = client.GetResponder(resp)
217	if err != nil {
218		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitConnectionsClient", "Get", resp, "Failure responding to request")
219	}
220
221	return
222}
223
224// GetPreparer prepares the Get request.
225func (client ExpressRouteCircuitConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string) (*http.Request, error) {
226	pathParameters := map[string]interface{}{
227		"circuitName":       autorest.Encode("path", circuitName),
228		"connectionName":    autorest.Encode("path", connectionName),
229		"peeringName":       autorest.Encode("path", peeringName),
230		"resourceGroupName": autorest.Encode("path", resourceGroupName),
231		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
232	}
233
234	const APIVersion = "2018-06-01"
235	queryParameters := map[string]interface{}{
236		"api-version": APIVersion,
237	}
238
239	preparer := autorest.CreatePreparer(
240		autorest.AsGet(),
241		autorest.WithBaseURL(client.BaseURI),
242		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections/{connectionName}", pathParameters),
243		autorest.WithQueryParameters(queryParameters))
244	return preparer.Prepare((&http.Request{}).WithContext(ctx))
245}
246
247// GetSender sends the Get request. The method will close the
248// http.Response Body if it receives an error.
249func (client ExpressRouteCircuitConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
250	return autorest.SendWithSender(client, req,
251		azure.DoRetryWithRegistration(client.Client))
252}
253
254// GetResponder handles the response to the Get request. The method always
255// closes the http.Response Body.
256func (client ExpressRouteCircuitConnectionsClient) GetResponder(resp *http.Response) (result ExpressRouteCircuitConnection, err error) {
257	err = autorest.Respond(
258		resp,
259		client.ByInspecting(),
260		azure.WithErrorUnlessStatusCode(http.StatusOK),
261		autorest.ByUnmarshallingJSON(&result),
262		autorest.ByClosing())
263	result.Response = autorest.Response{Response: resp}
264	return
265}
266