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/autorest/validation"
25	"net/http"
26)
27
28// PacketCapturesClient is the network Client
29type PacketCapturesClient struct {
30	BaseClient
31}
32
33// NewPacketCapturesClient creates an instance of the PacketCapturesClient client.
34func NewPacketCapturesClient(subscriptionID string) PacketCapturesClient {
35	return NewPacketCapturesClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewPacketCapturesClientWithBaseURI creates an instance of the PacketCapturesClient client.
39func NewPacketCapturesClientWithBaseURI(baseURI string, subscriptionID string) PacketCapturesClient {
40	return PacketCapturesClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// Create create and start a packet capture on the specified VM.
44// Parameters:
45// resourceGroupName - the name of the resource group.
46// networkWatcherName - the name of the network watcher.
47// packetCaptureName - the name of the packet capture session.
48// parameters - parameters that define the create packet capture operation.
49func (client PacketCapturesClient) Create(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, parameters PacketCapture) (result PacketCapturesCreateFuture, err error) {
50	if err := validation.Validate([]validation.Validation{
51		{TargetValue: parameters,
52			Constraints: []validation.Constraint{{Target: "parameters.PacketCaptureParameters", Name: validation.Null, Rule: true,
53				Chain: []validation.Constraint{{Target: "parameters.PacketCaptureParameters.Target", Name: validation.Null, Rule: true, Chain: nil},
54					{Target: "parameters.PacketCaptureParameters.StorageLocation", Name: validation.Null, Rule: true, Chain: nil},
55				}}}}}); err != nil {
56		return result, validation.NewError("network.PacketCapturesClient", "Create", err.Error())
57	}
58
59	req, err := client.CreatePreparer(ctx, resourceGroupName, networkWatcherName, packetCaptureName, parameters)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "Create", nil, "Failure preparing request")
62		return
63	}
64
65	result, err = client.CreateSender(req)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "Create", result.Response(), "Failure sending request")
68		return
69	}
70
71	return
72}
73
74// CreatePreparer prepares the Create request.
75func (client PacketCapturesClient) CreatePreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, parameters PacketCapture) (*http.Request, error) {
76	pathParameters := map[string]interface{}{
77		"networkWatcherName": autorest.Encode("path", networkWatcherName),
78		"packetCaptureName":  autorest.Encode("path", packetCaptureName),
79		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
80		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
81	}
82
83	const APIVersion = "2016-09-01"
84	queryParameters := map[string]interface{}{
85		"api-version": APIVersion,
86	}
87
88	preparer := autorest.CreatePreparer(
89		autorest.AsContentType("application/json; charset=utf-8"),
90		autorest.AsPut(),
91		autorest.WithBaseURL(client.BaseURI),
92		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures/{packetCaptureName}", pathParameters),
93		autorest.WithJSON(parameters),
94		autorest.WithQueryParameters(queryParameters))
95	return preparer.Prepare((&http.Request{}).WithContext(ctx))
96}
97
98// CreateSender sends the Create request. The method will close the
99// http.Response Body if it receives an error.
100func (client PacketCapturesClient) CreateSender(req *http.Request) (future PacketCapturesCreateFuture, err error) {
101	sender := autorest.DecorateSender(client, azure.DoRetryWithRegistration(client.Client))
102	future.Future = azure.NewFuture(req)
103	future.req = req
104	_, err = future.Done(sender)
105	if err != nil {
106		return
107	}
108	err = autorest.Respond(future.Response(),
109		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated))
110	return
111}
112
113// CreateResponder handles the response to the Create request. The method always
114// closes the http.Response Body.
115func (client PacketCapturesClient) CreateResponder(resp *http.Response) (result PacketCaptureResult, err error) {
116	err = autorest.Respond(
117		resp,
118		client.ByInspecting(),
119		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
120		autorest.ByUnmarshallingJSON(&result),
121		autorest.ByClosing())
122	result.Response = autorest.Response{Response: resp}
123	return
124}
125
126// Delete deletes the specified packet capture session.
127// Parameters:
128// resourceGroupName - the name of the resource group.
129// networkWatcherName - the name of the network watcher.
130// packetCaptureName - the name of the packet capture session.
131func (client PacketCapturesClient) Delete(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string) (result PacketCapturesDeleteFuture, err error) {
132	req, err := client.DeletePreparer(ctx, resourceGroupName, networkWatcherName, packetCaptureName)
133	if err != nil {
134		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "Delete", nil, "Failure preparing request")
135		return
136	}
137
138	result, err = client.DeleteSender(req)
139	if err != nil {
140		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "Delete", result.Response(), "Failure sending request")
141		return
142	}
143
144	return
145}
146
147// DeletePreparer prepares the Delete request.
148func (client PacketCapturesClient) DeletePreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string) (*http.Request, error) {
149	pathParameters := map[string]interface{}{
150		"networkWatcherName": autorest.Encode("path", networkWatcherName),
151		"packetCaptureName":  autorest.Encode("path", packetCaptureName),
152		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
153		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
154	}
155
156	const APIVersion = "2016-09-01"
157	queryParameters := map[string]interface{}{
158		"api-version": APIVersion,
159	}
160
161	preparer := autorest.CreatePreparer(
162		autorest.AsDelete(),
163		autorest.WithBaseURL(client.BaseURI),
164		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures/{packetCaptureName}", pathParameters),
165		autorest.WithQueryParameters(queryParameters))
166	return preparer.Prepare((&http.Request{}).WithContext(ctx))
167}
168
169// DeleteSender sends the Delete request. The method will close the
170// http.Response Body if it receives an error.
171func (client PacketCapturesClient) DeleteSender(req *http.Request) (future PacketCapturesDeleteFuture, err error) {
172	sender := autorest.DecorateSender(client, azure.DoRetryWithRegistration(client.Client))
173	future.Future = azure.NewFuture(req)
174	future.req = req
175	_, err = future.Done(sender)
176	if err != nil {
177		return
178	}
179	err = autorest.Respond(future.Response(),
180		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent))
181	return
182}
183
184// DeleteResponder handles the response to the Delete request. The method always
185// closes the http.Response Body.
186func (client PacketCapturesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
187	err = autorest.Respond(
188		resp,
189		client.ByInspecting(),
190		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
191		autorest.ByClosing())
192	result.Response = resp
193	return
194}
195
196// Get gets a packet capture session by name.
197// Parameters:
198// resourceGroupName - the name of the resource group.
199// networkWatcherName - the name of the network watcher.
200// packetCaptureName - the name of the packet capture session.
201func (client PacketCapturesClient) Get(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string) (result PacketCaptureResult, err error) {
202	req, err := client.GetPreparer(ctx, resourceGroupName, networkWatcherName, packetCaptureName)
203	if err != nil {
204		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "Get", nil, "Failure preparing request")
205		return
206	}
207
208	resp, err := client.GetSender(req)
209	if err != nil {
210		result.Response = autorest.Response{Response: resp}
211		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "Get", resp, "Failure sending request")
212		return
213	}
214
215	result, err = client.GetResponder(resp)
216	if err != nil {
217		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "Get", resp, "Failure responding to request")
218	}
219
220	return
221}
222
223// GetPreparer prepares the Get request.
224func (client PacketCapturesClient) GetPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string) (*http.Request, error) {
225	pathParameters := map[string]interface{}{
226		"networkWatcherName": autorest.Encode("path", networkWatcherName),
227		"packetCaptureName":  autorest.Encode("path", packetCaptureName),
228		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
229		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
230	}
231
232	const APIVersion = "2016-09-01"
233	queryParameters := map[string]interface{}{
234		"api-version": APIVersion,
235	}
236
237	preparer := autorest.CreatePreparer(
238		autorest.AsGet(),
239		autorest.WithBaseURL(client.BaseURI),
240		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures/{packetCaptureName}", pathParameters),
241		autorest.WithQueryParameters(queryParameters))
242	return preparer.Prepare((&http.Request{}).WithContext(ctx))
243}
244
245// GetSender sends the Get request. The method will close the
246// http.Response Body if it receives an error.
247func (client PacketCapturesClient) GetSender(req *http.Request) (*http.Response, error) {
248	return autorest.SendWithSender(client, req,
249		azure.DoRetryWithRegistration(client.Client))
250}
251
252// GetResponder handles the response to the Get request. The method always
253// closes the http.Response Body.
254func (client PacketCapturesClient) GetResponder(resp *http.Response) (result PacketCaptureResult, err error) {
255	err = autorest.Respond(
256		resp,
257		client.ByInspecting(),
258		azure.WithErrorUnlessStatusCode(http.StatusOK),
259		autorest.ByUnmarshallingJSON(&result),
260		autorest.ByClosing())
261	result.Response = autorest.Response{Response: resp}
262	return
263}
264
265// GetStatus query the status of a running packet capture session.
266// Parameters:
267// resourceGroupName - the name of the resource group.
268// networkWatcherName - the name of the Network Watcher resource.
269// packetCaptureName - the name given to the packet capture session.
270func (client PacketCapturesClient) GetStatus(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string) (result PacketCapturesGetStatusFuture, err error) {
271	req, err := client.GetStatusPreparer(ctx, resourceGroupName, networkWatcherName, packetCaptureName)
272	if err != nil {
273		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "GetStatus", nil, "Failure preparing request")
274		return
275	}
276
277	result, err = client.GetStatusSender(req)
278	if err != nil {
279		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "GetStatus", result.Response(), "Failure sending request")
280		return
281	}
282
283	return
284}
285
286// GetStatusPreparer prepares the GetStatus request.
287func (client PacketCapturesClient) GetStatusPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string) (*http.Request, error) {
288	pathParameters := map[string]interface{}{
289		"networkWatcherName": autorest.Encode("path", networkWatcherName),
290		"packetCaptureName":  autorest.Encode("path", packetCaptureName),
291		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
292		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
293	}
294
295	const APIVersion = "2016-09-01"
296	queryParameters := map[string]interface{}{
297		"api-version": APIVersion,
298	}
299
300	preparer := autorest.CreatePreparer(
301		autorest.AsPost(),
302		autorest.WithBaseURL(client.BaseURI),
303		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures/{packetCaptureName}/queryStatus", pathParameters),
304		autorest.WithQueryParameters(queryParameters))
305	return preparer.Prepare((&http.Request{}).WithContext(ctx))
306}
307
308// GetStatusSender sends the GetStatus request. The method will close the
309// http.Response Body if it receives an error.
310func (client PacketCapturesClient) GetStatusSender(req *http.Request) (future PacketCapturesGetStatusFuture, err error) {
311	sender := autorest.DecorateSender(client, azure.DoRetryWithRegistration(client.Client))
312	future.Future = azure.NewFuture(req)
313	future.req = req
314	_, err = future.Done(sender)
315	if err != nil {
316		return
317	}
318	err = autorest.Respond(future.Response(),
319		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted))
320	return
321}
322
323// GetStatusResponder handles the response to the GetStatus request. The method always
324// closes the http.Response Body.
325func (client PacketCapturesClient) GetStatusResponder(resp *http.Response) (result PacketCaptureQueryStatusResult, err error) {
326	err = autorest.Respond(
327		resp,
328		client.ByInspecting(),
329		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
330		autorest.ByUnmarshallingJSON(&result),
331		autorest.ByClosing())
332	result.Response = autorest.Response{Response: resp}
333	return
334}
335
336// List lists all packet capture sessions within the specified resource group.
337// Parameters:
338// resourceGroupName - the name of the resource group.
339// networkWatcherName - the name of the Network Watcher resource.
340func (client PacketCapturesClient) List(ctx context.Context, resourceGroupName string, networkWatcherName string) (result PacketCaptureListResult, err error) {
341	req, err := client.ListPreparer(ctx, resourceGroupName, networkWatcherName)
342	if err != nil {
343		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "List", nil, "Failure preparing request")
344		return
345	}
346
347	resp, err := client.ListSender(req)
348	if err != nil {
349		result.Response = autorest.Response{Response: resp}
350		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "List", resp, "Failure sending request")
351		return
352	}
353
354	result, err = client.ListResponder(resp)
355	if err != nil {
356		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "List", resp, "Failure responding to request")
357	}
358
359	return
360}
361
362// ListPreparer prepares the List request.
363func (client PacketCapturesClient) ListPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string) (*http.Request, error) {
364	pathParameters := map[string]interface{}{
365		"networkWatcherName": autorest.Encode("path", networkWatcherName),
366		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
367		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
368	}
369
370	const APIVersion = "2016-09-01"
371	queryParameters := map[string]interface{}{
372		"api-version": APIVersion,
373	}
374
375	preparer := autorest.CreatePreparer(
376		autorest.AsGet(),
377		autorest.WithBaseURL(client.BaseURI),
378		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures", pathParameters),
379		autorest.WithQueryParameters(queryParameters))
380	return preparer.Prepare((&http.Request{}).WithContext(ctx))
381}
382
383// ListSender sends the List request. The method will close the
384// http.Response Body if it receives an error.
385func (client PacketCapturesClient) ListSender(req *http.Request) (*http.Response, error) {
386	return autorest.SendWithSender(client, req,
387		azure.DoRetryWithRegistration(client.Client))
388}
389
390// ListResponder handles the response to the List request. The method always
391// closes the http.Response Body.
392func (client PacketCapturesClient) ListResponder(resp *http.Response) (result PacketCaptureListResult, err error) {
393	err = autorest.Respond(
394		resp,
395		client.ByInspecting(),
396		azure.WithErrorUnlessStatusCode(http.StatusOK),
397		autorest.ByUnmarshallingJSON(&result),
398		autorest.ByClosing())
399	result.Response = autorest.Response{Response: resp}
400	return
401}
402
403// Stop stops a specified packet capture session.
404// Parameters:
405// resourceGroupName - the name of the resource group.
406// networkWatcherName - the name of the network watcher.
407// packetCaptureName - the name of the packet capture session.
408func (client PacketCapturesClient) Stop(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string) (result PacketCapturesStopFuture, err error) {
409	req, err := client.StopPreparer(ctx, resourceGroupName, networkWatcherName, packetCaptureName)
410	if err != nil {
411		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "Stop", nil, "Failure preparing request")
412		return
413	}
414
415	result, err = client.StopSender(req)
416	if err != nil {
417		err = autorest.NewErrorWithError(err, "network.PacketCapturesClient", "Stop", result.Response(), "Failure sending request")
418		return
419	}
420
421	return
422}
423
424// StopPreparer prepares the Stop request.
425func (client PacketCapturesClient) StopPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string) (*http.Request, error) {
426	pathParameters := map[string]interface{}{
427		"networkWatcherName": autorest.Encode("path", networkWatcherName),
428		"packetCaptureName":  autorest.Encode("path", packetCaptureName),
429		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
430		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
431	}
432
433	const APIVersion = "2016-09-01"
434	queryParameters := map[string]interface{}{
435		"api-version": APIVersion,
436	}
437
438	preparer := autorest.CreatePreparer(
439		autorest.AsPost(),
440		autorest.WithBaseURL(client.BaseURI),
441		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures/{packetCaptureName}/stop", pathParameters),
442		autorest.WithQueryParameters(queryParameters))
443	return preparer.Prepare((&http.Request{}).WithContext(ctx))
444}
445
446// StopSender sends the Stop request. The method will close the
447// http.Response Body if it receives an error.
448func (client PacketCapturesClient) StopSender(req *http.Request) (future PacketCapturesStopFuture, err error) {
449	sender := autorest.DecorateSender(client, azure.DoRetryWithRegistration(client.Client))
450	future.Future = azure.NewFuture(req)
451	future.req = req
452	_, err = future.Done(sender)
453	if err != nil {
454		return
455	}
456	err = autorest.Respond(future.Response(),
457		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted))
458	return
459}
460
461// StopResponder handles the response to the Stop request. The method always
462// closes the http.Response Body.
463func (client PacketCapturesClient) StopResponder(resp *http.Response) (result autorest.Response, err error) {
464	err = autorest.Respond(
465		resp,
466		client.ByInspecting(),
467		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
468		autorest.ByClosing())
469	result.Response = resp
470	return
471}
472