Skip to content
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

add mc snapshot command and change nodepool snapshot #4594

Merged
merged 3 commits into from
Apr 6, 2022
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
149 changes: 149 additions & 0 deletions src/aks-preview/HISTORY.md

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/aks-preview/azext_aks_preview/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@ def cf_agent_pools(cli_ctx, *_):
return get_mgmt_service_client(cli_ctx, CUSTOM_MGMT_AKS_PREVIEW).agent_pools


def cf_snapshots_client(cli_ctx, subscription_id=None):
def cf_mc_snapshots_client(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx, CUSTOM_MGMT_AKS_PREVIEW, subscription_id=subscription_id).managed_cluster_snapshots


def cf_mc_snapshots(cli_ctx, *_):
return get_mgmt_service_client(cli_ctx, CUSTOM_MGMT_AKS_PREVIEW).managed_cluster_snapshots


def cf_nodepool_snapshots_client(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx, CUSTOM_MGMT_AKS_PREVIEW, subscription_id=subscription_id).snapshots


def cf_snapshots(cli_ctx, *_):
def cf_nodepool_snapshots(cli_ctx, *_):
return get_mgmt_service_client(cli_ctx, CUSTOM_MGMT_AKS_PREVIEW).snapshots


Expand Down
41 changes: 34 additions & 7 deletions src/aks-preview/azext_aks_preview/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,17 @@ def aks_pod_identities_table_format(result):
return parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))


def aks_list_snapshot_table_format(results):
""""Format a list of snapshots as summary results for display with "-o table"."""
return [_aks_snapshot_table_format(r) for r in results]
def aks_list_nodepool_snapshot_table_format(results):
""""Format a list of nodepool snapshots as summary results for display with "-o table"."""
return [_aks_nodepool_snapshot_table_format(r) for r in results]


def aks_show_snapshot_table_format(result):
"""Format a snapshot as summary results for display with "-o table"."""
return [_aks_snapshot_table_format(result)]
def aks_show_nodepool_snapshot_table_format(result):
"""Format a nodepool snapshot as summary results for display with "-o table"."""
return [_aks_nodepool_snapshot_table_format(result)]


def _aks_snapshot_table_format(result):
def _aks_nodepool_snapshot_table_format(result):
parsed = compile_jmes("""{
name: name,
location: location,
Expand All @@ -240,3 +240,30 @@ def _aks_snapshot_table_format(result):
}""")
# use ordered dicts so headers are predictable
return parsed.search(result, Options(dict_cls=OrderedDict))


def aks_list_snapshot_table_format(results):
""""Format a list of cluster snapshots as summary results for display with "-o table"."""
return [_aks_snapshot_table_format(r) for r in results]


def aks_show_snapshot_table_format(result):
"""Format a cluster snapshot as summary results for display with "-o table"."""
return [_aks_snapshot_table_format(result)]


def _aks_snapshot_table_format(result):
parsed = compile_jmes("""{
name: name,
location: location,
resourceGroup: resourceGroup,
sku: managedClusterPropertiesReadOnly.sku.tier,
enableRbac: managedClusterPropertiesReadOnly.enableRbac,
kubernetesVersion: managedClusterPropertiesReadOnly.kubernetesVersion,
networkPlugin: managedClusterPropertiesReadOnly.networkProfile.networkPlugin,
networkPolicy: managedClusterPropertiesReadOnly.networkProfile.networkPolicy,
networkMode: managedClusterPropertiesReadOnly.networkProfile.networkMode,
loadBalancerSku: managedClusterPropertiesReadOnly.networkProfile.loadBalancerSku
}""")
# use ordered dicts so headers are predictable
return parsed.search(result, Options(dict_cls=OrderedDict))
61 changes: 51 additions & 10 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,22 +1549,63 @@

helps['aks snapshot'] = """
type: group
short-summary: Commands to manage snapshots.
short-summary: Commands to manage cluster snapshots.
"""

helps['aks snapshot show'] = """
type: command
short-summary: Show the details of a snapshot.
short-summary: Show the details of a cluster snapshot.
"""

helps['aks snapshot list'] = """
type: command
short-summary: List snapshots.
short-summary: List cluster snapshots.
"""

helps['aks snapshot create'] = """
type: command
short-summary: Create a snapshot of a node pool.
short-summary: Create a snapshot of a cluster.
parameters:
- name: --cluster-id
type: string
short-summary: The source cluster id from which to create this snapshot.
- name: --tags
type: string
short-summary: The tags of the snapshot.
- name: --aks-custom-headers
type: string
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2

examples:
- name: Create a cluster snapshot.
text: az aks snapshot create -g MyResourceGroup -n snapshot1 --cluster-id "/subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.ContainerService/managedClusters/akscluster1"
- name: Create a cluster snapshot with custom tags.
text: az aks snapshot create -g MyResourceGroup -n snapshot1 --cluster-id "/subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.ContainerService/managedClusters/akscluster1" --tags "foo=bar" "key1=val1"
"""

helps['aks snapshot delete'] = """
type: command
short-summary: Delete a cluster snapshot.
"""

helps['aks nodepool snapshot'] = """
type: group
short-summary: Commands to manage nodepool snapshots.
"""

helps['aks nodepool snapshot show'] = """
type: command
short-summary: Show the details of a nodepool snapshot.
"""

helps['aks nodepool snapshot list'] = """
type: command
short-summary: List nodepool snapshots.
"""

helps['aks nodepool snapshot create'] = """
type: command
short-summary: Create a nodepool snapshot.
parameters:
- name: --nodepool-id
type: string
Expand All @@ -1577,13 +1618,13 @@
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2

examples:
- name: Create a snapshot.
text: az aks snapshot create -g MyResourceGroup -n snapshot1 --nodepool-id "/subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.ContainerService/managedClusters/akscluster1/agentPools/nodepool1"
- name: Create a snapshot with custom tags.
text: az aks snapshot create -g MyResourceGroup -n snapshot1 --nodepool-id "/subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.ContainerService/managedClusters/akscluster1/agentPools/nodepool1" --tags "foo=bar" "key1=val1"
- name: Create a nodepool snapshot.
text: az aks nodepool snapshot create -g MyResourceGroup -n snapshot1 --nodepool-id "/subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.ContainerService/managedClusters/akscluster1/agentPools/nodepool1"
- name: Create a nodepool snapshot with custom tags.
text: az aks nodepool snapshot create -g MyResourceGroup -n snapshot1 --nodepool-id "/subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.ContainerService/managedClusters/akscluster1/agentPools/nodepool1" --tags "foo=bar" "key1=val1"
"""

helps['aks snapshot delete'] = """
helps['aks nodepool snapshot delete'] = """
type: command
short-summary: Delete a snapshot.
short-summary: Delete a nodepool snapshot.
"""
43 changes: 32 additions & 11 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
get_vm_size_completion_list, get_k8s_versions_completion_list, get_k8s_upgrades_completion_list, get_ossku_completion_list)
from ._validators import (
validate_create_parameters, validate_k8s_version, validate_linux_host_name,
validate_ssh_key, validate_nodes_count, validate_ip_ranges,
validate_nodepool_name, validate_vm_set_type, validate_load_balancer_sku, validate_nodepool_id, validate_snapshot_id, validate_crg_id,
validate_ssh_key, validate_nodes_count, validate_ip_ranges, validate_snapshot_name,
validate_nodepool_name, validate_vm_set_type, validate_load_balancer_sku, validate_nodepool_id, validate_cluster_id, validate_snapshot_id, validate_crg_id,
validate_load_balancer_outbound_ips, validate_load_balancer_outbound_ip_prefixes, validate_nat_gateway_managed_outbound_ip_count,
validate_taints, validate_priority, validate_eviction_policy, validate_spot_max_price, validate_acr, validate_user,
validate_load_balancer_outbound_ports, validate_load_balancer_idle_timeout, validate_nat_gateway_idle_timeout, validate_nodepool_tags, validate_addon,
Expand Down Expand Up @@ -206,9 +206,12 @@ def load_arguments(self, _):
c.argument('host_group_id',
validator=validate_host_group_id, is_preview=True)
c.argument('crg_id', validator=validate_crg_id, is_preview=True)
c.argument('message_of_the_day', type=str) # no validation for aks create because it already only supports Linux.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why so many irrelevant changes in many files? without these changes, will Style or linter checks fail?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter didn't fail. And the style change auto-saved.

c.argument('enable_azure_keyvault_kms', action='store_true', is_preview=True)
c.argument('azure_keyvault_kms_key_id', validator=validate_azure_keyvault_kms_key_id, is_preview=True)
# no validation for aks create because it already only supports Linux.
c.argument('message_of_the_day', type=str)
c.argument('enable_azure_keyvault_kms',
action='store_true', is_preview=True)
c.argument('azure_keyvault_kms_key_id',
validator=validate_azure_keyvault_kms_key_id, is_preview=True)

with self.argument_context('aks update') as c:
c.argument('enable_cluster_autoscaler', options_list=[
Expand Down Expand Up @@ -270,8 +273,10 @@ def load_arguments(self, _):
help='space-separated labels: key[=value] [key[=value] ...]. See https://aka.ms/node-labels for syntax of labels.')
c.argument('enable_oidc_issuer', action='store_true', is_preview=True)
c.argument('http_proxy_config', type=str)
c.argument('enable_azure_keyvault_kms', action='store_true', is_preview=True)
c.argument('azure_keyvault_kms_key_id', validator=validate_azure_keyvault_kms_key_id, is_preview=True)
c.argument('enable_azure_keyvault_kms',
action='store_true', is_preview=True)
c.argument('azure_keyvault_kms_key_id',
validator=validate_azure_keyvault_kms_key_id, is_preview=True)

with self.argument_context('aks scale') as c:
c.argument('nodepool_name', type=str,
Expand Down Expand Up @@ -531,19 +536,35 @@ def load_arguments(self, _):
help='pod labels in key=value [key=value ...].',
validator=validate_pod_identity_pod_labels)

for scope in ['aks snapshot create']:
for scope in ['aks nodepool snapshot create']:
with self.argument_context(scope) as c:
c.argument('snapshot_name', type=str, options_list=[
'--name', '-n'], required=True, validator=validate_linux_host_name, help='The snapshot name.')
'--name', '-n'], required=True, help='The nodepool snapshot name.', validator=validate_snapshot_name)
c.argument('tags', tags_type)
c.argument('nodepool_id', type=str, required=True,
validator=validate_nodepool_id, help='The nodepool id.')
help='The nodepool id.', validator=validate_nodepool_id)
c.argument('aks_custom_headers')

for scope in ['aks nodepool snapshot show', 'aks nodepool snapshot delete']:
with self.argument_context(scope) as c:
c.argument('snapshot_name', type=str, options_list=[
'--name', '-n'], required=True, help='The nodepool snapshot name.', validator=validate_snapshot_name)
c.argument('yes', options_list=[
'--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')

for scope in ['aks snapshot create']:
with self.argument_context(scope) as c:
c.argument('snapshot_name', type=str, options_list=[
'--name', '-n'], required=True, help='The cluster snapshot name.', validator=validate_snapshot_name)
c.argument('tags', tags_type)
c.argument('cluster_id', type=str, required=True,
validator=validate_cluster_id, help='The cluster id.')
c.argument('aks_custom_headers')

for scope in ['aks snapshot show', 'aks snapshot delete']:
with self.argument_context(scope) as c:
c.argument('snapshot_name', type=str, options_list=[
'--name', '-n'], required=True, validator=validate_linux_host_name, help='The snapshot name.')
'--name', '-n'], required=True, help='The cluster snapshot name.', validator=validate_snapshot_name)
c.argument('yes', options_list=[
'--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')

Expand Down
Loading