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