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// ProfilesClient is the network Client
18type ProfilesClient struct {
19	BaseClient
20}
21
22// NewProfilesClient creates an instance of the ProfilesClient client.
23func NewProfilesClient(subscriptionID string) ProfilesClient {
24	return NewProfilesClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewProfilesClientWithBaseURI creates an instance of the ProfilesClient client using a custom endpoint.  Use this
28// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewProfilesClientWithBaseURI(baseURI string, subscriptionID string) ProfilesClient {
30	return ProfilesClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// CreateOrUpdate creates or updates a network profile.
34// Parameters:
35// resourceGroupName - the name of the resource group.
36// networkProfileName - the name of the network profile.
37// parameters - parameters supplied to the create or update network profile operation.
38func (client ProfilesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkProfileName string, parameters Profile) (result Profile, err error) {
39	if tracing.IsEnabled() {
40		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.CreateOrUpdate")
41		defer func() {
42			sc := -1
43			if result.Response.Response != nil {
44				sc = result.Response.Response.StatusCode
45			}
46			tracing.EndSpan(ctx, sc, err)
47		}()
48	}
49	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, networkProfileName, parameters)
50	if err != nil {
51		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "CreateOrUpdate", nil, "Failure preparing request")
52		return
53	}
54
55	resp, err := client.CreateOrUpdateSender(req)
56	if err != nil {
57		result.Response = autorest.Response{Response: resp}
58		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "CreateOrUpdate", resp, "Failure sending request")
59		return
60	}
61
62	result, err = client.CreateOrUpdateResponder(resp)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "CreateOrUpdate", resp, "Failure responding to request")
65		return
66	}
67
68	return
69}
70
71// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
72func (client ProfilesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, networkProfileName string, parameters Profile) (*http.Request, error) {
73	pathParameters := map[string]interface{}{
74		"networkProfileName": autorest.Encode("path", networkProfileName),
75		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
76		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
77	}
78
79	const APIVersion = "2020-03-01"
80	queryParameters := map[string]interface{}{
81		"api-version": APIVersion,
82	}
83
84	parameters.Etag = nil
85	preparer := autorest.CreatePreparer(
86		autorest.AsContentType("application/json; charset=utf-8"),
87		autorest.AsPut(),
88		autorest.WithBaseURL(client.BaseURI),
89		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}", pathParameters),
90		autorest.WithJSON(parameters),
91		autorest.WithQueryParameters(queryParameters))
92	return preparer.Prepare((&http.Request{}).WithContext(ctx))
93}
94
95// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
96// http.Response Body if it receives an error.
97func (client ProfilesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
98	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
99}
100
101// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
102// closes the http.Response Body.
103func (client ProfilesClient) CreateOrUpdateResponder(resp *http.Response) (result Profile, err error) {
104	err = autorest.Respond(
105		resp,
106		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
107		autorest.ByUnmarshallingJSON(&result),
108		autorest.ByClosing())
109	result.Response = autorest.Response{Response: resp}
110	return
111}
112
113// Delete deletes the specified network profile.
114// Parameters:
115// resourceGroupName - the name of the resource group.
116// networkProfileName - the name of the NetworkProfile.
117func (client ProfilesClient) Delete(ctx context.Context, resourceGroupName string, networkProfileName string) (result ProfilesDeleteFuture, err error) {
118	if tracing.IsEnabled() {
119		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.Delete")
120		defer func() {
121			sc := -1
122			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
123				sc = result.FutureAPI.Response().StatusCode
124			}
125			tracing.EndSpan(ctx, sc, err)
126		}()
127	}
128	req, err := client.DeletePreparer(ctx, resourceGroupName, networkProfileName)
129	if err != nil {
130		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "Delete", nil, "Failure preparing request")
131		return
132	}
133
134	result, err = client.DeleteSender(req)
135	if err != nil {
136		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "Delete", nil, "Failure sending request")
137		return
138	}
139
140	return
141}
142
143// DeletePreparer prepares the Delete request.
144func (client ProfilesClient) DeletePreparer(ctx context.Context, resourceGroupName string, networkProfileName string) (*http.Request, error) {
145	pathParameters := map[string]interface{}{
146		"networkProfileName": autorest.Encode("path", networkProfileName),
147		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
148		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
149	}
150
151	const APIVersion = "2020-03-01"
152	queryParameters := map[string]interface{}{
153		"api-version": APIVersion,
154	}
155
156	preparer := autorest.CreatePreparer(
157		autorest.AsDelete(),
158		autorest.WithBaseURL(client.BaseURI),
159		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}", pathParameters),
160		autorest.WithQueryParameters(queryParameters))
161	return preparer.Prepare((&http.Request{}).WithContext(ctx))
162}
163
164// DeleteSender sends the Delete request. The method will close the
165// http.Response Body if it receives an error.
166func (client ProfilesClient) DeleteSender(req *http.Request) (future ProfilesDeleteFuture, err error) {
167	var resp *http.Response
168	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
169	if err != nil {
170		return
171	}
172	var azf azure.Future
173	azf, err = azure.NewFutureFromResponse(resp)
174	future.FutureAPI = &azf
175	future.Result = future.result
176	return
177}
178
179// DeleteResponder handles the response to the Delete request. The method always
180// closes the http.Response Body.
181func (client ProfilesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
182	err = autorest.Respond(
183		resp,
184		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
185		autorest.ByClosing())
186	result.Response = resp
187	return
188}
189
190// Get gets the specified network profile in a specified resource group.
191// Parameters:
192// resourceGroupName - the name of the resource group.
193// networkProfileName - the name of the public IP prefix.
194// expand - expands referenced resources.
195func (client ProfilesClient) Get(ctx context.Context, resourceGroupName string, networkProfileName string, expand string) (result Profile, err error) {
196	if tracing.IsEnabled() {
197		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.Get")
198		defer func() {
199			sc := -1
200			if result.Response.Response != nil {
201				sc = result.Response.Response.StatusCode
202			}
203			tracing.EndSpan(ctx, sc, err)
204		}()
205	}
206	req, err := client.GetPreparer(ctx, resourceGroupName, networkProfileName, expand)
207	if err != nil {
208		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "Get", nil, "Failure preparing request")
209		return
210	}
211
212	resp, err := client.GetSender(req)
213	if err != nil {
214		result.Response = autorest.Response{Response: resp}
215		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "Get", resp, "Failure sending request")
216		return
217	}
218
219	result, err = client.GetResponder(resp)
220	if err != nil {
221		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "Get", resp, "Failure responding to request")
222		return
223	}
224
225	return
226}
227
228// GetPreparer prepares the Get request.
229func (client ProfilesClient) GetPreparer(ctx context.Context, resourceGroupName string, networkProfileName string, expand string) (*http.Request, error) {
230	pathParameters := map[string]interface{}{
231		"networkProfileName": autorest.Encode("path", networkProfileName),
232		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
233		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
234	}
235
236	const APIVersion = "2020-03-01"
237	queryParameters := map[string]interface{}{
238		"api-version": APIVersion,
239	}
240	if len(expand) > 0 {
241		queryParameters["$expand"] = autorest.Encode("query", expand)
242	}
243
244	preparer := autorest.CreatePreparer(
245		autorest.AsGet(),
246		autorest.WithBaseURL(client.BaseURI),
247		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}", pathParameters),
248		autorest.WithQueryParameters(queryParameters))
249	return preparer.Prepare((&http.Request{}).WithContext(ctx))
250}
251
252// GetSender sends the Get request. The method will close the
253// http.Response Body if it receives an error.
254func (client ProfilesClient) GetSender(req *http.Request) (*http.Response, error) {
255	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
256}
257
258// GetResponder handles the response to the Get request. The method always
259// closes the http.Response Body.
260func (client ProfilesClient) GetResponder(resp *http.Response) (result Profile, err error) {
261	err = autorest.Respond(
262		resp,
263		azure.WithErrorUnlessStatusCode(http.StatusOK),
264		autorest.ByUnmarshallingJSON(&result),
265		autorest.ByClosing())
266	result.Response = autorest.Response{Response: resp}
267	return
268}
269
270// List gets all network profiles in a resource group.
271// Parameters:
272// resourceGroupName - the name of the resource group.
273func (client ProfilesClient) List(ctx context.Context, resourceGroupName string) (result ProfileListResultPage, err error) {
274	if tracing.IsEnabled() {
275		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.List")
276		defer func() {
277			sc := -1
278			if result.plr.Response.Response != nil {
279				sc = result.plr.Response.Response.StatusCode
280			}
281			tracing.EndSpan(ctx, sc, err)
282		}()
283	}
284	result.fn = client.listNextResults
285	req, err := client.ListPreparer(ctx, resourceGroupName)
286	if err != nil {
287		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "List", nil, "Failure preparing request")
288		return
289	}
290
291	resp, err := client.ListSender(req)
292	if err != nil {
293		result.plr.Response = autorest.Response{Response: resp}
294		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "List", resp, "Failure sending request")
295		return
296	}
297
298	result.plr, err = client.ListResponder(resp)
299	if err != nil {
300		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "List", resp, "Failure responding to request")
301		return
302	}
303	if result.plr.hasNextLink() && result.plr.IsEmpty() {
304		err = result.NextWithContext(ctx)
305		return
306	}
307
308	return
309}
310
311// ListPreparer prepares the List request.
312func (client ProfilesClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
313	pathParameters := map[string]interface{}{
314		"resourceGroupName": autorest.Encode("path", resourceGroupName),
315		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
316	}
317
318	const APIVersion = "2020-03-01"
319	queryParameters := map[string]interface{}{
320		"api-version": APIVersion,
321	}
322
323	preparer := autorest.CreatePreparer(
324		autorest.AsGet(),
325		autorest.WithBaseURL(client.BaseURI),
326		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles", pathParameters),
327		autorest.WithQueryParameters(queryParameters))
328	return preparer.Prepare((&http.Request{}).WithContext(ctx))
329}
330
331// ListSender sends the List request. The method will close the
332// http.Response Body if it receives an error.
333func (client ProfilesClient) ListSender(req *http.Request) (*http.Response, error) {
334	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
335}
336
337// ListResponder handles the response to the List request. The method always
338// closes the http.Response Body.
339func (client ProfilesClient) ListResponder(resp *http.Response) (result ProfileListResult, err error) {
340	err = autorest.Respond(
341		resp,
342		azure.WithErrorUnlessStatusCode(http.StatusOK),
343		autorest.ByUnmarshallingJSON(&result),
344		autorest.ByClosing())
345	result.Response = autorest.Response{Response: resp}
346	return
347}
348
349// listNextResults retrieves the next set of results, if any.
350func (client ProfilesClient) listNextResults(ctx context.Context, lastResults ProfileListResult) (result ProfileListResult, err error) {
351	req, err := lastResults.profileListResultPreparer(ctx)
352	if err != nil {
353		return result, autorest.NewErrorWithError(err, "network.ProfilesClient", "listNextResults", nil, "Failure preparing next results request")
354	}
355	if req == nil {
356		return
357	}
358	resp, err := client.ListSender(req)
359	if err != nil {
360		result.Response = autorest.Response{Response: resp}
361		return result, autorest.NewErrorWithError(err, "network.ProfilesClient", "listNextResults", resp, "Failure sending next results request")
362	}
363	result, err = client.ListResponder(resp)
364	if err != nil {
365		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "listNextResults", resp, "Failure responding to next results request")
366	}
367	return
368}
369
370// ListComplete enumerates all values, automatically crossing page boundaries as required.
371func (client ProfilesClient) ListComplete(ctx context.Context, resourceGroupName string) (result ProfileListResultIterator, err error) {
372	if tracing.IsEnabled() {
373		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.List")
374		defer func() {
375			sc := -1
376			if result.Response().Response.Response != nil {
377				sc = result.page.Response().Response.Response.StatusCode
378			}
379			tracing.EndSpan(ctx, sc, err)
380		}()
381	}
382	result.page, err = client.List(ctx, resourceGroupName)
383	return
384}
385
386// ListAll gets all the network profiles in a subscription.
387func (client ProfilesClient) ListAll(ctx context.Context) (result ProfileListResultPage, err error) {
388	if tracing.IsEnabled() {
389		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.ListAll")
390		defer func() {
391			sc := -1
392			if result.plr.Response.Response != nil {
393				sc = result.plr.Response.Response.StatusCode
394			}
395			tracing.EndSpan(ctx, sc, err)
396		}()
397	}
398	result.fn = client.listAllNextResults
399	req, err := client.ListAllPreparer(ctx)
400	if err != nil {
401		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "ListAll", nil, "Failure preparing request")
402		return
403	}
404
405	resp, err := client.ListAllSender(req)
406	if err != nil {
407		result.plr.Response = autorest.Response{Response: resp}
408		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "ListAll", resp, "Failure sending request")
409		return
410	}
411
412	result.plr, err = client.ListAllResponder(resp)
413	if err != nil {
414		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "ListAll", resp, "Failure responding to request")
415		return
416	}
417	if result.plr.hasNextLink() && result.plr.IsEmpty() {
418		err = result.NextWithContext(ctx)
419		return
420	}
421
422	return
423}
424
425// ListAllPreparer prepares the ListAll request.
426func (client ProfilesClient) ListAllPreparer(ctx context.Context) (*http.Request, error) {
427	pathParameters := map[string]interface{}{
428		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
429	}
430
431	const APIVersion = "2020-03-01"
432	queryParameters := map[string]interface{}{
433		"api-version": APIVersion,
434	}
435
436	preparer := autorest.CreatePreparer(
437		autorest.AsGet(),
438		autorest.WithBaseURL(client.BaseURI),
439		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/networkProfiles", pathParameters),
440		autorest.WithQueryParameters(queryParameters))
441	return preparer.Prepare((&http.Request{}).WithContext(ctx))
442}
443
444// ListAllSender sends the ListAll request. The method will close the
445// http.Response Body if it receives an error.
446func (client ProfilesClient) ListAllSender(req *http.Request) (*http.Response, error) {
447	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
448}
449
450// ListAllResponder handles the response to the ListAll request. The method always
451// closes the http.Response Body.
452func (client ProfilesClient) ListAllResponder(resp *http.Response) (result ProfileListResult, err error) {
453	err = autorest.Respond(
454		resp,
455		azure.WithErrorUnlessStatusCode(http.StatusOK),
456		autorest.ByUnmarshallingJSON(&result),
457		autorest.ByClosing())
458	result.Response = autorest.Response{Response: resp}
459	return
460}
461
462// listAllNextResults retrieves the next set of results, if any.
463func (client ProfilesClient) listAllNextResults(ctx context.Context, lastResults ProfileListResult) (result ProfileListResult, err error) {
464	req, err := lastResults.profileListResultPreparer(ctx)
465	if err != nil {
466		return result, autorest.NewErrorWithError(err, "network.ProfilesClient", "listAllNextResults", nil, "Failure preparing next results request")
467	}
468	if req == nil {
469		return
470	}
471	resp, err := client.ListAllSender(req)
472	if err != nil {
473		result.Response = autorest.Response{Response: resp}
474		return result, autorest.NewErrorWithError(err, "network.ProfilesClient", "listAllNextResults", resp, "Failure sending next results request")
475	}
476	result, err = client.ListAllResponder(resp)
477	if err != nil {
478		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "listAllNextResults", resp, "Failure responding to next results request")
479	}
480	return
481}
482
483// ListAllComplete enumerates all values, automatically crossing page boundaries as required.
484func (client ProfilesClient) ListAllComplete(ctx context.Context) (result ProfileListResultIterator, err error) {
485	if tracing.IsEnabled() {
486		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.ListAll")
487		defer func() {
488			sc := -1
489			if result.Response().Response.Response != nil {
490				sc = result.page.Response().Response.Response.StatusCode
491			}
492			tracing.EndSpan(ctx, sc, err)
493		}()
494	}
495	result.page, err = client.ListAll(ctx)
496	return
497}
498
499// UpdateTags updates network profile tags.
500// Parameters:
501// resourceGroupName - the name of the resource group.
502// networkProfileName - the name of the network profile.
503// parameters - parameters supplied to update network profile tags.
504func (client ProfilesClient) UpdateTags(ctx context.Context, resourceGroupName string, networkProfileName string, parameters TagsObject) (result Profile, err error) {
505	if tracing.IsEnabled() {
506		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.UpdateTags")
507		defer func() {
508			sc := -1
509			if result.Response.Response != nil {
510				sc = result.Response.Response.StatusCode
511			}
512			tracing.EndSpan(ctx, sc, err)
513		}()
514	}
515	req, err := client.UpdateTagsPreparer(ctx, resourceGroupName, networkProfileName, parameters)
516	if err != nil {
517		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "UpdateTags", nil, "Failure preparing request")
518		return
519	}
520
521	resp, err := client.UpdateTagsSender(req)
522	if err != nil {
523		result.Response = autorest.Response{Response: resp}
524		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "UpdateTags", resp, "Failure sending request")
525		return
526	}
527
528	result, err = client.UpdateTagsResponder(resp)
529	if err != nil {
530		err = autorest.NewErrorWithError(err, "network.ProfilesClient", "UpdateTags", resp, "Failure responding to request")
531		return
532	}
533
534	return
535}
536
537// UpdateTagsPreparer prepares the UpdateTags request.
538func (client ProfilesClient) UpdateTagsPreparer(ctx context.Context, resourceGroupName string, networkProfileName string, parameters TagsObject) (*http.Request, error) {
539	pathParameters := map[string]interface{}{
540		"networkProfileName": autorest.Encode("path", networkProfileName),
541		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
542		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
543	}
544
545	const APIVersion = "2020-03-01"
546	queryParameters := map[string]interface{}{
547		"api-version": APIVersion,
548	}
549
550	preparer := autorest.CreatePreparer(
551		autorest.AsContentType("application/json; charset=utf-8"),
552		autorest.AsPatch(),
553		autorest.WithBaseURL(client.BaseURI),
554		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}", pathParameters),
555		autorest.WithJSON(parameters),
556		autorest.WithQueryParameters(queryParameters))
557	return preparer.Prepare((&http.Request{}).WithContext(ctx))
558}
559
560// UpdateTagsSender sends the UpdateTags request. The method will close the
561// http.Response Body if it receives an error.
562func (client ProfilesClient) UpdateTagsSender(req *http.Request) (*http.Response, error) {
563	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
564}
565
566// UpdateTagsResponder handles the response to the UpdateTags request. The method always
567// closes the http.Response Body.
568func (client ProfilesClient) UpdateTagsResponder(resp *http.Response) (result Profile, err error) {
569	err = autorest.Respond(
570		resp,
571		azure.WithErrorUnlessStatusCode(http.StatusOK),
572		autorest.ByUnmarshallingJSON(&result),
573		autorest.ByClosing())
574	result.Response = autorest.Response{Response: resp}
575	return
576}
577