github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/packetcaptures_client.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // Licensed under the MIT License. See License.txt in the project root for license information. 6 // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 package armnetwork 10 11 import ( 12 "context" 13 "errors" 14 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 18 "net/http" 19 "net/url" 20 "strings" 21 ) 22 23 // PacketCapturesClient contains the methods for the PacketCaptures group. 24 // Don't use this type directly, use NewPacketCapturesClient() instead. 25 type PacketCapturesClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewPacketCapturesClient creates a new instance of PacketCapturesClient with the specified values. 31 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 32 // ID forms part of the URI for every service call. 33 // - credential - used to authorize requests. Usually a credential from azidentity. 34 // - options - pass nil to accept the default values. 35 func NewPacketCapturesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*PacketCapturesClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &PacketCapturesClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreate - Create and start a packet capture on the specified VM. 48 // If the operation fails it returns an *azcore.ResponseError type. 49 // 50 // Generated from API version 2024-05-01 51 // - resourceGroupName - The name of the resource group. 52 // - networkWatcherName - The name of the network watcher. 53 // - packetCaptureName - The name of the packet capture session. 54 // - parameters - Parameters that define the create packet capture operation. 55 // - options - PacketCapturesClientBeginCreateOptions contains the optional parameters for the PacketCapturesClient.BeginCreate 56 // method. 57 func (client *PacketCapturesClient) BeginCreate(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, parameters PacketCapture, options *PacketCapturesClientBeginCreateOptions) (*runtime.Poller[PacketCapturesClientCreateResponse], error) { 58 if options == nil || options.ResumeToken == "" { 59 resp, err := client.create(ctx, resourceGroupName, networkWatcherName, packetCaptureName, parameters, options) 60 if err != nil { 61 return nil, err 62 } 63 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientCreateResponse]{ 64 FinalStateVia: runtime.FinalStateViaAzureAsyncOp, 65 Tracer: client.internal.Tracer(), 66 }) 67 return poller, err 68 } else { 69 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[PacketCapturesClientCreateResponse]{ 70 Tracer: client.internal.Tracer(), 71 }) 72 } 73 } 74 75 // Create - Create and start a packet capture on the specified VM. 76 // If the operation fails it returns an *azcore.ResponseError type. 77 // 78 // Generated from API version 2024-05-01 79 func (client *PacketCapturesClient) create(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, parameters PacketCapture, options *PacketCapturesClientBeginCreateOptions) (*http.Response, error) { 80 var err error 81 const operationName = "PacketCapturesClient.BeginCreate" 82 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 83 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 84 defer func() { endSpan(err) }() 85 req, err := client.createCreateRequest(ctx, resourceGroupName, networkWatcherName, packetCaptureName, parameters, options) 86 if err != nil { 87 return nil, err 88 } 89 httpResp, err := client.internal.Pipeline().Do(req) 90 if err != nil { 91 return nil, err 92 } 93 if !runtime.HasStatusCode(httpResp, http.StatusCreated) { 94 err = runtime.NewResponseError(httpResp) 95 return nil, err 96 } 97 return httpResp, nil 98 } 99 100 // createCreateRequest creates the Create request. 101 func (client *PacketCapturesClient) createCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, parameters PacketCapture, options *PacketCapturesClientBeginCreateOptions) (*policy.Request, error) { 102 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures/{packetCaptureName}" 103 if resourceGroupName == "" { 104 return nil, errors.New("parameter resourceGroupName cannot be empty") 105 } 106 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 107 if networkWatcherName == "" { 108 return nil, errors.New("parameter networkWatcherName cannot be empty") 109 } 110 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 111 if packetCaptureName == "" { 112 return nil, errors.New("parameter packetCaptureName cannot be empty") 113 } 114 urlPath = strings.ReplaceAll(urlPath, "{packetCaptureName}", url.PathEscape(packetCaptureName)) 115 if client.subscriptionID == "" { 116 return nil, errors.New("parameter client.subscriptionID cannot be empty") 117 } 118 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 119 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 120 if err != nil { 121 return nil, err 122 } 123 reqQP := req.Raw().URL.Query() 124 reqQP.Set("api-version", "2024-05-01") 125 req.Raw().URL.RawQuery = reqQP.Encode() 126 req.Raw().Header["Accept"] = []string{"application/json"} 127 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 128 return nil, err 129 } 130 return req, nil 131 } 132 133 // BeginDelete - Deletes the specified packet capture session. 134 // If the operation fails it returns an *azcore.ResponseError type. 135 // 136 // Generated from API version 2024-05-01 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. 140 // - options - PacketCapturesClientBeginDeleteOptions contains the optional parameters for the PacketCapturesClient.BeginDelete 141 // method. 142 func (client *PacketCapturesClient) BeginDelete(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginDeleteOptions) (*runtime.Poller[PacketCapturesClientDeleteResponse], error) { 143 if options == nil || options.ResumeToken == "" { 144 resp, err := client.deleteOperation(ctx, resourceGroupName, networkWatcherName, packetCaptureName, options) 145 if err != nil { 146 return nil, err 147 } 148 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientDeleteResponse]{ 149 FinalStateVia: runtime.FinalStateViaLocation, 150 Tracer: client.internal.Tracer(), 151 }) 152 return poller, err 153 } else { 154 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[PacketCapturesClientDeleteResponse]{ 155 Tracer: client.internal.Tracer(), 156 }) 157 } 158 } 159 160 // Delete - Deletes the specified packet capture session. 161 // If the operation fails it returns an *azcore.ResponseError type. 162 // 163 // Generated from API version 2024-05-01 164 func (client *PacketCapturesClient) deleteOperation(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginDeleteOptions) (*http.Response, error) { 165 var err error 166 const operationName = "PacketCapturesClient.BeginDelete" 167 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 168 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 169 defer func() { endSpan(err) }() 170 req, err := client.deleteCreateRequest(ctx, resourceGroupName, networkWatcherName, packetCaptureName, options) 171 if err != nil { 172 return nil, err 173 } 174 httpResp, err := client.internal.Pipeline().Do(req) 175 if err != nil { 176 return nil, err 177 } 178 if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { 179 err = runtime.NewResponseError(httpResp) 180 return nil, err 181 } 182 return httpResp, nil 183 } 184 185 // deleteCreateRequest creates the Delete request. 186 func (client *PacketCapturesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginDeleteOptions) (*policy.Request, error) { 187 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures/{packetCaptureName}" 188 if resourceGroupName == "" { 189 return nil, errors.New("parameter resourceGroupName cannot be empty") 190 } 191 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 192 if networkWatcherName == "" { 193 return nil, errors.New("parameter networkWatcherName cannot be empty") 194 } 195 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 196 if packetCaptureName == "" { 197 return nil, errors.New("parameter packetCaptureName cannot be empty") 198 } 199 urlPath = strings.ReplaceAll(urlPath, "{packetCaptureName}", url.PathEscape(packetCaptureName)) 200 if client.subscriptionID == "" { 201 return nil, errors.New("parameter client.subscriptionID cannot be empty") 202 } 203 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 204 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 205 if err != nil { 206 return nil, err 207 } 208 reqQP := req.Raw().URL.Query() 209 reqQP.Set("api-version", "2024-05-01") 210 req.Raw().URL.RawQuery = reqQP.Encode() 211 req.Raw().Header["Accept"] = []string{"application/json"} 212 return req, nil 213 } 214 215 // Get - Gets a packet capture session by name. 216 // If the operation fails it returns an *azcore.ResponseError type. 217 // 218 // Generated from API version 2024-05-01 219 // - resourceGroupName - The name of the resource group. 220 // - networkWatcherName - The name of the network watcher. 221 // - packetCaptureName - The name of the packet capture session. 222 // - options - PacketCapturesClientGetOptions contains the optional parameters for the PacketCapturesClient.Get method. 223 func (client *PacketCapturesClient) Get(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientGetOptions) (PacketCapturesClientGetResponse, error) { 224 var err error 225 const operationName = "PacketCapturesClient.Get" 226 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 227 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 228 defer func() { endSpan(err) }() 229 req, err := client.getCreateRequest(ctx, resourceGroupName, networkWatcherName, packetCaptureName, options) 230 if err != nil { 231 return PacketCapturesClientGetResponse{}, err 232 } 233 httpResp, err := client.internal.Pipeline().Do(req) 234 if err != nil { 235 return PacketCapturesClientGetResponse{}, err 236 } 237 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 238 err = runtime.NewResponseError(httpResp) 239 return PacketCapturesClientGetResponse{}, err 240 } 241 resp, err := client.getHandleResponse(httpResp) 242 return resp, err 243 } 244 245 // getCreateRequest creates the Get request. 246 func (client *PacketCapturesClient) getCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientGetOptions) (*policy.Request, error) { 247 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures/{packetCaptureName}" 248 if resourceGroupName == "" { 249 return nil, errors.New("parameter resourceGroupName cannot be empty") 250 } 251 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 252 if networkWatcherName == "" { 253 return nil, errors.New("parameter networkWatcherName cannot be empty") 254 } 255 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 256 if packetCaptureName == "" { 257 return nil, errors.New("parameter packetCaptureName cannot be empty") 258 } 259 urlPath = strings.ReplaceAll(urlPath, "{packetCaptureName}", url.PathEscape(packetCaptureName)) 260 if client.subscriptionID == "" { 261 return nil, errors.New("parameter client.subscriptionID cannot be empty") 262 } 263 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 264 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 265 if err != nil { 266 return nil, err 267 } 268 reqQP := req.Raw().URL.Query() 269 reqQP.Set("api-version", "2024-05-01") 270 req.Raw().URL.RawQuery = reqQP.Encode() 271 req.Raw().Header["Accept"] = []string{"application/json"} 272 return req, nil 273 } 274 275 // getHandleResponse handles the Get response. 276 func (client *PacketCapturesClient) getHandleResponse(resp *http.Response) (PacketCapturesClientGetResponse, error) { 277 result := PacketCapturesClientGetResponse{} 278 if err := runtime.UnmarshalAsJSON(resp, &result.PacketCaptureResult); err != nil { 279 return PacketCapturesClientGetResponse{}, err 280 } 281 return result, nil 282 } 283 284 // BeginGetStatus - Query the status of a running packet capture session. 285 // If the operation fails it returns an *azcore.ResponseError type. 286 // 287 // Generated from API version 2024-05-01 288 // - resourceGroupName - The name of the resource group. 289 // - networkWatcherName - The name of the Network Watcher resource. 290 // - packetCaptureName - The name given to the packet capture session. 291 // - options - PacketCapturesClientBeginGetStatusOptions contains the optional parameters for the PacketCapturesClient.BeginGetStatus 292 // method. 293 func (client *PacketCapturesClient) BeginGetStatus(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginGetStatusOptions) (*runtime.Poller[PacketCapturesClientGetStatusResponse], error) { 294 if options == nil || options.ResumeToken == "" { 295 resp, err := client.getStatus(ctx, resourceGroupName, networkWatcherName, packetCaptureName, options) 296 if err != nil { 297 return nil, err 298 } 299 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientGetStatusResponse]{ 300 FinalStateVia: runtime.FinalStateViaLocation, 301 Tracer: client.internal.Tracer(), 302 }) 303 return poller, err 304 } else { 305 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[PacketCapturesClientGetStatusResponse]{ 306 Tracer: client.internal.Tracer(), 307 }) 308 } 309 } 310 311 // GetStatus - Query the status of a running packet capture session. 312 // If the operation fails it returns an *azcore.ResponseError type. 313 // 314 // Generated from API version 2024-05-01 315 func (client *PacketCapturesClient) getStatus(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginGetStatusOptions) (*http.Response, error) { 316 var err error 317 const operationName = "PacketCapturesClient.BeginGetStatus" 318 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 319 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 320 defer func() { endSpan(err) }() 321 req, err := client.getStatusCreateRequest(ctx, resourceGroupName, networkWatcherName, packetCaptureName, options) 322 if err != nil { 323 return nil, err 324 } 325 httpResp, err := client.internal.Pipeline().Do(req) 326 if err != nil { 327 return nil, err 328 } 329 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 330 err = runtime.NewResponseError(httpResp) 331 return nil, err 332 } 333 return httpResp, nil 334 } 335 336 // getStatusCreateRequest creates the GetStatus request. 337 func (client *PacketCapturesClient) getStatusCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginGetStatusOptions) (*policy.Request, error) { 338 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures/{packetCaptureName}/queryStatus" 339 if resourceGroupName == "" { 340 return nil, errors.New("parameter resourceGroupName cannot be empty") 341 } 342 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 343 if networkWatcherName == "" { 344 return nil, errors.New("parameter networkWatcherName cannot be empty") 345 } 346 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 347 if packetCaptureName == "" { 348 return nil, errors.New("parameter packetCaptureName cannot be empty") 349 } 350 urlPath = strings.ReplaceAll(urlPath, "{packetCaptureName}", url.PathEscape(packetCaptureName)) 351 if client.subscriptionID == "" { 352 return nil, errors.New("parameter client.subscriptionID cannot be empty") 353 } 354 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 355 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 356 if err != nil { 357 return nil, err 358 } 359 reqQP := req.Raw().URL.Query() 360 reqQP.Set("api-version", "2024-05-01") 361 req.Raw().URL.RawQuery = reqQP.Encode() 362 req.Raw().Header["Accept"] = []string{"application/json"} 363 return req, nil 364 } 365 366 // NewListPager - Lists all packet capture sessions within the specified resource group. 367 // 368 // Generated from API version 2024-05-01 369 // - resourceGroupName - The name of the resource group. 370 // - networkWatcherName - The name of the Network Watcher resource. 371 // - options - PacketCapturesClientListOptions contains the optional parameters for the PacketCapturesClient.NewListPager method. 372 func (client *PacketCapturesClient) NewListPager(resourceGroupName string, networkWatcherName string, options *PacketCapturesClientListOptions) *runtime.Pager[PacketCapturesClientListResponse] { 373 return runtime.NewPager(runtime.PagingHandler[PacketCapturesClientListResponse]{ 374 More: func(page PacketCapturesClientListResponse) bool { 375 return false 376 }, 377 Fetcher: func(ctx context.Context, page *PacketCapturesClientListResponse) (PacketCapturesClientListResponse, error) { 378 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PacketCapturesClient.NewListPager") 379 req, err := client.listCreateRequest(ctx, resourceGroupName, networkWatcherName, options) 380 if err != nil { 381 return PacketCapturesClientListResponse{}, err 382 } 383 resp, err := client.internal.Pipeline().Do(req) 384 if err != nil { 385 return PacketCapturesClientListResponse{}, err 386 } 387 if !runtime.HasStatusCode(resp, http.StatusOK) { 388 return PacketCapturesClientListResponse{}, runtime.NewResponseError(resp) 389 } 390 return client.listHandleResponse(resp) 391 }, 392 Tracer: client.internal.Tracer(), 393 }) 394 } 395 396 // listCreateRequest creates the List request. 397 func (client *PacketCapturesClient) listCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, options *PacketCapturesClientListOptions) (*policy.Request, error) { 398 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures" 399 if resourceGroupName == "" { 400 return nil, errors.New("parameter resourceGroupName cannot be empty") 401 } 402 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 403 if networkWatcherName == "" { 404 return nil, errors.New("parameter networkWatcherName cannot be empty") 405 } 406 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 407 if client.subscriptionID == "" { 408 return nil, errors.New("parameter client.subscriptionID cannot be empty") 409 } 410 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 411 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 412 if err != nil { 413 return nil, err 414 } 415 reqQP := req.Raw().URL.Query() 416 reqQP.Set("api-version", "2024-05-01") 417 req.Raw().URL.RawQuery = reqQP.Encode() 418 req.Raw().Header["Accept"] = []string{"application/json"} 419 return req, nil 420 } 421 422 // listHandleResponse handles the List response. 423 func (client *PacketCapturesClient) listHandleResponse(resp *http.Response) (PacketCapturesClientListResponse, error) { 424 result := PacketCapturesClientListResponse{} 425 if err := runtime.UnmarshalAsJSON(resp, &result.PacketCaptureListResult); err != nil { 426 return PacketCapturesClientListResponse{}, err 427 } 428 return result, nil 429 } 430 431 // BeginStop - Stops a specified packet capture session. 432 // If the operation fails it returns an *azcore.ResponseError type. 433 // 434 // Generated from API version 2024-05-01 435 // - resourceGroupName - The name of the resource group. 436 // - networkWatcherName - The name of the network watcher. 437 // - packetCaptureName - The name of the packet capture session. 438 // - options - PacketCapturesClientBeginStopOptions contains the optional parameters for the PacketCapturesClient.BeginStop 439 // method. 440 func (client *PacketCapturesClient) BeginStop(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginStopOptions) (*runtime.Poller[PacketCapturesClientStopResponse], error) { 441 if options == nil || options.ResumeToken == "" { 442 resp, err := client.stop(ctx, resourceGroupName, networkWatcherName, packetCaptureName, options) 443 if err != nil { 444 return nil, err 445 } 446 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientStopResponse]{ 447 FinalStateVia: runtime.FinalStateViaLocation, 448 Tracer: client.internal.Tracer(), 449 }) 450 return poller, err 451 } else { 452 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[PacketCapturesClientStopResponse]{ 453 Tracer: client.internal.Tracer(), 454 }) 455 } 456 } 457 458 // Stop - Stops a specified packet capture session. 459 // If the operation fails it returns an *azcore.ResponseError type. 460 // 461 // Generated from API version 2024-05-01 462 func (client *PacketCapturesClient) stop(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginStopOptions) (*http.Response, error) { 463 var err error 464 const operationName = "PacketCapturesClient.BeginStop" 465 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 466 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 467 defer func() { endSpan(err) }() 468 req, err := client.stopCreateRequest(ctx, resourceGroupName, networkWatcherName, packetCaptureName, options) 469 if err != nil { 470 return nil, err 471 } 472 httpResp, err := client.internal.Pipeline().Do(req) 473 if err != nil { 474 return nil, err 475 } 476 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 477 err = runtime.NewResponseError(httpResp) 478 return nil, err 479 } 480 return httpResp, nil 481 } 482 483 // stopCreateRequest creates the Stop request. 484 func (client *PacketCapturesClient) stopCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginStopOptions) (*policy.Request, error) { 485 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/packetCaptures/{packetCaptureName}/stop" 486 if resourceGroupName == "" { 487 return nil, errors.New("parameter resourceGroupName cannot be empty") 488 } 489 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 490 if networkWatcherName == "" { 491 return nil, errors.New("parameter networkWatcherName cannot be empty") 492 } 493 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 494 if packetCaptureName == "" { 495 return nil, errors.New("parameter packetCaptureName cannot be empty") 496 } 497 urlPath = strings.ReplaceAll(urlPath, "{packetCaptureName}", url.PathEscape(packetCaptureName)) 498 if client.subscriptionID == "" { 499 return nil, errors.New("parameter client.subscriptionID cannot be empty") 500 } 501 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 502 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 503 if err != nil { 504 return nil, err 505 } 506 reqQP := req.Raw().URL.Query() 507 reqQP.Set("api-version", "2024-05-01") 508 req.Raw().URL.RawQuery = reqQP.Encode() 509 req.Raw().Header["Accept"] = []string{"application/json"} 510 return req, nil 511 }