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