Skip to content

Commit

Permalink
[CosmosDB] Managed Cassandra (Azure#3035)
Browse files Browse the repository at this point in the history
* First commit.  Project nova azure cli commands.

* Second commit. With feedback and tests.

* removing unintentional changes.

* fixing linting.

* Adding more help messages. renaming to managed-cassandra.

* test cases.

* Making style command happy.

* Updating version.

* updating version in setup file.
  • Loading branch information
AverageDesigner authored Feb 25, 2021
1 parent f1d655d commit e2bb614
Show file tree
Hide file tree
Showing 48 changed files with 10,473 additions and 502 deletions.
4 changes: 4 additions & 0 deletions src/cosmosdb-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.5.0
++++++
* Create and Manage Azure Managed Cassandra Clusters and Cassandra Datacenters.

0.4.0
++++++
* Fix error propagation for failures in case of data plane RBAC and Restore related requests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ def cf_restorable_mongodb_resources(cli_ctx, _):

def cf_sql_resources(cli_ctx, _):
return cf_cosmosdb_preview(cli_ctx).sql_resources


def cf_cassandra_cluster(cli_ctx, _):
return cf_cosmosdb_preview(cli_ctx).cassandra_cluster


def cf_cassandra_data_center(cli_ctx, _):
return cf_cosmosdb_preview(cli_ctx).cassandra_data_center
117 changes: 117 additions & 0 deletions src/cosmosdb-preview/azext_cosmosdb_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,120 @@
--role-assignment-id cb8ed2d7-2371-4e3c-bd31-6cc1560e84f8 \\
--role-definition-id updated-role-definition-id
"""

helps['managed-cassandra cluster'] = """
type: group
short-summary: Azure Managed Cassandra Cluster.
"""

helps['managed-cassandra cluster create'] = """
type: command
short-summary: Create a Managed Cassandra Cluster.
examples:
- name: Create a Managed Cassandra Cluster in a given Subscription and ResourceGroup. Either a cassandra admin password or external seed needs are required.
text: |
az managed-cassandra cluster create --cluster-name MyCluster --resource-group MyResourceGroup \\
--location westus2 \\
--delegated-management-subnet-id /subscriptions/94d9b402-77b4-4049-b4c1-947bc6b7729b/resourceGroups/My-vnet/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/test-subnet \\
--initial-cassandra-admin-password password
"""

helps['managed-cassandra cluster delete'] = """
type: command
short-summary: Deletes a Managed Cassandra Cluster.
examples:
- name: Deletes a Managed Cassandra Cluster in the given Subscription and ResourceGroup.
text: |
az managed-cassandra cluster delete --cluster-name MyCluster --resource-group MyResourceGroup \\
"""

helps['managed-cassandra cluster show'] = """
type: command
short-summary: Get a Managed Cassandra Cluster Resource.
examples:
- name: Gets a Managed Cassandra Cluster Resource. ProvisioningState tells the state of this cluster. If the cluster doesnot exist a NotFound response is returned.
text: |
az managed-cassandra cluster show --cluster-name MyCluster --resource-group MyResourceGroup \\
"""

helps['managed-cassandra cluster list'] = """
type: command
short-summary: Used to list the Managed Cassandra Clusters in a ResourceGroup and Subscription. If the ResourceGroup is not specified all the clusters in this Subscription are returned.
examples:
- name: List all Managed Cassandra Clusters in a given Subscription and ResourceGroup.
text: |
az managed-cassandra cluster list --resource-group MyResourceGroup \\
- name: List all Managed Cassandra Clusters in a given Subscription.
text: |
az managed-cassandra cluster list \\
"""

helps['managed-cassandra cluster node-status'] = """
type: command
short-summary: Gets Cassandra Cluster Node Status.
examples:
- name: Cassandra Cluster contains datacenters which inturn contains nodes. This command gets the status of these nodes.
text: |
az managed-cassandra cluster node-status --cluster-name MyCluster --resource-group MyResourceGroup \\
"""

helps['managed-cassandra datacenter'] = """
type: group
short-summary: Azure Managed Cassandra DataCenter.
"""

helps['managed-cassandra datacenter create'] = """
type: command
short-summary: Create a Datacenter in an Azure Managed Cassandra Cluster.
examples:
- name: Create a Managed Cassandra Datacenter in a Cassandra Cluster. Each datacenter should atleast have 3 nodes.
text: |
az managed-cassandra datacenter create --cluster-name MyCluster --data-center-name MyDataCenter \\
--resource-group MyResourceGroup \\
--data-center-location westus2 \\
--delegated-subnet-id /subscriptions/94d9b402-77b4-4049-b4c1-947bc6b7729b/resourceGroups/My-vnet/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/test-subnet \\
--node-count 3
"""

helps['managed-cassandra datacenter update'] = """
type: command
short-summary: Update a Datacenter in an Azure Managed Cassandra Cluster.
examples:
- name: Scale the number of nodes in a datacenter. This is a scale up operation assuming that the create datacenter was done with 3 nodes. Each datacenter should atleast have 3 nodes.
text: |
az managed-cassandra datacenter update --cluster-name MyCluster --data-center-name MyDataCenter \\
--resource-group MyResourceGroup \\
--node-count 6
- name: Scale the number of nodes in a datacenter. This is a scale down operation assuming that the create datacenter was done with 3 node, followed by a scale up to 6 nodes. Each datacenter should atleast have 3 nodes.
text: |
az managed-cassandra datacenter update --cluster-name MyCluster --data-center-name MyDataCenter \\
--resource-group MyResourceGroup \\
--node-count 4
"""

helps['managed-cassandra datacenter delete'] = """
type: command
short-summary: Deletes a Managed Cassandra Datacenter.
examples:
- name: Deletes a Managed Cassandra Datacenter in the given Cluster.
text: |
az managed-cassandra datacenter delete --data-center-name MyDataCenter --cluster-name MyCluster --resource-group MyResourceGroup \\
"""

helps['managed-cassandra datacenter show'] = """
type: command
short-summary: Get a Managed Cassandra DataCenter Resource.
examples:
- name: Gets a Managed Cassandra Datacenter Resource. ProvisioningState tells the state of this datacenter. If the datacenter doesnot exist a NotFound response is returned.
text: |
az managed-cassandra datacenter show --data-center-name MyDataCenter --cluster-name MyCluster --resource-group MyResourceGroup \\
"""

helps['managed-cassandra datacenter list'] = """
type: command
short-summary: Used to list the Managed Cassandra Datacenters in a given Cluster.
examples:
- name: List all Managed Cassandra DataCenters in a given Cluster.
text: |
az managed-cassandra datacenter list --cluster-name MyCluster --resource-group MyResourceGroup \\
"""
66 changes: 66 additions & 0 deletions src/cosmosdb-preview/azext_cosmosdb_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,69 @@ def load_arguments(self, _):
c.argument('role_definition_name', options_list=['--role-definition-name', '-n'], help="Unique Name of the Role Definition that this Role Assignment refers to. Eg. 'Contoso Reader Role'.")
c.argument('scope', validator=validate_scope, options_list=['--scope', '-s'], help="Data plane resource path at which this Role Assignment is being granted.")
c.argument('principal_id', options_list=['--principal-id', '-p'], help="AAD Object ID of the principal to which this Role Assignment is being granted.")

# Managed Cassandra Cluster
for scope in [
'managed-cassandra cluster create',
'managed-cassandra cluster update',
'managed-cassandra cluster show',
'managed-cassandra cluster delete',
'managed-cassandra cluster node-status']:
with self.argument_context(scope) as c:
c.argument('cluster_name', options_list=['--cluster-name', '-c'], help="Cluster Name", required=True)

# Managed Cassandra Cluster
for scope in [
'managed-cassandra cluster create',
'managed-cassandra cluster update']:
with self.argument_context(scope) as c:
c.argument('tags', arg_type=tags_type)
c.argument('external_gossip_certificates', options_list=['--external-gossip-certificates', '-e'], help="A list of certificates that the managed cassandra data center's should accept.")
c.argument('initial_cassandra_admin_password', options_list=['--initial-cassandra-admin-password', '-i'], help="The intial password to be configured when a cluster is created for authentication_method Cassandra. If none is specified, the password will be cassandra.")
c.argument('delegated_management_subnet_id', options_list=['--delegated-management-subnet-id', '-s'], help="The resource id of a subnet where the ip address of the cassandra management server will be allocated. This subnet must have connectivity to the delegated_subnet_id subnet of each data center.")
c.argument('cassandra_version', help="The version of Cassandra chosen.")
c.argument('restore_from_backup_id', help="The resource id of a backup. If provided on create, the backup will be used to prepopulate the cluster. The cluster data center count and node counts must match the backup.")
c.argument('cluster_name_override', help="If a cluster must have a name that is not a valid azure resource name, this field can be specified to choose the Cassandra cluster name. Otherwise, the resource name will be used as the cluster name.")
c.argument('authentication_method', help="Authentication mode can be None or Cassandra. If None, no authentication will be required to connect to the Cassandra API. If Cassandra, then passwords will be used.")
c.argument('hours_between_backups', help="The number of hours between backup attempts.")
c.argument('repair_enabled', help="The number of hours between backup attempts.")
c.argument('hours_between_backups', help="Enables automatic repair.")
c.argument('client_certificates', help="If specified, enables client certificate authentiation to the Cassandra API.")
c.argument('gossip_certificates', help="A list of certificates that should be accepted by on-premise data centers.")
c.argument('external_seed_nodes', help=" A list of ip addresses of the seed nodes of on-premise data centers.")
c.argument('identity', help="Identity used to authenticate.")

# Managed Cassandra Cluster
with self.argument_context('managed-cassandra cluster create') as c:
c.argument('location', options_list=['--location', '-l'], help="Azure Location of the Cluster", required=True)
c.argument('delegated_management_subnet_id', options_list=['--delegated-management-subnet-id', '-s'], help="The resource id of a subnet where the ip address of the cassandra management server will be allocated. This subnet must have connectivity to the delegated_subnet_id subnet of each data center.", required=True)

# Managed Cassandra Datacenter
for scope in [
'managed-cassandra datacenter create',
'managed-cassandra datacenter update',
'managed-cassandra datacenter show',
'managed-cassandra datacenter delete']:
with self.argument_context(scope) as c:
c.argument('cluster_name', options_list=['--cluster-name', '-c'], help="Cluster Name", required=True)
c.argument('data_center_name', options_list=['--data-center-name', '-d'], help="Datacenter Name", required=True)

# Managed Cassandra Datacenter
for scope in [
'managed-cassandra datacenter create',
'managed-cassandra datacenter update']:
with self.argument_context(scope) as c:
c.argument('node_count', options_list=['--node-count', '-n'], help="The number of Cassandra virtual machines in this data center.")
c.argument('base64_encoded_cassandra_yaml_fragment', options_list=['--base64-encoded-cassandra-yaml-fragment', '-b'], help="This is a Base64 encoded yaml file that is a subset of cassandra.yaml. Supported fields will be honored and others will be ignored.")
c.argument('data_center_location', options_list=['--data-center-location', '-l'], help="The region where the virtual machine for this data center will be located.")
c.argument('delegated_subnet_id', options_list=['--delegated-subnet-id', '-s'], help="The resource id of a subnet where ip addresses of the Cassandra virtual machines will be allocated. This must be in the same region as data_center_location.")

# Managed Cassandra Datacenter
with self.argument_context('managed-cassandra datacenter create') as c:
c.argument('data_center_location', options_list=['--data-center-location', '-l'], help="Azure Location of the Datacenter", required=True)
c.argument('delegated_subnet_id', options_list=['--delegated-subnet-id', '-s'], help="The resource id of a subnet where ip addresses of the Cassandra virtual machines will be allocated. This must be in the same region as data_center_location.", required=True)
c.argument('node_count', options_list=['--node-count', '-n'], help="The number of Cassandra virtual machines in this data center.", required=True)

# Managed Cassandra Datacenter
with self.argument_context('managed-cassandra datacenter list') as c:
c.argument('cluster_name', options_list=['--cluster-name', '-c'], help="Cluster Name", required=True)
27 changes: 26 additions & 1 deletion src/cosmosdb-preview/azext_cosmosdb_preview/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
cf_restorable_mongodb_databases,
cf_restorable_mongodb_collections,
cf_restorable_mongodb_resources,
cf_sql_resources
cf_sql_resources,
cf_cassandra_cluster,
cf_cassandra_data_center
)


Expand Down Expand Up @@ -56,6 +58,14 @@ def load_command_table(self, _):
operations_tmpl='azext_cosmosdb_preview.vendored_sdks.azure_mgmt_cosmosdb.operations#SqlResourcesOperations.{}',
client_factory=cf_sql_resources)

cosmosdb_managed_cassandra_cluster_sdk = CliCommandType(
operations_tmpl='azext_cosmosdb_preview.vendored_sdks.azure_mgmt_cosmosdb.operations#CassandraClusterOperations.{}',
client_factory=cf_cassandra_cluster)

cosmosdb_managed_cassandra_datacenter_sdk = CliCommandType(
operations_tmpl='azext_cosmosdb_preview.vendored_sdks.azure_mgmt_cosmosdb.operations#CassandraDataCenterOperations.{}',
client_factory=cf_cassandra_data_center)

with self.command_group('cosmosdb restorable-database-account', cosmosdb_restorable_database_accounts_sdk, client_factory=cf_restorable_database_accounts, is_preview=True) as g:
g.show_command('show', 'get_by_location')
g.custom_command('list', 'cli_cosmosdb_restorable_database_account_list')
Expand Down Expand Up @@ -100,3 +110,18 @@ def load_command_table(self, _):
g.command('list', 'list_sql_role_assignments')
g.show_command('show', 'get_sql_role_assignment')
g.command('delete', 'delete_sql_role_assignment', confirmation=True)

with self.command_group('managed-cassandra cluster', cosmosdb_managed_cassandra_cluster_sdk, client_factory=cf_cassandra_cluster, is_preview=True) as g:
g.custom_command('create', 'cli_cosmosdb_managed_cassandra_cluster_create')
g.custom_command('update', 'cli_cosmosdb_managed_cassandra_cluster_update')
g.custom_command('node-status', 'cli_cosmosdb_managed_cassandra_fetch_node_status')
g.custom_command('list', 'cli_cosmosdb_managed_cassandra_cluster_list')
g.show_command('show', 'get')
g.command('delete', 'delete', confirmation=True)

with self.command_group('managed-cassandra datacenter', cosmosdb_managed_cassandra_datacenter_sdk, client_factory=cf_cassandra_data_center, is_preview=True) as g:
g.custom_command('create', 'cli_cosmosdb_managed_cassandra_datacenter_create')
g.custom_command('update', 'cli_cosmosdb_managed_cassandra_datacenter_update')
g.command('list', 'list_data_centers_method')
g.show_command('show', 'get')
g.command('delete', 'delete', confirmation=True)
Loading

0 comments on commit e2bb614

Please sign in to comment.