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	"net/http"
25)
26
27// PublicIPAddressesClient is the network Client
28type PublicIPAddressesClient struct {
29	BaseClient
30}
31
32// NewPublicIPAddressesClient creates an instance of the PublicIPAddressesClient client.
33func NewPublicIPAddressesClient(subscriptionID string) PublicIPAddressesClient {
34	return NewPublicIPAddressesClientWithBaseURI(DefaultBaseURI, subscriptionID)
35}
36
37// NewPublicIPAddressesClientWithBaseURI creates an instance of the PublicIPAddressesClient client.
38func NewPublicIPAddressesClientWithBaseURI(baseURI string, subscriptionID string) PublicIPAddressesClient {
39	return PublicIPAddressesClient{NewWithBaseURI(baseURI, subscriptionID)}
40}
41
42// CreateOrUpdate the Put PublicIPAddress operation creates/updates a stable/dynamic PublicIP address
43// Parameters:
44// resourceGroupName - the name of the resource group.
45// publicIPAddressName - the name of the publicIpAddress.
46// parameters - parameters supplied to the create/update PublicIPAddress operation
47func (client PublicIPAddressesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, publicIPAddressName string, parameters PublicIPAddress) (result PublicIPAddressesCreateOrUpdateFuture, err error) {
48	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, publicIPAddressName, parameters)
49	if err != nil {
50		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "CreateOrUpdate", nil, "Failure preparing request")
51		return
52	}
53
54	result, err = client.CreateOrUpdateSender(req)
55	if err != nil {
56		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "CreateOrUpdate", result.Response(), "Failure sending request")
57		return
58	}
59
60	return
61}
62
63// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
64func (client PublicIPAddressesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, publicIPAddressName string, parameters PublicIPAddress) (*http.Request, error) {
65	pathParameters := map[string]interface{}{
66		"publicIpAddressName": autorest.Encode("path", publicIPAddressName),
67		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
68		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
69	}
70
71	const APIVersion = "2015-05-01-preview"
72	queryParameters := map[string]interface{}{
73		"api-version": APIVersion,
74	}
75
76	preparer := autorest.CreatePreparer(
77		autorest.AsContentType("application/json; charset=utf-8"),
78		autorest.AsPut(),
79		autorest.WithBaseURL(client.BaseURI),
80		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}/", pathParameters),
81		autorest.WithJSON(parameters),
82		autorest.WithQueryParameters(queryParameters))
83	return preparer.Prepare((&http.Request{}).WithContext(ctx))
84}
85
86// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
87// http.Response Body if it receives an error.
88func (client PublicIPAddressesClient) CreateOrUpdateSender(req *http.Request) (future PublicIPAddressesCreateOrUpdateFuture, err error) {
89	var resp *http.Response
90	resp, err = autorest.SendWithSender(client, req,
91		azure.DoRetryWithRegistration(client.Client))
92	if err != nil {
93		return
94	}
95	err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated))
96	if err != nil {
97		return
98	}
99	future.Future, err = azure.NewFutureFromResponse(resp)
100	return
101}
102
103// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
104// closes the http.Response Body.
105func (client PublicIPAddressesClient) CreateOrUpdateResponder(resp *http.Response) (result PublicIPAddress, err error) {
106	err = autorest.Respond(
107		resp,
108		client.ByInspecting(),
109		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
110		autorest.ByUnmarshallingJSON(&result),
111		autorest.ByClosing())
112	result.Response = autorest.Response{Response: resp}
113	return
114}
115
116// Delete the delete publicIpAddress operation deletes the specified publicIpAddress.
117// Parameters:
118// resourceGroupName - the name of the resource group.
119// publicIPAddressName - the name of the subnet.
120func (client PublicIPAddressesClient) Delete(ctx context.Context, resourceGroupName string, publicIPAddressName string) (result PublicIPAddressesDeleteFuture, err error) {
121	req, err := client.DeletePreparer(ctx, resourceGroupName, publicIPAddressName)
122	if err != nil {
123		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "Delete", nil, "Failure preparing request")
124		return
125	}
126
127	result, err = client.DeleteSender(req)
128	if err != nil {
129		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "Delete", result.Response(), "Failure sending request")
130		return
131	}
132
133	return
134}
135
136// DeletePreparer prepares the Delete request.
137func (client PublicIPAddressesClient) DeletePreparer(ctx context.Context, resourceGroupName string, publicIPAddressName string) (*http.Request, error) {
138	pathParameters := map[string]interface{}{
139		"publicIpAddressName": autorest.Encode("path", publicIPAddressName),
140		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
141		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
142	}
143
144	const APIVersion = "2015-05-01-preview"
145	queryParameters := map[string]interface{}{
146		"api-version": APIVersion,
147	}
148
149	preparer := autorest.CreatePreparer(
150		autorest.AsDelete(),
151		autorest.WithBaseURL(client.BaseURI),
152		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}/", pathParameters),
153		autorest.WithQueryParameters(queryParameters))
154	return preparer.Prepare((&http.Request{}).WithContext(ctx))
155}
156
157// DeleteSender sends the Delete request. The method will close the
158// http.Response Body if it receives an error.
159func (client PublicIPAddressesClient) DeleteSender(req *http.Request) (future PublicIPAddressesDeleteFuture, err error) {
160	var resp *http.Response
161	resp, err = autorest.SendWithSender(client, req,
162		azure.DoRetryWithRegistration(client.Client))
163	if err != nil {
164		return
165	}
166	err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent))
167	if err != nil {
168		return
169	}
170	future.Future, err = azure.NewFutureFromResponse(resp)
171	return
172}
173
174// DeleteResponder handles the response to the Delete request. The method always
175// closes the http.Response Body.
176func (client PublicIPAddressesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
177	err = autorest.Respond(
178		resp,
179		client.ByInspecting(),
180		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
181		autorest.ByClosing())
182	result.Response = resp
183	return
184}
185
186// Get the Get publicIpAddress operation retreives information about the specified pubicIpAddress
187// Parameters:
188// resourceGroupName - the name of the resource group.
189// publicIPAddressName - the name of the subnet.
190func (client PublicIPAddressesClient) Get(ctx context.Context, resourceGroupName string, publicIPAddressName string) (result PublicIPAddress, err error) {
191	req, err := client.GetPreparer(ctx, resourceGroupName, publicIPAddressName)
192	if err != nil {
193		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "Get", nil, "Failure preparing request")
194		return
195	}
196
197	resp, err := client.GetSender(req)
198	if err != nil {
199		result.Response = autorest.Response{Response: resp}
200		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "Get", resp, "Failure sending request")
201		return
202	}
203
204	result, err = client.GetResponder(resp)
205	if err != nil {
206		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "Get", resp, "Failure responding to request")
207	}
208
209	return
210}
211
212// GetPreparer prepares the Get request.
213func (client PublicIPAddressesClient) GetPreparer(ctx context.Context, resourceGroupName string, publicIPAddressName string) (*http.Request, error) {
214	pathParameters := map[string]interface{}{
215		"publicIpAddressName": autorest.Encode("path", publicIPAddressName),
216		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
217		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
218	}
219
220	const APIVersion = "2015-05-01-preview"
221	queryParameters := map[string]interface{}{
222		"api-version": APIVersion,
223	}
224
225	preparer := autorest.CreatePreparer(
226		autorest.AsGet(),
227		autorest.WithBaseURL(client.BaseURI),
228		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}/", pathParameters),
229		autorest.WithQueryParameters(queryParameters))
230	return preparer.Prepare((&http.Request{}).WithContext(ctx))
231}
232
233// GetSender sends the Get request. The method will close the
234// http.Response Body if it receives an error.
235func (client PublicIPAddressesClient) GetSender(req *http.Request) (*http.Response, error) {
236	return autorest.SendWithSender(client, req,
237		azure.DoRetryWithRegistration(client.Client))
238}
239
240// GetResponder handles the response to the Get request. The method always
241// closes the http.Response Body.
242func (client PublicIPAddressesClient) GetResponder(resp *http.Response) (result PublicIPAddress, err error) {
243	err = autorest.Respond(
244		resp,
245		client.ByInspecting(),
246		azure.WithErrorUnlessStatusCode(http.StatusOK),
247		autorest.ByUnmarshallingJSON(&result),
248		autorest.ByClosing())
249	result.Response = autorest.Response{Response: resp}
250	return
251}
252
253// List the List publicIpAddress opertion retrieves all the publicIpAddresses in a resource group.
254// Parameters:
255// resourceGroupName - the name of the resource group.
256func (client PublicIPAddressesClient) List(ctx context.Context, resourceGroupName string) (result PublicIPAddressListResultPage, err error) {
257	result.fn = client.listNextResults
258	req, err := client.ListPreparer(ctx, resourceGroupName)
259	if err != nil {
260		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", nil, "Failure preparing request")
261		return
262	}
263
264	resp, err := client.ListSender(req)
265	if err != nil {
266		result.pialr.Response = autorest.Response{Response: resp}
267		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", resp, "Failure sending request")
268		return
269	}
270
271	result.pialr, err = client.ListResponder(resp)
272	if err != nil {
273		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", resp, "Failure responding to request")
274	}
275
276	return
277}
278
279// ListPreparer prepares the List request.
280func (client PublicIPAddressesClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
281	pathParameters := map[string]interface{}{
282		"resourceGroupName": autorest.Encode("path", resourceGroupName),
283		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
284	}
285
286	const APIVersion = "2015-05-01-preview"
287	queryParameters := map[string]interface{}{
288		"api-version": APIVersion,
289	}
290
291	preparer := autorest.CreatePreparer(
292		autorest.AsGet(),
293		autorest.WithBaseURL(client.BaseURI),
294		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses", pathParameters),
295		autorest.WithQueryParameters(queryParameters))
296	return preparer.Prepare((&http.Request{}).WithContext(ctx))
297}
298
299// ListSender sends the List request. The method will close the
300// http.Response Body if it receives an error.
301func (client PublicIPAddressesClient) ListSender(req *http.Request) (*http.Response, error) {
302	return autorest.SendWithSender(client, req,
303		azure.DoRetryWithRegistration(client.Client))
304}
305
306// ListResponder handles the response to the List request. The method always
307// closes the http.Response Body.
308func (client PublicIPAddressesClient) ListResponder(resp *http.Response) (result PublicIPAddressListResult, err error) {
309	err = autorest.Respond(
310		resp,
311		client.ByInspecting(),
312		azure.WithErrorUnlessStatusCode(http.StatusOK),
313		autorest.ByUnmarshallingJSON(&result),
314		autorest.ByClosing())
315	result.Response = autorest.Response{Response: resp}
316	return
317}
318
319// listNextResults retrieves the next set of results, if any.
320func (client PublicIPAddressesClient) listNextResults(lastResults PublicIPAddressListResult) (result PublicIPAddressListResult, err error) {
321	req, err := lastResults.publicIPAddressListResultPreparer()
322	if err != nil {
323		return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listNextResults", nil, "Failure preparing next results request")
324	}
325	if req == nil {
326		return
327	}
328	resp, err := client.ListSender(req)
329	if err != nil {
330		result.Response = autorest.Response{Response: resp}
331		return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listNextResults", resp, "Failure sending next results request")
332	}
333	result, err = client.ListResponder(resp)
334	if err != nil {
335		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listNextResults", resp, "Failure responding to next results request")
336	}
337	return
338}
339
340// ListComplete enumerates all values, automatically crossing page boundaries as required.
341func (client PublicIPAddressesClient) ListComplete(ctx context.Context, resourceGroupName string) (result PublicIPAddressListResultIterator, err error) {
342	result.page, err = client.List(ctx, resourceGroupName)
343	return
344}
345
346// ListAll the List publicIpAddress opertion retrieves all the publicIpAddresses in a subscription.
347func (client PublicIPAddressesClient) ListAll(ctx context.Context) (result PublicIPAddressListResultPage, err error) {
348	result.fn = client.listAllNextResults
349	req, err := client.ListAllPreparer(ctx)
350	if err != nil {
351		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", nil, "Failure preparing request")
352		return
353	}
354
355	resp, err := client.ListAllSender(req)
356	if err != nil {
357		result.pialr.Response = autorest.Response{Response: resp}
358		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", resp, "Failure sending request")
359		return
360	}
361
362	result.pialr, err = client.ListAllResponder(resp)
363	if err != nil {
364		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", resp, "Failure responding to request")
365	}
366
367	return
368}
369
370// ListAllPreparer prepares the ListAll request.
371func (client PublicIPAddressesClient) ListAllPreparer(ctx context.Context) (*http.Request, error) {
372	pathParameters := map[string]interface{}{
373		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
374	}
375
376	const APIVersion = "2015-05-01-preview"
377	queryParameters := map[string]interface{}{
378		"api-version": APIVersion,
379	}
380
381	preparer := autorest.CreatePreparer(
382		autorest.AsGet(),
383		autorest.WithBaseURL(client.BaseURI),
384		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/publicIPAddresses", pathParameters),
385		autorest.WithQueryParameters(queryParameters))
386	return preparer.Prepare((&http.Request{}).WithContext(ctx))
387}
388
389// ListAllSender sends the ListAll request. The method will close the
390// http.Response Body if it receives an error.
391func (client PublicIPAddressesClient) ListAllSender(req *http.Request) (*http.Response, error) {
392	return autorest.SendWithSender(client, req,
393		azure.DoRetryWithRegistration(client.Client))
394}
395
396// ListAllResponder handles the response to the ListAll request. The method always
397// closes the http.Response Body.
398func (client PublicIPAddressesClient) ListAllResponder(resp *http.Response) (result PublicIPAddressListResult, err error) {
399	err = autorest.Respond(
400		resp,
401		client.ByInspecting(),
402		azure.WithErrorUnlessStatusCode(http.StatusOK),
403		autorest.ByUnmarshallingJSON(&result),
404		autorest.ByClosing())
405	result.Response = autorest.Response{Response: resp}
406	return
407}
408
409// listAllNextResults retrieves the next set of results, if any.
410func (client PublicIPAddressesClient) listAllNextResults(lastResults PublicIPAddressListResult) (result PublicIPAddressListResult, err error) {
411	req, err := lastResults.publicIPAddressListResultPreparer()
412	if err != nil {
413		return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listAllNextResults", nil, "Failure preparing next results request")
414	}
415	if req == nil {
416		return
417	}
418	resp, err := client.ListAllSender(req)
419	if err != nil {
420		result.Response = autorest.Response{Response: resp}
421		return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listAllNextResults", resp, "Failure sending next results request")
422	}
423	result, err = client.ListAllResponder(resp)
424	if err != nil {
425		err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listAllNextResults", resp, "Failure responding to next results request")
426	}
427	return
428}
429
430// ListAllComplete enumerates all values, automatically crossing page boundaries as required.
431func (client PublicIPAddressesClient) ListAllComplete(ctx context.Context) (result PublicIPAddressListResultIterator, err error) {
432	result.page, err = client.ListAll(ctx)
433	return
434}
435