Skip to content

Commit 8d8ad53

Browse files
[AKS] az aks machine list/az aks machine show: Add zones to cli output (#31668)
1 parent 595a644 commit 8d8ad53

4 files changed

Lines changed: 616 additions & 371 deletions

File tree

src/azure-cli/azure/cli/command_modules/acs/_format.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,36 @@ def aks_machine_list_table_format(results):
4545
return [aks_machine_show_table_format(r) for r in results]
4646

4747

48-
def aks_machine_show_table_format(result):
49-
def parser(entry):
48+
def aks_machine_show_table_format(result: dict):
49+
def parser(entry: dict):
5050
ip_addresses = ""
51-
for k in entry["properties"]["network"]["ipAddresses"]:
52-
ip_addresses += "ip:" + k["ip"] + "," + "family:" + k["family"] + ";"
51+
zones = ""
52+
if "zones" in entry and entry["zones"]:
53+
zones_data = entry["zones"]
54+
if isinstance(zones_data, list):
55+
zones = ', '.join(part.strip() for part in zones_data if part and part.strip())
56+
elif isinstance(zones_data, str):
57+
zones = zones_data.strip()
58+
# If no zones at top-level, check in properties
59+
elif "properties" in entry and "zones" in entry["properties"] and entry["properties"]["zones"]:
60+
zones_data = entry["properties"]["zones"]
61+
if isinstance(zones_data, list):
62+
zones = ', '.join(part.strip() for part in zones_data if part and part.strip())
63+
elif isinstance(zones_data, str):
64+
zones = zones_data.strip()
65+
if "properties" in entry and isinstance(entry["properties"], dict):
66+
if "network" in entry["properties"] and isinstance(entry["properties"]["network"], dict):
67+
if ("ipAddresses" in entry["properties"]["network"] and
68+
isinstance(entry["properties"]["network"]["ipAddresses"], list)):
69+
for k in entry["properties"]["network"]["ipAddresses"]:
70+
if isinstance(k, dict) and "ip" in k and "family" in k:
71+
ip_addresses += f"ip:{k['ip']},family:{k['family']};"
5372
entry["ip"] = ip_addresses
73+
entry["zones"] = zones
5474
parsed = compile_jmes("""{
5575
name: name,
56-
ip: ip
76+
ip: ip,
77+
zones: zones
5778
}""")
5879
return parsed.search(entry, Options(dict_cls=OrderedDict))
5980
return parser(result)

src/azure-cli/azure/cli/command_modules/acs/_help.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,9 +2609,9 @@
26092609
- name: --nodepool-name
26102610
type: string
26112611
short-summary: Name of the agentpool of a managed cluster
2612-
exmaples:
2613-
- name: Get information about IP Addresses, Hostname for all machines in an agentpool
2614-
text: az aks machine list --cluster-name <clusterName> --nodepool-name <apName>
2612+
examples:
2613+
- name: Get information about IP Addresses, Hostname, Availability Zones for all machines in an agentpool
2614+
text: az aks machine list --resource-group <rg> --cluster-name <clusterName> --nodepool-name <apName>
26152615
"""
26162616
helps['aks machine show'] = """
26172617
type: command
@@ -2627,6 +2627,6 @@
26272627
type: string
26282628
short-summary: Name of the machine in the agentpool of a managed cluster
26292629
exmaples:
2630-
- name: Get IP Addresses, Hostname for a specific machine in an agentpool
2631-
text: az aks machine show --cluster-name <clusterName> --nodepool-name <apName> --machine-name <machineName>
2630+
- name: Get IP Addresses, Hostname, Availability Zones for a specific machine in an agentpool
2631+
text: az aks machine show --resource-group <rg> --cluster-name <clusterName> --nodepool-name <apName> --machine-name <machineName>
26322632
"""

0 commit comments

Comments
 (0)