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