github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/connectionmonitors_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 // ConnectionMonitorsClient contains the methods for the ConnectionMonitors group. 24 // Don't use this type directly, use NewConnectionMonitorsClient() instead. 25 type ConnectionMonitorsClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewConnectionMonitorsClient creates a new instance of ConnectionMonitorsClient 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 NewConnectionMonitorsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ConnectionMonitorsClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &ConnectionMonitorsClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreateOrUpdate - Create or update a connection monitor. 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 containing Network Watcher. 52 // - networkWatcherName - The name of the Network Watcher resource. 53 // - connectionMonitorName - The name of the connection monitor. 54 // - parameters - Parameters that define the operation to create a connection monitor. 55 // - options - ConnectionMonitorsClientBeginCreateOrUpdateOptions contains the optional parameters for the ConnectionMonitorsClient.BeginCreateOrUpdate 56 // method. 57 func (client *ConnectionMonitorsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters ConnectionMonitor, options *ConnectionMonitorsClientBeginCreateOrUpdateOptions) (*runtime.Poller[ConnectionMonitorsClientCreateOrUpdateResponse], error) { 58 if options == nil || options.ResumeToken == "" { 59 resp, err := client.createOrUpdate(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, parameters, options) 60 if err != nil { 61 return nil, err 62 } 63 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientCreateOrUpdateResponse]{ 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[ConnectionMonitorsClientCreateOrUpdateResponse]{ 70 Tracer: client.internal.Tracer(), 71 }) 72 } 73 } 74 75 // CreateOrUpdate - Create or update a connection monitor. 76 // If the operation fails it returns an *azcore.ResponseError type. 77 // 78 // Generated from API version 2024-05-01 79 func (client *ConnectionMonitorsClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters ConnectionMonitor, options *ConnectionMonitorsClientBeginCreateOrUpdateOptions) (*http.Response, error) { 80 var err error 81 const operationName = "ConnectionMonitorsClient.BeginCreateOrUpdate" 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.createOrUpdateCreateRequest(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, 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.StatusOK, http.StatusCreated) { 94 err = runtime.NewResponseError(httpResp) 95 return nil, err 96 } 97 return httpResp, nil 98 } 99 100 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 101 func (client *ConnectionMonitorsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters ConnectionMonitor, options *ConnectionMonitorsClientBeginCreateOrUpdateOptions) (*policy.Request, error) { 102 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}" 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 connectionMonitorName == "" { 112 return nil, errors.New("parameter connectionMonitorName cannot be empty") 113 } 114 urlPath = strings.ReplaceAll(urlPath, "{connectionMonitorName}", url.PathEscape(connectionMonitorName)) 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 if options != nil && options.Migrate != nil { 126 reqQP.Set("migrate", *options.Migrate) 127 } 128 req.Raw().URL.RawQuery = reqQP.Encode() 129 req.Raw().Header["Accept"] = []string{"application/json"} 130 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 131 return nil, err 132 } 133 return req, nil 134 } 135 136 // BeginDelete - Deletes the specified connection monitor. 137 // If the operation fails it returns an *azcore.ResponseError type. 138 // 139 // Generated from API version 2024-05-01 140 // - resourceGroupName - The name of the resource group containing Network Watcher. 141 // - networkWatcherName - The name of the Network Watcher resource. 142 // - connectionMonitorName - The name of the connection monitor. 143 // - options - ConnectionMonitorsClientBeginDeleteOptions contains the optional parameters for the ConnectionMonitorsClient.BeginDelete 144 // method. 145 func (client *ConnectionMonitorsClient) BeginDelete(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginDeleteOptions) (*runtime.Poller[ConnectionMonitorsClientDeleteResponse], error) { 146 if options == nil || options.ResumeToken == "" { 147 resp, err := client.deleteOperation(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, options) 148 if err != nil { 149 return nil, err 150 } 151 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientDeleteResponse]{ 152 FinalStateVia: runtime.FinalStateViaLocation, 153 Tracer: client.internal.Tracer(), 154 }) 155 return poller, err 156 } else { 157 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ConnectionMonitorsClientDeleteResponse]{ 158 Tracer: client.internal.Tracer(), 159 }) 160 } 161 } 162 163 // Delete - Deletes the specified connection monitor. 164 // If the operation fails it returns an *azcore.ResponseError type. 165 // 166 // Generated from API version 2024-05-01 167 func (client *ConnectionMonitorsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginDeleteOptions) (*http.Response, error) { 168 var err error 169 const operationName = "ConnectionMonitorsClient.BeginDelete" 170 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 171 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 172 defer func() { endSpan(err) }() 173 req, err := client.deleteCreateRequest(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, options) 174 if err != nil { 175 return nil, err 176 } 177 httpResp, err := client.internal.Pipeline().Do(req) 178 if err != nil { 179 return nil, err 180 } 181 if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { 182 err = runtime.NewResponseError(httpResp) 183 return nil, err 184 } 185 return httpResp, nil 186 } 187 188 // deleteCreateRequest creates the Delete request. 189 func (client *ConnectionMonitorsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginDeleteOptions) (*policy.Request, error) { 190 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}" 191 if resourceGroupName == "" { 192 return nil, errors.New("parameter resourceGroupName cannot be empty") 193 } 194 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 195 if networkWatcherName == "" { 196 return nil, errors.New("parameter networkWatcherName cannot be empty") 197 } 198 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 199 if connectionMonitorName == "" { 200 return nil, errors.New("parameter connectionMonitorName cannot be empty") 201 } 202 urlPath = strings.ReplaceAll(urlPath, "{connectionMonitorName}", url.PathEscape(connectionMonitorName)) 203 if client.subscriptionID == "" { 204 return nil, errors.New("parameter client.subscriptionID cannot be empty") 205 } 206 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 207 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 208 if err != nil { 209 return nil, err 210 } 211 reqQP := req.Raw().URL.Query() 212 reqQP.Set("api-version", "2024-05-01") 213 req.Raw().URL.RawQuery = reqQP.Encode() 214 req.Raw().Header["Accept"] = []string{"application/json"} 215 return req, nil 216 } 217 218 // Get - Gets a connection monitor by name. 219 // If the operation fails it returns an *azcore.ResponseError type. 220 // 221 // Generated from API version 2024-05-01 222 // - resourceGroupName - The name of the resource group containing Network Watcher. 223 // - networkWatcherName - The name of the Network Watcher resource. 224 // - connectionMonitorName - The name of the connection monitor. 225 // - options - ConnectionMonitorsClientGetOptions contains the optional parameters for the ConnectionMonitorsClient.Get method. 226 func (client *ConnectionMonitorsClient) Get(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientGetOptions) (ConnectionMonitorsClientGetResponse, error) { 227 var err error 228 const operationName = "ConnectionMonitorsClient.Get" 229 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 230 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 231 defer func() { endSpan(err) }() 232 req, err := client.getCreateRequest(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, options) 233 if err != nil { 234 return ConnectionMonitorsClientGetResponse{}, err 235 } 236 httpResp, err := client.internal.Pipeline().Do(req) 237 if err != nil { 238 return ConnectionMonitorsClientGetResponse{}, err 239 } 240 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 241 err = runtime.NewResponseError(httpResp) 242 return ConnectionMonitorsClientGetResponse{}, err 243 } 244 resp, err := client.getHandleResponse(httpResp) 245 return resp, err 246 } 247 248 // getCreateRequest creates the Get request. 249 func (client *ConnectionMonitorsClient) getCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientGetOptions) (*policy.Request, error) { 250 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}" 251 if resourceGroupName == "" { 252 return nil, errors.New("parameter resourceGroupName cannot be empty") 253 } 254 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 255 if networkWatcherName == "" { 256 return nil, errors.New("parameter networkWatcherName cannot be empty") 257 } 258 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 259 if connectionMonitorName == "" { 260 return nil, errors.New("parameter connectionMonitorName cannot be empty") 261 } 262 urlPath = strings.ReplaceAll(urlPath, "{connectionMonitorName}", url.PathEscape(connectionMonitorName)) 263 if client.subscriptionID == "" { 264 return nil, errors.New("parameter client.subscriptionID cannot be empty") 265 } 266 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 267 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 268 if err != nil { 269 return nil, err 270 } 271 reqQP := req.Raw().URL.Query() 272 reqQP.Set("api-version", "2024-05-01") 273 req.Raw().URL.RawQuery = reqQP.Encode() 274 req.Raw().Header["Accept"] = []string{"application/json"} 275 return req, nil 276 } 277 278 // getHandleResponse handles the Get response. 279 func (client *ConnectionMonitorsClient) getHandleResponse(resp *http.Response) (ConnectionMonitorsClientGetResponse, error) { 280 result := ConnectionMonitorsClientGetResponse{} 281 if err := runtime.UnmarshalAsJSON(resp, &result.ConnectionMonitorResult); err != nil { 282 return ConnectionMonitorsClientGetResponse{}, err 283 } 284 return result, nil 285 } 286 287 // NewListPager - Lists all connection monitors for the specified Network Watcher. 288 // 289 // Generated from API version 2024-05-01 290 // - resourceGroupName - The name of the resource group containing Network Watcher. 291 // - networkWatcherName - The name of the Network Watcher resource. 292 // - options - ConnectionMonitorsClientListOptions contains the optional parameters for the ConnectionMonitorsClient.NewListPager 293 // method. 294 func (client *ConnectionMonitorsClient) NewListPager(resourceGroupName string, networkWatcherName string, options *ConnectionMonitorsClientListOptions) *runtime.Pager[ConnectionMonitorsClientListResponse] { 295 return runtime.NewPager(runtime.PagingHandler[ConnectionMonitorsClientListResponse]{ 296 More: func(page ConnectionMonitorsClientListResponse) bool { 297 return false 298 }, 299 Fetcher: func(ctx context.Context, page *ConnectionMonitorsClientListResponse) (ConnectionMonitorsClientListResponse, error) { 300 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ConnectionMonitorsClient.NewListPager") 301 req, err := client.listCreateRequest(ctx, resourceGroupName, networkWatcherName, options) 302 if err != nil { 303 return ConnectionMonitorsClientListResponse{}, err 304 } 305 resp, err := client.internal.Pipeline().Do(req) 306 if err != nil { 307 return ConnectionMonitorsClientListResponse{}, err 308 } 309 if !runtime.HasStatusCode(resp, http.StatusOK) { 310 return ConnectionMonitorsClientListResponse{}, runtime.NewResponseError(resp) 311 } 312 return client.listHandleResponse(resp) 313 }, 314 Tracer: client.internal.Tracer(), 315 }) 316 } 317 318 // listCreateRequest creates the List request. 319 func (client *ConnectionMonitorsClient) listCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, options *ConnectionMonitorsClientListOptions) (*policy.Request, error) { 320 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors" 321 if resourceGroupName == "" { 322 return nil, errors.New("parameter resourceGroupName cannot be empty") 323 } 324 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 325 if networkWatcherName == "" { 326 return nil, errors.New("parameter networkWatcherName cannot be empty") 327 } 328 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 329 if client.subscriptionID == "" { 330 return nil, errors.New("parameter client.subscriptionID cannot be empty") 331 } 332 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 333 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 334 if err != nil { 335 return nil, err 336 } 337 reqQP := req.Raw().URL.Query() 338 reqQP.Set("api-version", "2024-05-01") 339 req.Raw().URL.RawQuery = reqQP.Encode() 340 req.Raw().Header["Accept"] = []string{"application/json"} 341 return req, nil 342 } 343 344 // listHandleResponse handles the List response. 345 func (client *ConnectionMonitorsClient) listHandleResponse(resp *http.Response) (ConnectionMonitorsClientListResponse, error) { 346 result := ConnectionMonitorsClientListResponse{} 347 if err := runtime.UnmarshalAsJSON(resp, &result.ConnectionMonitorListResult); err != nil { 348 return ConnectionMonitorsClientListResponse{}, err 349 } 350 return result, nil 351 } 352 353 // BeginQuery - Query a snapshot of the most recent connection states. 354 // If the operation fails it returns an *azcore.ResponseError type. 355 // 356 // Generated from API version 2024-05-01 357 // - resourceGroupName - The name of the resource group containing Network Watcher. 358 // - networkWatcherName - The name of the Network Watcher resource. 359 // - connectionMonitorName - The name given to the connection monitor. 360 // - options - ConnectionMonitorsClientBeginQueryOptions contains the optional parameters for the ConnectionMonitorsClient.BeginQuery 361 // method. 362 func (client *ConnectionMonitorsClient) BeginQuery(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginQueryOptions) (*runtime.Poller[ConnectionMonitorsClientQueryResponse], error) { 363 if options == nil || options.ResumeToken == "" { 364 resp, err := client.query(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, options) 365 if err != nil { 366 return nil, err 367 } 368 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientQueryResponse]{ 369 FinalStateVia: runtime.FinalStateViaLocation, 370 Tracer: client.internal.Tracer(), 371 }) 372 return poller, err 373 } else { 374 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ConnectionMonitorsClientQueryResponse]{ 375 Tracer: client.internal.Tracer(), 376 }) 377 } 378 } 379 380 // Query - Query a snapshot of the most recent connection states. 381 // If the operation fails it returns an *azcore.ResponseError type. 382 // 383 // Generated from API version 2024-05-01 384 func (client *ConnectionMonitorsClient) query(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginQueryOptions) (*http.Response, error) { 385 var err error 386 const operationName = "ConnectionMonitorsClient.BeginQuery" 387 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 388 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 389 defer func() { endSpan(err) }() 390 req, err := client.queryCreateRequest(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, options) 391 if err != nil { 392 return nil, err 393 } 394 httpResp, err := client.internal.Pipeline().Do(req) 395 if err != nil { 396 return nil, err 397 } 398 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 399 err = runtime.NewResponseError(httpResp) 400 return nil, err 401 } 402 return httpResp, nil 403 } 404 405 // queryCreateRequest creates the Query request. 406 func (client *ConnectionMonitorsClient) queryCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginQueryOptions) (*policy.Request, error) { 407 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}/query" 408 if resourceGroupName == "" { 409 return nil, errors.New("parameter resourceGroupName cannot be empty") 410 } 411 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 412 if networkWatcherName == "" { 413 return nil, errors.New("parameter networkWatcherName cannot be empty") 414 } 415 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 416 if connectionMonitorName == "" { 417 return nil, errors.New("parameter connectionMonitorName cannot be empty") 418 } 419 urlPath = strings.ReplaceAll(urlPath, "{connectionMonitorName}", url.PathEscape(connectionMonitorName)) 420 if client.subscriptionID == "" { 421 return nil, errors.New("parameter client.subscriptionID cannot be empty") 422 } 423 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 424 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 425 if err != nil { 426 return nil, err 427 } 428 reqQP := req.Raw().URL.Query() 429 reqQP.Set("api-version", "2024-05-01") 430 req.Raw().URL.RawQuery = reqQP.Encode() 431 req.Raw().Header["Accept"] = []string{"application/json"} 432 return req, nil 433 } 434 435 // BeginStart - Starts the specified connection monitor. 436 // If the operation fails it returns an *azcore.ResponseError type. 437 // 438 // Generated from API version 2024-05-01 439 // - resourceGroupName - The name of the resource group containing Network Watcher. 440 // - networkWatcherName - The name of the Network Watcher resource. 441 // - connectionMonitorName - The name of the connection monitor. 442 // - options - ConnectionMonitorsClientBeginStartOptions contains the optional parameters for the ConnectionMonitorsClient.BeginStart 443 // method. 444 func (client *ConnectionMonitorsClient) BeginStart(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginStartOptions) (*runtime.Poller[ConnectionMonitorsClientStartResponse], error) { 445 if options == nil || options.ResumeToken == "" { 446 resp, err := client.start(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, options) 447 if err != nil { 448 return nil, err 449 } 450 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientStartResponse]{ 451 FinalStateVia: runtime.FinalStateViaLocation, 452 Tracer: client.internal.Tracer(), 453 }) 454 return poller, err 455 } else { 456 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ConnectionMonitorsClientStartResponse]{ 457 Tracer: client.internal.Tracer(), 458 }) 459 } 460 } 461 462 // Start - Starts the specified connection monitor. 463 // If the operation fails it returns an *azcore.ResponseError type. 464 // 465 // Generated from API version 2024-05-01 466 func (client *ConnectionMonitorsClient) start(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginStartOptions) (*http.Response, error) { 467 var err error 468 const operationName = "ConnectionMonitorsClient.BeginStart" 469 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 470 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 471 defer func() { endSpan(err) }() 472 req, err := client.startCreateRequest(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, options) 473 if err != nil { 474 return nil, err 475 } 476 httpResp, err := client.internal.Pipeline().Do(req) 477 if err != nil { 478 return nil, err 479 } 480 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 481 err = runtime.NewResponseError(httpResp) 482 return nil, err 483 } 484 return httpResp, nil 485 } 486 487 // startCreateRequest creates the Start request. 488 func (client *ConnectionMonitorsClient) startCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginStartOptions) (*policy.Request, error) { 489 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}/start" 490 if resourceGroupName == "" { 491 return nil, errors.New("parameter resourceGroupName cannot be empty") 492 } 493 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 494 if networkWatcherName == "" { 495 return nil, errors.New("parameter networkWatcherName cannot be empty") 496 } 497 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 498 if connectionMonitorName == "" { 499 return nil, errors.New("parameter connectionMonitorName cannot be empty") 500 } 501 urlPath = strings.ReplaceAll(urlPath, "{connectionMonitorName}", url.PathEscape(connectionMonitorName)) 502 if client.subscriptionID == "" { 503 return nil, errors.New("parameter client.subscriptionID cannot be empty") 504 } 505 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 506 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 507 if err != nil { 508 return nil, err 509 } 510 reqQP := req.Raw().URL.Query() 511 reqQP.Set("api-version", "2024-05-01") 512 req.Raw().URL.RawQuery = reqQP.Encode() 513 req.Raw().Header["Accept"] = []string{"application/json"} 514 return req, nil 515 } 516 517 // BeginStop - Stops the specified connection monitor. 518 // If the operation fails it returns an *azcore.ResponseError type. 519 // 520 // Generated from API version 2024-05-01 521 // - resourceGroupName - The name of the resource group containing Network Watcher. 522 // - networkWatcherName - The name of the Network Watcher resource. 523 // - connectionMonitorName - The name of the connection monitor. 524 // - options - ConnectionMonitorsClientBeginStopOptions contains the optional parameters for the ConnectionMonitorsClient.BeginStop 525 // method. 526 func (client *ConnectionMonitorsClient) BeginStop(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginStopOptions) (*runtime.Poller[ConnectionMonitorsClientStopResponse], error) { 527 if options == nil || options.ResumeToken == "" { 528 resp, err := client.stop(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, options) 529 if err != nil { 530 return nil, err 531 } 532 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientStopResponse]{ 533 FinalStateVia: runtime.FinalStateViaLocation, 534 Tracer: client.internal.Tracer(), 535 }) 536 return poller, err 537 } else { 538 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ConnectionMonitorsClientStopResponse]{ 539 Tracer: client.internal.Tracer(), 540 }) 541 } 542 } 543 544 // Stop - Stops the specified connection monitor. 545 // If the operation fails it returns an *azcore.ResponseError type. 546 // 547 // Generated from API version 2024-05-01 548 func (client *ConnectionMonitorsClient) stop(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginStopOptions) (*http.Response, error) { 549 var err error 550 const operationName = "ConnectionMonitorsClient.BeginStop" 551 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 552 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 553 defer func() { endSpan(err) }() 554 req, err := client.stopCreateRequest(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, options) 555 if err != nil { 556 return nil, err 557 } 558 httpResp, err := client.internal.Pipeline().Do(req) 559 if err != nil { 560 return nil, err 561 } 562 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 563 err = runtime.NewResponseError(httpResp) 564 return nil, err 565 } 566 return httpResp, nil 567 } 568 569 // stopCreateRequest creates the Stop request. 570 func (client *ConnectionMonitorsClient) stopCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginStopOptions) (*policy.Request, error) { 571 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}/stop" 572 if resourceGroupName == "" { 573 return nil, errors.New("parameter resourceGroupName cannot be empty") 574 } 575 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 576 if networkWatcherName == "" { 577 return nil, errors.New("parameter networkWatcherName cannot be empty") 578 } 579 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 580 if connectionMonitorName == "" { 581 return nil, errors.New("parameter connectionMonitorName cannot be empty") 582 } 583 urlPath = strings.ReplaceAll(urlPath, "{connectionMonitorName}", url.PathEscape(connectionMonitorName)) 584 if client.subscriptionID == "" { 585 return nil, errors.New("parameter client.subscriptionID cannot be empty") 586 } 587 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 588 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 589 if err != nil { 590 return nil, err 591 } 592 reqQP := req.Raw().URL.Query() 593 reqQP.Set("api-version", "2024-05-01") 594 req.Raw().URL.RawQuery = reqQP.Encode() 595 req.Raw().Header["Accept"] = []string{"application/json"} 596 return req, nil 597 } 598 599 // UpdateTags - Update tags of the specified connection monitor. 600 // If the operation fails it returns an *azcore.ResponseError type. 601 // 602 // Generated from API version 2024-05-01 603 // - resourceGroupName - The name of the resource group. 604 // - networkWatcherName - The name of the network watcher. 605 // - connectionMonitorName - The name of the connection monitor. 606 // - parameters - Parameters supplied to update connection monitor tags. 607 // - options - ConnectionMonitorsClientUpdateTagsOptions contains the optional parameters for the ConnectionMonitorsClient.UpdateTags 608 // method. 609 func (client *ConnectionMonitorsClient) UpdateTags(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters TagsObject, options *ConnectionMonitorsClientUpdateTagsOptions) (ConnectionMonitorsClientUpdateTagsResponse, error) { 610 var err error 611 const operationName = "ConnectionMonitorsClient.UpdateTags" 612 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 613 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 614 defer func() { endSpan(err) }() 615 req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, parameters, options) 616 if err != nil { 617 return ConnectionMonitorsClientUpdateTagsResponse{}, err 618 } 619 httpResp, err := client.internal.Pipeline().Do(req) 620 if err != nil { 621 return ConnectionMonitorsClientUpdateTagsResponse{}, err 622 } 623 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 624 err = runtime.NewResponseError(httpResp) 625 return ConnectionMonitorsClientUpdateTagsResponse{}, err 626 } 627 resp, err := client.updateTagsHandleResponse(httpResp) 628 return resp, err 629 } 630 631 // updateTagsCreateRequest creates the UpdateTags request. 632 func (client *ConnectionMonitorsClient) updateTagsCreateRequest(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters TagsObject, options *ConnectionMonitorsClientUpdateTagsOptions) (*policy.Request, error) { 633 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}" 634 if resourceGroupName == "" { 635 return nil, errors.New("parameter resourceGroupName cannot be empty") 636 } 637 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 638 if networkWatcherName == "" { 639 return nil, errors.New("parameter networkWatcherName cannot be empty") 640 } 641 urlPath = strings.ReplaceAll(urlPath, "{networkWatcherName}", url.PathEscape(networkWatcherName)) 642 if connectionMonitorName == "" { 643 return nil, errors.New("parameter connectionMonitorName cannot be empty") 644 } 645 urlPath = strings.ReplaceAll(urlPath, "{connectionMonitorName}", url.PathEscape(connectionMonitorName)) 646 if client.subscriptionID == "" { 647 return nil, errors.New("parameter client.subscriptionID cannot be empty") 648 } 649 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 650 req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 651 if err != nil { 652 return nil, err 653 } 654 reqQP := req.Raw().URL.Query() 655 reqQP.Set("api-version", "2024-05-01") 656 req.Raw().URL.RawQuery = reqQP.Encode() 657 req.Raw().Header["Accept"] = []string{"application/json"} 658 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 659 return nil, err 660 } 661 return req, nil 662 } 663 664 // updateTagsHandleResponse handles the UpdateTags response. 665 func (client *ConnectionMonitorsClient) updateTagsHandleResponse(resp *http.Response) (ConnectionMonitorsClientUpdateTagsResponse, error) { 666 result := ConnectionMonitorsClientUpdateTagsResponse{} 667 if err := runtime.UnmarshalAsJSON(resp, &result.ConnectionMonitorResult); err != nil { 668 return ConnectionMonitorsClientUpdateTagsResponse{}, err 669 } 670 return result, nil 671 }