Skip to content

Commit bd9c96f

Browse files
[AKS] Add machine cli preview (#9045)
1 parent f2397a7 commit bd9c96f

File tree

9 files changed

+2158
-0
lines changed

9 files changed

+2158
-0
lines changed

src/aks-preview/HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ To release a new version, please select a new version number (usually plus 1 to
1111

1212
Pending
1313
+++++++
14+
* Add machine command `az aks machine add` to add a machine to an existing machine pool.
1415

1516
18.0.0b36
1617
+++++++

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,63 @@
23832383
short-summary: Get information about machines in a nodepool of a managed clusters
23842384
"""
23852385

2386+
helps['aks machine add'] = """
2387+
type: command
2388+
short-summary: Add a machine to the specified node pool
2389+
parameters:
2390+
- name: --cluster-name
2391+
type: string
2392+
short-summary: Name of the managed cluster.
2393+
- name: --nodepool-name
2394+
type: string
2395+
short-summary: Name of the agentpool of a managed cluster.
2396+
- name: --machine-name
2397+
type: string
2398+
short-summary: Host name of the machine.
2399+
- name: --zones -z
2400+
type: string array
2401+
short-summary: Space-separated list of availability zones where a machine will be placed.
2402+
- name: --priority
2403+
type: string
2404+
short-summary: The priority of the machine.
2405+
- name: --tags
2406+
type: string
2407+
short-summary: The tags of the machine.
2408+
- name: --vm-size
2409+
type: string
2410+
short-summary: The size of the machine
2411+
- name: --os-type
2412+
type: string
2413+
short-summary: The operating system type of the machine.
2414+
- name: --os-sku
2415+
type: string
2416+
short-summary: The os-sku of the agent node pool.
2417+
- name: --kubernetes-version
2418+
type: string
2419+
short-summary: Version of Kubernetes to use for creating the machine, such as "1.7.12" or "1.8.7".
2420+
- name: --enable-fips-image
2421+
type: bool
2422+
short-summary: Switch to use FIPS-enabled OS on the machine.
2423+
- name: --disable-fips-image
2424+
type: bool
2425+
short-summary: Switch to use non-FIPS-enabled OS on the machine.
2426+
- name: --vnet-subnet-id
2427+
type: string
2428+
short-summary: The ID of a subnet in an existing VNet into which to deploy the machine.
2429+
- name: --pod-subnet-id
2430+
type: string
2431+
short-summary: The ID of a subnet in an existing VNet into which to assign pods in the machine (requires azure network-plugin).
2432+
- name: --enable-node-public-ip
2433+
type: bool
2434+
short-summary: Enable the machine public IP.
2435+
- name: --node-public-ip-prefix-id
2436+
type: string
2437+
short-summary: Public IP prefix ID used to assign public IPs to the machine.
2438+
- name: --node-public-ip-tags
2439+
type: string
2440+
short-summary: The ipTags of the machine public IPs.
2441+
"""
2442+
23862443
helps['aks machine list'] = """
23872444
type: command
23882445
short-summary: List the details for all machines in an agentpool

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,61 @@ def load_arguments(self, _):
19491949
"machine_name", help="to display specific information for all machines."
19501950
)
19511951

1952+
with self.argument_context("aks machine add") as c:
1953+
c.argument("tags", tags_type, help="The tags to set to the machine")
1954+
c.argument(
1955+
"priority",
1956+
arg_type=get_enum_type(node_priorities),
1957+
validator=validate_priority,
1958+
)
1959+
c.argument(
1960+
"vm_size",
1961+
completer=get_vm_size_completion_list,
1962+
)
1963+
c.argument("os_type")
1964+
c.argument(
1965+
"machine_name", help="The machine name."
1966+
)
1967+
c.argument(
1968+
"os_sku", arg_type=get_enum_type(node_os_skus), validator=validate_os_sku
1969+
)
1970+
c.argument(
1971+
"zones",
1972+
zones_type,
1973+
options_list=["--zones", "-z"],
1974+
help="Space-separated list of availability zones where agent nodes will be placed.",
1975+
)
1976+
c.argument(
1977+
"enable_fips_image",
1978+
action="store_true"
1979+
)
1980+
c.argument(
1981+
"disable_fips_image",
1982+
action="store_true"
1983+
)
1984+
# network setting
1985+
c.argument("vnet_subnet_id", validator=validate_vnet_subnet_id)
1986+
c.argument("pod_subnet_id", validator=validate_pod_subnet_id)
1987+
c.argument("enable_node_public_ip", action="store_true")
1988+
c.argument(
1989+
"node_public_ip_prefix_id",
1990+
options_list=["--node-public-ip-prefix-id"],
1991+
help="The resource ID of the node public IP prefix to use for the node public IPs.",
1992+
)
1993+
c.argument(
1994+
"node_public_ip_tags",
1995+
arg_type=tags_type,
1996+
validator=validate_node_public_ip_tags,
1997+
help="space-separated tags: key[=value] [key[=value] ...].",
1998+
)
1999+
# kubernetes setting
2000+
c.argument(
2001+
"kubernetes_version",
2002+
options_list=["--kubernetes-version"],
2003+
validator=validate_k8s_version,
2004+
help="Version of Kubernetes to use for the machine.",
2005+
)
2006+
19522007
with self.argument_context("aks operation") as c:
19532008
c.argument(
19542009
"nodepool_name",

src/aks-preview/azext_aks_preview/commands.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def load_command_table(self, _):
292292
g.custom_show_command(
293293
"show", "aks_machine_show", table_transformer=aks_machine_show_table_format
294294
)
295+
g.custom_command("add", "aks_machine_add", supports_no_wait=True)
295296

296297
with self.command_group(
297298
"aks operation", operations_sdk, client_factory=cf_operations

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@
115115
aks_managed_namespace_add,
116116
aks_managed_namespace_update,
117117
)
118+
from azext_aks_preview.machine import (
119+
add_machine,
120+
)
118121
from azure.cli.command_modules.acs._helpers import (
119122
get_user_assigned_identity_by_resource_id
120123
)
@@ -2071,6 +2074,46 @@ def aks_machine_show(cmd, client, resource_group_name, cluster_name, nodepool_na
20712074
return client.get(resource_group_name, cluster_name, nodepool_name, machine_name)
20722075

20732076

2077+
# pylint: disable=unused-argument
2078+
def aks_machine_add(
2079+
cmd,
2080+
client,
2081+
resource_group_name,
2082+
cluster_name,
2083+
nodepool_name,
2084+
machine_name=None,
2085+
zones=None,
2086+
tags=None,
2087+
priority=None,
2088+
os_type=None,
2089+
os_sku=None,
2090+
enable_fips_image=False,
2091+
disable_fips_image=False,
2092+
vnet_subnet_id=None,
2093+
pod_subnet_id=None,
2094+
enable_node_public_ip=False,
2095+
node_public_ip_prefix_id=None,
2096+
node_public_ip_tags=None,
2097+
vm_size=None,
2098+
kubernetes_version=None,
2099+
no_wait=False,
2100+
):
2101+
existedMachine = None
2102+
try:
2103+
existedMachine = client.get(resource_group_name, cluster_name, nodepool_name, machine_name)
2104+
except ResourceNotFoundError:
2105+
pass
2106+
2107+
if existedMachine:
2108+
raise ClientRequestError(
2109+
f"Machine '{machine_name}' already exists. Please use 'az aks machine update' to update it."
2110+
)
2111+
2112+
# DO NOT MOVE: get all the original parameters and save them as a dictionary
2113+
raw_parameters = locals()
2114+
return add_machine(cmd, client, raw_parameters, no_wait)
2115+
2116+
20742117
def aks_addon_list_available():
20752118
available_addons = []
20762119
for k, v in ADDONS.items():
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# pylint: disable=too-many-lines
2+
# --------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# --------------------------------------------------------------------------------------------
6+
7+
from azext_aks_preview._client_factory import CUSTOM_MGMT_AKS_PREVIEW
8+
9+
from azure.cli.core.azclierror import RequiredArgumentMissingError
10+
11+
from azure.cli.core.util import sdk_no_wait
12+
13+
14+
def add_machine(cmd, client, raw_parameters, no_wait):
15+
resource_group_name = raw_parameters.get("resource_group_name")
16+
cluster_name = raw_parameters.get("cluster_name")
17+
nodepool_name = raw_parameters.get("nodepool_name")
18+
machine_name = raw_parameters.get("machine_name")
19+
20+
machine = constructMachine(cmd, raw_parameters, machine_name)
21+
22+
return sdk_no_wait(
23+
no_wait,
24+
client.begin_create_or_update,
25+
resource_group_name,
26+
cluster_name,
27+
nodepool_name,
28+
machine_name,
29+
machine,
30+
)
31+
32+
33+
def constructMachine(cmd, raw_parameters, machine_name):
34+
machine_name = raw_parameters.get("machine_name")
35+
if machine_name is None:
36+
raise RequiredArgumentMissingError(
37+
"Please specify --machine-name."
38+
)
39+
MachineProperties = cmd.get_models(
40+
"MachineProperties",
41+
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
42+
operation_group="machines"
43+
)
44+
tags = raw_parameters.get("tags")
45+
priority = raw_parameters.get("priority")
46+
machineProperties = MachineProperties(
47+
tags=tags,
48+
priority=priority,
49+
network=set_machine_network(cmd, raw_parameters),
50+
hardware=set_machine_hardware_profile(cmd, raw_parameters),
51+
kubernetes=set_machine_kubernetes_profile(cmd, raw_parameters),
52+
operating_system=set_machine_os_profile(cmd, raw_parameters)
53+
)
54+
Machine = cmd.get_models(
55+
"Machine",
56+
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
57+
operation_group="machines"
58+
)
59+
zones = raw_parameters.get("zones", [])
60+
machine = Machine(
61+
zones=zones,
62+
properties=machineProperties
63+
)
64+
return machine
65+
66+
67+
def set_machine_hardware_profile(cmd, raw_parameters):
68+
vm_size = raw_parameters.get("vm_size")
69+
if vm_size is None:
70+
raise RequiredArgumentMissingError(
71+
"Please specify --vm-size."
72+
)
73+
MachineHardwareProfile = cmd.get_models(
74+
"MachineHardwareProfile",
75+
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
76+
operation_group="machines"
77+
)
78+
machine_hardware_profile = MachineHardwareProfile(
79+
vm_size=vm_size
80+
)
81+
return machine_hardware_profile
82+
83+
84+
def set_machine_network(cmd, raw_parameters):
85+
MachineNetworkProperties = cmd.get_models(
86+
"MachineNetworkProperties",
87+
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
88+
operation_group="machines"
89+
)
90+
vnet_subnet_id = raw_parameters.get("vnet_subnet_id")
91+
pod_subnet_id = raw_parameters.get("pod_subnet_id")
92+
enable_node_public_ip = raw_parameters.get("enable_node_public_ip")
93+
node_public_ip_prefix_id = raw_parameters.get("node_public_ip_prefix_id")
94+
node_public_ip_tags = raw_parameters.get("node_public_ip_tags")
95+
machineNetworkProperties = MachineNetworkProperties(
96+
vnet_subnet_id=vnet_subnet_id,
97+
pod_subnet_id=pod_subnet_id,
98+
enable_node_public_ip=enable_node_public_ip,
99+
node_public_ip_prefix_id=node_public_ip_prefix_id,
100+
node_public_ip_tags=node_public_ip_tags
101+
)
102+
return machineNetworkProperties
103+
104+
105+
def set_machine_kubernetes_profile(cmd, raw_parameters):
106+
kubernetes_version = raw_parameters.get("kubernetes_version")
107+
MachineKubernetesProfile = cmd.get_models(
108+
"MachineKubernetesProfile",
109+
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
110+
operation_group="machines"
111+
)
112+
machineKubernetesProfile = MachineKubernetesProfile(
113+
orchestrator_version=kubernetes_version
114+
)
115+
return machineKubernetesProfile
116+
117+
118+
def set_machine_os_profile(cmd, raw_parameters):
119+
MachineOSProfile = cmd.get_models(
120+
"MachineOSProfile",
121+
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
122+
operation_group="machines"
123+
)
124+
os_type = raw_parameters.get("os_type")
125+
os_sku = raw_parameters.get("os_sku")
126+
enable_fips = False
127+
if raw_parameters.get("enable_fips_image"):
128+
enable_fips = True
129+
if raw_parameters.get("disable_fips_image"):
130+
enable_fips = False
131+
machineOSProfile = MachineOSProfile(
132+
os_type=os_type,
133+
os_sku=os_sku,
134+
enable_fips=enable_fips
135+
)
136+
return machineOSProfile

0 commit comments

Comments
 (0)