#94 Rich client messages
diff --git a/python-cli/mft_cli/airavata_mft_cli/base.py b/python-cli/mft_cli/airavata_mft_cli/base.py
index 4e9a6a8..92d28bd 100644
--- a/python-cli/mft_cli/airavata_mft_cli/base.py
+++ b/python-cli/mft_cli/airavata_mft_cli/base.py
@@ -19,16 +19,26 @@
import typer
import airavata_mft_cli.operations as operations
import airavata_mft_cli.bootstrap as bootstrap
+import grpc
+from rich import print
app = typer.Typer()
@app.command("ls")
def list(storage_path):
- operations.list(storage_path)
+ try:
+ operations.list(storage_path)
+ except grpc.RpcError as rpc_error:
+ if rpc_error.code() == grpc.StatusCode.UNAVAILABLE:
+ print(f'Could not list resources for your storage path {storage_path} due to MFT server unavailable')
@app.command("cp")
def copy(source, destination):
- operations.copy(source, destination)
+ try:
+ operations.copy(source, destination)
+ except grpc.RpcError as rpc_error:
+ if rpc_error.code() == grpc.StatusCode.UNAVAILABLE:
+ print(f'Could not copy resources from source = {source} to destination = {destination} due to MFT server unavailable')
@app.command("init")
def init_mft():
diff --git a/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py b/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py
index d4f00e8..cb6b8b6 100644
--- a/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py
+++ b/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py
@@ -28,7 +28,9 @@
from airavata_mft_sdk.common import StorageCommon_pb2
from rich.console import Console
from rich.table import Table
+from rich import print
import sys
+import grpc
sys.path.append('../airavata_mft_cli')
from airavata_mft_cli import config as configcli
@@ -36,46 +38,53 @@
@app.command("add")
def add_storage():
- title = "Select storage type: "
- options = ["S3", "Google Cloud Storage (GCS)", "Azure Storage", "Openstack SWIFT", "SCP", "FTP", "Box", "DropBox", "OData", "Agent" ]
- option, index = pick(options, title, indicator="=>")
- if option == "S3":
- s3.handle_add_storage()
- elif option == "Azure Storage":
- azure.handle_add_storage()
- elif option == "Google Cloud Storage (GCS)":
- gcs.handle_add_storage()
- elif option == "Agent":
- local.handle_add_storage()
- elif option == "Openstack SWIFT":
- swift.handle_add_storage()
- elif option == "SCP":
- scp.handle_add_storage()
-
+ try:
+ title = "Select storage type: "
+ options = ["S3", "Google Cloud Storage (GCS)", "Azure Storage", "Openstack SWIFT", "SCP", "FTP", "Box", "DropBox", "OData", "Agent" ]
+ option, index = pick(options, title, indicator="=>")
+ if option == "S3":
+ s3.handle_add_storage()
+ elif option == "Azure Storage":
+ azure.handle_add_storage()
+ elif option == "Google Cloud Storage (GCS)":
+ gcs.handle_add_storage()
+ elif option == "Agent":
+ local.handle_add_storage()
+ elif option == "Openstack SWIFT":
+ swift.handle_add_storage()
+ elif option == "SCP":
+ scp.handle_add_storage()
+ except grpc.RpcError as rpc_error:
+ if rpc_error.code() == grpc.StatusCode.UNAVAILABLE:
+ print(f'Could not add storage in {option} due to MFT server grpc unavailable error')
@app.command("list")
def list_storage():
- client = mft_client.MFTClient(transfer_api_port = configcli.transfer_api_port,
- transfer_api_secured = configcli.transfer_api_secured,
- resource_service_host = configcli.resource_service_host,
- resource_service_port = configcli.resource_service_port,
- resource_service_secured = configcli.resource_service_secured,
- secret_service_host = configcli.secret_service_host,
- secret_service_port = configcli.secret_service_port)
- list_req = StorageCommon_pb2.StorageListRequest()
- list_response = client.common_api.listStorages(list_req)
+ try:
+ client = mft_client.MFTClient(transfer_api_port = configcli.transfer_api_port,
+ transfer_api_secured = configcli.transfer_api_secured,
+ resource_service_host = configcli.resource_service_host,
+ resource_service_port = configcli.resource_service_port,
+ resource_service_secured = configcli.resource_service_secured,
+ secret_service_host = configcli.secret_service_host,
+ secret_service_port = configcli.secret_service_port)
+ list_req = StorageCommon_pb2.StorageListRequest()
+ list_response = client.common_api.listStorages(list_req)
- console = Console()
- table = Table(show_header=True, header_style='bold #2070b2')
+ console = Console()
+ table = Table(show_header=True, header_style='bold #2070b2')
- table.add_column('Storage Name', justify='left')
- table.add_column('Type', justify='center')
- table.add_column('Storage ID', justify='center')
+ table.add_column('Storage Name', justify='left')
+ table.add_column('Type', justify='center')
+ table.add_column('Storage ID', justify='center')
- for storage in list_response.storageList:
+ for storage in list_response.storageList:
- table.add_row('[bold]' + storage.storageName + '[/bold]',
- StorageCommon_pb2.StorageType.Name(storage.storageType),
- storage.storageId)
+ table.add_row('[bold]' + storage.storageName + '[/bold]',
+ StorageCommon_pb2.StorageType.Name(storage.storageType),
+ storage.storageId)
- console.print(table)
\ No newline at end of file
+ console.print(table)
+ except grpc.RpcError as rpc_error:
+ if rpc_error.code() == grpc.StatusCode.UNAVAILABLE:
+ print('Could not fetch storage list due to MFT server grpc unavailable error')