Skip to content

Commit 9ef9f30

Browse files
authored
{Compute} Detach Azure Stack from Profiles (#30384)
1 parent 092f1b7 commit 9ef9f30

File tree

103 files changed

+20135
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+20135
-298
lines changed

src/azure-cli/azure/cli/command_modules/vm/__init__.py

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,79 @@ def load_arguments(self, command):
6565
pass
6666

6767

68-
COMMAND_LOADER_CLS = ComputeCommandsLoader
68+
class AzureStackComputeCommandsLoader(AzCommandsLoader):
69+
70+
def __init__(self, cli_ctx=None):
71+
from azure.cli.core.commands import CliCommandType
72+
compute_custom = CliCommandType(
73+
operations_tmpl='azure.cli.command_modules.vm.azure_stack.custom#{}',
74+
operation_group='virtual_machines'
75+
)
76+
super().__init__(cli_ctx=cli_ctx,
77+
resource_type=ResourceType.MGMT_COMPUTE,
78+
operation_group='virtual_machines',
79+
custom_command_type=compute_custom)
80+
81+
def load_command_table(self, args):
82+
from azure.cli.command_modules.vm.azure_stack.commands import load_command_table
83+
from azure.cli.core.aaz import load_aaz_command_table
84+
try:
85+
from . import aaz
86+
except ImportError:
87+
aaz = None
88+
89+
if aaz:
90+
load_aaz_command_table(
91+
loader=self,
92+
aaz_pkg_name=aaz.__name__,
93+
args=args
94+
)
95+
load_command_table(self, args)
96+
try:
97+
# When generated commands are required uncomment the following two lines.
98+
from .generated.commands import load_command_table as load_command_table_generated
99+
load_command_table_generated(self, args)
100+
from .manual.commands import load_command_table as load_command_table_manual
101+
load_command_table_manual(self, args)
102+
except ImportError:
103+
pass
104+
105+
profile = self.get_module_by_profile("commands")
106+
if profile and hasattr(profile, 'load_command_table'):
107+
profile.load_command_table(self, args)
108+
109+
return self.command_table
110+
111+
def load_arguments(self, command):
112+
from azure.cli.command_modules.vm.azure_stack._params import load_arguments
113+
load_arguments(self, command)
114+
try:
115+
from .generated._params import load_arguments as load_arguments_generated
116+
load_arguments_generated(self, command)
117+
from .manual._params import load_arguments as load_arguments_manual
118+
load_arguments_manual(self, command)
119+
except ImportError:
120+
pass
121+
122+
profile = self.get_module_by_profile("_params")
123+
if profile and hasattr(profile, 'load_arguments'):
124+
profile.load_arguments(self, command)
125+
126+
def get_module_name_by_profile(self, module_name):
127+
from azure.cli.core.aaz.utils import get_aaz_profile_module_name
128+
profile_module_name = get_aaz_profile_module_name(profile_name=self.cli_ctx.cloud.profile)
129+
if module_name:
130+
return f'azure.cli.command_modules.vm.azure_stack.{profile_module_name}.{module_name}'
131+
return f'azure.cli.command_modules.vm.azure_stack.{profile_module_name}'
132+
133+
def get_module_by_profile(self, name):
134+
import importlib
135+
module_name = self.get_module_name_by_profile(name)
136+
return importlib.import_module(module_name)
137+
138+
139+
def get_command_loader(cli_ctx):
140+
if cli_ctx.cloud.profile.lower() != "latest":
141+
return AzureStackComputeCommandsLoader
142+
143+
return ComputeCommandsLoader

src/azure-cli/azure/cli/command_modules/vm/_params.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -883,9 +883,10 @@ def load_arguments(self, _):
883883
c.argument('enable_auto_os_upgrade', enable_auto_os_upgrade_type)
884884
c.argument('upgrade_policy_mode', help='Specify the mode of an upgrade to virtual machines in the scale set.', arg_type=get_enum_type(UpgradeMode))
885885

886-
for scope, help_prefix in [('vmss update', 'Update the'), ('vmss wait', 'Wait on the')]:
887-
with self.argument_context(scope) as c:
888-
c.argument('instance_id', id_part='child_name_1', help="{0} VM instance with this ID. If missing, {0} VMSS.".format(help_prefix))
886+
with self.argument_context('vmss update') as c:
887+
c.argument('instance_id', id_part='child_name_1', help="Update the VM instance with this ID. If missing, update the VMSS.")
888+
with self.argument_context('vmss wait') as c:
889+
c.argument('instance_id', id_part='child_name_1', help="Wait on the VM instance with this ID. If missing, wait on the VMSS.")
889890

890891
for scope in ['vmss update-instances', 'vmss delete-instances']:
891892
with self.argument_context(scope) as c:
@@ -926,15 +927,18 @@ def load_arguments(self, _):
926927
arg_type=get_three_state_flag(),
927928
help='If set, the extension service will not automatically pick or upgrade to the latest minor version, even if the extension is redeployed.')
928929

930+
for scope in ['vm', 'vmss']:
929931
with self.argument_context('{} run-command'.format(scope)) as c:
930932
c.argument('command_id', completer=get_vm_run_command_completion_list, help="The command id. Use 'az {} run-command list' to get the list".format(scope))
931933
if scope == 'vmss':
932934
c.argument('vmss_name', vmss_name_type)
933935

936+
for scope in ['vm', 'vmss']:
934937
with self.argument_context('{} run-command invoke'.format(scope)) as c:
935938
c.argument('parameters', nargs='+', help="space-separated parameters in the format of '[name=]value'")
936939
c.argument('scripts', nargs='+', help="Space-separated script lines. Use @{file} to load script from a file")
937940

941+
for scope in ['vm', 'vmss']:
938942
with self.argument_context('{} stop'.format(scope)) as c:
939943
c.argument('skip_shutdown', action='store_true', help='Skip shutdown and power-off immediately.', min_api='2019-03-01')
940944

@@ -1083,6 +1087,7 @@ def load_arguments(self, _):
10831087
c.argument('os_disk_secure_vm_disk_encryption_set', min_api='2021-11-01', help='Specify the customer managed disk encryption set resource ID or name for the managed disk that is used for customer managed key encrypted Confidential VM OS disk and VM guest blob.')
10841088
c.argument('disable_integrity_monitoring_autoupgrade', action='store_true', min_api='2020-12-01', help='Disable auto upgrade of guest attestation extension for Trusted Launch enabled VMs and VMSS.')
10851089

1090+
for scope in ['vm create', 'vmss create']:
10861091
with self.argument_context(scope, arg_group='Authentication') as c:
10871092
c.argument('generate_ssh_keys', action='store_true', help='Generate SSH public and private key files if missing. The keys will be stored in the ~/.ssh directory')
10881093
c.argument('ssh_key_type', arg_type=get_enum_type(['RSA', 'Ed25519']), default='RSA', min_api='2023-09-01', help='Specify the type of SSH public and private key files to be generated if missing.')
@@ -1092,6 +1097,7 @@ def load_arguments(self, _):
10921097
c.argument('ssh_dest_key_path', help='Destination file path on the VM for the SSH key. If the file already exists, the specified key(s) are appended to the file. Destination path for SSH public keys is currently limited to its default value "/home/username/.ssh/authorized_keys" due to a known issue in Linux provisioning agent.')
10931098
c.argument('authentication_type', help='Type of authentication to use with the VM. Defaults to password for Windows and SSH public key for Linux. "all" enables both ssh and password authentication. ', arg_type=get_enum_type(['ssh', 'password', 'all']))
10941099

1100+
for scope in ['vm create', 'vmss create']:
10951101
with self.argument_context(scope, arg_group='Storage') as c:
10961102
if DiskStorageAccountTypes:
10971103
allowed_values = ", ".join([sku.value for sku in DiskStorageAccountTypes])
@@ -1129,6 +1135,7 @@ def load_arguments(self, _):
11291135
c.argument('specialized', arg_type=get_three_state_flag(), help='Indicate whether the source image is specialized.')
11301136
c.argument('encryption_at_host', arg_type=get_three_state_flag(), help='Enable Host Encryption for the VM or VMSS. This will enable the encryption for all the disks including Resource/Temp disk at host itself.')
11311137

1138+
for scope in ['vm create', 'vmss create']:
11321139
with self.argument_context(scope, arg_group='Network') as c:
11331140
c.argument('vnet_name', help='Name of the virtual network when creating a new one or referencing an existing one.')
11341141
c.argument('vnet_address_prefix', help='The IP address prefix to use when creating a new VNet in CIDR format.')
@@ -1149,6 +1156,7 @@ def load_arguments(self, _):
11491156
'value to apply on all resources, or use <Name>=<Value> to configure '
11501157
'the delete behavior for individual resources. Possible options are Delete and Detach.')
11511158

1159+
for scope in ['vm create', 'vmss create']:
11521160
with self.argument_context(scope, arg_group='Marketplace Image Plan') as c:
11531161
c.argument('plan_name', help='plan name')
11541162
c.argument('plan_product', help='plan product')
@@ -1528,13 +1536,29 @@ def load_arguments(self, _):
15281536
c.argument('ppg_type', options_list=['--type', '-t'], arg_type=get_enum_type(self.get_models('ProximityPlacementGroupType')), min_api='2018-04-01', help="The type of the proximity placement group.")
15291537
c.argument('intent_vm_sizes', nargs='*', min_api='2021-11-01', help="Specify possible sizes of virtual machines that can be created in the proximity placement group.")
15301538

1531-
for scope, item in [('vm create', 'VM'), ('vmss create', 'VMSS'),
1532-
('vm availability-set create', 'availability set'),
1533-
('vm update', 'VM'), ('vmss update', 'VMSS'),
1534-
('vm availability-set update', 'availability set')]:
1535-
with self.argument_context(scope, min_api='2018-04-01') as c:
1536-
c.argument('proximity_placement_group', options_list=['--ppg'], help="The name or ID of the proximity placement group the {} should be associated with.".format(item),
1537-
validator=_validate_proximity_placement_group) # only availability set does not have a command level validator, so this should be added.
1539+
with self.argument_context('vm create', min_api='2018-04-01') as c:
1540+
c.argument('proximity_placement_group', options_list=['--ppg'], help="The name or ID of the proximity placement group the VM should be associated with.",
1541+
validator=_validate_proximity_placement_group)
1542+
1543+
with self.argument_context('vmss create', min_api='2018-04-01') as c:
1544+
c.argument('proximity_placement_group', options_list=['--ppg'], help="The name or ID of the proximity placement group the VMSS should be associated with.",
1545+
validator=_validate_proximity_placement_group)
1546+
1547+
with self.argument_context('vm availability-set create', min_api='2018-04-01') as c:
1548+
c.argument('proximity_placement_group', options_list=['--ppg'], help="The name or ID of the proximity placement group the availability set should be associated with.",
1549+
validator=_validate_proximity_placement_group)
1550+
1551+
with self.argument_context('vm update', min_api='2018-04-01') as c:
1552+
c.argument('proximity_placement_group', options_list=['--ppg'], help="The name or ID of the proximity placement group the VM should be associated with.",
1553+
validator=_validate_proximity_placement_group)
1554+
1555+
with self.argument_context('vmss update', min_api='2018-04-01') as c:
1556+
c.argument('proximity_placement_group', options_list=['--ppg'], help="The name or ID of the proximity placement group the VMSS should be associated with.",
1557+
validator=_validate_proximity_placement_group)
1558+
1559+
with self.argument_context('vm availability-set update', min_api='2018-04-01') as c:
1560+
c.argument('proximity_placement_group', options_list=['--ppg'], help="The name or ID of the proximity placement group the availability set should be associated with.",
1561+
validator=_validate_proximity_placement_group)
15381562
# endregion
15391563

15401564
# region VM Monitor

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/capacity/reservation/group/_list.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class List(AAZCommand):
2020
:example: List capacity reservation groups
2121
az capacity reservation group list -g rg
2222
23-
:example: List the capacity reservation groups containing VM instances and VMSS instance which are associated to capacity reservation group
23+
:example: List the capacity reservation groups containing VM instances and VMSS instance which are associated to capacity reservation group
2424
az capacity reservation group list -g rg --vm-instance --vmss-instance
2525
"""
2626

@@ -200,6 +200,7 @@ def _build_schema_on_200(cls):
200200
)
201201
properties.instance_view = AAZObjectType(
202202
serialized_name="instanceView",
203+
flags={"read_only": True},
203204
)
204205
properties.sharing_profile = AAZObjectType(
205206
serialized_name="sharingProfile",
@@ -404,6 +405,7 @@ def _build_schema_on_200(cls):
404405
)
405406
properties.instance_view = AAZObjectType(
406407
serialized_name="instanceView",
408+
flags={"read_only": True},
407409
)
408410
properties.sharing_profile = AAZObjectType(
409411
serialized_name="sharingProfile",

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/disk/__cmd_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class __CMDGroup(AAZCommandGroup):
1818
"""Manage Azure Managed Disks.
1919
2020
Azure Virtual Machines use disks as a place to store an operating system, applications, and data. All Azure virtual machines have at least two disks: An operating system disk, and a temporary disk. The operating system disk is created from an image, and both the operating system disk and the image are actually virtual hard disks (VHDs) stored in an Azure storage account. Virtual machines also can have one or more data disks, that are also stored as VHDs.
21-
Azure Unmanaged Data Disks have a maximum size of 4095 GB. To use disks larger than 4095 GB use [Azure Managed Disks](https://docs.microsoft.com/azure/virtual-machines/managed-disks-overview)
21+
Azure Unmanaged Data Disks have a maximum size of 4095 GB. To use disks larger than 4095 GB use [Azure Managed Disks](https://learn.microsoft.com/azure/virtual-machines/managed-disks-overview)
2222
"""
2323
pass
2424

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/network/nsg/__cmd_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class __CMDGroup(AAZCommandGroup):
1515
"""Manage Azure Network Security Groups (NSGs).
1616
17-
You can control network traffic to resources in a virtual network using a network security group. A network security group contains a list of security rules that allow or deny inbound or outbound network traffic based on source or destination IP addresses, Application Security Groups, ports, and protocols. For more information visit https://docs.microsoft.com/azure/virtual-network/virtual-networks-create-nsg-arm-cli.
17+
You can control network traffic to resources in a virtual network using a network security group. A network security group contains a list of security rules that allow or deny inbound or outbound network traffic based on source or destination IP addresses, Application Security Groups, ports, and protocols. For more information visit https://learn.microsoft.com/azure/virtual-network/virtual-networks-create-nsg-arm-cli.
1818
"""
1919
pass
2020

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/network/public_ip/__cmd_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class __CMDGroup(AAZCommandGroup):
1515
"""Manage public IP addresses.
1616
17-
To learn more about public IP addresses visit https://docs.microsoft.com/azure/virtual-network/virtual-network-public-ip-address.
17+
To learn more about public IP addresses visit https://learn.microsoft.com/azure/virtual-network/virtual-network-public-ip-address.
1818
"""
1919
pass
2020

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/network/vnet/__cmd_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class __CMDGroup(AAZCommandGroup):
1515
"""Check if a private IP address is available for use within a virtual network.
1616
17-
To learn more about Virtual Networks visit https://docs.microsoft.com/azure/virtual-network/virtual-network-manage-network.
17+
To learn more about Virtual Networks visit https://learn.microsoft.com/azure/virtual-network/virtual-network-manage-network.
1818
"""
1919
pass
2020

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/network/vnet/subnet/__cmd_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class __CMDGroup(AAZCommandGroup):
1515
"""Manage subnets in an Azure Virtual Network.
1616
17-
To learn more about subnets visit https://docs.microsoft.com/azure/virtual-network/virtual-network-manage-subnet.
17+
To learn more about subnets visit https://learn.microsoft.com/azure/virtual-network/virtual-network-manage-subnet.
1818
"""
1919
pass
2020

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/disk/__cmd_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class __CMDGroup(AAZCommandGroup):
2323
Azure Managed and Unmanaged Data Disks have a maximum size of 4095 GB (with the exception of
2424
larger disks in preview). Azure Unmanaged Disks also have a maximum capacity of 4095 GB.
2525
For more information, see:
26-
- Azure Disks - https://docs.microsoft.com/azure/virtual-machines/managed-disks-overview.
26+
- Azure Disks - https://learn.microsoft.com/azure/virtual-machines/managed-disks-overview.
2727
- Larger Managed Disks in Public Preview - https://azure.microsoft.com/blog/introducing-the-
2828
public-preview-of-larger-managed-disks-sizes/
29-
- Ultra SSD Managed Disks in Public Preview - https://docs.microsoft.com/azure/virtual-
29+
- Ultra SSD Managed Disks in Public Preview - https://learn.microsoft.com/azure/virtual-
3030
machines/disks-types.
3131
"""
3232
pass
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command_group(
15+
"capacity",
16+
)
17+
class __CMDGroup(AAZCommandGroup):
18+
"""Manage capacity.
19+
"""
20+
pass
21+
22+
23+
__all__ = ["__CMDGroup"]

0 commit comments

Comments
 (0)