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

[AKS] aks nodepool stop/start: Add nodepool stop/start bindings #23055

Merged
merged 4 commits into from
Jun 29, 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
30 changes: 30 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,36 @@
short-summary: Comma-separated key-value pairs to specify custom headers.
"""

helps['aks nodepool stop'] = """
type: command
short-summary: Stop running agent pool in the managed Kubernetes cluster.
parameters:
- name: --nodepool-name
type: string
short-summary: Agent pool name
- name: --aks-custom-headers
type: string
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2
examples:
- name: Stop agent pool in the managed cluster
text: az aks nodepool stop --nodepool-name nodepool1 -g MyResourceGroup --cluster-name MyManagedCluster
"""

helps['aks nodepool start'] = """
type: command
short-summary: Start stopped agent pool in the managed Kubernetes cluster.
parameters:
- name: --nodepool-name
type: string
short-summary: Agent pool name
- name: --aks-custom-headers
type: string
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2
examples:
- name: Start agent pool in the managed cluster
text: az aks nodepool start --nodepool-name nodepool1 -g MyResourceGroup --cluster-name MyManagedCluster
"""

helps['aks remove-dev-spaces'] = """
type: command
short-summary: Remove Azure Dev Spaces from a managed Kubernetes cluster.
Expand Down
2 changes: 2 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def load_command_table(self, _):
g.custom_command('delete', 'aks_agentpool_delete', supports_no_wait=True)
g.custom_show_command('show', 'aks_agentpool_show', table_transformer=aks_agentpool_show_table_format)
g.custom_command('list', 'aks_agentpool_list', table_transformer=aks_agentpool_list_table_format)
g.custom_command('stop', 'aks_agentpool_stop', supports_no_wait=True)
g.custom_command('start', 'aks_agentpool_start', supports_no_wait=True)
g.wait_command('wait')

with self.command_group('aks command', managed_clusters_sdk, client_factory=cf_managed_clusters) as g:
Expand Down
46 changes: 46 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3136,6 +3136,52 @@ def aks_agentpool_scale(cmd, client, resource_group_name, cluster_name,
)


def aks_agentpool_start(cmd, # pylint: disable=unused-argument
client,
resource_group_name,
cluster_name,
nodepool_name,
aks_custom_headers=None,
no_wait=False):
agentpool_exists = False
instances = client.list(resource_group_name, cluster_name)
for agentpool_profile in instances:
if agentpool_profile.name.lower() == nodepool_name.lower():
agentpool_exists = True
break
if not agentpool_exists:
raise InvalidArgumentValueError(
"Node pool {} doesnt exist, use 'aks nodepool list' to get current node pool list".format(nodepool_name))
instance = client.get(resource_group_name, cluster_name, nodepool_name)
PowerState = cmd.get_models('PowerState', operation_group='agent_pools')
power_state = PowerState(code="Running")
instance.power_state = power_state
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, cluster_name, nodepool_name, instance, headers=None)


def aks_agentpool_stop(cmd, # pylint: disable=unused-argument
client,
resource_group_name,
cluster_name,
nodepool_name,
aks_custom_headers=None,
no_wait=False):
agentpool_exists = False
instances = client.list(resource_group_name, cluster_name)
for agentpool_profile in instances:
if agentpool_profile.name.lower() == nodepool_name.lower():
agentpool_exists = True
break
if not agentpool_exists:
raise InvalidArgumentValueError(
"Node pool {} doesnt exist, use 'aks nodepool list' to get current node pool list".format(nodepool_name))
instance = client.get(resource_group_name, cluster_name, nodepool_name)
PowerState = cmd.get_models('PowerState', operation_group='agent_pools')
power_state = PowerState(code="Stopped")
instance.power_state = power_state
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, cluster_name, nodepool_name, instance, headers=None)


def aks_agentpool_delete(cmd, client, resource_group_name, cluster_name,
nodepool_name,
no_wait=False):
Expand Down
Loading