Skip to content

Commit

Permalink
Add 'metastores get-assignment' CLI for UC (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcain-db authored Aug 11, 2022
1 parent ecfee34 commit 93a8fe2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions databricks_cli/unity_catalog/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def update_metastore_assignment(self, workspace_id, metastore_id, default_catalo
def delete_metastore_assignment(self, workspace_id, metastore_id):
return self.client.delete_metastore_assignment(workspace_id, metastore_id)

def get_current_metastore_assignment(self):
return self.client.get_current_metastore_assignment()

# External Location APIs

def create_external_location(self, loc_spec, skip_validation):
Expand Down
16 changes: 16 additions & 0 deletions databricks_cli/unity_catalog/metastore_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ def metastore_summary_cli(api_client):
summary_json = UnityCatalogApi(api_client).get_metastore_summary()
click.echo(mc_pretty_format(summary_json))

@click.command(context_settings=CONTEXT_SETTINGS,
short_help='Get metastore assignment for workspace.')
@debug_option
@profile_option
@eat_exceptions
@provide_api_client
def get_metastore_assignment_cli(api_client):
"""
Get current metastore assignment for workspace.
"""
assign_json = UnityCatalogApi(api_client).get_current_metastore_assignment()
click.echo(mc_pretty_format(assign_json))


@click.command(context_settings=CONTEXT_SETTINGS,
short_help='Assign a metastore to a workspace.')
Expand Down Expand Up @@ -193,6 +206,8 @@ def register_metastore_commands(cmd_group):
cmd_group.add_command(hide(metastore_summary_cli), name='metastore-summary')
cmd_group.add_command(hide(assign_metastore_cli), name='assign-metastore')
cmd_group.add_command(hide(unassign_metastore_cli), name='unassign-metastore')
cmd_group.add_command(hide(get_metastore_assignment_cli),
name='get-metastore-assignment')

# Register command group.
metastores_group.add_command(create_metastore_cli, name='create')
Expand All @@ -203,4 +218,5 @@ def register_metastore_commands(cmd_group):
metastores_group.add_command(metastore_summary_cli, name='get-summary')
metastores_group.add_command(assign_metastore_cli, name='assign')
metastores_group.add_command(unassign_metastore_cli, name='unassign')
metastores_group.add_command(get_metastore_assignment_cli, name='get-assignment')
cmd_group.add_command(metastores_group, name='metastores')
5 changes: 5 additions & 0 deletions databricks_cli/unity_catalog/uc_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def delete_metastore_assignment(self, workspace_id, metastore_id, headers=None):
url = '/unity-catalog/workspaces/%s/metastore' % (workspace_id)
return self.client.perform_query('DELETE', url, data=_data, headers=headers)

def get_current_metastore_assignment(self, headers=None):
_data = {}
return self.client.perform_query('GET', '/unity-catalog/current-metastore-assignment',
data=_data, headers=headers)

# External Location Operations

def create_external_location(self, loc_spec, skip_validation, headers=None):
Expand Down

0 comments on commit 93a8fe2

Please sign in to comment.