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// VirtualNetworkGatewaysClient is the network Client
30type VirtualNetworkGatewaysClient struct {
31	BaseClient
32}
33
34// NewVirtualNetworkGatewaysClient creates an instance of the VirtualNetworkGatewaysClient client.
35func NewVirtualNetworkGatewaysClient(subscriptionID string) VirtualNetworkGatewaysClient {
36	return NewVirtualNetworkGatewaysClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewVirtualNetworkGatewaysClientWithBaseURI creates an instance of the VirtualNetworkGatewaysClient client using a
40// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
41// Azure stack).
42func NewVirtualNetworkGatewaysClientWithBaseURI(baseURI string, subscriptionID string) VirtualNetworkGatewaysClient {
43	return VirtualNetworkGatewaysClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// CreateOrUpdate creates or updates a virtual network gateway in the specified resource group.
47// Parameters:
48// resourceGroupName - the name of the resource group.
49// virtualNetworkGatewayName - the name of the virtual network gateway.
50// parameters - parameters supplied to create or update virtual network gateway operation.
51func (client VirtualNetworkGatewaysClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters VirtualNetworkGateway) (result VirtualNetworkGatewaysCreateOrUpdateFuture, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworkGatewaysClient.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: parameters,
64			Constraints: []validation.Constraint{{Target: "parameters.VirtualNetworkGatewayPropertiesFormat", Name: validation.Null, Rule: true,
65				Chain: []validation.Constraint{{Target: "parameters.VirtualNetworkGatewayPropertiesFormat.IPConfigurations", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
66		return result, validation.NewError("network.VirtualNetworkGatewaysClient", "CreateOrUpdate", err.Error())
67	}
68
69	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, virtualNetworkGatewayName, parameters)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "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.VirtualNetworkGatewaysClient", "CreateOrUpdate", nil, "Failure sending request")
78		return
79	}
80
81	return
82}
83
84// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
85func (client VirtualNetworkGatewaysClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters VirtualNetworkGateway) (*http.Request, error) {
86	pathParameters := map[string]interface{}{
87		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
88		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
89		"virtualNetworkGatewayName": autorest.Encode("path", virtualNetworkGatewayName),
90	}
91
92	const APIVersion = "2016-09-01"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	preparer := autorest.CreatePreparer(
98		autorest.AsContentType("application/json; charset=utf-8"),
99		autorest.AsPut(),
100		autorest.WithBaseURL(client.BaseURI),
101		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}", pathParameters),
102		autorest.WithJSON(parameters),
103		autorest.WithQueryParameters(queryParameters))
104	return preparer.Prepare((&http.Request{}).WithContext(ctx))
105}
106
107// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
108// http.Response Body if it receives an error.
109func (client VirtualNetworkGatewaysClient) CreateOrUpdateSender(req *http.Request) (future VirtualNetworkGatewaysCreateOrUpdateFuture, err error) {
110	var resp *http.Response
111	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
112	if err != nil {
113		return
114	}
115	var azf azure.Future
116	azf, err = azure.NewFutureFromResponse(resp)
117	future.FutureAPI = &azf
118	future.Result = func(client VirtualNetworkGatewaysClient) (vng VirtualNetworkGateway, err error) {
119		var done bool
120		done, err = future.DoneWithContext(context.Background(), client)
121		if err != nil {
122			err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysCreateOrUpdateFuture", "Result", future.Response(), "Polling failure")
123			return
124		}
125		if !done {
126			err = azure.NewAsyncOpIncompleteError("network.VirtualNetworkGatewaysCreateOrUpdateFuture")
127			return
128		}
129		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
130		if vng.Response.Response, err = future.GetResult(sender); err == nil && vng.Response.Response.StatusCode != http.StatusNoContent {
131			vng, err = client.CreateOrUpdateResponder(vng.Response.Response)
132			if err != nil {
133				err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysCreateOrUpdateFuture", "Result", vng.Response.Response, "Failure responding to request")
134			}
135		}
136		return
137	}
138	return
139}
140
141// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
142// closes the http.Response Body.
143func (client VirtualNetworkGatewaysClient) CreateOrUpdateResponder(resp *http.Response) (result VirtualNetworkGateway, err error) {
144	err = autorest.Respond(
145		resp,
146		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
147		autorest.ByUnmarshallingJSON(&result),
148		autorest.ByClosing())
149	result.Response = autorest.Response{Response: resp}
150	return
151}
152
153// Delete deletes the specified virtual network gateway.
154// Parameters:
155// resourceGroupName - the name of the resource group.
156// virtualNetworkGatewayName - the name of the virtual network gateway.
157func (client VirtualNetworkGatewaysClient) Delete(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string) (result VirtualNetworkGatewaysDeleteFuture, err error) {
158	if tracing.IsEnabled() {
159		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworkGatewaysClient.Delete")
160		defer func() {
161			sc := -1
162			if result.Response() != nil {
163				sc = result.Response().StatusCode
164			}
165			tracing.EndSpan(ctx, sc, err)
166		}()
167	}
168	req, err := client.DeletePreparer(ctx, resourceGroupName, virtualNetworkGatewayName)
169	if err != nil {
170		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "Delete", nil, "Failure preparing request")
171		return
172	}
173
174	result, err = client.DeleteSender(req)
175	if err != nil {
176		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "Delete", nil, "Failure sending request")
177		return
178	}
179
180	return
181}
182
183// DeletePreparer prepares the Delete request.
184func (client VirtualNetworkGatewaysClient) DeletePreparer(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string) (*http.Request, error) {
185	pathParameters := map[string]interface{}{
186		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
187		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
188		"virtualNetworkGatewayName": autorest.Encode("path", virtualNetworkGatewayName),
189	}
190
191	const APIVersion = "2016-09-01"
192	queryParameters := map[string]interface{}{
193		"api-version": APIVersion,
194	}
195
196	preparer := autorest.CreatePreparer(
197		autorest.AsDelete(),
198		autorest.WithBaseURL(client.BaseURI),
199		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}", pathParameters),
200		autorest.WithQueryParameters(queryParameters))
201	return preparer.Prepare((&http.Request{}).WithContext(ctx))
202}
203
204// DeleteSender sends the Delete request. The method will close the
205// http.Response Body if it receives an error.
206func (client VirtualNetworkGatewaysClient) DeleteSender(req *http.Request) (future VirtualNetworkGatewaysDeleteFuture, err error) {
207	var resp *http.Response
208	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
209	if err != nil {
210		return
211	}
212	var azf azure.Future
213	azf, err = azure.NewFutureFromResponse(resp)
214	future.FutureAPI = &azf
215	future.Result = func(client VirtualNetworkGatewaysClient) (ar autorest.Response, err error) {
216		var done bool
217		done, err = future.DoneWithContext(context.Background(), client)
218		if err != nil {
219			err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysDeleteFuture", "Result", future.Response(), "Polling failure")
220			return
221		}
222		if !done {
223			err = azure.NewAsyncOpIncompleteError("network.VirtualNetworkGatewaysDeleteFuture")
224			return
225		}
226		ar.Response = future.Response()
227		return
228	}
229	return
230}
231
232// DeleteResponder handles the response to the Delete request. The method always
233// closes the http.Response Body.
234func (client VirtualNetworkGatewaysClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
235	err = autorest.Respond(
236		resp,
237		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
238		autorest.ByClosing())
239	result.Response = resp
240	return
241}
242
243// Generatevpnclientpackage generates VPN client package for P2S client of the virtual network gateway in the specified
244// resource group.
245// Parameters:
246// resourceGroupName - the name of the resource group.
247// virtualNetworkGatewayName - the name of the virtual network gateway.
248// parameters - parameters supplied to the generate virtual network gateway VPN client package operation.
249func (client VirtualNetworkGatewaysClient) Generatevpnclientpackage(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters VpnClientParameters) (result VirtualNetworkGatewaysGeneratevpnclientpackageFuture, err error) {
250	if tracing.IsEnabled() {
251		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworkGatewaysClient.Generatevpnclientpackage")
252		defer func() {
253			sc := -1
254			if result.Response() != nil {
255				sc = result.Response().StatusCode
256			}
257			tracing.EndSpan(ctx, sc, err)
258		}()
259	}
260	req, err := client.GeneratevpnclientpackagePreparer(ctx, resourceGroupName, virtualNetworkGatewayName, parameters)
261	if err != nil {
262		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "Generatevpnclientpackage", nil, "Failure preparing request")
263		return
264	}
265
266	result, err = client.GeneratevpnclientpackageSender(req)
267	if err != nil {
268		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "Generatevpnclientpackage", nil, "Failure sending request")
269		return
270	}
271
272	return
273}
274
275// GeneratevpnclientpackagePreparer prepares the Generatevpnclientpackage request.
276func (client VirtualNetworkGatewaysClient) GeneratevpnclientpackagePreparer(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters VpnClientParameters) (*http.Request, error) {
277	pathParameters := map[string]interface{}{
278		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
279		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
280		"virtualNetworkGatewayName": autorest.Encode("path", virtualNetworkGatewayName),
281	}
282
283	const APIVersion = "2016-09-01"
284	queryParameters := map[string]interface{}{
285		"api-version": APIVersion,
286	}
287
288	preparer := autorest.CreatePreparer(
289		autorest.AsContentType("application/json; charset=utf-8"),
290		autorest.AsPost(),
291		autorest.WithBaseURL(client.BaseURI),
292		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/generatevpnclientpackage", pathParameters),
293		autorest.WithJSON(parameters),
294		autorest.WithQueryParameters(queryParameters))
295	return preparer.Prepare((&http.Request{}).WithContext(ctx))
296}
297
298// GeneratevpnclientpackageSender sends the Generatevpnclientpackage request. The method will close the
299// http.Response Body if it receives an error.
300func (client VirtualNetworkGatewaysClient) GeneratevpnclientpackageSender(req *http.Request) (future VirtualNetworkGatewaysGeneratevpnclientpackageFuture, err error) {
301	var resp *http.Response
302	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
303	if err != nil {
304		return
305	}
306	var azf azure.Future
307	azf, err = azure.NewFutureFromResponse(resp)
308	future.FutureAPI = &azf
309	future.Result = func(client VirtualNetworkGatewaysClient) (s String, err error) {
310		var done bool
311		done, err = future.DoneWithContext(context.Background(), client)
312		if err != nil {
313			err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysGeneratevpnclientpackageFuture", "Result", future.Response(), "Polling failure")
314			return
315		}
316		if !done {
317			err = azure.NewAsyncOpIncompleteError("network.VirtualNetworkGatewaysGeneratevpnclientpackageFuture")
318			return
319		}
320		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
321		if s.Response.Response, err = future.GetResult(sender); err == nil && s.Response.Response.StatusCode != http.StatusNoContent {
322			s, err = client.GeneratevpnclientpackageResponder(s.Response.Response)
323			if err != nil {
324				err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysGeneratevpnclientpackageFuture", "Result", s.Response.Response, "Failure responding to request")
325			}
326		}
327		return
328	}
329	return
330}
331
332// GeneratevpnclientpackageResponder handles the response to the Generatevpnclientpackage request. The method always
333// closes the http.Response Body.
334func (client VirtualNetworkGatewaysClient) GeneratevpnclientpackageResponder(resp *http.Response) (result String, err error) {
335	err = autorest.Respond(
336		resp,
337		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
338		autorest.ByUnmarshallingJSON(&result),
339		autorest.ByClosing())
340	result.Response = autorest.Response{Response: resp}
341	return
342}
343
344// Get gets the specified virtual network gateway by resource group.
345// Parameters:
346// resourceGroupName - the name of the resource group.
347// virtualNetworkGatewayName - the name of the virtual network gateway.
348func (client VirtualNetworkGatewaysClient) Get(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string) (result VirtualNetworkGateway, err error) {
349	if tracing.IsEnabled() {
350		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworkGatewaysClient.Get")
351		defer func() {
352			sc := -1
353			if result.Response.Response != nil {
354				sc = result.Response.Response.StatusCode
355			}
356			tracing.EndSpan(ctx, sc, err)
357		}()
358	}
359	req, err := client.GetPreparer(ctx, resourceGroupName, virtualNetworkGatewayName)
360	if err != nil {
361		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "Get", nil, "Failure preparing request")
362		return
363	}
364
365	resp, err := client.GetSender(req)
366	if err != nil {
367		result.Response = autorest.Response{Response: resp}
368		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "Get", resp, "Failure sending request")
369		return
370	}
371
372	result, err = client.GetResponder(resp)
373	if err != nil {
374		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "Get", resp, "Failure responding to request")
375		return
376	}
377
378	return
379}
380
381// GetPreparer prepares the Get request.
382func (client VirtualNetworkGatewaysClient) GetPreparer(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string) (*http.Request, error) {
383	pathParameters := map[string]interface{}{
384		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
385		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
386		"virtualNetworkGatewayName": autorest.Encode("path", virtualNetworkGatewayName),
387	}
388
389	const APIVersion = "2016-09-01"
390	queryParameters := map[string]interface{}{
391		"api-version": APIVersion,
392	}
393
394	preparer := autorest.CreatePreparer(
395		autorest.AsGet(),
396		autorest.WithBaseURL(client.BaseURI),
397		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}", pathParameters),
398		autorest.WithQueryParameters(queryParameters))
399	return preparer.Prepare((&http.Request{}).WithContext(ctx))
400}
401
402// GetSender sends the Get request. The method will close the
403// http.Response Body if it receives an error.
404func (client VirtualNetworkGatewaysClient) GetSender(req *http.Request) (*http.Response, error) {
405	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
406}
407
408// GetResponder handles the response to the Get request. The method always
409// closes the http.Response Body.
410func (client VirtualNetworkGatewaysClient) GetResponder(resp *http.Response) (result VirtualNetworkGateway, err error) {
411	err = autorest.Respond(
412		resp,
413		azure.WithErrorUnlessStatusCode(http.StatusOK),
414		autorest.ByUnmarshallingJSON(&result),
415		autorest.ByClosing())
416	result.Response = autorest.Response{Response: resp}
417	return
418}
419
420// GetAdvertisedRoutes this operation retrieves a list of routes the virtual network gateway is advertising to the
421// specified peer.
422// Parameters:
423// resourceGroupName - the name of the resource group.
424// virtualNetworkGatewayName - the name of the virtual network gateway.
425// peer - the IP address of the peer
426func (client VirtualNetworkGatewaysClient) GetAdvertisedRoutes(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, peer string) (result VirtualNetworkGatewaysGetAdvertisedRoutesFuture, err error) {
427	if tracing.IsEnabled() {
428		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworkGatewaysClient.GetAdvertisedRoutes")
429		defer func() {
430			sc := -1
431			if result.Response() != nil {
432				sc = result.Response().StatusCode
433			}
434			tracing.EndSpan(ctx, sc, err)
435		}()
436	}
437	req, err := client.GetAdvertisedRoutesPreparer(ctx, resourceGroupName, virtualNetworkGatewayName, peer)
438	if err != nil {
439		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "GetAdvertisedRoutes", nil, "Failure preparing request")
440		return
441	}
442
443	result, err = client.GetAdvertisedRoutesSender(req)
444	if err != nil {
445		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "GetAdvertisedRoutes", nil, "Failure sending request")
446		return
447	}
448
449	return
450}
451
452// GetAdvertisedRoutesPreparer prepares the GetAdvertisedRoutes request.
453func (client VirtualNetworkGatewaysClient) GetAdvertisedRoutesPreparer(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, peer string) (*http.Request, error) {
454	pathParameters := map[string]interface{}{
455		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
456		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
457		"virtualNetworkGatewayName": autorest.Encode("path", virtualNetworkGatewayName),
458	}
459
460	const APIVersion = "2016-09-01"
461	queryParameters := map[string]interface{}{
462		"api-version": APIVersion,
463		"peer":        autorest.Encode("query", peer),
464	}
465
466	preparer := autorest.CreatePreparer(
467		autorest.AsPost(),
468		autorest.WithBaseURL(client.BaseURI),
469		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/getAdvertisedRoutes", pathParameters),
470		autorest.WithQueryParameters(queryParameters))
471	return preparer.Prepare((&http.Request{}).WithContext(ctx))
472}
473
474// GetAdvertisedRoutesSender sends the GetAdvertisedRoutes request. The method will close the
475// http.Response Body if it receives an error.
476func (client VirtualNetworkGatewaysClient) GetAdvertisedRoutesSender(req *http.Request) (future VirtualNetworkGatewaysGetAdvertisedRoutesFuture, err error) {
477	var resp *http.Response
478	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
479	if err != nil {
480		return
481	}
482	var azf azure.Future
483	azf, err = azure.NewFutureFromResponse(resp)
484	future.FutureAPI = &azf
485	future.Result = func(client VirtualNetworkGatewaysClient) (grlr GatewayRouteListResult, err error) {
486		var done bool
487		done, err = future.DoneWithContext(context.Background(), client)
488		if err != nil {
489			err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysGetAdvertisedRoutesFuture", "Result", future.Response(), "Polling failure")
490			return
491		}
492		if !done {
493			err = azure.NewAsyncOpIncompleteError("network.VirtualNetworkGatewaysGetAdvertisedRoutesFuture")
494			return
495		}
496		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
497		if grlr.Response.Response, err = future.GetResult(sender); err == nil && grlr.Response.Response.StatusCode != http.StatusNoContent {
498			grlr, err = client.GetAdvertisedRoutesResponder(grlr.Response.Response)
499			if err != nil {
500				err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysGetAdvertisedRoutesFuture", "Result", grlr.Response.Response, "Failure responding to request")
501			}
502		}
503		return
504	}
505	return
506}
507
508// GetAdvertisedRoutesResponder handles the response to the GetAdvertisedRoutes request. The method always
509// closes the http.Response Body.
510func (client VirtualNetworkGatewaysClient) GetAdvertisedRoutesResponder(resp *http.Response) (result GatewayRouteListResult, err error) {
511	err = autorest.Respond(
512		resp,
513		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
514		autorest.ByUnmarshallingJSON(&result),
515		autorest.ByClosing())
516	result.Response = autorest.Response{Response: resp}
517	return
518}
519
520// GetBgpPeerStatus the GetBgpPeerStatus operation retrieves the status of all BGP peers.
521// Parameters:
522// resourceGroupName - the name of the resource group.
523// virtualNetworkGatewayName - the name of the virtual network gateway.
524// peer - the IP address of the peer to retrieve the status of.
525func (client VirtualNetworkGatewaysClient) GetBgpPeerStatus(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, peer string) (result VirtualNetworkGatewaysGetBgpPeerStatusFuture, err error) {
526	if tracing.IsEnabled() {
527		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworkGatewaysClient.GetBgpPeerStatus")
528		defer func() {
529			sc := -1
530			if result.Response() != nil {
531				sc = result.Response().StatusCode
532			}
533			tracing.EndSpan(ctx, sc, err)
534		}()
535	}
536	req, err := client.GetBgpPeerStatusPreparer(ctx, resourceGroupName, virtualNetworkGatewayName, peer)
537	if err != nil {
538		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "GetBgpPeerStatus", nil, "Failure preparing request")
539		return
540	}
541
542	result, err = client.GetBgpPeerStatusSender(req)
543	if err != nil {
544		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "GetBgpPeerStatus", nil, "Failure sending request")
545		return
546	}
547
548	return
549}
550
551// GetBgpPeerStatusPreparer prepares the GetBgpPeerStatus request.
552func (client VirtualNetworkGatewaysClient) GetBgpPeerStatusPreparer(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, peer string) (*http.Request, error) {
553	pathParameters := map[string]interface{}{
554		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
555		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
556		"virtualNetworkGatewayName": autorest.Encode("path", virtualNetworkGatewayName),
557	}
558
559	const APIVersion = "2016-09-01"
560	queryParameters := map[string]interface{}{
561		"api-version": APIVersion,
562	}
563	if len(peer) > 0 {
564		queryParameters["peer"] = autorest.Encode("query", peer)
565	}
566
567	preparer := autorest.CreatePreparer(
568		autorest.AsPost(),
569		autorest.WithBaseURL(client.BaseURI),
570		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/getBgpPeerStatus", pathParameters),
571		autorest.WithQueryParameters(queryParameters))
572	return preparer.Prepare((&http.Request{}).WithContext(ctx))
573}
574
575// GetBgpPeerStatusSender sends the GetBgpPeerStatus request. The method will close the
576// http.Response Body if it receives an error.
577func (client VirtualNetworkGatewaysClient) GetBgpPeerStatusSender(req *http.Request) (future VirtualNetworkGatewaysGetBgpPeerStatusFuture, err error) {
578	var resp *http.Response
579	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
580	if err != nil {
581		return
582	}
583	var azf azure.Future
584	azf, err = azure.NewFutureFromResponse(resp)
585	future.FutureAPI = &azf
586	future.Result = func(client VirtualNetworkGatewaysClient) (bpslr BgpPeerStatusListResult, err error) {
587		var done bool
588		done, err = future.DoneWithContext(context.Background(), client)
589		if err != nil {
590			err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysGetBgpPeerStatusFuture", "Result", future.Response(), "Polling failure")
591			return
592		}
593		if !done {
594			err = azure.NewAsyncOpIncompleteError("network.VirtualNetworkGatewaysGetBgpPeerStatusFuture")
595			return
596		}
597		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
598		if bpslr.Response.Response, err = future.GetResult(sender); err == nil && bpslr.Response.Response.StatusCode != http.StatusNoContent {
599			bpslr, err = client.GetBgpPeerStatusResponder(bpslr.Response.Response)
600			if err != nil {
601				err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysGetBgpPeerStatusFuture", "Result", bpslr.Response.Response, "Failure responding to request")
602			}
603		}
604		return
605	}
606	return
607}
608
609// GetBgpPeerStatusResponder handles the response to the GetBgpPeerStatus request. The method always
610// closes the http.Response Body.
611func (client VirtualNetworkGatewaysClient) GetBgpPeerStatusResponder(resp *http.Response) (result BgpPeerStatusListResult, err error) {
612	err = autorest.Respond(
613		resp,
614		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
615		autorest.ByUnmarshallingJSON(&result),
616		autorest.ByClosing())
617	result.Response = autorest.Response{Response: resp}
618	return
619}
620
621// GetLearnedRoutes this operation retrieves a list of routes the virtual network gateway has learned, including routes
622// learned from BGP peers.
623// Parameters:
624// resourceGroupName - the name of the resource group.
625// virtualNetworkGatewayName - the name of the virtual network gateway.
626func (client VirtualNetworkGatewaysClient) GetLearnedRoutes(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string) (result VirtualNetworkGatewaysGetLearnedRoutesFuture, err error) {
627	if tracing.IsEnabled() {
628		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworkGatewaysClient.GetLearnedRoutes")
629		defer func() {
630			sc := -1
631			if result.Response() != nil {
632				sc = result.Response().StatusCode
633			}
634			tracing.EndSpan(ctx, sc, err)
635		}()
636	}
637	req, err := client.GetLearnedRoutesPreparer(ctx, resourceGroupName, virtualNetworkGatewayName)
638	if err != nil {
639		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "GetLearnedRoutes", nil, "Failure preparing request")
640		return
641	}
642
643	result, err = client.GetLearnedRoutesSender(req)
644	if err != nil {
645		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "GetLearnedRoutes", nil, "Failure sending request")
646		return
647	}
648
649	return
650}
651
652// GetLearnedRoutesPreparer prepares the GetLearnedRoutes request.
653func (client VirtualNetworkGatewaysClient) GetLearnedRoutesPreparer(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string) (*http.Request, error) {
654	pathParameters := map[string]interface{}{
655		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
656		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
657		"virtualNetworkGatewayName": autorest.Encode("path", virtualNetworkGatewayName),
658	}
659
660	const APIVersion = "2016-09-01"
661	queryParameters := map[string]interface{}{
662		"api-version": APIVersion,
663	}
664
665	preparer := autorest.CreatePreparer(
666		autorest.AsPost(),
667		autorest.WithBaseURL(client.BaseURI),
668		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/getLearnedRoutes", pathParameters),
669		autorest.WithQueryParameters(queryParameters))
670	return preparer.Prepare((&http.Request{}).WithContext(ctx))
671}
672
673// GetLearnedRoutesSender sends the GetLearnedRoutes request. The method will close the
674// http.Response Body if it receives an error.
675func (client VirtualNetworkGatewaysClient) GetLearnedRoutesSender(req *http.Request) (future VirtualNetworkGatewaysGetLearnedRoutesFuture, err error) {
676	var resp *http.Response
677	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
678	if err != nil {
679		return
680	}
681	var azf azure.Future
682	azf, err = azure.NewFutureFromResponse(resp)
683	future.FutureAPI = &azf
684	future.Result = func(client VirtualNetworkGatewaysClient) (grlr GatewayRouteListResult, err error) {
685		var done bool
686		done, err = future.DoneWithContext(context.Background(), client)
687		if err != nil {
688			err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysGetLearnedRoutesFuture", "Result", future.Response(), "Polling failure")
689			return
690		}
691		if !done {
692			err = azure.NewAsyncOpIncompleteError("network.VirtualNetworkGatewaysGetLearnedRoutesFuture")
693			return
694		}
695		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
696		if grlr.Response.Response, err = future.GetResult(sender); err == nil && grlr.Response.Response.StatusCode != http.StatusNoContent {
697			grlr, err = client.GetLearnedRoutesResponder(grlr.Response.Response)
698			if err != nil {
699				err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysGetLearnedRoutesFuture", "Result", grlr.Response.Response, "Failure responding to request")
700			}
701		}
702		return
703	}
704	return
705}
706
707// GetLearnedRoutesResponder handles the response to the GetLearnedRoutes request. The method always
708// closes the http.Response Body.
709func (client VirtualNetworkGatewaysClient) GetLearnedRoutesResponder(resp *http.Response) (result GatewayRouteListResult, err error) {
710	err = autorest.Respond(
711		resp,
712		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
713		autorest.ByUnmarshallingJSON(&result),
714		autorest.ByClosing())
715	result.Response = autorest.Response{Response: resp}
716	return
717}
718
719// List gets all virtual network gateways by resource group.
720// Parameters:
721// resourceGroupName - the name of the resource group.
722func (client VirtualNetworkGatewaysClient) List(ctx context.Context, resourceGroupName string) (result VirtualNetworkGatewayListResultPage, err error) {
723	if tracing.IsEnabled() {
724		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworkGatewaysClient.List")
725		defer func() {
726			sc := -1
727			if result.vnglr.Response.Response != nil {
728				sc = result.vnglr.Response.Response.StatusCode
729			}
730			tracing.EndSpan(ctx, sc, err)
731		}()
732	}
733	result.fn = client.listNextResults
734	req, err := client.ListPreparer(ctx, resourceGroupName)
735	if err != nil {
736		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "List", nil, "Failure preparing request")
737		return
738	}
739
740	resp, err := client.ListSender(req)
741	if err != nil {
742		result.vnglr.Response = autorest.Response{Response: resp}
743		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "List", resp, "Failure sending request")
744		return
745	}
746
747	result.vnglr, err = client.ListResponder(resp)
748	if err != nil {
749		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "List", resp, "Failure responding to request")
750		return
751	}
752	if result.vnglr.hasNextLink() && result.vnglr.IsEmpty() {
753		err = result.NextWithContext(ctx)
754		return
755	}
756
757	return
758}
759
760// ListPreparer prepares the List request.
761func (client VirtualNetworkGatewaysClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
762	pathParameters := map[string]interface{}{
763		"resourceGroupName": autorest.Encode("path", resourceGroupName),
764		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
765	}
766
767	const APIVersion = "2016-09-01"
768	queryParameters := map[string]interface{}{
769		"api-version": APIVersion,
770	}
771
772	preparer := autorest.CreatePreparer(
773		autorest.AsGet(),
774		autorest.WithBaseURL(client.BaseURI),
775		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways", pathParameters),
776		autorest.WithQueryParameters(queryParameters))
777	return preparer.Prepare((&http.Request{}).WithContext(ctx))
778}
779
780// ListSender sends the List request. The method will close the
781// http.Response Body if it receives an error.
782func (client VirtualNetworkGatewaysClient) ListSender(req *http.Request) (*http.Response, error) {
783	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
784}
785
786// ListResponder handles the response to the List request. The method always
787// closes the http.Response Body.
788func (client VirtualNetworkGatewaysClient) ListResponder(resp *http.Response) (result VirtualNetworkGatewayListResult, err error) {
789	err = autorest.Respond(
790		resp,
791		azure.WithErrorUnlessStatusCode(http.StatusOK),
792		autorest.ByUnmarshallingJSON(&result),
793		autorest.ByClosing())
794	result.Response = autorest.Response{Response: resp}
795	return
796}
797
798// listNextResults retrieves the next set of results, if any.
799func (client VirtualNetworkGatewaysClient) listNextResults(ctx context.Context, lastResults VirtualNetworkGatewayListResult) (result VirtualNetworkGatewayListResult, err error) {
800	req, err := lastResults.virtualNetworkGatewayListResultPreparer(ctx)
801	if err != nil {
802		return result, autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "listNextResults", nil, "Failure preparing next results request")
803	}
804	if req == nil {
805		return
806	}
807	resp, err := client.ListSender(req)
808	if err != nil {
809		result.Response = autorest.Response{Response: resp}
810		return result, autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "listNextResults", resp, "Failure sending next results request")
811	}
812	result, err = client.ListResponder(resp)
813	if err != nil {
814		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "listNextResults", resp, "Failure responding to next results request")
815	}
816	return
817}
818
819// ListComplete enumerates all values, automatically crossing page boundaries as required.
820func (client VirtualNetworkGatewaysClient) ListComplete(ctx context.Context, resourceGroupName string) (result VirtualNetworkGatewayListResultIterator, err error) {
821	if tracing.IsEnabled() {
822		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworkGatewaysClient.List")
823		defer func() {
824			sc := -1
825			if result.Response().Response.Response != nil {
826				sc = result.page.Response().Response.Response.StatusCode
827			}
828			tracing.EndSpan(ctx, sc, err)
829		}()
830	}
831	result.page, err = client.List(ctx, resourceGroupName)
832	return
833}
834
835// Reset resets the primary of the virtual network gateway in the specified resource group.
836// Parameters:
837// resourceGroupName - the name of the resource group.
838// virtualNetworkGatewayName - the name of the virtual network gateway.
839// gatewayVip - virtual network gateway vip address supplied to the begin reset of the active-active feature
840// enabled gateway.
841func (client VirtualNetworkGatewaysClient) Reset(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, gatewayVip string) (result VirtualNetworkGatewaysResetFuture, err error) {
842	if tracing.IsEnabled() {
843		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworkGatewaysClient.Reset")
844		defer func() {
845			sc := -1
846			if result.Response() != nil {
847				sc = result.Response().StatusCode
848			}
849			tracing.EndSpan(ctx, sc, err)
850		}()
851	}
852	req, err := client.ResetPreparer(ctx, resourceGroupName, virtualNetworkGatewayName, gatewayVip)
853	if err != nil {
854		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "Reset", nil, "Failure preparing request")
855		return
856	}
857
858	result, err = client.ResetSender(req)
859	if err != nil {
860		err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "Reset", nil, "Failure sending request")
861		return
862	}
863
864	return
865}
866
867// ResetPreparer prepares the Reset request.
868func (client VirtualNetworkGatewaysClient) ResetPreparer(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, gatewayVip string) (*http.Request, error) {
869	pathParameters := map[string]interface{}{
870		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
871		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
872		"virtualNetworkGatewayName": autorest.Encode("path", virtualNetworkGatewayName),
873	}
874
875	const APIVersion = "2016-09-01"
876	queryParameters := map[string]interface{}{
877		"api-version": APIVersion,
878	}
879	if len(gatewayVip) > 0 {
880		queryParameters["gatewayVip"] = autorest.Encode("query", gatewayVip)
881	}
882
883	preparer := autorest.CreatePreparer(
884		autorest.AsPost(),
885		autorest.WithBaseURL(client.BaseURI),
886		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/reset", pathParameters),
887		autorest.WithQueryParameters(queryParameters))
888	return preparer.Prepare((&http.Request{}).WithContext(ctx))
889}
890
891// ResetSender sends the Reset request. The method will close the
892// http.Response Body if it receives an error.
893func (client VirtualNetworkGatewaysClient) ResetSender(req *http.Request) (future VirtualNetworkGatewaysResetFuture, err error) {
894	var resp *http.Response
895	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
896	if err != nil {
897		return
898	}
899	var azf azure.Future
900	azf, err = azure.NewFutureFromResponse(resp)
901	future.FutureAPI = &azf
902	future.Result = func(client VirtualNetworkGatewaysClient) (vng VirtualNetworkGateway, err error) {
903		var done bool
904		done, err = future.DoneWithContext(context.Background(), client)
905		if err != nil {
906			err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysResetFuture", "Result", future.Response(), "Polling failure")
907			return
908		}
909		if !done {
910			err = azure.NewAsyncOpIncompleteError("network.VirtualNetworkGatewaysResetFuture")
911			return
912		}
913		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
914		if vng.Response.Response, err = future.GetResult(sender); err == nil && vng.Response.Response.StatusCode != http.StatusNoContent {
915			vng, err = client.ResetResponder(vng.Response.Response)
916			if err != nil {
917				err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysResetFuture", "Result", vng.Response.Response, "Failure responding to request")
918			}
919		}
920		return
921	}
922	return
923}
924
925// ResetResponder handles the response to the Reset request. The method always
926// closes the http.Response Body.
927func (client VirtualNetworkGatewaysClient) ResetResponder(resp *http.Response) (result VirtualNetworkGateway, err error) {
928	err = autorest.Respond(
929		resp,
930		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
931		autorest.ByUnmarshallingJSON(&result),
932		autorest.ByClosing())
933	result.Response = autorest.Response{Response: resp}
934	return
935}
936