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

update some apis for pymilvus v2.2.0 #19

Merged
merged 2 commits into from
Dec 15, 2022
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
11 changes: 2 additions & 9 deletions milvus_cli/scripts/milvus_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,12 @@ def listDetails(obj):
default=None,
type=float,
)
@click.option(
"--show-loaded",
"-l",
"showLoaded",
help="[Optional] - Only show loaded collections.",
default=False,
)
@click.pass_obj
def collections(obj, timeout, showLoaded):
def collections(obj, timeout):
"""List all collections."""
try:
obj.checkConnection()
click.echo(obj.listCollections(timeout, showLoaded))
click.echo(obj.listCollections(timeout))
except Exception as e:
click.echo(message=e, err=True)

Expand Down
47 changes: 23 additions & 24 deletions milvus_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def connect(self, alias=None, host=None, port=None, disconnect=False, secure=Fal
if disconnect:
connections.disconnect(alias)
return
connections.connect(self.alias, host=self.host, port=self.port,user=trimUsername,password=trimPwd,secure=secure)
try:
connections.connect(self.alias, host=self.host, port=self.port,user=trimUsername,password=trimPwd,secure=secure)
except Exception as e:
raise ConnectException(f"Connect to Milvus error!{str(e)}")

def checkConnection(self):
from pymilvus import list_collections
Expand All @@ -59,30 +62,30 @@ def checkConnection(self):
except Exception as e:
raise ConnectException(f"Connect to Milvus error!{str(e)}")

def showConnection(self, alias="default", showAll=False):
def showConnection(self, alias, showAll=False):
from pymilvus import connections

tempAlias = self.alias if self.alias else alias
tempAlias = alias if alias else self.alias
allConnections = connections.list_connections()
if showAll:
return tabulate(
allConnections, headers=["Alias", "Instance"], tablefmt="pretty"
)
aliasList = map(lambda x: x[0], allConnections)

if tempAlias in aliasList:
secure, host, port = connections.get_connection_addr(tempAlias).values()
address, user = connections.get_connection_addr(tempAlias).values()
# return """Host: {}\nPort: {}\nAlias: {}""".format(host, port, alias)
return tabulate(
[["Host", host], ["Port", port], ["Alias", tempAlias],["Secure",secure]],
[["Address", address], ["User", user], ["Alias", tempAlias]],
tablefmt="pretty",
)
else:
return "Connection not found!"

def _list_collection_names(self, timeout=None):
from pymilvus import list_collections
from pymilvus import utility

return list(list_collections(timeout, self.alias))
return list(utility.list_collections(timeout, self.alias))

def _list_partition_names(self, collectionName):
target = self.getTargetCollection(collectionName)
Expand Down Expand Up @@ -116,19 +119,15 @@ def _list_index(self, collectionName):
# details[p] = result.params['params'][p]
return details

def listCollections(self, timeout=None, showLoadedOnly=False):
def listCollections(self, timeout=None):
result = []
collectionNames = self._list_collection_names(timeout)
for name in collectionNames:
loadingProgress = self.showCollectionLoadingProgress(name)
loaded, total, alias = loadingProgress.values()
# isLoaded = (total > 0) and (loaded == total)
# shouldBeAdded = isLoaded if showLoadedOnly else True
# if shouldBeAdded:
result.append([name, "{}/{}".format(loaded, total)])
result.append([name])

return tabulate(
result,
headers=["Collection Name", "Entities(Loaded/Total)"],
headers=["Collection Name"],
tablefmt="grid",
showindex=True,
)
Expand All @@ -138,10 +137,10 @@ def flushCollectionByNumEntities(self, collectionName):
return col.num_entities

def showCollectionLoadingProgress(self, collectionName, partition_names=None):
from pymilvus import loading_progress
from pymilvus import utility

self.flushCollectionByNumEntities(collectionName)
return loading_progress(collectionName, partition_names, self.alias)
return utility.loading_progress(collectionName, partition_names, self.alias)

def showIndexBuildingProgress(self, collectionName, index_name=""):
from pymilvus import index_building_progress
Expand Down Expand Up @@ -598,18 +597,18 @@ def getCompactCollectionPlans(self, collectionName, timeout=None):
return collection.get_compaction_plans(timeout=timeout)

def listCredUsers(self):
from pymilvus import list_cred_users
users = list_cred_users(self.alias)
from pymilvus import utility
users = utility.list_usernames(self.alias)
return users

def createCredUser(self, username=None, password=None):
from pymilvus import create_credential
create_credential(username, password, self.alias)
from pymilvus import utility
utility.create_user(username, password, self.alias)
return self.listCredUsers()

def deleteCredUser(self, username=None):
from pymilvus import delete_credential
delete_credential(username, self.alias)
from pymilvus import utility
utility.delete_user(username, self.alias)
return self.listCredUsers()


Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="milvus_cli",
version="v0.3.0",
version="v0.3.1",
author="Milvus Team",
author_email="milvus-team@zilliz.com",
url="https://github.com/zilliztech/milvus_cli",
Expand All @@ -17,7 +17,7 @@
include_package_data=True,
install_requires=[
"Click==8.0.1",
"pymilvus==2.1.2",
"pymilvus==2.2.0",
"tabulate==0.8.9",
"requests==2.26.0",
],
Expand Down