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