-
Notifications
You must be signed in to change notification settings - Fork 1.7k
{aimanager} Improve az aimanager list/show table output
#10322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Liqian Luo (circy9)
merged 16 commits into
Azure:main
from
circy9:aimanager-list-table-format
Sep 11, 2026
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cd1292a
{aimanager} Improve `az aimanager list/show` table output
circy9 6d9c41a
{aimanager} Reorder table columns
circy9 60cfbb5
{aimanager} Handle null properties in table formatter
circy9 2bf36a6
{aimanager} Drop Subscription column from table output
circy9 4f5a4d3
{aimanager} Add table formatter for namespace list/show
circy9 b4e5d7f
{aimanager} Add table formatter for modeldeployment list/show
circy9 dfad17f
{aimanager} Memoize AIModel lookups when resolving modelId
circy9 b1452df
{aimanager} Trim namespace and modeldeployment table columns
circy9 c787e12
{aimanager} Add Labels column to namespace table
circy9 bd26ba7
{aimanager} Add Age column to namespace table
circy9 ed43d1f
{aimanager} Reorder modeldeployment table and add Age
circy9 d7fb702
{aimanager} Clean up table format tests per review
circy9 8fc8330
{aimanager} Show blank ModelId when resolution fails
circy9 35dab0f
{aimanager} Fix empty ModelId by returning plain dicts
circy9 ca64068
{aimanager} Use todict for modeldeployment dict conversion
circy9 524025d
Merge branch 'main' into aimanager-list-table-format
circy9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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 _parse_resource_id(resource_id): | ||
| """Parse an ARM resource id into its component parts (best-effort).""" | ||
| if not resource_id: | ||
| return {} | ||
| from azure.mgmt.core.tools import parse_resource_id | ||
| return parse_resource_id(resource_id) | ||
|
|
||
|
|
||
| def aimanager_table_format(result): | ||
| """Format a single AI Manager resource for display with "-o table".""" | ||
| parsed = _parse_resource_id(result.get('id', '')) | ||
| properties = result.get('properties') or {} | ||
| return OrderedDict([ | ||
| ('Name', result.get('name', '')), | ||
| ('ProvisioningState', properties.get('provisioningState', '')), | ||
| ('ResourceGroup', parsed.get('resource_group', '')), | ||
| ('Location', result.get('location', '')), | ||
| ]) | ||
|
|
||
|
|
||
| def aimanager_list_table_format(results): | ||
| """Format a list of AI Manager resources for display with "-o table".""" | ||
| return [aimanager_table_format(r) for r in results] | ||
|
|
||
|
|
||
| def _labels_display(labels): | ||
| """Render a labels dict as comma-joined key=value pairs, sorted for stable output.""" | ||
| if not labels: | ||
| return '' | ||
| return ','.join('{}={}'.format(k, labels[k]) for k in sorted(labels)) | ||
|
|
||
|
|
||
| def _age_display(result): | ||
| """Render the resource age from systemData.createdAt, kubectl-style (e.g. 45d, 3h, 12m). | ||
|
|
||
| Best-effort: returns '' when the timestamp is missing or cannot be parsed. | ||
| """ | ||
| created_at = (result.get('systemData') or {}).get('createdAt') | ||
| if not created_at: | ||
| return '' | ||
| try: | ||
| from datetime import datetime, timezone | ||
| from dateutil.parser import parse as parse_datetime | ||
| created = parse_datetime(created_at) | ||
| if created.tzinfo is None: | ||
| created = created.replace(tzinfo=timezone.utc) | ||
| delta = datetime.now(timezone.utc) - created | ||
| seconds = int(delta.total_seconds()) | ||
| if seconds < 0: | ||
| return '' | ||
| days, rem = divmod(seconds, 86400) | ||
| hours, rem = divmod(rem, 3600) | ||
| minutes, secs = divmod(rem, 60) | ||
| if days > 0: | ||
| return '{}d'.format(days) if hours == 0 else '{}d{}h'.format(days, hours) | ||
| if hours > 0: | ||
| return '{}h'.format(hours) if minutes == 0 else '{}h{}m'.format(hours, minutes) | ||
| if minutes > 0: | ||
| return '{}m'.format(minutes) | ||
| return '{}s'.format(secs) | ||
| except Exception: # pylint: disable=broad-except | ||
| return '' | ||
|
|
||
|
|
||
| def namespace_table_format(result): | ||
| """Format a single AI Manager namespace resource for display with "-o table".""" | ||
| properties = result.get('properties') or {} | ||
| return OrderedDict([ | ||
| ('Name', result.get('name', '')), | ||
| ('ProvisioningState', properties.get('provisioningState', '')), | ||
| ('Age', _age_display(result)), | ||
| ('Labels', _labels_display(properties.get('labels'))), | ||
| ]) | ||
|
|
||
|
|
||
| def namespace_list_table_format(results): | ||
| """Format a list of AI Manager namespace resources for display with "-o table".""" | ||
| return [namespace_table_format(r) for r in results] | ||
|
|
||
|
|
||
| def _replica_display(value): | ||
| """Render a replica count, using '-' when the count is not yet reported.""" | ||
| return str(value) if value is not None else '-' | ||
|
|
||
|
|
||
| def modeldeployment_table_format(result): | ||
| """Format a single model deployment resource for display with "-o table".""" | ||
| parsed = _parse_resource_id(result.get('id', '')) | ||
| properties = result.get('properties') or {} | ||
| status = properties.get('status') or {} | ||
|
|
||
| # ``modelId`` (human-readable, e.g. "meta-llama/Llama-3-8B") is resolved from the | ||
| # deployment's ``modelResourceId`` by the custom list/show functions and injected onto | ||
| # the result. Shown blank when resolution is unavailable (the raw AIModel resource name | ||
| # is not human-readable, so it is intentionally not used as a fallback). | ||
| model_id = result.get('modelId') or '' | ||
|
|
||
| replicas = '{}/{}'.format( | ||
| _replica_display(status.get('currentReplicas')), | ||
| _replica_display(status.get('desiredReplicas')), | ||
| ) | ||
|
|
||
| return OrderedDict([ | ||
| ('Namespace', parsed.get('child_name_1', '')), | ||
| ('Name', result.get('name', '')), | ||
| ('ProvisioningState', properties.get('provisioningState', '')), | ||
| ('Replicas', replicas), | ||
| ('Age', _age_display(result)), | ||
| ('ModelId', model_id), | ||
| ('Endpoint', status.get('endpoint', '')), | ||
| ]) | ||
|
|
||
|
|
||
| def modeldeployment_list_table_format(results): | ||
| """Format a list of model deployment resources for display with "-o table".""" | ||
| return [modeldeployment_table_format(r) for r in results] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.