Skip to content
Merged
1 change: 1 addition & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ To release a new version, please select a new version number (usually plus 1 to

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

18.0.0b36
+++++++
Expand Down
57 changes: 57 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2383,6 +2383,63 @@
short-summary: Get information about machines in a nodepool of a managed clusters
"""

helps['aks machine add'] = """
type: command
short-summary: Add a machine to the specified node pool
parameters:
- name: --cluster-name
type: string
short-summary: Name of the managed cluster.
- name: --nodepool-name
type: string
short-summary: Name of the agentpool of a managed cluster.
- name: --machine-name
type: string
short-summary: Host name of the machine.
- name: --zones -z
type: string array
short-summary: Space-separated list of availability zones where a machine will be placed.
- name: --priority
type: string
short-summary: The priority of the machine.
- name: --tags
type: string
short-summary: The tags of the machine.
- name: --vm-size
type: string
short-summary: The size of the machine
- name: --os-type
type: string
short-summary: The operating system type of the machine.
- name: --os-sku
type: string
short-summary: The os-sku of the agent node pool.
- name: --kubernetes-version
type: string
short-summary: Version of Kubernetes to use for creating the machine, such as "1.7.12" or "1.8.7".
- name: --enable-fips-image
type: bool
short-summary: Switch to use FIPS-enabled OS on the machine.
- name: --disable-fips-image
type: bool
short-summary: Switch to use non-FIPS-enabled OS on the machine.
- name: --vnet-subnet-id
type: string
short-summary: The ID of a subnet in an existing VNet into which to deploy the machine.
- name: --pod-subnet-id
type: string
short-summary: The ID of a subnet in an existing VNet into which to assign pods in the machine (requires azure network-plugin).
- name: --enable-node-public-ip
type: bool
short-summary: Enable the machine public IP.
- name: --node-public-ip-prefix-id
type: string
short-summary: Public IP prefix ID used to assign public IPs to the machine.
- name: --node-public-ip-tags
type: string
short-summary: The ipTags of the machine public IPs.
"""

helps['aks machine list'] = """
type: command
short-summary: List the details for all machines in an agentpool
Expand Down
55 changes: 55 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,61 @@ def load_arguments(self, _):
"machine_name", help="to display specific information for all machines."
)

with self.argument_context("aks machine add") as c:
c.argument("tags", tags_type, help="The tags to set to the machine")
c.argument(
"priority",
arg_type=get_enum_type(node_priorities),
validator=validate_priority,
)
c.argument(
"vm_size",
completer=get_vm_size_completion_list,
)
c.argument("os_type")
c.argument(
"machine_name", help="The machine name."
)
c.argument(
"os_sku", arg_type=get_enum_type(node_os_skus), validator=validate_os_sku
)
c.argument(
"zones",
zones_type,
options_list=["--zones", "-z"],
help="Space-separated list of availability zones where agent nodes will be placed.",
)
c.argument(
"enable_fips_image",
action="store_true"
)
c.argument(
"disable_fips_image",
action="store_true"
)
# network setting
c.argument("vnet_subnet_id", validator=validate_vnet_subnet_id)
c.argument("pod_subnet_id", validator=validate_pod_subnet_id)
c.argument("enable_node_public_ip", action="store_true")
c.argument(
"node_public_ip_prefix_id",
options_list=["--node-public-ip-prefix-id"],
help="The resource ID of the node public IP prefix to use for the node public IPs.",
)
c.argument(
"node_public_ip_tags",
arg_type=tags_type,
validator=validate_node_public_ip_tags,
help="space-separated tags: key[=value] [key[=value] ...].",
)
# kubernetes setting
c.argument(
"kubernetes_version",
options_list=["--kubernetes-version"],
validator=validate_k8s_version,
help="Version of Kubernetes to use for the machine.",
)

with self.argument_context("aks operation") as c:
c.argument(
"nodepool_name",
Expand Down
1 change: 1 addition & 0 deletions src/aks-preview/azext_aks_preview/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def load_command_table(self, _):
g.custom_show_command(
"show", "aks_machine_show", table_transformer=aks_machine_show_table_format
)
g.custom_command("add", "aks_machine_add", supports_no_wait=True)

with self.command_group(
"aks operation", operations_sdk, client_factory=cf_operations
Expand Down
43 changes: 43 additions & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
aks_managed_namespace_add,
aks_managed_namespace_update,
)
from azext_aks_preview.machine import (
add_machine,
)
from azure.cli.command_modules.acs._helpers import (
get_user_assigned_identity_by_resource_id
)
Expand Down Expand Up @@ -2071,6 +2074,46 @@ def aks_machine_show(cmd, client, resource_group_name, cluster_name, nodepool_na
return client.get(resource_group_name, cluster_name, nodepool_name, machine_name)


# pylint: disable=unused-argument
def aks_machine_add(
cmd,
client,
resource_group_name,
cluster_name,
nodepool_name,
machine_name=None,
zones=None,
tags=None,
priority=None,
os_type=None,
os_sku=None,
enable_fips_image=False,
disable_fips_image=False,
vnet_subnet_id=None,
pod_subnet_id=None,
enable_node_public_ip=False,
node_public_ip_prefix_id=None,
node_public_ip_tags=None,
vm_size=None,
kubernetes_version=None,
no_wait=False,
):
existedMachine = None
try:
existedMachine = client.get(resource_group_name, cluster_name, nodepool_name, machine_name)
except ResourceNotFoundError:
pass

if existedMachine:
raise ClientRequestError(
f"Machine '{machine_name}' already exists. Please use 'az aks machine update' to update it."
)

# DO NOT MOVE: get all the original parameters and save them as a dictionary
raw_parameters = locals()
return add_machine(cmd, client, raw_parameters, no_wait)


def aks_addon_list_available():
available_addons = []
for k, v in ADDONS.items():
Expand Down
136 changes: 136 additions & 0 deletions src/aks-preview/azext_aks_preview/machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# pylint: disable=too-many-lines
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azext_aks_preview._client_factory import CUSTOM_MGMT_AKS_PREVIEW

from azure.cli.core.azclierror import RequiredArgumentMissingError

from azure.cli.core.util import sdk_no_wait


def add_machine(cmd, client, raw_parameters, no_wait):
resource_group_name = raw_parameters.get("resource_group_name")
cluster_name = raw_parameters.get("cluster_name")
nodepool_name = raw_parameters.get("nodepool_name")
machine_name = raw_parameters.get("machine_name")

machine = constructMachine(cmd, raw_parameters, machine_name)

return sdk_no_wait(
no_wait,
client.begin_create_or_update,
resource_group_name,
cluster_name,
nodepool_name,
machine_name,
machine,
)


def constructMachine(cmd, raw_parameters, machine_name):
machine_name = raw_parameters.get("machine_name")
if machine_name is None:
raise RequiredArgumentMissingError(
"Please specify --machine-name."
)
MachineProperties = cmd.get_models(
"MachineProperties",
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
operation_group="machines"
)
tags = raw_parameters.get("tags")
priority = raw_parameters.get("priority")
machineProperties = MachineProperties(
tags=tags,
priority=priority,
network=set_machine_network(cmd, raw_parameters),
hardware=set_machine_hardware_profile(cmd, raw_parameters),
kubernetes=set_machine_kubernetes_profile(cmd, raw_parameters),
operating_system=set_machine_os_profile(cmd, raw_parameters)
)
Machine = cmd.get_models(
"Machine",
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
operation_group="machines"
)
zones = raw_parameters.get("zones", [])
machine = Machine(
zones=zones,
properties=machineProperties
)
return machine


def set_machine_hardware_profile(cmd, raw_parameters):
vm_size = raw_parameters.get("vm_size")
if vm_size is None:
raise RequiredArgumentMissingError(
"Please specify --vm-size."
)
MachineHardwareProfile = cmd.get_models(
"MachineHardwareProfile",
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
operation_group="machines"
)
machine_hardware_profile = MachineHardwareProfile(
vm_size=vm_size
)
return machine_hardware_profile


def set_machine_network(cmd, raw_parameters):
MachineNetworkProperties = cmd.get_models(
"MachineNetworkProperties",
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
operation_group="machines"
)
vnet_subnet_id = raw_parameters.get("vnet_subnet_id")
pod_subnet_id = raw_parameters.get("pod_subnet_id")
enable_node_public_ip = raw_parameters.get("enable_node_public_ip")
node_public_ip_prefix_id = raw_parameters.get("node_public_ip_prefix_id")
node_public_ip_tags = raw_parameters.get("node_public_ip_tags")
machineNetworkProperties = MachineNetworkProperties(
vnet_subnet_id=vnet_subnet_id,
pod_subnet_id=pod_subnet_id,
enable_node_public_ip=enable_node_public_ip,
node_public_ip_prefix_id=node_public_ip_prefix_id,
node_public_ip_tags=node_public_ip_tags
)
return machineNetworkProperties


def set_machine_kubernetes_profile(cmd, raw_parameters):
kubernetes_version = raw_parameters.get("kubernetes_version")
MachineKubernetesProfile = cmd.get_models(
"MachineKubernetesProfile",
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
operation_group="machines"
)
machineKubernetesProfile = MachineKubernetesProfile(
orchestrator_version=kubernetes_version
)
return machineKubernetesProfile


def set_machine_os_profile(cmd, raw_parameters):
MachineOSProfile = cmd.get_models(
"MachineOSProfile",
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
operation_group="machines"
)
os_type = raw_parameters.get("os_type")
os_sku = raw_parameters.get("os_sku")
enable_fips = False
if raw_parameters.get("enable_fips_image"):
enable_fips = True
if raw_parameters.get("disable_fips_image"):
enable_fips = False
machineOSProfile = MachineOSProfile(
os_type=os_type,
os_sku=os_sku,
enable_fips=enable_fips
)
return machineOSProfile
Loading
Loading