1// +build go1.13
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// Code generated by Microsoft (R) AutoRest Code Generator.
6// Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
8package armnetwork
9
10import (
11	"context"
12	"github.com/Azure/azure-sdk-for-go/sdk/armcore"
13	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
14	"net/http"
15	"net/url"
16	"strings"
17)
18
19// NetworkInterfaceIPConfigurationsClient contains the methods for the NetworkInterfaceIPConfigurations group.
20// Don't use this type directly, use NewNetworkInterfaceIPConfigurationsClient() instead.
21type NetworkInterfaceIPConfigurationsClient struct {
22	con            *armcore.Connection
23	subscriptionID string
24}
25
26// NewNetworkInterfaceIPConfigurationsClient creates a new instance of NetworkInterfaceIPConfigurationsClient with the specified values.
27func NewNetworkInterfaceIPConfigurationsClient(con *armcore.Connection, subscriptionID string) *NetworkInterfaceIPConfigurationsClient {
28	return &NetworkInterfaceIPConfigurationsClient{con: con, subscriptionID: subscriptionID}
29}
30
31// Get - Gets the specified network interface ip configuration.
32func (client *NetworkInterfaceIPConfigurationsClient) Get(ctx context.Context, resourceGroupName string, networkInterfaceName string, ipConfigurationName string, options *NetworkInterfaceIPConfigurationsGetOptions) (NetworkInterfaceIPConfigurationResponse, error) {
33	req, err := client.getCreateRequest(ctx, resourceGroupName, networkInterfaceName, ipConfigurationName, options)
34	if err != nil {
35		return NetworkInterfaceIPConfigurationResponse{}, err
36	}
37	resp, err := client.con.Pipeline().Do(req)
38	if err != nil {
39		return NetworkInterfaceIPConfigurationResponse{}, err
40	}
41	if !resp.HasStatusCode(http.StatusOK) {
42		return NetworkInterfaceIPConfigurationResponse{}, client.getHandleError(resp)
43	}
44	return client.getHandleResponse(resp)
45}
46
47// getCreateRequest creates the Get request.
48func (client *NetworkInterfaceIPConfigurationsClient) getCreateRequest(ctx context.Context, resourceGroupName string, networkInterfaceName string, ipConfigurationName string, options *NetworkInterfaceIPConfigurationsGetOptions) (*azcore.Request, error) {
49	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}/ipConfigurations/{ipConfigurationName}"
50	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
51	urlPath = strings.ReplaceAll(urlPath, "{networkInterfaceName}", url.PathEscape(networkInterfaceName))
52	urlPath = strings.ReplaceAll(urlPath, "{ipConfigurationName}", url.PathEscape(ipConfigurationName))
53	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
54	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
55	if err != nil {
56		return nil, err
57	}
58	req.Telemetry(telemetryInfo)
59	query := req.URL.Query()
60	query.Set("api-version", "2020-07-01")
61	req.URL.RawQuery = query.Encode()
62	req.Header.Set("Accept", "application/json")
63	return req, nil
64}
65
66// getHandleResponse handles the Get response.
67func (client *NetworkInterfaceIPConfigurationsClient) getHandleResponse(resp *azcore.Response) (NetworkInterfaceIPConfigurationResponse, error) {
68	var val *NetworkInterfaceIPConfiguration
69	if err := resp.UnmarshalAsJSON(&val); err != nil {
70		return NetworkInterfaceIPConfigurationResponse{}, err
71	}
72	return NetworkInterfaceIPConfigurationResponse{RawResponse: resp.Response, NetworkInterfaceIPConfiguration: val}, nil
73}
74
75// getHandleError handles the Get error response.
76func (client *NetworkInterfaceIPConfigurationsClient) getHandleError(resp *azcore.Response) error {
77	var err CloudError
78	if err := resp.UnmarshalAsJSON(&err); err != nil {
79		return err
80	}
81	return azcore.NewResponseError(&err, resp.Response)
82}
83
84// List - Get all ip configurations in a network interface.
85func (client *NetworkInterfaceIPConfigurationsClient) List(resourceGroupName string, networkInterfaceName string, options *NetworkInterfaceIPConfigurationsListOptions) NetworkInterfaceIPConfigurationListResultPager {
86	return &networkInterfaceIPConfigurationListResultPager{
87		pipeline: client.con.Pipeline(),
88		requester: func(ctx context.Context) (*azcore.Request, error) {
89			return client.listCreateRequest(ctx, resourceGroupName, networkInterfaceName, options)
90		},
91		responder: client.listHandleResponse,
92		errorer:   client.listHandleError,
93		advancer: func(ctx context.Context, resp NetworkInterfaceIPConfigurationListResultResponse) (*azcore.Request, error) {
94			return azcore.NewRequest(ctx, http.MethodGet, *resp.NetworkInterfaceIPConfigurationListResult.NextLink)
95		},
96		statusCodes: []int{http.StatusOK},
97	}
98}
99
100// listCreateRequest creates the List request.
101func (client *NetworkInterfaceIPConfigurationsClient) listCreateRequest(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *NetworkInterfaceIPConfigurationsListOptions) (*azcore.Request, error) {
102	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}/ipConfigurations"
103	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
104	urlPath = strings.ReplaceAll(urlPath, "{networkInterfaceName}", url.PathEscape(networkInterfaceName))
105	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
106	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
107	if err != nil {
108		return nil, err
109	}
110	req.Telemetry(telemetryInfo)
111	query := req.URL.Query()
112	query.Set("api-version", "2020-07-01")
113	req.URL.RawQuery = query.Encode()
114	req.Header.Set("Accept", "application/json")
115	return req, nil
116}
117
118// listHandleResponse handles the List response.
119func (client *NetworkInterfaceIPConfigurationsClient) listHandleResponse(resp *azcore.Response) (NetworkInterfaceIPConfigurationListResultResponse, error) {
120	var val *NetworkInterfaceIPConfigurationListResult
121	if err := resp.UnmarshalAsJSON(&val); err != nil {
122		return NetworkInterfaceIPConfigurationListResultResponse{}, err
123	}
124	return NetworkInterfaceIPConfigurationListResultResponse{RawResponse: resp.Response, NetworkInterfaceIPConfigurationListResult: val}, nil
125}
126
127// listHandleError handles the List error response.
128func (client *NetworkInterfaceIPConfigurationsClient) listHandleError(resp *azcore.Response) error {
129	var err CloudError
130	if err := resp.UnmarshalAsJSON(&err); err != nil {
131		return err
132	}
133	return azcore.NewResponseError(&err, resp.Response)
134}
135