Skip to content

Commit

Permalink
[HDInsight] Migrate to track2 python sdk 7.0.0 (#18237)
Browse files Browse the repository at this point in the history
  • Loading branch information
aim-for-better authored Jun 1, 2021
1 parent 1b02b32 commit 05714f0
Show file tree
Hide file tree
Showing 28 changed files with 7,218 additions and 9,758 deletions.
21 changes: 19 additions & 2 deletions src/azure-cli/azure/cli/command_modules/hdinsight/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
helps['hdinsight create'] = """
type: command
short-summary: Create a new cluster.
long-summary: 'Create a new cluster. Incoming BREAKING CHANGE: The default value "large" of parameters `--workernode-size` and `--headnode-size` will be removed in the next CLI version.'
examples:
- name: Create a cluster with an existing storage account.
text: |-
Expand Down Expand Up @@ -158,6 +157,24 @@
--enable-compute-isolation --workernode-size "Standard_E8S_V3" --headnode-size "Standard_E8S_V3"
"""

helps['hdinsight resize'] = """
type: command
short-summary: Resize the specified HDInsight cluster to the specified size.
examples:
- name: Resize the cluster's workernode.
text: |-
az hdinsight resize --name MyCluster --resource-group rg --workernode-count 5
"""

helps['hdinsight update'] = """
type: command
short-summary: Update the tags of the specified HDInsight cluster.
examples:
- name: Update the tags.
text: |-
az hdinsight update --name MyCluster --resource-group rg --tags key=value
"""

helps['hdinsight list'] = """
type: command
short-summary: List HDInsight clusters in a resource group or subscription.
Expand Down Expand Up @@ -313,7 +330,7 @@
examples:
- name: Update a schedule condition.
text: |-
az hdinsight autoscale condition update --resource-group MyResourceGroup --cluster-name MyCluster --index 0\\
az hdinsight autoscale condition update --resource-group MyResourceGroup --cluster-name MyCluster --index 0 \\
--time 10:00 --workernode-count 5
"""

Expand Down
12 changes: 6 additions & 6 deletions src/azure-cli/azure/cli/command_modules/hdinsight/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def load_command_table(self, _): # pylint: disable=too-many-statements
# cluster operations
with self.command_group('hdinsight', hdinsight_clusters_sdk, client_factory=cf_hdinsight_clusters) as g:
g.custom_command('create', 'create_cluster', supports_no_wait=True)
g.command('resize', 'resize', supports_no_wait=True)
g.custom_command('resize', 'resize_cluster', supports_no_wait=True)
g.show_command('show', 'get')
g.custom_command('list', 'list_clusters')
g.wait_command('wait')
g.command('delete', 'delete', confirmation=True, supports_no_wait=True)
g.command('delete', 'begin_delete', confirmation=True, supports_no_wait=True)
g.custom_command('rotate-disk-encryption-key', 'rotate_hdi_cluster_key', supports_no_wait=True)
g.command('update', 'update', supports_no_wait=True)
g.custom_command('update', 'update_cluster', supports_no_wait=True)

# usage operations
with self.command_group('hdinsight', hdinsight_locations_sdk, client_factory=cf_hdinsight_locations) as g:
Expand Down Expand Up @@ -91,19 +91,19 @@ def load_command_table(self, _): # pylint: disable=too-many-statements
g.show_command('show', 'get')
g.command('list', 'list_by_cluster')
g.wait_command('wait')
g.command('delete', 'delete', confirmation=True, supports_no_wait=True)
g.command('delete', 'begin_delete', confirmation=True, supports_no_wait=True)

# Monitoring operations
with self.command_group('hdinsight monitor', hdinsight_extensions_sdk, client_factory=cf_hdinsight_extensions) as g:
g.show_command('show', 'get_monitoring_status')
g.custom_command('enable', 'enable_hdi_monitoring')
g.command('disable', 'disable_monitoring')
g.command('disable', 'begin_disable_monitoring')

# VirtualMachine operations
with self.command_group('hdinsight host', hdinsight_virtual_machines_sdk,
client_factory=cf_hdinsight_virtual_machines) as g:
g.command('list', 'list_hosts')
g.command('restart', 'restart_hosts', confirmation=True)
g.command('restart', 'begin_restart_hosts', confirmation=True)

# Autoscale operations
with self.command_group('hdinsight autoscale', hdinsight_clusters_sdk, client_factory=cf_hdinsight_clusters) as g:
Expand Down
111 changes: 79 additions & 32 deletions src/azure-cli/azure/cli/command_modules/hdinsight/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.log import get_logger
from knack.prompting import prompt_pass, NoTTYException
from knack.util import CLIError
Expand Down Expand Up @@ -43,7 +44,7 @@ def create_cluster(cmd, client, cluster_name, resource_group_name, cluster_type,
from azure.mgmt.hdinsight.models import ClusterCreateParametersExtended, ClusterCreateProperties, OSType, \
ClusterDefinition, ComputeProfile, HardwareProfile, Role, OsProfile, LinuxOperatingSystemProfile, \
StorageProfile, StorageAccount, DataDisksGroups, SecurityProfile, \
DirectoryType, DiskEncryptionProperties, Tier, SshProfile, SshPublicKey, \
DiskEncryptionProperties, Tier, SshProfile, SshPublicKey, \
KafkaRestProperties, ClientGroupInfo, EncryptionInTransitProperties, \
Autoscale, AutoscaleCapacity, AutoscaleRecurrence, AutoscaleSchedule, AutoscaleTimeAndCapacity, \
NetworkProperties, PrivateLink, ComputeIsolationProperties
Expand Down Expand Up @@ -319,7 +320,7 @@ def create_cluster(cmd, client, cluster_name, resource_group_name, cluster_type,
ldaps_urls = ['ldaps://{}:636'.format(domain_name)]

security_profile = domain and SecurityProfile(
directory_type=DirectoryType.active_directory,
directory_type=SecurityProfile.directory_type,
domain=domain_name,
ldaps_urls=ldaps_urls,
domain_username=cluster_admin_account,
Expand Down Expand Up @@ -395,10 +396,7 @@ def create_cluster(cmd, client, cluster_name, resource_group_name, cluster_type,
identity=cluster_identity
)

if no_wait:
return sdk_no_wait(no_wait, client.create, resource_group_name, cluster_name, create_params)

return client.create(resource_group_name, cluster_name, create_params)
return sdk_no_wait(no_wait, client.begin_create, resource_group_name, cluster_name, create_params)


def list_clusters(cmd, client, resource_group_name=None): # pylint: disable=unused-argument
Expand All @@ -408,6 +406,15 @@ def list_clusters(cmd, client, resource_group_name=None): # pylint: disable=unu
return list(clusters_list)


def update_cluster(cmd, client, cluster_name, resource_group_name, tags=None, no_wait=False):
from azure.mgmt.hdinsight.models import ClusterPatchParameters
cluster_patch_parameters = ClusterPatchParameters(
tags=tags
)

return sdk_no_wait(no_wait, client.update, resource_group_name, cluster_name, cluster_patch_parameters)


# pylint: disable=unused-argument
def rotate_hdi_cluster_key(cmd, client, resource_group_name, cluster_name,
encryption_vault_uri, encryption_key_name, encryption_key_version, no_wait=False):
Expand All @@ -418,10 +425,18 @@ def rotate_hdi_cluster_key(cmd, client, resource_group_name, cluster_name,
key_version=encryption_key_version
)

if no_wait:
return sdk_no_wait(no_wait, client.rotate_disk_encryption_key, resource_group_name, cluster_name, rotate_params)
return sdk_no_wait(no_wait, client.begin_rotate_disk_encryption_key, resource_group_name, cluster_name,
rotate_params)

return client.rotate_disk_encryption_key(resource_group_name, cluster_name, rotate_params)

def resize_cluster(cmd, client, cluster_name, resource_group_name, target_instance_count, no_wait=False):
from azure.mgmt.hdinsight.models import ClusterResizeParameters, RoleName
resize_cluster_parameters = ClusterResizeParameters(
target_instance_count=target_instance_count
)

return sdk_no_wait(no_wait, client.begin_resize, resource_group_name, cluster_name, RoleName.WORKERNODE,
resize_cluster_parameters)


def _all_or_none(*params):
Expand Down Expand Up @@ -508,12 +523,13 @@ def create_hdi_application(cmd, client, resource_group_name, cluster_name, appli
properties=application_properties
)

return client.create(resource_group_name, cluster_name, application_name, create_params)
return client.begin_create(resource_group_name, cluster_name, application_name, create_params)


# pylint: disable=unused-argument
def enable_hdi_monitoring(cmd, client, resource_group_name, cluster_name, workspace,
primary_key=None, workspace_type='resource_id', no_validation_timeout=False):
from azure.mgmt.hdinsight.models import ClusterMonitoringRequest
from msrestazure.tools import parse_resource_id
from ._client_factory import cf_log_analytics

Expand Down Expand Up @@ -542,18 +558,21 @@ def enable_hdi_monitoring(cmd, client, resource_group_name, cluster_name, worksp

workspace_id = log_analytics_workspace.customer_id

return client.enable_monitoring(
monitor_request_parameter = ClusterMonitoringRequest(
workspace_id=workspace_id,
primary_key=primary_key
)
return client.begin_enable_monitoring(
resource_group_name,
cluster_name,
workspace_id,
primary_key)
monitor_request_parameter)


# pylint: disable=unused-argument
def execute_hdi_script_action(cmd, client, resource_group_name, cluster_name,
script_uri, script_action_name, roles, script_parameters=None,
persist_on_success=False):
from azure.mgmt.hdinsight.models import RuntimeScriptAction
from azure.mgmt.hdinsight.models import RuntimeScriptAction, ExecuteScriptActionParameters

script_actions_params = [
RuntimeScriptAction(
Expand All @@ -563,16 +582,19 @@ def execute_hdi_script_action(cmd, client, resource_group_name, cluster_name,
roles=roles
)
]

return client.execute_script_actions(resource_group_name, cluster_name, persist_on_success, script_actions_params)
execute_script_action_parameters = ExecuteScriptActionParameters(
persist_on_success=persist_on_success,
script_actions=script_actions_params
)
return client.begin_execute_script_actions(resource_group_name, cluster_name, execute_script_action_parameters)


# pylint: disable=redefined-builtin
def create_autoscale(cmd, client, resource_group_name, cluster_name, type, min_workernode_count=None,
max_workernode_count=None, timezone=None, days=None, time=None, workernode_count=None,
no_wait=False, yes=False):
from azure.mgmt.hdinsight.models import Autoscale, AutoscaleCapacity, AutoscaleRecurrence, AutoscaleSchedule, \
AutoscaleTimeAndCapacity
AutoscaleTimeAndCapacity, AutoscaleConfigurationUpdateParameter, RoleName
load_based_type = "Load"
schedule_based_type = "Schedule"
autoscale_configuration = None
Expand Down Expand Up @@ -612,13 +634,17 @@ def create_autoscale(cmd, client, resource_group_name, cluster_name, type, min_w
"This operation will override previous autoscale configuration. "
"Are you sure you want to perform this operation", yes)

return sdk_no_wait(no_wait, client.update_auto_scale_configuration, resource_group_name, cluster_name,
autoscale_configuration)
autoscale_configuration_update_parameter = AutoscaleConfigurationUpdateParameter(
autoscale=autoscale_configuration
)
return sdk_no_wait(no_wait, client.begin_update_auto_scale_configuration, resource_group_name, cluster_name,
RoleName.WORKERNODE, autoscale_configuration_update_parameter)


def update_autoscale(cmd, client, resource_group_name, cluster_name, min_workernode_count=None,
max_workernode_count=None, timezone=None, no_wait=False):
from azure.mgmt.hdinsight.models import AutoscaleCapacity, AutoscaleRecurrence
from azure.mgmt.hdinsight.models import AutoscaleCapacity, AutoscaleRecurrence, \
AutoscaleConfigurationUpdateParameter, RoleName
cluster = client.get(resource_group_name, cluster_name)
autoscale_configuration = _extract_and_validate_autoscale_configuration(cluster)

Expand All @@ -644,8 +670,11 @@ def update_autoscale(cmd, client, resource_group_name, cluster_name, min_workern
elif not autoscale_configuration.recurrence:
autoscale_configuration.recurrence = AutoscaleRecurrence(time_zone=timezone)

return sdk_no_wait(no_wait, client.update_auto_scale_configuration, resource_group_name, cluster_name,
autoscale_configuration)
autoscale_configuration_update_parameter = AutoscaleConfigurationUpdateParameter(
autoscale=autoscale_configuration
)
return sdk_no_wait(no_wait, client.begin_update_auto_scale_configuration, resource_group_name, cluster_name,
RoleName.WORKERNODE, autoscale_configuration_update_parameter)


def show_autoscale(cmd, client, resource_group_name, cluster_name):
Expand All @@ -655,12 +684,17 @@ def show_autoscale(cmd, client, resource_group_name, cluster_name):


def delete_autoscale(cmd, client, resource_group_name, cluster_name, no_wait=False):
from azure.mgmt.hdinsight.models import AutoscaleConfigurationUpdateParameter, RoleName

cluster = client.get(resource_group_name, cluster_name)
_extract_and_validate_autoscale_configuration(cluster)
autoscale_configuration = None

return sdk_no_wait(no_wait, client.update_auto_scale_configuration, resource_group_name, cluster_name,
autoscale_configuration)
autoscale_configuration_update_parameter = AutoscaleConfigurationUpdateParameter(
autoscale=autoscale_configuration
)
return sdk_no_wait(no_wait, client.begin_update_auto_scale_configuration, resource_group_name, cluster_name,
RoleName.WORKERNODE, autoscale_configuration_update_parameter)


def list_timezones(cmd, client):
Expand All @@ -670,7 +704,8 @@ def list_timezones(cmd, client):

def create_autoscale_condition(cmd, client, resource_group_name, cluster_name, days, time, workernode_count,
no_wait=False):
from azure.mgmt.hdinsight.models import AutoscaleRecurrence, AutoscaleSchedule, AutoscaleTimeAndCapacity
from azure.mgmt.hdinsight.models import AutoscaleRecurrence, AutoscaleSchedule, AutoscaleTimeAndCapacity, \
AutoscaleConfigurationUpdateParameter, RoleName
cluster = client.get(resource_group_name, cluster_name)
autoscale_configuration = _extract_and_validate_autoscale_configuration(cluster)

Expand All @@ -688,13 +723,17 @@ def create_autoscale_condition(cmd, client, resource_group_name, cluster_name, d
autoscale_configuration.recurrence = AutoscaleRecurrence(
schedule=[condition]
)

return sdk_no_wait(no_wait, client.update_auto_scale_configuration, resource_group_name, cluster_name,
autoscale_configuration)
autoscale_configuration_update_parameter = AutoscaleConfigurationUpdateParameter(
autoscale=autoscale_configuration
)
return sdk_no_wait(no_wait, client.begin_update_auto_scale_configuration, resource_group_name, cluster_name,
RoleName.WORKERNODE, autoscale_configuration_update_parameter)


def update_autoscale_condition(cmd, client, resource_group_name, cluster_name, index, days=None, time=None,
workernode_count=None, no_wait=False):
from azure.mgmt.hdinsight.models import AutoscaleConfigurationUpdateParameter, RoleName

cluster = client.get(resource_group_name, cluster_name)
autoscale_configuration = _extract_and_validate_autoscale_configuration(cluster)
_validate_schedule_configuration(autoscale_configuration)
Expand All @@ -713,11 +752,16 @@ def update_autoscale_condition(cmd, client, resource_group_name, cluster_name, i
autoscale_configuration.recurrence.schedule[index].time_and_capacity.min_instance_count = workernode_count
autoscale_configuration.recurrence.schedule[index].time_and_capacity.max_instance_count = workernode_count

return sdk_no_wait(no_wait, client.update_auto_scale_configuration, resource_group_name, cluster_name,
autoscale_configuration)
autoscale_configuration_update_parameter = AutoscaleConfigurationUpdateParameter(
autoscale=autoscale_configuration
)
return sdk_no_wait(no_wait, client.begin_update_auto_scale_configuration, resource_group_name, cluster_name,
RoleName.WORKERNODE, autoscale_configuration_update_parameter)


def delete_autoscale_condition(cmd, client, resource_group_name, cluster_name, index, no_wait=False):
from azure.mgmt.hdinsight.models import AutoscaleConfigurationUpdateParameter, RoleName

cluster = client.get(resource_group_name, cluster_name)
autoscale_configuration = _extract_and_validate_autoscale_configuration(cluster)
_validate_schedule_configuration(autoscale_configuration)
Expand All @@ -728,8 +772,11 @@ def delete_autoscale_condition(cmd, client, resource_group_name, cluster_name, i
'If you want to disable autoscale please use `az hdinsight autoscale delete`.')
autoscale_configuration.recurrence.schedule = [autoscale_configuration.recurrence.schedule[i] for i in
range(conditions_count) if i not in index]
return sdk_no_wait(no_wait, client.update_auto_scale_configuration, resource_group_name, cluster_name,
autoscale_configuration)
autoscale_configuration_update_parameter = AutoscaleConfigurationUpdateParameter(
autoscale=autoscale_configuration
)
return sdk_no_wait(no_wait, client.begin_update_auto_scale_configuration, resource_group_name, cluster_name,
RoleName.WORKERNODE, autoscale_configuration_update_parameter)


def list_autoscale_condition(cmd, client, resource_group_name, cluster_name):
Expand Down
Loading

0 comments on commit 05714f0

Please sign in to comment.