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