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
6 changes: 5 additions & 1 deletion src/vme/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ Release History

1.0.0b1
++++++
* Initial release.
* Initial release.

1.0.0b2
++++++
* Add new 'az vme list' command to list all version managed extensions.
21 changes: 21 additions & 0 deletions src/vme/azext_vme/_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from collections import OrderedDict


def vme_list_table_format(results):
return [__get_table_row(result) for result in results]


def __get_table_row(result):
return OrderedDict([
('name', result['name']),
('extensionType', result.get('properties', {}).get('extensionType', '')),
('version', result.get('properties', {}).get('version', '')),
('provisioningState', result.get('properties', {}).get('provisioningState', '')),
('isSystemExtension', result.get('properties', {}).get('isSystemExtension', '')),
('lastModifiedAt', result.get('systemData', {}).get('lastModifiedAt', '')),
])
12 changes: 12 additions & 0 deletions src/vme/azext_vme/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,15 @@
text: |-
az vme upgrade --resource-group my-resource-group --cluster-name my-cluster --wait
"""

helps['vme list'] = """
type: command
short-summary: List version managed extensions.
examples:
- name: List version managed extensions
text: |-
az vme list --resource-group my-resource-group --cluster-name my-cluster
- name: List version managed extensions with table format
text: |-
az vme list --resource-group my-resource-group --cluster-name my-cluster --output table
"""
12 changes: 12 additions & 0 deletions src/vme/azext_vme/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,15 @@ def load_arguments(self, _):
help='Extension types to be uninstalled.',
arg_type=get_enum_type(IncludedExtensionTypes),
)

with self.argument_context('vme list') as c:
c.argument(
'resource_group',
options_list=['--resource-group', '-g'],
help='Name of the resource group'
)
c.argument(
'cluster_name',
options_list=['--cluster-name', '-c'],
help='Name of the Kubernetes cluster'
)
3 changes: 3 additions & 0 deletions src/vme/azext_vme/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
from ._format import vme_list_table_format


def load_command_table(self, _):

with self.command_group('vme') as g:
g.custom_command('upgrade', 'upgrade_vme')
g.custom_command('install', 'install_vme')
g.custom_command('uninstall', 'uninstall_vme')
g.custom_command('list', 'list_vme', table_transformer=vme_list_table_format)
11 changes: 8 additions & 3 deletions src/vme/azext_vme/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
SUCCEEDED = "Succeeded"
CANCELLED = "Cancelled"
Bundle_FeatureFlag_NotEnabled = "Bundle feature flag is not enabled."
UPGRADE_IN_PROGRESS_MSG = "Version managed extensions upgrade is in progress"
UPGRADE_IN_PROGRESS_MSG = "Version managed extensions upgrade is in progress..."
UPGRADE_SUCCEEDED_MSG = "Version managed extensions upgrade completed!"
UPGRADE_FAILED_MSG = "Version managed extensions upgrade failed. Error: "
UPGRADE_CANCELED_MSG = "Version managed extensions upgrade is canceled."
UPGRADE_NOTSTARTED_MSG = "Waiting for version managed extensions upgrade to start"
UPGRADE_NOTSTARTED_MSG = "Waiting for version managed extensions upgrade to start..."
UPGRADE_TIMEOUT_MSG = """
Error: version managed extensions upgrade could not start in {0} seconds. Check out common issues here: <url>
"""
Expand All @@ -34,9 +34,14 @@
"microsoft.azure.secretstore"
]

BundleExtensionNames = {
BundleExtensionTypeNames = {
"microsoft.arc.containerstorage": "azure-arc-containerstorage",
"microsoft.azure.secretstore": "azure-secret-store",
}

IncludedExtensionTypes = BundleExtensionTypes + ["all"]
BundleExtensionNames = [
"azure-arc-containerstorage",
"azure-secret-store",
"microsoft.extensiondiagnostics-v0"
]
41 changes: 36 additions & 5 deletions src/vme/azext_vme/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ def install_vme(
for extension_type in include_extension_types:
extension_resource_id = (
f"{cluster_resource_id}/Providers/Microsoft.KubernetesConfiguration/"
f"extensions/{consts.BundleExtensionNames[extension_type]}"
f"extensions/{consts.BundleExtensionTypeNames[extension_type]}"
)
try:
resources.get_by_id(extension_resource_id, '2022-11-01')
ext = resources.get_by_id(extension_resource_id, '2022-11-01')
if ext.properties['provisioningState'] == 'Failed':
raise ResourceNotFoundError()
print(f"Extension {extension_type} already exists, skipping installation.")
continue
except ResourceNotFoundError:
Expand All @@ -61,14 +63,15 @@ def install_vme(
"--cluster-type",
consts.CONNECTEDCLUSTER_TYPE,
"--name",
consts.BundleExtensionNames[extension_type],
consts.BundleExtensionTypeNames[extension_type],
"--extension-type",
extension_type,
"--scope",
"cluster"
]
utils.call_subprocess_raise_output(command)
result = utils.call_subprocess_raise_output(command)
print(f"Installed extension {extension_type} successfully.")
print(result)

print("All extensions installed successfully.")

Expand Down Expand Up @@ -103,7 +106,7 @@ def uninstall_vme(
"--cluster-type",
"connectedClusters",
"--name",
consts.BundleExtensionNames[extension_type],
consts.BundleExtensionTypeNames[extension_type],
"--force",
"--yes"]
utils.call_subprocess_raise_output(command)
Expand Down Expand Up @@ -177,3 +180,31 @@ def upgrade_vme(

if (not deployment):
raise CLIError(consts.UPGRADE_TIMEOUT_MSG.format(wait_timeout))


def list_vme(
cmd,
resource_group_name: str,
cluster_name: str):
subscription_id = get_subscription_id(cmd.cli_ctx)

# Check whether the cluster exists
resources = cf_resources(cmd.cli_ctx, subscription_id)
cluster_resource_id = '/subscriptions/{0}/resourceGroups/{1}/providers/{2}/{3}/{4}'.format(
subscription_id, resource_group_name, consts.CONNECTEDCLUSTER_RP, consts.CONNECTEDCLUSTER_TYPE, cluster_name)
resources.get_by_id(cluster_resource_id, '2024-12-01-preview')

results = []
extension_names = consts.BundleExtensionNames
for extension_name in extension_names:
extension_resource_id = (
f"{cluster_resource_id}/Providers/Microsoft.KubernetesConfiguration/"
f"extensions/{extension_name}"
)
try:
ext = resources.get_by_id(extension_resource_id, '2022-11-01')
results.append(ext)
except ResourceNotFoundError:
continue

return results
3,960 changes: 0 additions & 3,960 deletions src/vme/azext_vme/tests/latest/recordings/test_vme_install_uninstall_live.yaml

This file was deleted.

3,575 changes: 3,575 additions & 0 deletions src/vme/azext_vme/tests/latest/recordings/test_vme_live.yaml

Large diffs are not rendered by default.

Loading
Loading