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/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// ExpressRouteGatewaysClient is the network Client
30type ExpressRouteGatewaysClient struct {
31	BaseClient
32}
33
34// NewExpressRouteGatewaysClient creates an instance of the ExpressRouteGatewaysClient client.
35func NewExpressRouteGatewaysClient(subscriptionID string) ExpressRouteGatewaysClient {
36	return NewExpressRouteGatewaysClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewExpressRouteGatewaysClientWithBaseURI creates an instance of the ExpressRouteGatewaysClient client using a custom
40// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
41// stack).
42func NewExpressRouteGatewaysClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteGatewaysClient {
43	return ExpressRouteGatewaysClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// CreateOrUpdate creates or updates a ExpressRoute gateway in a specified resource group.
47// Parameters:
48// resourceGroupName - the name of the resource group.
49// expressRouteGatewayName - the name of the ExpressRoute gateway.
50// putExpressRouteGatewayParameters - parameters required in an ExpressRoute gateway PUT operation.
51func (client ExpressRouteGatewaysClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, putExpressRouteGatewayParameters ExpressRouteGateway) (result ExpressRouteGatewaysCreateOrUpdateFuture, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.CreateOrUpdate")
54		defer func() {
55			sc := -1
56			if result.Response() != nil {
57				sc = result.Response().StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	if err := validation.Validate([]validation.Validation{
63		{TargetValue: putExpressRouteGatewayParameters,
64			Constraints: []validation.Constraint{{Target: "putExpressRouteGatewayParameters.ExpressRouteGatewayProperties", Name: validation.Null, Rule: false,
65				Chain: []validation.Constraint{{Target: "putExpressRouteGatewayParameters.ExpressRouteGatewayProperties.VirtualHub", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
66		return result, validation.NewError("network.ExpressRouteGatewaysClient", "CreateOrUpdate", err.Error())
67	}
68
69	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, expressRouteGatewayName, putExpressRouteGatewayParameters)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "CreateOrUpdate", nil, "Failure preparing request")
72		return
73	}
74
75	result, err = client.CreateOrUpdateSender(req)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "CreateOrUpdate", nil, "Failure sending request")
78		return
79	}
80
81	return
82}
83
84// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
85func (client ExpressRouteGatewaysClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, putExpressRouteGatewayParameters ExpressRouteGateway) (*http.Request, error) {
86	pathParameters := map[string]interface{}{
87		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
88		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
89		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2019-07-01"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	putExpressRouteGatewayParameters.Etag = nil
98	preparer := autorest.CreatePreparer(
99		autorest.AsContentType("application/json; charset=utf-8"),
100		autorest.AsPut(),
101		autorest.WithBaseURL(client.BaseURI),
102		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}", pathParameters),
103		autorest.WithJSON(putExpressRouteGatewayParameters),
104		autorest.WithQueryParameters(queryParameters))
105	return preparer.Prepare((&http.Request{}).WithContext(ctx))
106}
107
108// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
109// http.Response Body if it receives an error.
110func (client ExpressRouteGatewaysClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteGatewaysCreateOrUpdateFuture, err error) {
111	var resp *http.Response
112	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
113	if err != nil {
114		return
115	}
116	var azf azure.Future
117	azf, err = azure.NewFutureFromResponse(resp)
118	future.FutureAPI = &azf
119	future.Result = func(client ExpressRouteGatewaysClient) (erg ExpressRouteGateway, err error) {
120		var done bool
121		done, err = future.DoneWithContext(context.Background(), client)
122		if err != nil {
123			err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysCreateOrUpdateFuture", "Result", future.Response(), "Polling failure")
124			return
125		}
126		if !done {
127			err = azure.NewAsyncOpIncompleteError("network.ExpressRouteGatewaysCreateOrUpdateFuture")
128			return
129		}
130		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
131		if erg.Response.Response, err = future.GetResult(sender); err == nil && erg.Response.Response.StatusCode != http.StatusNoContent {
132			erg, err = client.CreateOrUpdateResponder(erg.Response.Response)
133			if err != nil {
134				err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysCreateOrUpdateFuture", "Result", erg.Response.Response, "Failure responding to request")
135			}
136		}
137		return
138	}
139	return
140}
141
142// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
143// closes the http.Response Body.
144func (client ExpressRouteGatewaysClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteGateway, err error) {
145	err = autorest.Respond(
146		resp,
147		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
148		autorest.ByUnmarshallingJSON(&result),
149		autorest.ByClosing())
150	result.Response = autorest.Response{Response: resp}
151	return
152}
153
154// Delete deletes the specified ExpressRoute gateway in a resource group. An ExpressRoute gateway resource can only be
155// deleted when there are no connection subresources.
156// Parameters:
157// resourceGroupName - the name of the resource group.
158// expressRouteGatewayName - the name of the ExpressRoute gateway.
159func (client ExpressRouteGatewaysClient) Delete(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (result ExpressRouteGatewaysDeleteFuture, err error) {
160	if tracing.IsEnabled() {
161		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.Delete")
162		defer func() {
163			sc := -1
164			if result.Response() != nil {
165				sc = result.Response().StatusCode
166			}
167			tracing.EndSpan(ctx, sc, err)
168		}()
169	}
170	req, err := client.DeletePreparer(ctx, resourceGroupName, expressRouteGatewayName)
171	if err != nil {
172		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Delete", nil, "Failure preparing request")
173		return
174	}
175
176	result, err = client.DeleteSender(req)
177	if err != nil {
178		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Delete", nil, "Failure sending request")
179		return
180	}
181
182	return
183}
184
185// DeletePreparer prepares the Delete request.
186func (client ExpressRouteGatewaysClient) DeletePreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (*http.Request, error) {
187	pathParameters := map[string]interface{}{
188		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
189		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
190		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
191	}
192
193	const APIVersion = "2019-07-01"
194	queryParameters := map[string]interface{}{
195		"api-version": APIVersion,
196	}
197
198	preparer := autorest.CreatePreparer(
199		autorest.AsDelete(),
200		autorest.WithBaseURL(client.BaseURI),
201		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}", pathParameters),
202		autorest.WithQueryParameters(queryParameters))
203	return preparer.Prepare((&http.Request{}).WithContext(ctx))
204}
205
206// DeleteSender sends the Delete request. The method will close the
207// http.Response Body if it receives an error.
208func (client ExpressRouteGatewaysClient) DeleteSender(req *http.Request) (future ExpressRouteGatewaysDeleteFuture, err error) {
209	var resp *http.Response
210	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
211	if err != nil {
212		return
213	}
214	var azf azure.Future
215	azf, err = azure.NewFutureFromResponse(resp)
216	future.FutureAPI = &azf
217	future.Result = func(client ExpressRouteGatewaysClient) (ar autorest.Response, err error) {
218		var done bool
219		done, err = future.DoneWithContext(context.Background(), client)
220		if err != nil {
221			err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysDeleteFuture", "Result", future.Response(), "Polling failure")
222			return
223		}
224		if !done {
225			err = azure.NewAsyncOpIncompleteError("network.ExpressRouteGatewaysDeleteFuture")
226			return
227		}
228		ar.Response = future.Response()
229		return
230	}
231	return
232}
233
234// DeleteResponder handles the response to the Delete request. The method always
235// closes the http.Response Body.
236func (client ExpressRouteGatewaysClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
237	err = autorest.Respond(
238		resp,
239		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
240		autorest.ByClosing())
241	result.Response = resp
242	return
243}
244
245// Get fetches the details of a ExpressRoute gateway in a resource group.
246// Parameters:
247// resourceGroupName - the name of the resource group.
248// expressRouteGatewayName - the name of the ExpressRoute gateway.
249func (client ExpressRouteGatewaysClient) Get(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (result ExpressRouteGateway, err error) {
250	if tracing.IsEnabled() {
251		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.Get")
252		defer func() {
253			sc := -1
254			if result.Response.Response != nil {
255				sc = result.Response.Response.StatusCode
256			}
257			tracing.EndSpan(ctx, sc, err)
258		}()
259	}
260	req, err := client.GetPreparer(ctx, resourceGroupName, expressRouteGatewayName)
261	if err != nil {
262		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Get", nil, "Failure preparing request")
263		return
264	}
265
266	resp, err := client.GetSender(req)
267	if err != nil {
268		result.Response = autorest.Response{Response: resp}
269		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Get", resp, "Failure sending request")
270		return
271	}
272
273	result, err = client.GetResponder(resp)
274	if err != nil {
275		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Get", resp, "Failure responding to request")
276		return
277	}
278
279	return
280}
281
282// GetPreparer prepares the Get request.
283func (client ExpressRouteGatewaysClient) GetPreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (*http.Request, error) {
284	pathParameters := map[string]interface{}{
285		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
286		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
287		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
288	}
289
290	const APIVersion = "2019-07-01"
291	queryParameters := map[string]interface{}{
292		"api-version": APIVersion,
293	}
294
295	preparer := autorest.CreatePreparer(
296		autorest.AsGet(),
297		autorest.WithBaseURL(client.BaseURI),
298		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}", pathParameters),
299		autorest.WithQueryParameters(queryParameters))
300	return preparer.Prepare((&http.Request{}).WithContext(ctx))
301}
302
303// GetSender sends the Get request. The method will close the
304// http.Response Body if it receives an error.
305func (client ExpressRouteGatewaysClient) GetSender(req *http.Request) (*http.Response, error) {
306	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
307}
308
309// GetResponder handles the response to the Get request. The method always
310// closes the http.Response Body.
311func (client ExpressRouteGatewaysClient) GetResponder(resp *http.Response) (result ExpressRouteGateway, err error) {
312	err = autorest.Respond(
313		resp,
314		azure.WithErrorUnlessStatusCode(http.StatusOK),
315		autorest.ByUnmarshallingJSON(&result),
316		autorest.ByClosing())
317	result.Response = autorest.Response{Response: resp}
318	return
319}
320
321// ListByResourceGroup lists ExpressRoute gateways in a given resource group.
322// Parameters:
323// resourceGroupName - the name of the resource group.
324func (client ExpressRouteGatewaysClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ExpressRouteGatewayList, err error) {
325	if tracing.IsEnabled() {
326		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.ListByResourceGroup")
327		defer func() {
328			sc := -1
329			if result.Response.Response != nil {
330				sc = result.Response.Response.StatusCode
331			}
332			tracing.EndSpan(ctx, sc, err)
333		}()
334	}
335	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
336	if err != nil {
337		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListByResourceGroup", nil, "Failure preparing request")
338		return
339	}
340
341	resp, err := client.ListByResourceGroupSender(req)
342	if err != nil {
343		result.Response = autorest.Response{Response: resp}
344		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListByResourceGroup", resp, "Failure sending request")
345		return
346	}
347
348	result, err = client.ListByResourceGroupResponder(resp)
349	if err != nil {
350		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListByResourceGroup", resp, "Failure responding to request")
351		return
352	}
353
354	return
355}
356
357// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
358func (client ExpressRouteGatewaysClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
359	pathParameters := map[string]interface{}{
360		"resourceGroupName": autorest.Encode("path", resourceGroupName),
361		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
362	}
363
364	const APIVersion = "2019-07-01"
365	queryParameters := map[string]interface{}{
366		"api-version": APIVersion,
367	}
368
369	preparer := autorest.CreatePreparer(
370		autorest.AsGet(),
371		autorest.WithBaseURL(client.BaseURI),
372		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways", pathParameters),
373		autorest.WithQueryParameters(queryParameters))
374	return preparer.Prepare((&http.Request{}).WithContext(ctx))
375}
376
377// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
378// http.Response Body if it receives an error.
379func (client ExpressRouteGatewaysClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
380	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
381}
382
383// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
384// closes the http.Response Body.
385func (client ExpressRouteGatewaysClient) ListByResourceGroupResponder(resp *http.Response) (result ExpressRouteGatewayList, err error) {
386	err = autorest.Respond(
387		resp,
388		azure.WithErrorUnlessStatusCode(http.StatusOK),
389		autorest.ByUnmarshallingJSON(&result),
390		autorest.ByClosing())
391	result.Response = autorest.Response{Response: resp}
392	return
393}
394
395// ListBySubscription lists ExpressRoute gateways under a given subscription.
396func (client ExpressRouteGatewaysClient) ListBySubscription(ctx context.Context) (result ExpressRouteGatewayList, err error) {
397	if tracing.IsEnabled() {
398		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.ListBySubscription")
399		defer func() {
400			sc := -1
401			if result.Response.Response != nil {
402				sc = result.Response.Response.StatusCode
403			}
404			tracing.EndSpan(ctx, sc, err)
405		}()
406	}
407	req, err := client.ListBySubscriptionPreparer(ctx)
408	if err != nil {
409		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListBySubscription", nil, "Failure preparing request")
410		return
411	}
412
413	resp, err := client.ListBySubscriptionSender(req)
414	if err != nil {
415		result.Response = autorest.Response{Response: resp}
416		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListBySubscription", resp, "Failure sending request")
417		return
418	}
419
420	result, err = client.ListBySubscriptionResponder(resp)
421	if err != nil {
422		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListBySubscription", resp, "Failure responding to request")
423		return
424	}
425
426	return
427}
428
429// ListBySubscriptionPreparer prepares the ListBySubscription request.
430func (client ExpressRouteGatewaysClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) {
431	pathParameters := map[string]interface{}{
432		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
433	}
434
435	const APIVersion = "2019-07-01"
436	queryParameters := map[string]interface{}{
437		"api-version": APIVersion,
438	}
439
440	preparer := autorest.CreatePreparer(
441		autorest.AsGet(),
442		autorest.WithBaseURL(client.BaseURI),
443		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/expressRouteGateways", pathParameters),
444		autorest.WithQueryParameters(queryParameters))
445	return preparer.Prepare((&http.Request{}).WithContext(ctx))
446}
447
448// ListBySubscriptionSender sends the ListBySubscription request. The method will close the
449// http.Response Body if it receives an error.
450func (client ExpressRouteGatewaysClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
451	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
452}
453
454// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
455// closes the http.Response Body.
456func (client ExpressRouteGatewaysClient) ListBySubscriptionResponder(resp *http.Response) (result ExpressRouteGatewayList, err error) {
457	err = autorest.Respond(
458		resp,
459		azure.WithErrorUnlessStatusCode(http.StatusOK),
460		autorest.ByUnmarshallingJSON(&result),
461		autorest.ByClosing())
462	result.Response = autorest.Response{Response: resp}
463	return
464}
465