Skip to content
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

Add 'metastores get-assignment' CLI for UC #527

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? Based on the comment, these are "deprecated" commands

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I just kinda liked the get-metastore-assignment version. Can remove it, if you prefer.

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