1package network
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/tracing"
25	"net/http"
26)
27
28// RouteTablesClient is the network Client
29type RouteTablesClient struct {
30	BaseClient
31}
32
33// NewRouteTablesClient creates an instance of the RouteTablesClient client.
34func NewRouteTablesClient(subscriptionID string) RouteTablesClient {
35	return NewRouteTablesClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewRouteTablesClientWithBaseURI creates an instance of the RouteTablesClient client.
39func NewRouteTablesClientWithBaseURI(baseURI string, subscriptionID string) RouteTablesClient {
40	return RouteTablesClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// CreateOrUpdate create or updates a route table in a specified resource group.
44// Parameters:
45// resourceGroupName - the name of the resource group.
46// routeTableName - the name of the route table.
47// parameters - parameters supplied to the create or update route table operation.
48func (client RouteTablesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, parameters RouteTable) (result RouteTablesCreateOrUpdateFuture, err error) {
49	if tracing.IsEnabled() {
50		ctx = tracing.StartSpan(ctx, fqdn+"/RouteTablesClient.CreateOrUpdate")
51		defer func() {
52			sc := -1
53			if result.Response() != nil {
54				sc = result.Response().StatusCode
55			}
56			tracing.EndSpan(ctx, sc, err)
57		}()
58	}
59	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, routeTableName, parameters)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "CreateOrUpdate", nil, "Failure preparing request")
62		return
63	}
64
65	result, err = client.CreateOrUpdateSender(req)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "CreateOrUpdate", result.Response(), "Failure sending request")
68		return
69	}
70
71	return
72}
73
74// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
75func (client RouteTablesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, routeTableName string, parameters RouteTable) (*http.Request, error) {
76	pathParameters := map[string]interface{}{
77		"resourceGroupName": autorest.Encode("path", resourceGroupName),
78		"routeTableName":    autorest.Encode("path", routeTableName),
79		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
80	}
81
82	const APIVersion = "2018-10-01"
83	queryParameters := map[string]interface{}{
84		"api-version": APIVersion,
85	}
86
87	preparer := autorest.CreatePreparer(
88		autorest.AsContentType("application/json; charset=utf-8"),
89		autorest.AsPut(),
90		autorest.WithBaseURL(client.BaseURI),
91		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}", pathParameters),
92		autorest.WithJSON(parameters),
93		autorest.WithQueryParameters(queryParameters))
94	return preparer.Prepare((&http.Request{}).WithContext(ctx))
95}
96
97// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
98// http.Response Body if it receives an error.
99func (client RouteTablesClient) CreateOrUpdateSender(req *http.Request) (future RouteTablesCreateOrUpdateFuture, err error) {
100	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
101	var resp *http.Response
102	resp, err = autorest.SendWithSender(client, req, sd...)
103	if err != nil {
104		return
105	}
106	future.Future, err = azure.NewFutureFromResponse(resp)
107	return
108}
109
110// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
111// closes the http.Response Body.
112func (client RouteTablesClient) CreateOrUpdateResponder(resp *http.Response) (result RouteTable, err error) {
113	err = autorest.Respond(
114		resp,
115		client.ByInspecting(),
116		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
117		autorest.ByUnmarshallingJSON(&result),
118		autorest.ByClosing())
119	result.Response = autorest.Response{Response: resp}
120	return
121}
122
123// Delete deletes the specified route table.
124// Parameters:
125// resourceGroupName - the name of the resource group.
126// routeTableName - the name of the route table.
127func (client RouteTablesClient) Delete(ctx context.Context, resourceGroupName string, routeTableName string) (result RouteTablesDeleteFuture, err error) {
128	if tracing.IsEnabled() {
129		ctx = tracing.StartSpan(ctx, fqdn+"/RouteTablesClient.Delete")
130		defer func() {
131			sc := -1
132			if result.Response() != nil {
133				sc = result.Response().StatusCode
134			}
135			tracing.EndSpan(ctx, sc, err)
136		}()
137	}
138	req, err := client.DeletePreparer(ctx, resourceGroupName, routeTableName)
139	if err != nil {
140		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "Delete", nil, "Failure preparing request")
141		return
142	}
143
144	result, err = client.DeleteSender(req)
145	if err != nil {
146		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "Delete", result.Response(), "Failure sending request")
147		return
148	}
149
150	return
151}
152
153// DeletePreparer prepares the Delete request.
154func (client RouteTablesClient) DeletePreparer(ctx context.Context, resourceGroupName string, routeTableName string) (*http.Request, error) {
155	pathParameters := map[string]interface{}{
156		"resourceGroupName": autorest.Encode("path", resourceGroupName),
157		"routeTableName":    autorest.Encode("path", routeTableName),
158		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
159	}
160
161	const APIVersion = "2018-10-01"
162	queryParameters := map[string]interface{}{
163		"api-version": APIVersion,
164	}
165
166	preparer := autorest.CreatePreparer(
167		autorest.AsDelete(),
168		autorest.WithBaseURL(client.BaseURI),
169		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}", pathParameters),
170		autorest.WithQueryParameters(queryParameters))
171	return preparer.Prepare((&http.Request{}).WithContext(ctx))
172}
173
174// DeleteSender sends the Delete request. The method will close the
175// http.Response Body if it receives an error.
176func (client RouteTablesClient) DeleteSender(req *http.Request) (future RouteTablesDeleteFuture, err error) {
177	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
178	var resp *http.Response
179	resp, err = autorest.SendWithSender(client, req, sd...)
180	if err != nil {
181		return
182	}
183	future.Future, err = azure.NewFutureFromResponse(resp)
184	return
185}
186
187// DeleteResponder handles the response to the Delete request. The method always
188// closes the http.Response Body.
189func (client RouteTablesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
190	err = autorest.Respond(
191		resp,
192		client.ByInspecting(),
193		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
194		autorest.ByClosing())
195	result.Response = resp
196	return
197}
198
199// Get gets the specified route table.
200// Parameters:
201// resourceGroupName - the name of the resource group.
202// routeTableName - the name of the route table.
203// expand - expands referenced resources.
204func (client RouteTablesClient) Get(ctx context.Context, resourceGroupName string, routeTableName string, expand string) (result RouteTable, err error) {
205	if tracing.IsEnabled() {
206		ctx = tracing.StartSpan(ctx, fqdn+"/RouteTablesClient.Get")
207		defer func() {
208			sc := -1
209			if result.Response.Response != nil {
210				sc = result.Response.Response.StatusCode
211			}
212			tracing.EndSpan(ctx, sc, err)
213		}()
214	}
215	req, err := client.GetPreparer(ctx, resourceGroupName, routeTableName, expand)
216	if err != nil {
217		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "Get", nil, "Failure preparing request")
218		return
219	}
220
221	resp, err := client.GetSender(req)
222	if err != nil {
223		result.Response = autorest.Response{Response: resp}
224		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "Get", resp, "Failure sending request")
225		return
226	}
227
228	result, err = client.GetResponder(resp)
229	if err != nil {
230		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "Get", resp, "Failure responding to request")
231	}
232
233	return
234}
235
236// GetPreparer prepares the Get request.
237func (client RouteTablesClient) GetPreparer(ctx context.Context, resourceGroupName string, routeTableName string, expand string) (*http.Request, error) {
238	pathParameters := map[string]interface{}{
239		"resourceGroupName": autorest.Encode("path", resourceGroupName),
240		"routeTableName":    autorest.Encode("path", routeTableName),
241		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
242	}
243
244	const APIVersion = "2018-10-01"
245	queryParameters := map[string]interface{}{
246		"api-version": APIVersion,
247	}
248	if len(expand) > 0 {
249		queryParameters["$expand"] = autorest.Encode("query", expand)
250	}
251
252	preparer := autorest.CreatePreparer(
253		autorest.AsGet(),
254		autorest.WithBaseURL(client.BaseURI),
255		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}", pathParameters),
256		autorest.WithQueryParameters(queryParameters))
257	return preparer.Prepare((&http.Request{}).WithContext(ctx))
258}
259
260// GetSender sends the Get request. The method will close the
261// http.Response Body if it receives an error.
262func (client RouteTablesClient) GetSender(req *http.Request) (*http.Response, error) {
263	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
264	return autorest.SendWithSender(client, req, sd...)
265}
266
267// GetResponder handles the response to the Get request. The method always
268// closes the http.Response Body.
269func (client RouteTablesClient) GetResponder(resp *http.Response) (result RouteTable, err error) {
270	err = autorest.Respond(
271		resp,
272		client.ByInspecting(),
273		azure.WithErrorUnlessStatusCode(http.StatusOK),
274		autorest.ByUnmarshallingJSON(&result),
275		autorest.ByClosing())
276	result.Response = autorest.Response{Response: resp}
277	return
278}
279
280// List gets all route tables in a resource group.
281// Parameters:
282// resourceGroupName - the name of the resource group.
283func (client RouteTablesClient) List(ctx context.Context, resourceGroupName string) (result RouteTableListResultPage, err error) {
284	if tracing.IsEnabled() {
285		ctx = tracing.StartSpan(ctx, fqdn+"/RouteTablesClient.List")
286		defer func() {
287			sc := -1
288			if result.rtlr.Response.Response != nil {
289				sc = result.rtlr.Response.Response.StatusCode
290			}
291			tracing.EndSpan(ctx, sc, err)
292		}()
293	}
294	result.fn = client.listNextResults
295	req, err := client.ListPreparer(ctx, resourceGroupName)
296	if err != nil {
297		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "List", nil, "Failure preparing request")
298		return
299	}
300
301	resp, err := client.ListSender(req)
302	if err != nil {
303		result.rtlr.Response = autorest.Response{Response: resp}
304		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "List", resp, "Failure sending request")
305		return
306	}
307
308	result.rtlr, err = client.ListResponder(resp)
309	if err != nil {
310		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "List", resp, "Failure responding to request")
311	}
312
313	return
314}
315
316// ListPreparer prepares the List request.
317func (client RouteTablesClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
318	pathParameters := map[string]interface{}{
319		"resourceGroupName": autorest.Encode("path", resourceGroupName),
320		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
321	}
322
323	const APIVersion = "2018-10-01"
324	queryParameters := map[string]interface{}{
325		"api-version": APIVersion,
326	}
327
328	preparer := autorest.CreatePreparer(
329		autorest.AsGet(),
330		autorest.WithBaseURL(client.BaseURI),
331		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables", pathParameters),
332		autorest.WithQueryParameters(queryParameters))
333	return preparer.Prepare((&http.Request{}).WithContext(ctx))
334}
335
336// ListSender sends the List request. The method will close the
337// http.Response Body if it receives an error.
338func (client RouteTablesClient) ListSender(req *http.Request) (*http.Response, error) {
339	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
340	return autorest.SendWithSender(client, req, sd...)
341}
342
343// ListResponder handles the response to the List request. The method always
344// closes the http.Response Body.
345func (client RouteTablesClient) ListResponder(resp *http.Response) (result RouteTableListResult, err error) {
346	err = autorest.Respond(
347		resp,
348		client.ByInspecting(),
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 RouteTablesClient) listNextResults(ctx context.Context, lastResults RouteTableListResult) (result RouteTableListResult, err error) {
358	req, err := lastResults.routeTableListResultPreparer(ctx)
359	if err != nil {
360		return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "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.RouteTablesClient", "listNextResults", resp, "Failure sending next results request")
369	}
370	result, err = client.ListResponder(resp)
371	if err != nil {
372		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "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 RouteTablesClient) ListComplete(ctx context.Context, resourceGroupName string) (result RouteTableListResultIterator, err error) {
379	if tracing.IsEnabled() {
380		ctx = tracing.StartSpan(ctx, fqdn+"/RouteTablesClient.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)
390	return
391}
392
393// ListAll gets all route tables in a subscription.
394func (client RouteTablesClient) ListAll(ctx context.Context) (result RouteTableListResultPage, err error) {
395	if tracing.IsEnabled() {
396		ctx = tracing.StartSpan(ctx, fqdn+"/RouteTablesClient.ListAll")
397		defer func() {
398			sc := -1
399			if result.rtlr.Response.Response != nil {
400				sc = result.rtlr.Response.Response.StatusCode
401			}
402			tracing.EndSpan(ctx, sc, err)
403		}()
404	}
405	result.fn = client.listAllNextResults
406	req, err := client.ListAllPreparer(ctx)
407	if err != nil {
408		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "ListAll", nil, "Failure preparing request")
409		return
410	}
411
412	resp, err := client.ListAllSender(req)
413	if err != nil {
414		result.rtlr.Response = autorest.Response{Response: resp}
415		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "ListAll", resp, "Failure sending request")
416		return
417	}
418
419	result.rtlr, err = client.ListAllResponder(resp)
420	if err != nil {
421		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "ListAll", resp, "Failure responding to request")
422	}
423
424	return
425}
426
427// ListAllPreparer prepares the ListAll request.
428func (client RouteTablesClient) ListAllPreparer(ctx context.Context) (*http.Request, error) {
429	pathParameters := map[string]interface{}{
430		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
431	}
432
433	const APIVersion = "2018-10-01"
434	queryParameters := map[string]interface{}{
435		"api-version": APIVersion,
436	}
437
438	preparer := autorest.CreatePreparer(
439		autorest.AsGet(),
440		autorest.WithBaseURL(client.BaseURI),
441		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/routeTables", pathParameters),
442		autorest.WithQueryParameters(queryParameters))
443	return preparer.Prepare((&http.Request{}).WithContext(ctx))
444}
445
446// ListAllSender sends the ListAll request. The method will close the
447// http.Response Body if it receives an error.
448func (client RouteTablesClient) ListAllSender(req *http.Request) (*http.Response, error) {
449	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
450	return autorest.SendWithSender(client, req, sd...)
451}
452
453// ListAllResponder handles the response to the ListAll request. The method always
454// closes the http.Response Body.
455func (client RouteTablesClient) ListAllResponder(resp *http.Response) (result RouteTableListResult, err error) {
456	err = autorest.Respond(
457		resp,
458		client.ByInspecting(),
459		azure.WithErrorUnlessStatusCode(http.StatusOK),
460		autorest.ByUnmarshallingJSON(&result),
461		autorest.ByClosing())
462	result.Response = autorest.Response{Response: resp}
463	return
464}
465
466// listAllNextResults retrieves the next set of results, if any.
467func (client RouteTablesClient) listAllNextResults(ctx context.Context, lastResults RouteTableListResult) (result RouteTableListResult, err error) {
468	req, err := lastResults.routeTableListResultPreparer(ctx)
469	if err != nil {
470		return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "listAllNextResults", nil, "Failure preparing next results request")
471	}
472	if req == nil {
473		return
474	}
475	resp, err := client.ListAllSender(req)
476	if err != nil {
477		result.Response = autorest.Response{Response: resp}
478		return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "listAllNextResults", resp, "Failure sending next results request")
479	}
480	result, err = client.ListAllResponder(resp)
481	if err != nil {
482		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "listAllNextResults", resp, "Failure responding to next results request")
483	}
484	return
485}
486
487// ListAllComplete enumerates all values, automatically crossing page boundaries as required.
488func (client RouteTablesClient) ListAllComplete(ctx context.Context) (result RouteTableListResultIterator, err error) {
489	if tracing.IsEnabled() {
490		ctx = tracing.StartSpan(ctx, fqdn+"/RouteTablesClient.ListAll")
491		defer func() {
492			sc := -1
493			if result.Response().Response.Response != nil {
494				sc = result.page.Response().Response.Response.StatusCode
495			}
496			tracing.EndSpan(ctx, sc, err)
497		}()
498	}
499	result.page, err = client.ListAll(ctx)
500	return
501}
502
503// UpdateTags updates a route table tags.
504// Parameters:
505// resourceGroupName - the name of the resource group.
506// routeTableName - the name of the route table.
507// parameters - parameters supplied to update route table tags.
508func (client RouteTablesClient) UpdateTags(ctx context.Context, resourceGroupName string, routeTableName string, parameters TagsObject) (result RouteTablesUpdateTagsFuture, err error) {
509	if tracing.IsEnabled() {
510		ctx = tracing.StartSpan(ctx, fqdn+"/RouteTablesClient.UpdateTags")
511		defer func() {
512			sc := -1
513			if result.Response() != nil {
514				sc = result.Response().StatusCode
515			}
516			tracing.EndSpan(ctx, sc, err)
517		}()
518	}
519	req, err := client.UpdateTagsPreparer(ctx, resourceGroupName, routeTableName, parameters)
520	if err != nil {
521		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "UpdateTags", nil, "Failure preparing request")
522		return
523	}
524
525	result, err = client.UpdateTagsSender(req)
526	if err != nil {
527		err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "UpdateTags", result.Response(), "Failure sending request")
528		return
529	}
530
531	return
532}
533
534// UpdateTagsPreparer prepares the UpdateTags request.
535func (client RouteTablesClient) UpdateTagsPreparer(ctx context.Context, resourceGroupName string, routeTableName string, parameters TagsObject) (*http.Request, error) {
536	pathParameters := map[string]interface{}{
537		"resourceGroupName": autorest.Encode("path", resourceGroupName),
538		"routeTableName":    autorest.Encode("path", routeTableName),
539		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
540	}
541
542	const APIVersion = "2018-10-01"
543	queryParameters := map[string]interface{}{
544		"api-version": APIVersion,
545	}
546
547	preparer := autorest.CreatePreparer(
548		autorest.AsContentType("application/json; charset=utf-8"),
549		autorest.AsPatch(),
550		autorest.WithBaseURL(client.BaseURI),
551		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}", pathParameters),
552		autorest.WithJSON(parameters),
553		autorest.WithQueryParameters(queryParameters))
554	return preparer.Prepare((&http.Request{}).WithContext(ctx))
555}
556
557// UpdateTagsSender sends the UpdateTags request. The method will close the
558// http.Response Body if it receives an error.
559func (client RouteTablesClient) UpdateTagsSender(req *http.Request) (future RouteTablesUpdateTagsFuture, err error) {
560	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
561	var resp *http.Response
562	resp, err = autorest.SendWithSender(client, req, sd...)
563	if err != nil {
564		return
565	}
566	future.Future, err = azure.NewFutureFromResponse(resp)
567	return
568}
569
570// UpdateTagsResponder handles the response to the UpdateTags request. The method always
571// closes the http.Response Body.
572func (client RouteTablesClient) UpdateTagsResponder(resp *http.Response) (result RouteTable, err error) {
573	err = autorest.Respond(
574		resp,
575		client.ByInspecting(),
576		azure.WithErrorUnlessStatusCode(http.StatusOK),
577		autorest.ByUnmarshallingJSON(&result),
578		autorest.ByClosing())
579	result.Response = autorest.Response{Response: resp}
580	return
581}
582