-
Notifications
You must be signed in to change notification settings - Fork 545
Expand file tree
/
Copy pathNodepoolGetCommand.cs
More file actions
83 lines (71 loc) · 3.21 KB
/
Copy pathNodepoolGetCommand.cs
File metadata and controls
83 lines (71 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Azure.Mcp.Tools.Aks.Options;
using Azure.Mcp.Tools.Aks.Options.Nodepool;
using Azure.Mcp.Tools.Aks.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Mcp.Core.Commands;
using Microsoft.Mcp.Core.Extensions;
using Microsoft.Mcp.Core.Models.Command;
using Microsoft.Mcp.Core.Models.Option;
namespace Azure.Mcp.Tools.Aks.Commands.Nodepool;
[CommandMetadata(
Id = "9abb0904-2ffc-4aab-b4ea-fc454b6351b1",
Name = "get",
Title = "Get Azure Kubernetes Service (AKS) Node Pool Details",
Description = "List/enumerate all AKS (Azure Kubernetes Service) node pools in a cluster. Get/retrieve/show the details of a specific node pool if a node pool name is provided.",
Destructive = false,
Idempotent = true,
OpenWorld = false,
ReadOnly = true,
Secret = false,
LocalRequired = false)]
public sealed class NodepoolGetCommand(ILogger<NodepoolGetCommand> logger, IAksService aksService) : BaseAksCommand<NodepoolGetOptions>
{
private readonly ILogger<NodepoolGetCommand> _logger = logger;
private readonly IAksService _aksService = aksService;
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsRequired());
command.Options.Add(AksOptionDefinitions.Cluster.AsRequired());
command.Options.Add(AksOptionDefinitions.Nodepool);
}
protected override NodepoolGetOptions BindOptions(ParseResult parseResult)
{
var options = base.BindOptions(parseResult);
options.ResourceGroup ??= parseResult.GetValueOrDefault(OptionDefinitions.Common.ResourceGroup);
options.ClusterName = parseResult.GetValueOrDefault(AksOptionDefinitions.Cluster);
options.NodepoolName = parseResult.GetValueOrDefault(AksOptionDefinitions.Nodepool);
return options;
}
public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult, CancellationToken cancellationToken)
{
if (!Validate(parseResult.CommandResult, context.Response).IsValid)
{
return context.Response;
}
var options = BindOptions(parseResult);
try
{
var nodePools = await _aksService.GetNodePools(
options.Subscription!,
options.ResourceGroup!,
options.ClusterName!,
options.NodepoolName,
options.Tenant,
options.RetryPolicy,
cancellationToken);
context.Response.Results = ResponseResult.Create(new(nodePools ?? []), AksJsonContext.Default.NodepoolGetCommandResult);
}
catch (Exception ex)
{
_logger.LogError(ex,
"Error getting AKS node pool. Subscription: {Subscription}, ResourceGroup: {ResourceGroup}, ClusterName: {ClusterName}, Nodepool: {Nodepool}.",
options.Subscription, options.ResourceGroup, options.ClusterName, options.NodepoolName);
HandleException(context, ex);
}
return context.Response;
}
internal record NodepoolGetCommandResult(List<Models.NodePool> NodePools);
}