Skip to content

Commit

Permalink
Merge pull request #95 from weaviate/jose/get-single-tenant
Browse files Browse the repository at this point in the history
Add an option to get tenant information for a single tenant.
  • Loading branch information
jfrancoa authored Nov 22, 2024
2 parents c746804 + 5f9d233 commit 50a9b50
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion weaviate_cli/commands/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ def get_collection_cli(ctx, collection):
default=GetTenantsDefaults.collection,
help="The name of the collection to get tenants from.",
)
@click.option(
"--tenant_id",
help="The tenant ID to get.",
)
@click.option("--verbose", is_flag=True, help="Print verbose output.")
@click.pass_context
def get_tenants_cli(ctx, collection, verbose):
def get_tenants_cli(ctx, collection, tenant_id, verbose):
"""Get tenants from a collection in Weaviate."""

client = None
Expand All @@ -62,6 +66,7 @@ def get_tenants_cli(ctx, collection, verbose):
tenant_manager = TenantManager(client)
tenant_manager.get_tenants(
collection=collection,
tenant_id=tenant_id,
verbose=verbose,
)
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions weaviate_cli/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class GetCollectionDefaults:
@dataclass
class GetTenantsDefaults:
collection: str = "Movies"
tenant_id: Optional[str] = None
verbose: bool = False


Expand Down
11 changes: 10 additions & 1 deletion weaviate_cli/managers/tenant_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,15 @@ def delete_tenants(
def get_tenants(
self,
collection: str = GetTenantsDefaults.collection,
tenant_id: str = GetTenantsDefaults.tenant_id,
verbose: bool = GetTenantsDefaults.verbose,
) -> dict:
"""
Retrieve tenants for a given collection in Weaviate.
Args:
collection (str): The name of the collection to retrieve tenants from.
tenant_id (str): The ID of the tenant to retrieve. If None, retrieves all tenants.
verbose (bool): If True, prints detailed tenant information. If False, prints summary.
Returns:
Expand All @@ -199,7 +201,14 @@ def get_tenants(
Raises:
Exception: If the collection does not exist or multi-tenancy is not enabled.
"""
tenants = self.client.collections.get(collection).tenants.get()
if tenant_id:
tenants = self.client.collections.get(collection).tenants.get_by_names(
[tenant_id]
)
if not tenants:
raise Exception(f"Tenant '{tenant_id}' not found in class {collection}")
else:
tenants = self.client.collections.get(collection).tenants.get()

if verbose:
click.echo(f"{'Tenant Name':<20}{'Activity Status':<20}")
Expand Down

0 comments on commit 50a9b50

Please sign in to comment.