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
DocumentDB Azure CLI support #1815
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
59c571b
Initial documentdb commandlet
8343d2b
most commands completed
4674ded
create command completed
58dbd31
Addressed PR comments
093aca9
import ResourceManagementClient before using
e47f7e8
fixed linter warnings
ed792ff
fixed help output
d191e3d
fixed additional linter errors
fdaf9d5
removed help for resource_group_location and added validation for ip …
d5e6ee8
null check ip_range_filter
9840144
added multiple arguments capability to ip range filter
aafe5c3
fixed pylint errors
d4786b7
Merge remote-tracking branch 'upstream/master'
dmakwana d3668c0
perform a get on database account after create completes
8fa859c
use documentdb pypi package instead
ea33873
cleared test
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.. :changelog: | ||
|
||
Release History | ||
=============== | ||
|
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,7 @@ | ||
Microsoft Azure CLI 'documentdb' Command Module | ||
================================== | ||
|
||
This package is for the 'documentdb' module. | ||
i.e. 'az documentdb' | ||
|
||
|
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-documentdb/azure/cli/__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__) |
7 changes: 7 additions & 0 deletions
7
src/command_modules/azure-cli-documentdb/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__) |
12 changes: 12 additions & 0 deletions
12
src/command_modules/azure-cli-documentdb/azure/cli/command_modules/documentdb/__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,12 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
import azure.cli.command_modules.documentdb._help # pylint: disable=unused-import | ||
|
||
def load_params(_): | ||
import azure.cli.command_modules.documentdb._params #pylint: disable=redefined-outer-name | ||
|
||
def load_commands(): | ||
import azure.cli.command_modules.documentdb.commands #pylint: disable=redefined-outer-name |
9 changes: 9 additions & 0 deletions
9
...mand_modules/azure-cli-documentdb/azure/cli/command_modules/documentdb/_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,9 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
def cf_documentdb(_): | ||
from azure.cli.core.commands.client_factory import get_mgmt_service_client | ||
from azure.mgmt.documentdb import DocumentDB | ||
return get_mgmt_service_client(DocumentDB) |
13 changes: 13 additions & 0 deletions
13
src/command_modules/azure-cli-documentdb/azure/cli/command_modules/documentdb/_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,13 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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.help_files import helps #pylint: disable=unused-import | ||
|
||
#pylint: disable=line-too-long | ||
|
||
helps['documentdb'] = """ | ||
type: group | ||
short-summary: Commands to manage your Azure DocumentDB (NoSQL) database accounts. | ||
""" |
52 changes: 52 additions & 0 deletions
52
src/command_modules/azure-cli-documentdb/azure/cli/command_modules/documentdb/_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,52 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 azure.cli.core.commands.parameters import ( | ||
get_resource_name_completion_list, | ||
enum_choice_list, | ||
name_type, | ||
ignore_type) | ||
from azure.cli.core.commands import register_cli_argument | ||
import azure.cli.core.commands.arm # pylint: disable=unused-import | ||
from azure.mgmt.documentdb.models.document_db_enums import KeyKind | ||
from azure.mgmt.documentdb.models.document_db_enums import DefaultConsistencyLevel | ||
from azure.mgmt.documentdb.models.failover_policy import FailoverPolicy | ||
from azure.mgmt.documentdb.models.location import Location | ||
|
||
|
||
def validate_failover_policies(ns): | ||
''' Extracts multiple space-separated failoverPolicies in regionName=failoverPriority format ''' | ||
fp_dict = [] | ||
for item in ns.failover_policies: | ||
comps = item.split('=', 1) | ||
fp_dict.append(FailoverPolicy(comps[0], int(comps[1]))) | ||
ns.failover_policies = fp_dict | ||
|
||
def validate_locations(ns): | ||
''' Extracts multiple space-separated locations in regionName=failoverPriority format ''' | ||
loc_dict = [] | ||
for item in ns.locations: | ||
comps = item.split('=', 1) | ||
loc_dict.append(Location(location_name=comps[0], failover_priority=int(comps[1]))) | ||
ns.locations = loc_dict | ||
|
||
def validate_ip_range_filter(ns): | ||
if ns.ip_range_filter: | ||
ns.ip_range_filter = ",".join(ns.ip_range_filter) | ||
|
||
register_cli_argument('documentdb', 'account_name', arg_type=name_type, help='Name of the DocumentDB Database Account', completer=get_resource_name_completion_list('Microsoft.DocumentDb/databaseAccounts'), id_part="name") | ||
|
||
register_cli_argument('documentdb regenerate-key', 'key_kind', **enum_choice_list(KeyKind)) | ||
register_cli_argument('documentdb failover-priority-change', 'failover_policies', validator=validate_failover_policies, help="space separated failover policies in 'regionName=failoverPriority' format. E.g \"East US\"=0", nargs='+') | ||
|
||
register_cli_argument('documentdb create', 'account_name', completer=None) | ||
register_cli_argument('documentdb create', 'resource_group_name', help="name of the resource group") | ||
register_cli_argument('documentdb create', 'resource_group_location', ignore_type) | ||
register_cli_argument('documentdb create', 'locations', validator=validate_locations, help="space separated locations in 'regionName=failoverPriority' format. E.g \"East US\"=0. Failover priority values are 0 for write regions and greater than 0 for read regions. A failover priority value must be unique and less than the total number of regions.", nargs='+') | ||
register_cli_argument('documentdb create', 'default_consistency_level', help="default consistency level of the DocumentDB Database account", **enum_choice_list(DefaultConsistencyLevel)) | ||
register_cli_argument('documentdb create', 'max_staleness_prefix', help="when used with Bounded Staleness consistency, this value represents the number of stale requests tolerated. Accepted range for this value is 1 - 2,147,483,647", type=int) | ||
register_cli_argument('documentdb create', 'max_interval', help="when used with Bounded Staleness consistency, this value represents the time amount of staleness (in seconds) tolerated. Accepted range for this value is 1 - 100", type=int) | ||
register_cli_argument('documentdb create', 'ip_range_filter', validator=validate_ip_range_filter, help="firewall support. Specifies the set of IP addresses or IP address ranges in CIDR form to be included as the allowed list of client IPs for a given database account. IP addresses/ranges must be comma separated and must not contain any spaces", nargs='+') |
22 changes: 22 additions & 0 deletions
22
src/command_modules/azure-cli-documentdb/azure/cli/command_modules/documentdb/commands.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,22 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 azure.cli.core.commands import cli_command | ||
from azure.cli.command_modules.documentdb._client_factory import (cf_documentdb) | ||
|
||
custom_path = 'azure.mgmt.documentdb.operations.database_accounts_operations#{}' | ||
|
||
cli_command(__name__, 'documentdb show', custom_path.format('DatabaseAccountsOperations.get'), cf_documentdb) | ||
cli_command(__name__, 'documentdb list', custom_path.format('DatabaseAccountsOperations.list_by_resource_group'), cf_documentdb) | ||
cli_command(__name__, 'documentdb list-all', custom_path.format('DatabaseAccountsOperations.list'), cf_documentdb) | ||
cli_command(__name__, 'documentdb list-keys', custom_path.format('DatabaseAccountsOperations.list_keys'), cf_documentdb) | ||
cli_command(__name__, 'documentdb list-read-only-keys', custom_path.format('DatabaseAccountsOperations.list_read_only_keys'), cf_documentdb) | ||
cli_command(__name__, 'documentdb regenerate-key', custom_path.format('DatabaseAccountsOperations.regenerate_key'), cf_documentdb) | ||
cli_command(__name__, 'documentdb check-name-exists', custom_path.format('DatabaseAccountsOperations.check_name_exists'), cf_documentdb) | ||
cli_command(__name__, 'documentdb delete', custom_path.format('DatabaseAccountsOperations.delete'), cf_documentdb) | ||
cli_command(__name__, 'documentdb failover-priority-change', custom_path.format('DatabaseAccountsOperations.failover_priority_change'), cf_documentdb) | ||
cli_command(__name__, 'documentdb create', 'azure.cli.command_modules.documentdb.custom#cli_documentdb_create', cf_documentdb) |
52 changes: 52 additions & 0 deletions
52
src/command_modules/azure-cli-documentdb/azure/cli/command_modules/documentdb/custom.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,52 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# --locations | ||
# -ipRangeFilter | ||
# -defaultConsistencyLevel | ||
# - MaxIntervalInSeconds | ||
# - MaxStalenessPrefix | ||
# - resource-group-location | ||
# -Kind | ||
|
||
from azure.mgmt.documentdb.models import ( | ||
ConsistencyPolicy, | ||
DatabaseAccountCreateUpdateParameters, | ||
) | ||
|
||
# pylint:disable=too-many-arguments | ||
def cli_documentdb_create(client, | ||
resource_group_name, | ||
account_name, | ||
locations, | ||
default_consistency_level=None, | ||
max_staleness_prefix=100, | ||
max_interval=5, | ||
ip_range_filter=None): | ||
# pylint:disable=line-too-long | ||
"""Create a new Azure DocumentDB database account. | ||
""" | ||
|
||
consistency_policy = None | ||
if default_consistency_level is not None: | ||
consistency_policy = ConsistencyPolicy(default_consistency_level, max_staleness_prefix, max_interval) | ||
|
||
|
||
from azure.mgmt.resource.resources import ResourceManagementClient | ||
from azure.cli.core.commands.client_factory import get_mgmt_service_client | ||
resource_client = get_mgmt_service_client(ResourceManagementClient) | ||
rg = resource_client.resource_groups.get(resource_group_name) | ||
resource_group_location = rg.location # pylint: disable=no-member | ||
|
||
params = DatabaseAccountCreateUpdateParameters( | ||
resource_group_location, | ||
locations, | ||
consistency_policy=consistency_policy, | ||
ip_range_filter=ip_range_filter) | ||
|
||
async_docdb_create = client.database_accounts.create_or_update(resource_group_name, account_name, params) | ||
docdb_account = async_docdb_create.result() # Will be empty, shouldn't | ||
docdb_account = client.database_accounts.get(resource_group_name, account_name) # Workaround | ||
return docdb_account |
4 changes: 4 additions & 0 deletions
4
...mmand_modules/azure-cli-documentdb/azure/cli/command_modules/documentdb/tests/__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,4 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- |
4 changes: 4 additions & 0 deletions
4
...azure-cli-documentdb/azure/cli/command_modules/documentdb/tests/test_documentdb_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,4 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- |
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,2 @@ | ||
[bdist_wheel] | ||
universal=1 |
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,58 @@ | ||
#!/usr/bin/env python | ||
|
||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
|
||
from codecs import open | ||
from setuptools import setup | ||
|
||
VERSION = '0.1.1b1+dev' | ||
|
||
# The full list of classifiers is available at | ||
# https://pypi.python.org/pypi?%3Aaction=list_classifiers | ||
CLASSIFIERS = [ | ||
'Development Status :: 4 - Beta', | ||
'Intended Audience :: Developers', | ||
'Intended Audience :: System Administrators', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'License :: OSI Approved :: MIT License', | ||
] | ||
|
||
DEPENDENCIES = [ | ||
'azure-mgmt-documentdb==0.1.0', | ||
'azure-cli-core' | ||
] | ||
|
||
with open('README.rst', 'r', encoding='utf-8') as f: | ||
README = f.read() | ||
with open('HISTORY.rst', 'r', encoding='utf-8') as f: | ||
HISTORY = f.read() | ||
|
||
setup( | ||
name='azure-cli-documentdb', | ||
version=VERSION, | ||
description='Microsoft Azure Command-Line Tools DocumentDB Command Module', | ||
long_description=README + '\n\n' + HISTORY, | ||
license='MIT', | ||
author='Microsoft Corporation', | ||
author_email='azpycli@microsoft.com', | ||
url='https://github.com/Azure/azure-cli', | ||
classifiers=CLASSIFIERS, | ||
namespace_packages=[ | ||
'azure', | ||
'azure.cli', | ||
'azure.cli.command_modules', | ||
], | ||
packages=[ | ||
'azure.cli.command_modules.documentdb', | ||
], | ||
install_requires=DEPENDENCIES, | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since these are identical in logic, you could just have "validate_failover_policies_or_locations" or something. If in the future you think they might be handled differently, then leaving them like this is fine. If they will always move together, then this becomes an added maintenance burden for your team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I believe the 'location' object could change in the future so I will leave it as is