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/tracing"
14	"net/http"
15)
16
17// HubRouteTablesClient is the network Client
18type HubRouteTablesClient struct {
19	BaseClient
20}
21
22// NewHubRouteTablesClient creates an instance of the HubRouteTablesClient client.
23func NewHubRouteTablesClient(subscriptionID string) HubRouteTablesClient {
24	return NewHubRouteTablesClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewHubRouteTablesClientWithBaseURI creates an instance of the HubRouteTablesClient client using a custom endpoint.
28// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewHubRouteTablesClientWithBaseURI(baseURI string, subscriptionID string) HubRouteTablesClient {
30	return HubRouteTablesClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// CreateOrUpdate creates a RouteTable resource if it doesn't exist else updates the existing RouteTable.
34// Parameters:
35// resourceGroupName - the resource group name of the VirtualHub.
36// virtualHubName - the name of the VirtualHub.
37// routeTableName - the name of the RouteTable.
38// routeTableParameters - parameters supplied to create or update RouteTable.
39func (client HubRouteTablesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, routeTableParameters HubRouteTable) (result HubRouteTablesCreateOrUpdateFuture, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/HubRouteTablesClient.CreateOrUpdate")
42		defer func() {
43			sc := -1
44			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
45				sc = result.FutureAPI.Response().StatusCode
46			}
47			tracing.EndSpan(ctx, sc, err)
48		}()
49	}
50	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, virtualHubName, routeTableName, routeTableParameters)
51	if err != nil {
52		err = autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "CreateOrUpdate", nil, "Failure preparing request")
53		return
54	}
55
56	result, err = client.CreateOrUpdateSender(req)
57	if err != nil {
58		err = autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "CreateOrUpdate", nil, "Failure sending request")
59		return
60	}
61
62	return
63}
64
65// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
66func (client HubRouteTablesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, routeTableParameters HubRouteTable) (*http.Request, error) {
67	pathParameters := map[string]interface{}{
68		"resourceGroupName": autorest.Encode("path", resourceGroupName),
69		"routeTableName":    autorest.Encode("path", routeTableName),
70		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
71		"virtualHubName":    autorest.Encode("path", virtualHubName),
72	}
73
74	const APIVersion = "2020-08-01"
75	queryParameters := map[string]interface{}{
76		"api-version": APIVersion,
77	}
78
79	routeTableParameters.Etag = nil
80	routeTableParameters.Type = nil
81	preparer := autorest.CreatePreparer(
82		autorest.AsContentType("application/json; charset=utf-8"),
83		autorest.AsPut(),
84		autorest.WithBaseURL(client.BaseURI),
85		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/hubRouteTables/{routeTableName}", pathParameters),
86		autorest.WithJSON(routeTableParameters),
87		autorest.WithQueryParameters(queryParameters))
88	return preparer.Prepare((&http.Request{}).WithContext(ctx))
89}
90
91// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
92// http.Response Body if it receives an error.
93func (client HubRouteTablesClient) CreateOrUpdateSender(req *http.Request) (future HubRouteTablesCreateOrUpdateFuture, err error) {
94	var resp *http.Response
95	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
96	if err != nil {
97		return
98	}
99	var azf azure.Future
100	azf, err = azure.NewFutureFromResponse(resp)
101	future.FutureAPI = &azf
102	future.Result = future.result
103	return
104}
105
106// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
107// closes the http.Response Body.
108func (client HubRouteTablesClient) CreateOrUpdateResponder(resp *http.Response) (result HubRouteTable, err error) {
109	err = autorest.Respond(
110		resp,
111		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
112		autorest.ByUnmarshallingJSON(&result),
113		autorest.ByClosing())
114	result.Response = autorest.Response{Response: resp}
115	return
116}
117
118// Delete deletes a RouteTable.
119// Parameters:
120// resourceGroupName - the resource group name of the RouteTable.
121// virtualHubName - the name of the VirtualHub.
122// routeTableName - the name of the RouteTable.
123func (client HubRouteTablesClient) Delete(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string) (result HubRouteTablesDeleteFuture, err error) {
124	if tracing.IsEnabled() {
125		ctx = tracing.StartSpan(ctx, fqdn+"/HubRouteTablesClient.Delete")
126		defer func() {
127			sc := -1
128			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
129				sc = result.FutureAPI.Response().StatusCode
130			}
131			tracing.EndSpan(ctx, sc, err)
132		}()
133	}
134	req, err := client.DeletePreparer(ctx, resourceGroupName, virtualHubName, routeTableName)
135	if err != nil {
136		err = autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "Delete", nil, "Failure preparing request")
137		return
138	}
139
140	result, err = client.DeleteSender(req)
141	if err != nil {
142		err = autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "Delete", nil, "Failure sending request")
143		return
144	}
145
146	return
147}
148
149// DeletePreparer prepares the Delete request.
150func (client HubRouteTablesClient) DeletePreparer(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string) (*http.Request, error) {
151	pathParameters := map[string]interface{}{
152		"resourceGroupName": autorest.Encode("path", resourceGroupName),
153		"routeTableName":    autorest.Encode("path", routeTableName),
154		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
155		"virtualHubName":    autorest.Encode("path", virtualHubName),
156	}
157
158	const APIVersion = "2020-08-01"
159	queryParameters := map[string]interface{}{
160		"api-version": APIVersion,
161	}
162
163	preparer := autorest.CreatePreparer(
164		autorest.AsDelete(),
165		autorest.WithBaseURL(client.BaseURI),
166		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/hubRouteTables/{routeTableName}", pathParameters),
167		autorest.WithQueryParameters(queryParameters))
168	return preparer.Prepare((&http.Request{}).WithContext(ctx))
169}
170
171// DeleteSender sends the Delete request. The method will close the
172// http.Response Body if it receives an error.
173func (client HubRouteTablesClient) DeleteSender(req *http.Request) (future HubRouteTablesDeleteFuture, err error) {
174	var resp *http.Response
175	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
176	if err != nil {
177		return
178	}
179	var azf azure.Future
180	azf, err = azure.NewFutureFromResponse(resp)
181	future.FutureAPI = &azf
182	future.Result = future.result
183	return
184}
185
186// DeleteResponder handles the response to the Delete request. The method always
187// closes the http.Response Body.
188func (client HubRouteTablesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
189	err = autorest.Respond(
190		resp,
191		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
192		autorest.ByClosing())
193	result.Response = resp
194	return
195}
196
197// Get retrieves the details of a RouteTable.
198// Parameters:
199// resourceGroupName - the resource group name of the VirtualHub.
200// virtualHubName - the name of the VirtualHub.
201// routeTableName - the name of the RouteTable.
202func (client HubRouteTablesClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string) (result HubRouteTable, err error) {
203	if tracing.IsEnabled() {
204		ctx = tracing.StartSpan(ctx, fqdn+"/HubRouteTablesClient.Get")
205		defer func() {
206			sc := -1
207			if result.Response.Response != nil {
208				sc = result.Response.Response.StatusCode
209			}
210			tracing.EndSpan(ctx, sc, err)
211		}()
212	}
213	req, err := client.GetPreparer(ctx, resourceGroupName, virtualHubName, routeTableName)
214	if err != nil {
215		err = autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "Get", nil, "Failure preparing request")
216		return
217	}
218
219	resp, err := client.GetSender(req)
220	if err != nil {
221		result.Response = autorest.Response{Response: resp}
222		err = autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "Get", resp, "Failure sending request")
223		return
224	}
225
226	result, err = client.GetResponder(resp)
227	if err != nil {
228		err = autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "Get", resp, "Failure responding to request")
229		return
230	}
231
232	return
233}
234
235// GetPreparer prepares the Get request.
236func (client HubRouteTablesClient) GetPreparer(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string) (*http.Request, error) {
237	pathParameters := map[string]interface{}{
238		"resourceGroupName": autorest.Encode("path", resourceGroupName),
239		"routeTableName":    autorest.Encode("path", routeTableName),
240		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
241		"virtualHubName":    autorest.Encode("path", virtualHubName),
242	}
243
244	const APIVersion = "2020-08-01"
245	queryParameters := map[string]interface{}{
246		"api-version": APIVersion,
247	}
248
249	preparer := autorest.CreatePreparer(
250		autorest.AsGet(),
251		autorest.WithBaseURL(client.BaseURI),
252		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/hubRouteTables/{routeTableName}", pathParameters),
253		autorest.WithQueryParameters(queryParameters))
254	return preparer.Prepare((&http.Request{}).WithContext(ctx))
255}
256
257// GetSender sends the Get request. The method will close the
258// http.Response Body if it receives an error.
259func (client HubRouteTablesClient) GetSender(req *http.Request) (*http.Response, error) {
260	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
261}
262
263// GetResponder handles the response to the Get request. The method always
264// closes the http.Response Body.
265func (client HubRouteTablesClient) GetResponder(resp *http.Response) (result HubRouteTable, err error) {
266	err = autorest.Respond(
267		resp,
268		azure.WithErrorUnlessStatusCode(http.StatusOK),
269		autorest.ByUnmarshallingJSON(&result),
270		autorest.ByClosing())
271	result.Response = autorest.Response{Response: resp}
272	return
273}
274
275// List retrieves the details of all RouteTables.
276// Parameters:
277// resourceGroupName - the resource group name of the VirtualHub.
278// virtualHubName - the name of the VirtualHub.
279func (client HubRouteTablesClient) List(ctx context.Context, resourceGroupName string, virtualHubName string) (result ListHubRouteTablesResultPage, err error) {
280	if tracing.IsEnabled() {
281		ctx = tracing.StartSpan(ctx, fqdn+"/HubRouteTablesClient.List")
282		defer func() {
283			sc := -1
284			if result.lhrtr.Response.Response != nil {
285				sc = result.lhrtr.Response.Response.StatusCode
286			}
287			tracing.EndSpan(ctx, sc, err)
288		}()
289	}
290	result.fn = client.listNextResults
291	req, err := client.ListPreparer(ctx, resourceGroupName, virtualHubName)
292	if err != nil {
293		err = autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "List", nil, "Failure preparing request")
294		return
295	}
296
297	resp, err := client.ListSender(req)
298	if err != nil {
299		result.lhrtr.Response = autorest.Response{Response: resp}
300		err = autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "List", resp, "Failure sending request")
301		return
302	}
303
304	result.lhrtr, err = client.ListResponder(resp)
305	if err != nil {
306		err = autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "List", resp, "Failure responding to request")
307		return
308	}
309	if result.lhrtr.hasNextLink() && result.lhrtr.IsEmpty() {
310		err = result.NextWithContext(ctx)
311		return
312	}
313
314	return
315}
316
317// ListPreparer prepares the List request.
318func (client HubRouteTablesClient) ListPreparer(ctx context.Context, resourceGroupName string, virtualHubName string) (*http.Request, error) {
319	pathParameters := map[string]interface{}{
320		"resourceGroupName": autorest.Encode("path", resourceGroupName),
321		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
322		"virtualHubName":    autorest.Encode("path", virtualHubName),
323	}
324
325	const APIVersion = "2020-08-01"
326	queryParameters := map[string]interface{}{
327		"api-version": APIVersion,
328	}
329
330	preparer := autorest.CreatePreparer(
331		autorest.AsGet(),
332		autorest.WithBaseURL(client.BaseURI),
333		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/hubRouteTables", pathParameters),
334		autorest.WithQueryParameters(queryParameters))
335	return preparer.Prepare((&http.Request{}).WithContext(ctx))
336}
337
338// ListSender sends the List request. The method will close the
339// http.Response Body if it receives an error.
340func (client HubRouteTablesClient) ListSender(req *http.Request) (*http.Response, error) {
341	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
342}
343
344// ListResponder handles the response to the List request. The method always
345// closes the http.Response Body.
346func (client HubRouteTablesClient) ListResponder(resp *http.Response) (result ListHubRouteTablesResult, err error) {
347	err = autorest.Respond(
348		resp,
349		azure.WithErrorUnlessStatusCode(http.StatusOK),
350		autorest.ByUnmarshallingJSON(&result),
351		autorest.ByClosing())
352	result.Response = autorest.Response{Response: resp}
353	return
354}
355
356// listNextResults retrieves the next set of results, if any.
357func (client HubRouteTablesClient) listNextResults(ctx context.Context, lastResults ListHubRouteTablesResult) (result ListHubRouteTablesResult, err error) {
358	req, err := lastResults.listHubRouteTablesResultPreparer(ctx)
359	if err != nil {
360		return result, autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "listNextResults", nil, "Failure preparing next results request")
361	}
362	if req == nil {
363		return
364	}
365	resp, err := client.ListSender(req)
366	if err != nil {
367		result.Response = autorest.Response{Response: resp}
368		return result, autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "listNextResults", resp, "Failure sending next results request")
369	}
370	result, err = client.ListResponder(resp)
371	if err != nil {
372		err = autorest.NewErrorWithError(err, "network.HubRouteTablesClient", "listNextResults", resp, "Failure responding to next results request")
373	}
374	return
375}
376
377// ListComplete enumerates all values, automatically crossing page boundaries as required.
378func (client HubRouteTablesClient) ListComplete(ctx context.Context, resourceGroupName string, virtualHubName string) (result ListHubRouteTablesResultIterator, err error) {
379	if tracing.IsEnabled() {
380		ctx = tracing.StartSpan(ctx, fqdn+"/HubRouteTablesClient.List")
381		defer func() {
382			sc := -1
383			if result.Response().Response.Response != nil {
384				sc = result.page.Response().Response.Response.StatusCode
385			}
386			tracing.EndSpan(ctx, sc, err)
387		}()
388	}
389	result.page, err = client.List(ctx, resourceGroupName, virtualHubName)
390	return
391}
392