Skip to content

Commit

Permalink
Added Kusto (Azure#8147)
Browse files Browse the repository at this point in the history
* Added Kusto

* fixed history file

* fixed kusto readme

* Fixed tests

* fixed semantics

* removed pointless-string-statement

* Fixed comments
  • Loading branch information
oflipman authored and tjprescott committed Jan 24, 2019
1 parent 4ca8566 commit 7b4012a
Show file tree
Hide file tree
Showing 24 changed files with 6,343 additions and 1 deletion.
21 changes: 20 additions & 1 deletion azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<OutputPath>.</OutputPath>
<ProjectTypeGuids>{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
<LaunchProvider>Standard Python launcher</LaunchProvider>
<InterpreterId>MSBuild|{f0ce7f81-ab4f-4088-b037-81002e6ddc44}|$(MSBuildProjectFullPath)</InterpreterId>
<InterpreterId>MSBuild|{2151c13d-4041-4c88-bb0b-54ce1a741de6}|$(MSBuildProjectFullPath)</InterpreterId>
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
<CommandLineArguments>
</CommandLineArguments>
Expand Down Expand Up @@ -503,6 +503,16 @@
<Compile Include="command_modules\azure-cli-batch\azure\cli\command_modules\batch\_validators.py" />
<Compile Include="command_modules\azure-cli-batch\azure\cli\command_modules\batch\__init__.py" />
<Compile Include="command_modules\azure-cli-batch\setup.py" />
<Compile Include="command_modules\azure-cli-kusto\azure\cli\command_modules\kusto\commands.py" />
<Compile Include="command_modules\azure-cli-kusto\azure\cli\command_modules\kusto\custom.py" />
<Compile Include="command_modules\azure-cli-kusto\azure\cli\command_modules\kusto\tests\latest\test_kusto_commands.py" />
<Compile Include="command_modules\azure-cli-kusto\azure\cli\command_modules\kusto\_client_factory.py" />
<Compile Include="command_modules\azure-cli-kusto\azure\cli\command_modules\kusto\_help.py" />
<Compile Include="command_modules\azure-cli-kusto\azure\cli\command_modules\kusto\_params.py" />
<Compile Include="command_modules\azure-cli-kusto\azure\cli\command_modules\kusto\_validators.py" />
<Compile Include="command_modules\azure-cli-kusto\azure\cli\command_modules\kusto\__init__.py" />
<Compile Include="command_modules\azure-cli-kusto\azure_bdist_wheel.py" />
<Compile Include="command_modules\azure-cli-kusto\setup.py" />
<Compile Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\commands.py" />
<Compile Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\custom.py" />
<Compile Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\tests\latest\test_lab.py" />
Expand Down Expand Up @@ -988,6 +998,12 @@
<Folder Include="command_modules\azure-cli-batch\azure\cli\command_modules\batch\" />
<Folder Include="command_modules\azure-cli-keyvault\azure\cli\command_modules\keyvault\tests\" />
<Folder Include="command_modules\azure-cli-keyvault\azure\cli\command_modules\keyvault\tests\latest\" />
<Folder Include="command_modules\azure-cli-kusto\azure\" />
<Folder Include="command_modules\azure-cli-kusto\azure\cli\" />
<Folder Include="command_modules\azure-cli-kusto\azure\cli\command_modules\" />
<Folder Include="command_modules\azure-cli-kusto\azure\cli\command_modules\kusto\" />
<Folder Include="command_modules\azure-cli-kusto\azure\cli\command_modules\kusto\tests\" />
<Folder Include="command_modules\azure-cli-kusto\azure\cli\command_modules\kusto\tests\latest\" />
<Folder Include="command_modules\azure-cli-lab\" />
<Folder Include="command_modules\azure-cli-lab\azure\" />
<Folder Include="command_modules\azure-cli-lab\azure\cli\" />
Expand Down Expand Up @@ -1093,6 +1109,8 @@
<Folder Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\tests\" />
<Folder Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\tests\latest\" />
<Folder Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\tests\latest\keyvault\" />
<Folder Include="C:\Git\Clients\CLI\azure-cli\src\command_modules\azure-cli-kusto\" />
<Folder Include="command_modules\azure-cli-kusto\" />
</ItemGroup>
<ItemGroup>
<Content Include="azure-cli-command_modules-nspkg\HISTORY.rst" />
Expand Down Expand Up @@ -1256,6 +1274,7 @@
<Content Include="command_modules\azure-cli-keyvault\azure\cli\command_modules\keyvault\tests\latest\policy_pending.json" />
<Content Include="command_modules\azure-cli-keyvault\azure\cli\command_modules\keyvault\tests\latest\test_secret.txt" />
<Content Include="command_modules\azure-cli-keyvault\HISTORY.rst" />
<Content Include="command_modules\azure-cli-kusto\HISTORY.rst" />
<Content Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\tests\latest\docdbenv_parameters.json" />
<Content Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\tests\latest\lab_template.json" />
<Content Include="command_modules\azure-cli-lab\HISTORY.rst" />
Expand Down
1 change: 1 addition & 0 deletions doc/sphinx/azhelpgen/doc_source_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"iot": "src/command_modules/azure-cli-iot/azure/cli/command_modules/iot/_help.py",
"iotcentral": "src/command_modules/azure-cli-iotcentral/azure/cli/command_modules/iotcentral/_help.py",
"keyvault": "src/command_modules/azure-cli-keyvault/azure/cli/command_modules/keyvault/_help.py",
"kusto": "src/command_modules/azure-cli-kusto/azure/cli/command_modules/kusto/_help.py",
"lab": "src/command_modules/azure-cli-lab/azure/cli/command_modules/lab/_help.py",
"maps": "src/command_modules/azure-cli-maps/azure/cli/command_modules/maps/_help.py",
"monitor": "src/command_modules/azure-cli-monitor/azure/cli/command_modules/monitor/_help.py",
Expand Down
1 change: 1 addition & 0 deletions src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, import_prefix, client_name):

class ResourceType(Enum): # pylint: disable=too-few-public-methods

MGMT_KUSTO = ('azure.mgmt.kusto', 'KustoManagementClient')
MGMT_KEYVAULT = ('azure.mgmt.keyvault', 'KeyVaultManagementClient')
MGMT_STORAGE = ('azure.mgmt.storage', 'StorageManagementClient')
MGMT_COMPUTE = ('azure.mgmt.compute', 'ComputeManagementClient')
Expand Down
9 changes: 9 additions & 0 deletions src/command_modules/azure-cli-kusto/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. :changelog:
Release History
===============

0.1.0
+++++

* Preview release.
1 change: 1 addition & 0 deletions src/command_modules/azure-cli-kusto/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include *.rst
4 changes: 4 additions & 0 deletions src/command_modules/azure-cli-kusto/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Microsoft Azure CLI 'KUSTO' Command Module
==========================================

Provides management capabilities for Kusto (Azure Data Explorer) clusters.
7 changes: 7 additions & 0 deletions src/command_modules/azure-cli-kusto/azure/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import pkg_resources
pkg_resources.declare_namespace(__name__)
7 changes: 7 additions & 0 deletions src/command_modules/azure-cli-kusto/azure/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import pkg_resources
pkg_resources.declare_namespace(__name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import pkg_resources
pkg_resources.declare_namespace(__name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

import azure.cli.command_modules.kusto._help # pylint: disable=unused-import


class KustoCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
kusto_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.kusto.custom#{}')
super(KustoCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=kusto_custom,
min_profile='2017-03-10-profile')

def load_command_table(self, args):
from azure.cli.command_modules.kusto.commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azure.cli.command_modules.kusto._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = KustoCommandsLoader
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.profiles import ResourceType
from azure.cli.core.commands.client_factory import get_mgmt_service_client


def get_kusto_management_client(cli_ctx, **_):
from azure.mgmt.kusto import KustoManagementClient
return get_mgmt_service_client(cli_ctx, KustoManagementClient)


def cf_cluster(cli_ctx, _):
return get_kusto_management_client(cli_ctx).clusters


def cf_database(cli_ctx, _):
return get_kusto_management_client(cli_ctx).databases


def cf_resource_groups(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES,
subscription_id=subscription_id).resource_groups
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.help_files import helps

# pylint: disable=line-too-long

helps['kusto'] = """
type: group
short-summary: Manage Azure Kusto resources
"""

# Kusto cluster
helps['kusto cluster'] = """
type: group
short-summary: Manage Azure Kusto clusters.
"""

helps['kusto cluster create'] = """
type: command
short-summary: Create a Kusto cluster.
examples:
- name: Create a Kusto Cluster.
text: |-
az kusto cluster create -l "Central US" -n myclustername -g myrgname --sku D13_v2 --capacity 10
"""

helps['kusto cluster start'] = """
type: command
short-summary: Start a Kusto cluster.
long-summary: When the cluster is restarted, it takes about ten minutes for it to become available (like when it was originally provisioned). It takes additional time for data to load into the hot cache.
"""

helps['kusto cluster stop'] = """
type: command
short-summary: Stop a Kusto cluster.
long-summary: When the cluster is stopped, data is not available for queries, and you can't ingest new data. Start cluster to enable queries
"""

helps['kusto cluster update'] = """
type: command
short-summary: Update a Kusto cluster.
examples:
- name: update a Kusto Cluster.
text: |-
az kusto cluster update -n myclustername -g myrgname --sku D14_v2 --capacity 4
"""

helps['kusto cluster show'] = """
type: command
short-summary: Get a Kusto cluster.
"""

helps['kusto cluster list'] = """
type: command
short-summary: List a Kusto cluster.
"""

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

helps['kusto cluster wait'] = """
type: command
short-summary: Wait for a managed Kusto cluster to reach a desired state.
long-summary: If an operation on a cluster was interrupted or was started with `--no-wait`, use this command to
wait for it to complete.
"""


# Kusto database
helps['kusto database'] = """
type: group
short-summary: Manage Azure Kusto databases.
"""

helps['kusto database create'] = """
type: command
short-summary: Create a Kusto database.
examples:
- name: create a Kusto Database.
text: |-
az kusto database create --cluster-name myclustername -g myrgname -n mydbname --soft-delete-period 365:00:00:00 --hot-cache-period 31:00:00:00
"""


helps['kusto database update'] = """
type: command
short-summary: Update a Kusto database.
examples:
- name: create a Kusto Database.
text: |-
az kusto database update --cluster-name myclustername -g myrgname -n mydbname --soft-delete-period 3650:00:00:00 --hot-cache-period 30:00:00:00
"""

helps['kusto database delete'] = """
type: command
short-summary: Delete a Kusto database.
"""

helps['kusto database list'] = """
type: command
short-summary: List a Kusto database.
"""

helps['kusto database show'] = """
type: command
short-summary: Get a Kusto database.
"""

helps['kusto database wait'] = """
type: command
short-summary: Wait for a managed Kusto database to reach a desired state.
long-summary: If an operation on a database was interrupted or was started with `--no-wait`, use this command to
wait for it to complete.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
from knack.arguments import CLIArgumentType

from azure.cli.core.commands.parameters import (name_type)
from azure.mgmt.kusto.models import AzureSkuName
from azure.cli.core.commands.parameters import (get_enum_type)


def load_arguments(self, _):

# Kusto clusters
sku_arg_type = CLIArgumentType(help='The name of the sku.',
arg_type=get_enum_type(AzureSkuName))
time_format_explenation = 'Time format is DDDD:HH:MM:SS (for example, 10 years would be 3650:00:00:00).'

with self.argument_context('kusto cluster') as c:
c.ignore('kusto_management_request_options')
c.argument('cluster_name', arg_type=name_type, help='The name of the cluster.', id_part='name')
c.argument('sku', arg_type=sku_arg_type)
c.argument('capacity', type=int, help='The instance number of the VM.')

# Kusto databases
with self.argument_context('kusto database') as c:
c.ignore('kusto_management_request_options')
c.argument('cluster_name', help='The name of the cluster.', id_part='name')
c.argument('database_name', arg_type=name_type, help='The name of the database.', id_part='child_name_1')
c.argument('soft_delete_period', help='Amount of time that data should be kept so it is available to query. ' + time_format_explenation)
c.argument('hot_cache_period', help='Amount of time that data should be kept in cache.' + time_format_explenation)

# Kusto database list
with self.argument_context('kusto database list') as c:
c.argument('cluster_name', id_part=None)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from knack.util import CLIError


def validate_database_args(namespace):
if namespace.hot_cache_period:
hot_cache_period_in_days = round_hot_cache_to_days(namespace.hot_cache_period)
if hot_cache_period_in_days < 0:
raise CLIError('hot_cache_period must be a valid time')
if namespace.soft_delete_period:
soft_delete_period_in_days = round_soft_delete_to_days(namespace.soft_delete_period)
if soft_delete_period_in_days < 0:
raise CLIError('soft_delete_period must be a valid time')


def validate_cluster_args(namespace):
max_name_length = 22
name_length = len(namespace.cluster_name)
if name_length > max_name_length:
raise CLIError('name can not be longer then ' + str(max_name_length) + " letters")


def round_hot_cache_to_days(time):
return round_timedelta_to_days(time, 'hot_cache_period')


def round_soft_delete_to_days(time):
return round_timedelta_to_days(time, 'soft_delete_period')


def round_timedelta_to_days(time, parameter_name):
try:
splitted = time.split(":")
numberOfDays = int(splitted[0])
if int(splitted[1]) > 0:
numberOfDays += 1
return numberOfDays
except:
raise CLIError(parameter_name + ' must be a valid time format')
Loading

0 comments on commit 7b4012a

Please sign in to comment.