forked from Azure/azure-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Kusto * fixed history file * fixed kusto readme * Fixed tests * fixed semantics * removed pointless-string-statement * Fixed comments
- Loading branch information
1 parent
4ca8566
commit 7b4012a
Showing
24 changed files
with
6,343 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.. :changelog: | ||
Release History | ||
=============== | ||
|
||
0.1.0 | ||
+++++ | ||
|
||
* Preview release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include *.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
7
src/command_modules/azure-cli-kusto/azure/cli/command_modules/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) |
30 changes: 30 additions & 0 deletions
30
src/command_modules/azure-cli-kusto/azure/cli/command_modules/kusto/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
25 changes: 25 additions & 0 deletions
25
src/command_modules/azure-cli-kusto/azure/cli/command_modules/kusto/_client_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
119 changes: 119 additions & 0 deletions
119
src/command_modules/azure-cli-kusto/azure/cli/command_modules/kusto/_help.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
""" |
37 changes: 37 additions & 0 deletions
37
src/command_modules/azure-cli-kusto/azure/cli/command_modules/kusto/_params.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
42 changes: 42 additions & 0 deletions
42
src/command_modules/azure-cli-kusto/azure/cli/command_modules/kusto/_validators.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Oops, something went wrong.