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// InterfaceIPConfigurationsClient is the network Client
29type InterfaceIPConfigurationsClient struct {
30	BaseClient
31}
32
33// NewInterfaceIPConfigurationsClient creates an instance of the InterfaceIPConfigurationsClient client.
34func NewInterfaceIPConfigurationsClient(subscriptionID string) InterfaceIPConfigurationsClient {
35	return NewInterfaceIPConfigurationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewInterfaceIPConfigurationsClientWithBaseURI creates an instance of the InterfaceIPConfigurationsClient client
39// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
40// clouds, Azure stack).
41func NewInterfaceIPConfigurationsClientWithBaseURI(baseURI string, subscriptionID string) InterfaceIPConfigurationsClient {
42	return InterfaceIPConfigurationsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Get gets the specified network interface ip configuration.
46// Parameters:
47// resourceGroupName - the name of the resource group.
48// networkInterfaceName - the name of the network interface.
49// IPConfigurationName - the name of the ip configuration name.
50func (client InterfaceIPConfigurationsClient) Get(ctx context.Context, resourceGroupName string, networkInterfaceName string, IPConfigurationName string) (result InterfaceIPConfiguration, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/InterfaceIPConfigurationsClient.Get")
53		defer func() {
54			sc := -1
55			if result.Response.Response != nil {
56				sc = result.Response.Response.StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	req, err := client.GetPreparer(ctx, resourceGroupName, networkInterfaceName, IPConfigurationName)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "network.InterfaceIPConfigurationsClient", "Get", nil, "Failure preparing request")
64		return
65	}
66
67	resp, err := client.GetSender(req)
68	if err != nil {
69		result.Response = autorest.Response{Response: resp}
70		err = autorest.NewErrorWithError(err, "network.InterfaceIPConfigurationsClient", "Get", resp, "Failure sending request")
71		return
72	}
73
74	result, err = client.GetResponder(resp)
75	if err != nil {
76		err = autorest.NewErrorWithError(err, "network.InterfaceIPConfigurationsClient", "Get", resp, "Failure responding to request")
77		return
78	}
79
80	return
81}
82
83// GetPreparer prepares the Get request.
84func (client InterfaceIPConfigurationsClient) GetPreparer(ctx context.Context, resourceGroupName string, networkInterfaceName string, IPConfigurationName string) (*http.Request, error) {
85	pathParameters := map[string]interface{}{
86		"ipConfigurationName":  autorest.Encode("path", IPConfigurationName),
87		"networkInterfaceName": autorest.Encode("path", networkInterfaceName),
88		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
89		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2019-06-01"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	preparer := autorest.CreatePreparer(
98		autorest.AsGet(),
99		autorest.WithBaseURL(client.BaseURI),
100		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}/ipConfigurations/{ipConfigurationName}", pathParameters),
101		autorest.WithQueryParameters(queryParameters))
102	return preparer.Prepare((&http.Request{}).WithContext(ctx))
103}
104
105// GetSender sends the Get request. The method will close the
106// http.Response Body if it receives an error.
107func (client InterfaceIPConfigurationsClient) GetSender(req *http.Request) (*http.Response, error) {
108	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
109}
110
111// GetResponder handles the response to the Get request. The method always
112// closes the http.Response Body.
113func (client InterfaceIPConfigurationsClient) GetResponder(resp *http.Response) (result InterfaceIPConfiguration, err error) {
114	err = autorest.Respond(
115		resp,
116		azure.WithErrorUnlessStatusCode(http.StatusOK),
117		autorest.ByUnmarshallingJSON(&result),
118		autorest.ByClosing())
119	result.Response = autorest.Response{Response: resp}
120	return
121}
122
123// List get all ip configurations in a network interface.
124// Parameters:
125// resourceGroupName - the name of the resource group.
126// networkInterfaceName - the name of the network interface.
127func (client InterfaceIPConfigurationsClient) List(ctx context.Context, resourceGroupName string, networkInterfaceName string) (result InterfaceIPConfigurationListResultPage, err error) {
128	if tracing.IsEnabled() {
129		ctx = tracing.StartSpan(ctx, fqdn+"/InterfaceIPConfigurationsClient.List")
130		defer func() {
131			sc := -1
132			if result.iiclr.Response.Response != nil {
133				sc = result.iiclr.Response.Response.StatusCode
134			}
135			tracing.EndSpan(ctx, sc, err)
136		}()
137	}
138	result.fn = client.listNextResults
139	req, err := client.ListPreparer(ctx, resourceGroupName, networkInterfaceName)
140	if err != nil {
141		err = autorest.NewErrorWithError(err, "network.InterfaceIPConfigurationsClient", "List", nil, "Failure preparing request")
142		return
143	}
144
145	resp, err := client.ListSender(req)
146	if err != nil {
147		result.iiclr.Response = autorest.Response{Response: resp}
148		err = autorest.NewErrorWithError(err, "network.InterfaceIPConfigurationsClient", "List", resp, "Failure sending request")
149		return
150	}
151
152	result.iiclr, err = client.ListResponder(resp)
153	if err != nil {
154		err = autorest.NewErrorWithError(err, "network.InterfaceIPConfigurationsClient", "List", resp, "Failure responding to request")
155		return
156	}
157	if result.iiclr.hasNextLink() && result.iiclr.IsEmpty() {
158		err = result.NextWithContext(ctx)
159		return
160	}
161
162	return
163}
164
165// ListPreparer prepares the List request.
166func (client InterfaceIPConfigurationsClient) ListPreparer(ctx context.Context, resourceGroupName string, networkInterfaceName string) (*http.Request, error) {
167	pathParameters := map[string]interface{}{
168		"networkInterfaceName": autorest.Encode("path", networkInterfaceName),
169		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
170		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
171	}
172
173	const APIVersion = "2019-06-01"
174	queryParameters := map[string]interface{}{
175		"api-version": APIVersion,
176	}
177
178	preparer := autorest.CreatePreparer(
179		autorest.AsGet(),
180		autorest.WithBaseURL(client.BaseURI),
181		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}/ipConfigurations", pathParameters),
182		autorest.WithQueryParameters(queryParameters))
183	return preparer.Prepare((&http.Request{}).WithContext(ctx))
184}
185
186// ListSender sends the List request. The method will close the
187// http.Response Body if it receives an error.
188func (client InterfaceIPConfigurationsClient) ListSender(req *http.Request) (*http.Response, error) {
189	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
190}
191
192// ListResponder handles the response to the List request. The method always
193// closes the http.Response Body.
194func (client InterfaceIPConfigurationsClient) ListResponder(resp *http.Response) (result InterfaceIPConfigurationListResult, err error) {
195	err = autorest.Respond(
196		resp,
197		azure.WithErrorUnlessStatusCode(http.StatusOK),
198		autorest.ByUnmarshallingJSON(&result),
199		autorest.ByClosing())
200	result.Response = autorest.Response{Response: resp}
201	return
202}
203
204// listNextResults retrieves the next set of results, if any.
205func (client InterfaceIPConfigurationsClient) listNextResults(ctx context.Context, lastResults InterfaceIPConfigurationListResult) (result InterfaceIPConfigurationListResult, err error) {
206	req, err := lastResults.interfaceIPConfigurationListResultPreparer(ctx)
207	if err != nil {
208		return result, autorest.NewErrorWithError(err, "network.InterfaceIPConfigurationsClient", "listNextResults", nil, "Failure preparing next results request")
209	}
210	if req == nil {
211		return
212	}
213	resp, err := client.ListSender(req)
214	if err != nil {
215		result.Response = autorest.Response{Response: resp}
216		return result, autorest.NewErrorWithError(err, "network.InterfaceIPConfigurationsClient", "listNextResults", resp, "Failure sending next results request")
217	}
218	result, err = client.ListResponder(resp)
219	if err != nil {
220		err = autorest.NewErrorWithError(err, "network.InterfaceIPConfigurationsClient", "listNextResults", resp, "Failure responding to next results request")
221	}
222	return
223}
224
225// ListComplete enumerates all values, automatically crossing page boundaries as required.
226func (client InterfaceIPConfigurationsClient) ListComplete(ctx context.Context, resourceGroupName string, networkInterfaceName string) (result InterfaceIPConfigurationListResultIterator, err error) {
227	if tracing.IsEnabled() {
228		ctx = tracing.StartSpan(ctx, fqdn+"/InterfaceIPConfigurationsClient.List")
229		defer func() {
230			sc := -1
231			if result.Response().Response.Response != nil {
232				sc = result.page.Response().Response.Response.StatusCode
233			}
234			tracing.EndSpan(ctx, sc, err)
235		}()
236	}
237	result.page, err = client.List(ctx, resourceGroupName, networkInterfaceName)
238	return
239}
240