Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/azure-cli/azure/cli/command_modules/vm/_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,60 +216,69 @@ def load_extension_images_thru_services(cli_ctx, publisher, name, version, locat
from concurrent.futures import ThreadPoolExecutor, as_completed
from packaging.version import parse # pylint: disable=no-name-in-module,import-error
all_images = []
client = _compute_client_factory(cli_ctx)
if location is None:
location = get_one_of_subscription_locations(cli_ctx)

def _load_extension_images_from_publisher(publisher):
from azure.core.exceptions import ResourceNotFoundError
from .aaz.latest.vm.extension.image import ListNames as _ListTypes, ListVersions as _ListVersions
try:
types = client.virtual_machine_extension_images.list_types(location, publisher)
types = _ListTypes(cli_ctx=cli_ctx)(command_args={
'location': location,
'publisher_name': publisher
})
except ResourceNotFoundError as e:
# PIR image publishers might not have any extension images, exception could raise
logger.warning(str(e))
types = []
if name:
types = [t for t in types if _matched(name, t.name, partial_match)]
types = [t for t in types if _matched(name, t['name'], partial_match)]
for t in types:
try:
versions = client.virtual_machine_extension_images.list_versions(
location, publisher, t.name)
versions = _ListVersions(cli_ctx=cli_ctx)(command_args={
'location': location,
'publisher_name': publisher,
'name': t['name']
})
except ResourceNotFoundError as e:
logger.warning(str(e))
continue
if version:
versions = [v for v in versions if _matched(version, v.name, partial_match)]
versions = [v for v in versions if _matched(version, v['name'], partial_match)]

if show_latest:
# pylint: disable=no-member
versions.sort(key=lambda v: parse(v.name), reverse=True)
versions.sort(key=lambda v: parse(v['name']), reverse=True)
try:
all_images.append({
'publisher': publisher,
'name': t.name,
'version': versions[0].name})
'name': t['name'],
'version': versions[0]['name']})
except IndexError:
pass # if no versions for this type continue to next type.
else:
for v in versions:
all_images.append({
'publisher': publisher,
'name': t.name,
'version': v.name})
'name': t['name'],
'version': v['name']})

publishers = client.virtual_machine_images.list_publishers(location=location)
from .aaz.latest.vm.image import ListPublishers
publishers = ListPublishers(cli_ctx=cli_ctx)(command_args={
'location': location
})
if publisher:
publishers = [p for p in publishers if _matched(publisher, p.name, partial_match)]
publishers = [p for p in publishers if _matched(publisher, p['name'], partial_match)]

publisher_num = len(publishers)
if publisher_num > 1:
with ThreadPoolExecutor(max_workers=_get_thread_count()) as executor:
tasks = [executor.submit(_load_extension_images_from_publisher,
p.name) for p in publishers]
p['name']) for p in publishers]
for t in as_completed(tasks):
t.result() # don't use the result but expose exceptions from the threads
elif publisher_num == 1:
_load_extension_images_from_publisher(publishers[0].name)
_load_extension_images_from_publisher(publishers[0]['name'])

return all_images

Expand Down
18 changes: 0 additions & 18 deletions src/azure-cli/azure/cli/command_modules/vm/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1490,24 +1490,6 @@
text: az vm extension show -g MyResourceGroup --vm-name MyVm -n extension_name
"""

helps['vm extension wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of a virtual machine extension is met.
examples:
- name: Place the CLI in a waiting state until a condition of a virtual machine extension is met. (autogenerated)
text: |
az vm extension wait --created --name MyExtension --resource-group MyResourceGroup --vm-name MyVm
crafted: true
- name: Place the CLI in a waiting state until a condition of a virtual machine extension is met. (autogenerated)
text: |
az vm extension wait --exists --name MyExtension --resource-group MyResourceGroup --vm-name MyVm
crafted: true
- name: Place the CLI in a waiting state until a condition of a virtual machine extension is met. (autogenerated)
text: |
az vm extension wait --ids @- --name MyExtension --subscription MySubscription --updated --vm-name MyVm
crafted: true
"""

helps['vm get-instance-view'] = """
type: command
short-summary: Get instance information about a VM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class Show(AAZCommand):
"""

_aaz_info = {
"version": "2024-07-01",
"version": "2024-11-01",
"resources": [
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/virtualmachines/{}", "2024-07-01"],
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/virtualmachines/{}", "2024-11-01"],
]
}

Expand Down Expand Up @@ -122,7 +122,7 @@ def query_parameters(self):
"$expand", self.ctx.args.expand,
),
**self.serialize_query_param(
"api-version", "2024-07-01",
"api-version", "2024-11-01",
required=True,
),
}
Expand Down Expand Up @@ -175,6 +175,7 @@ def _build_schema_on_200(cls):
_schema_on_200.name = AAZStrType(
flags={"read_only": True},
)
_schema_on_200.placement = AAZObjectType()
_schema_on_200.plan = AAZObjectType()
_schema_on_200.properties = AAZObjectType(
flags={"client_flatten": True},
Expand Down Expand Up @@ -219,6 +220,23 @@ def _build_schema_on_200(cls):
flags={"read_only": True},
)

placement = cls._schema_on_200.placement
placement.exclude_zones = AAZListType(
serialized_name="excludeZones",
)
placement.include_zones = AAZListType(
serialized_name="includeZones",
)
placement.zone_placement_policy = AAZStrType(
serialized_name="zonePlacementPolicy",
)

exclude_zones = cls._schema_on_200.placement.exclude_zones
exclude_zones.Element = AAZStrType()

include_zones = cls._schema_on_200.placement.include_zones
include_zones.Element = AAZStrType()

plan = cls._schema_on_200.plan
plan.name = AAZStrType()
plan.product = AAZStrType()
Expand Down Expand Up @@ -1050,10 +1068,16 @@ def _build_schema_on_200(cls):

proxy_agent_settings = cls._schema_on_200.properties.security_profile.proxy_agent_settings
proxy_agent_settings.enabled = AAZBoolType()
proxy_agent_settings.imds = AAZObjectType()
_ShowHelper._build_schema_host_endpoint_settings_read(proxy_agent_settings.imds)
proxy_agent_settings.key_incarnation_id = AAZIntType(
serialized_name="keyIncarnationId",
)
proxy_agent_settings.mode = AAZStrType()
proxy_agent_settings.wire_server = AAZObjectType(
serialized_name="wireServer",
)
_ShowHelper._build_schema_host_endpoint_settings_read(proxy_agent_settings.wire_server)

uefi_settings = cls._schema_on_200.properties.security_profile.uefi_settings
uefi_settings.secure_boot_enabled = AAZBoolType(
Expand All @@ -1064,6 +1088,9 @@ def _build_schema_on_200(cls):
)

storage_profile = cls._schema_on_200.properties.storage_profile
storage_profile.align_regional_disks_to_vm_zone = AAZBoolType(
serialized_name="alignRegionalDisksToVMZone",
)
storage_profile.data_disks = AAZListType(
serialized_name="dataDisks",
)
Expand Down Expand Up @@ -1352,6 +1379,26 @@ def _build_schema_disk_encryption_settings_read(cls, _schema):
_schema.enabled = cls._schema_disk_encryption_settings_read.enabled
_schema.key_encryption_key = cls._schema_disk_encryption_settings_read.key_encryption_key

_schema_host_endpoint_settings_read = None

@classmethod
def _build_schema_host_endpoint_settings_read(cls, _schema):
if cls._schema_host_endpoint_settings_read is not None:
_schema.in_vm_access_control_profile_reference_id = cls._schema_host_endpoint_settings_read.in_vm_access_control_profile_reference_id
_schema.mode = cls._schema_host_endpoint_settings_read.mode
return

cls._schema_host_endpoint_settings_read = _schema_host_endpoint_settings_read = AAZObjectType()

host_endpoint_settings_read = _schema_host_endpoint_settings_read
host_endpoint_settings_read.in_vm_access_control_profile_reference_id = AAZStrType(
serialized_name="inVMAccessControlProfileReferenceId",
)
host_endpoint_settings_read.mode = AAZStrType()

_schema.in_vm_access_control_profile_reference_id = cls._schema_host_endpoint_settings_read.in_vm_access_control_profile_reference_id
_schema.mode = cls._schema_host_endpoint_settings_read.mode

_schema_instance_view_status_read = None

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
# flake8: noqa

from .__cmd_group import *
from ._create import *
from ._delete import *
from ._list import *
from ._show import *
from ._wait import *
Loading