Skip to content

Commit

Permalink
[AKS] aks nodepool stop/start: Add nodepool stop/start bindings (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
rsamigullin authored Jun 29, 2022
1 parent e894197 commit ac1759b
Show file tree
Hide file tree
Showing 5 changed files with 2,042 additions and 0 deletions.
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 @@ -3148,6 +3148,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

0 comments on commit ac1759b

Please sign in to comment.