Skip to content

Commit 93a8fe2

Browse files
authored
Add 'metastores get-assignment' CLI for UC (#527)
1 parent ecfee34 commit 93a8fe2

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

databricks_cli/unity_catalog/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def update_metastore_assignment(self, workspace_id, metastore_id, default_catalo
5959
def delete_metastore_assignment(self, workspace_id, metastore_id):
6060
return self.client.delete_metastore_assignment(workspace_id, metastore_id)
6161

62+
def get_current_metastore_assignment(self):
63+
return self.client.get_current_metastore_assignment()
64+
6265
# External Location APIs
6366

6467
def create_external_location(self, loc_spec, skip_validation):

databricks_cli/unity_catalog/metastore_cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ def metastore_summary_cli(api_client):
132132
summary_json = UnityCatalogApi(api_client).get_metastore_summary()
133133
click.echo(mc_pretty_format(summary_json))
134134

135+
@click.command(context_settings=CONTEXT_SETTINGS,
136+
short_help='Get metastore assignment for workspace.')
137+
@debug_option
138+
@profile_option
139+
@eat_exceptions
140+
@provide_api_client
141+
def get_metastore_assignment_cli(api_client):
142+
"""
143+
Get current metastore assignment for workspace.
144+
"""
145+
assign_json = UnityCatalogApi(api_client).get_current_metastore_assignment()
146+
click.echo(mc_pretty_format(assign_json))
147+
135148

136149
@click.command(context_settings=CONTEXT_SETTINGS,
137150
short_help='Assign a metastore to a workspace.')
@@ -193,6 +206,8 @@ def register_metastore_commands(cmd_group):
193206
cmd_group.add_command(hide(metastore_summary_cli), name='metastore-summary')
194207
cmd_group.add_command(hide(assign_metastore_cli), name='assign-metastore')
195208
cmd_group.add_command(hide(unassign_metastore_cli), name='unassign-metastore')
209+
cmd_group.add_command(hide(get_metastore_assignment_cli),
210+
name='get-metastore-assignment')
196211

197212
# Register command group.
198213
metastores_group.add_command(create_metastore_cli, name='create')
@@ -203,4 +218,5 @@ def register_metastore_commands(cmd_group):
203218
metastores_group.add_command(metastore_summary_cli, name='get-summary')
204219
metastores_group.add_command(assign_metastore_cli, name='assign')
205220
metastores_group.add_command(unassign_metastore_cli, name='unassign')
221+
metastores_group.add_command(get_metastore_assignment_cli, name='get-assignment')
206222
cmd_group.add_command(metastores_group, name='metastores')

databricks_cli/unity_catalog/uc_service.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ def delete_metastore_assignment(self, workspace_id, metastore_id, headers=None):
9292
url = '/unity-catalog/workspaces/%s/metastore' % (workspace_id)
9393
return self.client.perform_query('DELETE', url, data=_data, headers=headers)
9494

95+
def get_current_metastore_assignment(self, headers=None):
96+
_data = {}
97+
return self.client.perform_query('GET', '/unity-catalog/current-metastore-assignment',
98+
data=_data, headers=headers)
99+
95100
# External Location Operations
96101

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

0 commit comments

Comments
 (0)