github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/reachabilityanalysisruns_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 "strconv" 21 "strings" 22 ) 23 24 // ReachabilityAnalysisRunsClient contains the methods for the ReachabilityAnalysisRuns group. 25 // Don't use this type directly, use NewReachabilityAnalysisRunsClient() instead. 26 type ReachabilityAnalysisRunsClient struct { 27 internal *arm.Client 28 subscriptionID string 29 } 30 31 // NewReachabilityAnalysisRunsClient creates a new instance of ReachabilityAnalysisRunsClient with the specified values. 32 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 33 // ID forms part of the URI for every service call. 34 // - credential - used to authorize requests. Usually a credential from azidentity. 35 // - options - pass nil to accept the default values. 36 func NewReachabilityAnalysisRunsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ReachabilityAnalysisRunsClient, error) { 37 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 38 if err != nil { 39 return nil, err 40 } 41 client := &ReachabilityAnalysisRunsClient{ 42 subscriptionID: subscriptionID, 43 internal: cl, 44 } 45 return client, nil 46 } 47 48 // Create - Creates Reachability Analysis Runs. 49 // If the operation fails it returns an *azcore.ResponseError type. 50 // 51 // Generated from API version 2024-05-01 52 // - resourceGroupName - The name of the resource group. 53 // - networkManagerName - The name of the network manager. 54 // - workspaceName - Workspace name. 55 // - reachabilityAnalysisRunName - Reachability Analysis Run name. 56 // - body - Analysis Run resource object to create/update. 57 // - options - ReachabilityAnalysisRunsClientCreateOptions contains the optional parameters for the ReachabilityAnalysisRunsClient.Create 58 // method. 59 func (client *ReachabilityAnalysisRunsClient) Create(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, reachabilityAnalysisRunName string, body ReachabilityAnalysisRun, options *ReachabilityAnalysisRunsClientCreateOptions) (ReachabilityAnalysisRunsClientCreateResponse, error) { 60 var err error 61 const operationName = "ReachabilityAnalysisRunsClient.Create" 62 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 63 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 64 defer func() { endSpan(err) }() 65 req, err := client.createCreateRequest(ctx, resourceGroupName, networkManagerName, workspaceName, reachabilityAnalysisRunName, body, options) 66 if err != nil { 67 return ReachabilityAnalysisRunsClientCreateResponse{}, err 68 } 69 httpResp, err := client.internal.Pipeline().Do(req) 70 if err != nil { 71 return ReachabilityAnalysisRunsClientCreateResponse{}, err 72 } 73 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 74 err = runtime.NewResponseError(httpResp) 75 return ReachabilityAnalysisRunsClientCreateResponse{}, err 76 } 77 resp, err := client.createHandleResponse(httpResp) 78 return resp, err 79 } 80 81 // createCreateRequest creates the Create request. 82 func (client *ReachabilityAnalysisRunsClient) createCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, reachabilityAnalysisRunName string, body ReachabilityAnalysisRun, options *ReachabilityAnalysisRunsClientCreateOptions) (*policy.Request, error) { 83 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/verifierWorkspaces/{workspaceName}/reachabilityAnalysisRuns/{reachabilityAnalysisRunName}" 84 if client.subscriptionID == "" { 85 return nil, errors.New("parameter client.subscriptionID cannot be empty") 86 } 87 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 88 if resourceGroupName == "" { 89 return nil, errors.New("parameter resourceGroupName cannot be empty") 90 } 91 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 92 if networkManagerName == "" { 93 return nil, errors.New("parameter networkManagerName cannot be empty") 94 } 95 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 96 if workspaceName == "" { 97 return nil, errors.New("parameter workspaceName cannot be empty") 98 } 99 urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName)) 100 if reachabilityAnalysisRunName == "" { 101 return nil, errors.New("parameter reachabilityAnalysisRunName cannot be empty") 102 } 103 urlPath = strings.ReplaceAll(urlPath, "{reachabilityAnalysisRunName}", url.PathEscape(reachabilityAnalysisRunName)) 104 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 105 if err != nil { 106 return nil, err 107 } 108 reqQP := req.Raw().URL.Query() 109 reqQP.Set("api-version", "2024-05-01") 110 req.Raw().URL.RawQuery = reqQP.Encode() 111 req.Raw().Header["Accept"] = []string{"application/json"} 112 if err := runtime.MarshalAsJSON(req, body); err != nil { 113 return nil, err 114 } 115 return req, nil 116 } 117 118 // createHandleResponse handles the Create response. 119 func (client *ReachabilityAnalysisRunsClient) createHandleResponse(resp *http.Response) (ReachabilityAnalysisRunsClientCreateResponse, error) { 120 result := ReachabilityAnalysisRunsClientCreateResponse{} 121 if err := runtime.UnmarshalAsJSON(resp, &result.ReachabilityAnalysisRun); err != nil { 122 return ReachabilityAnalysisRunsClientCreateResponse{}, err 123 } 124 return result, nil 125 } 126 127 // BeginDelete - Deletes Reachability Analysis Run. 128 // If the operation fails it returns an *azcore.ResponseError type. 129 // 130 // Generated from API version 2024-05-01 131 // - resourceGroupName - The name of the resource group. 132 // - networkManagerName - The name of the network manager. 133 // - workspaceName - Workspace name. 134 // - reachabilityAnalysisRunName - Reachability Analysis Run name. 135 // - options - ReachabilityAnalysisRunsClientBeginDeleteOptions contains the optional parameters for the ReachabilityAnalysisRunsClient.BeginDelete 136 // method. 137 func (client *ReachabilityAnalysisRunsClient) BeginDelete(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, reachabilityAnalysisRunName string, options *ReachabilityAnalysisRunsClientBeginDeleteOptions) (*runtime.Poller[ReachabilityAnalysisRunsClientDeleteResponse], error) { 138 if options == nil || options.ResumeToken == "" { 139 resp, err := client.deleteOperation(ctx, resourceGroupName, networkManagerName, workspaceName, reachabilityAnalysisRunName, options) 140 if err != nil { 141 return nil, err 142 } 143 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ReachabilityAnalysisRunsClientDeleteResponse]{ 144 FinalStateVia: runtime.FinalStateViaLocation, 145 Tracer: client.internal.Tracer(), 146 }) 147 return poller, err 148 } else { 149 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ReachabilityAnalysisRunsClientDeleteResponse]{ 150 Tracer: client.internal.Tracer(), 151 }) 152 } 153 } 154 155 // Delete - Deletes Reachability Analysis Run. 156 // If the operation fails it returns an *azcore.ResponseError type. 157 // 158 // Generated from API version 2024-05-01 159 func (client *ReachabilityAnalysisRunsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, reachabilityAnalysisRunName string, options *ReachabilityAnalysisRunsClientBeginDeleteOptions) (*http.Response, error) { 160 var err error 161 const operationName = "ReachabilityAnalysisRunsClient.BeginDelete" 162 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 163 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 164 defer func() { endSpan(err) }() 165 req, err := client.deleteCreateRequest(ctx, resourceGroupName, networkManagerName, workspaceName, reachabilityAnalysisRunName, options) 166 if err != nil { 167 return nil, err 168 } 169 httpResp, err := client.internal.Pipeline().Do(req) 170 if err != nil { 171 return nil, err 172 } 173 if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { 174 err = runtime.NewResponseError(httpResp) 175 return nil, err 176 } 177 return httpResp, nil 178 } 179 180 // deleteCreateRequest creates the Delete request. 181 func (client *ReachabilityAnalysisRunsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, reachabilityAnalysisRunName string, options *ReachabilityAnalysisRunsClientBeginDeleteOptions) (*policy.Request, error) { 182 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/verifierWorkspaces/{workspaceName}/reachabilityAnalysisRuns/{reachabilityAnalysisRunName}" 183 if client.subscriptionID == "" { 184 return nil, errors.New("parameter client.subscriptionID cannot be empty") 185 } 186 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 187 if resourceGroupName == "" { 188 return nil, errors.New("parameter resourceGroupName cannot be empty") 189 } 190 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 191 if networkManagerName == "" { 192 return nil, errors.New("parameter networkManagerName cannot be empty") 193 } 194 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 195 if workspaceName == "" { 196 return nil, errors.New("parameter workspaceName cannot be empty") 197 } 198 urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName)) 199 if reachabilityAnalysisRunName == "" { 200 return nil, errors.New("parameter reachabilityAnalysisRunName cannot be empty") 201 } 202 urlPath = strings.ReplaceAll(urlPath, "{reachabilityAnalysisRunName}", url.PathEscape(reachabilityAnalysisRunName)) 203 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 204 if err != nil { 205 return nil, err 206 } 207 reqQP := req.Raw().URL.Query() 208 reqQP.Set("api-version", "2024-05-01") 209 req.Raw().URL.RawQuery = reqQP.Encode() 210 req.Raw().Header["Accept"] = []string{"application/json"} 211 return req, nil 212 } 213 214 // Get - Gets Reachability Analysis Run. 215 // If the operation fails it returns an *azcore.ResponseError type. 216 // 217 // Generated from API version 2024-05-01 218 // - resourceGroupName - The name of the resource group. 219 // - networkManagerName - The name of the network manager. 220 // - workspaceName - Workspace name. 221 // - reachabilityAnalysisRunName - Reachability Analysis Run name. 222 // - options - ReachabilityAnalysisRunsClientGetOptions contains the optional parameters for the ReachabilityAnalysisRunsClient.Get 223 // method. 224 func (client *ReachabilityAnalysisRunsClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, reachabilityAnalysisRunName string, options *ReachabilityAnalysisRunsClientGetOptions) (ReachabilityAnalysisRunsClientGetResponse, error) { 225 var err error 226 const operationName = "ReachabilityAnalysisRunsClient.Get" 227 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 228 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 229 defer func() { endSpan(err) }() 230 req, err := client.getCreateRequest(ctx, resourceGroupName, networkManagerName, workspaceName, reachabilityAnalysisRunName, options) 231 if err != nil { 232 return ReachabilityAnalysisRunsClientGetResponse{}, err 233 } 234 httpResp, err := client.internal.Pipeline().Do(req) 235 if err != nil { 236 return ReachabilityAnalysisRunsClientGetResponse{}, err 237 } 238 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 239 err = runtime.NewResponseError(httpResp) 240 return ReachabilityAnalysisRunsClientGetResponse{}, err 241 } 242 resp, err := client.getHandleResponse(httpResp) 243 return resp, err 244 } 245 246 // getCreateRequest creates the Get request. 247 func (client *ReachabilityAnalysisRunsClient) getCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, reachabilityAnalysisRunName string, options *ReachabilityAnalysisRunsClientGetOptions) (*policy.Request, error) { 248 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/verifierWorkspaces/{workspaceName}/reachabilityAnalysisRuns/{reachabilityAnalysisRunName}" 249 if client.subscriptionID == "" { 250 return nil, errors.New("parameter client.subscriptionID cannot be empty") 251 } 252 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 253 if resourceGroupName == "" { 254 return nil, errors.New("parameter resourceGroupName cannot be empty") 255 } 256 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 257 if networkManagerName == "" { 258 return nil, errors.New("parameter networkManagerName cannot be empty") 259 } 260 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 261 if workspaceName == "" { 262 return nil, errors.New("parameter workspaceName cannot be empty") 263 } 264 urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName)) 265 if reachabilityAnalysisRunName == "" { 266 return nil, errors.New("parameter reachabilityAnalysisRunName cannot be empty") 267 } 268 urlPath = strings.ReplaceAll(urlPath, "{reachabilityAnalysisRunName}", url.PathEscape(reachabilityAnalysisRunName)) 269 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 270 if err != nil { 271 return nil, err 272 } 273 reqQP := req.Raw().URL.Query() 274 reqQP.Set("api-version", "2024-05-01") 275 req.Raw().URL.RawQuery = reqQP.Encode() 276 req.Raw().Header["Accept"] = []string{"application/json"} 277 return req, nil 278 } 279 280 // getHandleResponse handles the Get response. 281 func (client *ReachabilityAnalysisRunsClient) getHandleResponse(resp *http.Response) (ReachabilityAnalysisRunsClientGetResponse, error) { 282 result := ReachabilityAnalysisRunsClientGetResponse{} 283 if err := runtime.UnmarshalAsJSON(resp, &result.ReachabilityAnalysisRun); err != nil { 284 return ReachabilityAnalysisRunsClientGetResponse{}, err 285 } 286 return result, nil 287 } 288 289 // NewListPager - Gets list of Reachability Analysis Runs. 290 // 291 // Generated from API version 2024-05-01 292 // - resourceGroupName - The name of the resource group. 293 // - networkManagerName - The name of the network manager. 294 // - workspaceName - Workspace name. 295 // - options - ReachabilityAnalysisRunsClientListOptions contains the optional parameters for the ReachabilityAnalysisRunsClient.NewListPager 296 // method. 297 func (client *ReachabilityAnalysisRunsClient) NewListPager(resourceGroupName string, networkManagerName string, workspaceName string, options *ReachabilityAnalysisRunsClientListOptions) *runtime.Pager[ReachabilityAnalysisRunsClientListResponse] { 298 return runtime.NewPager(runtime.PagingHandler[ReachabilityAnalysisRunsClientListResponse]{ 299 More: func(page ReachabilityAnalysisRunsClientListResponse) bool { 300 return page.NextLink != nil && len(*page.NextLink) > 0 301 }, 302 Fetcher: func(ctx context.Context, page *ReachabilityAnalysisRunsClientListResponse) (ReachabilityAnalysisRunsClientListResponse, error) { 303 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ReachabilityAnalysisRunsClient.NewListPager") 304 nextLink := "" 305 if page != nil { 306 nextLink = *page.NextLink 307 } 308 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 309 return client.listCreateRequest(ctx, resourceGroupName, networkManagerName, workspaceName, options) 310 }, nil) 311 if err != nil { 312 return ReachabilityAnalysisRunsClientListResponse{}, err 313 } 314 return client.listHandleResponse(resp) 315 }, 316 Tracer: client.internal.Tracer(), 317 }) 318 } 319 320 // listCreateRequest creates the List request. 321 func (client *ReachabilityAnalysisRunsClient) listCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, options *ReachabilityAnalysisRunsClientListOptions) (*policy.Request, error) { 322 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/verifierWorkspaces/{workspaceName}/reachabilityAnalysisRuns" 323 if client.subscriptionID == "" { 324 return nil, errors.New("parameter client.subscriptionID cannot be empty") 325 } 326 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 327 if resourceGroupName == "" { 328 return nil, errors.New("parameter resourceGroupName cannot be empty") 329 } 330 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 331 if networkManagerName == "" { 332 return nil, errors.New("parameter networkManagerName cannot be empty") 333 } 334 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 335 if workspaceName == "" { 336 return nil, errors.New("parameter workspaceName cannot be empty") 337 } 338 urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName)) 339 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 340 if err != nil { 341 return nil, err 342 } 343 reqQP := req.Raw().URL.Query() 344 reqQP.Set("api-version", "2024-05-01") 345 if options != nil && options.Skip != nil { 346 reqQP.Set("skip", strconv.FormatInt(int64(*options.Skip), 10)) 347 } 348 if options != nil && options.SkipToken != nil { 349 reqQP.Set("skipToken", *options.SkipToken) 350 } 351 if options != nil && options.SortKey != nil { 352 reqQP.Set("sortKey", *options.SortKey) 353 } 354 if options != nil && options.SortValue != nil { 355 reqQP.Set("sortValue", *options.SortValue) 356 } 357 if options != nil && options.Top != nil { 358 reqQP.Set("top", strconv.FormatInt(int64(*options.Top), 10)) 359 } 360 req.Raw().URL.RawQuery = reqQP.Encode() 361 req.Raw().Header["Accept"] = []string{"application/json"} 362 return req, nil 363 } 364 365 // listHandleResponse handles the List response. 366 func (client *ReachabilityAnalysisRunsClient) listHandleResponse(resp *http.Response) (ReachabilityAnalysisRunsClientListResponse, error) { 367 result := ReachabilityAnalysisRunsClientListResponse{} 368 if err := runtime.UnmarshalAsJSON(resp, &result.ReachabilityAnalysisRunListResult); err != nil { 369 return ReachabilityAnalysisRunsClientListResponse{}, err 370 } 371 return result, nil 372 }