Commit c2b918ef authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added 'tabulate' Python package + added pretty print on 'vos_data' and...


Added 'tabulate' Python package + added pretty print on 'vos_data' and 'vos_storage' + added 'list()' method to 'vos_storage' cmd.

Signed-off-by: default avatarCristiano Urban <cristiano.urban@inaf.it>
parent 30a6abe1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -21,4 +21,4 @@ USER client
WORKDIR /home/client/

# Install python dependencies
RUN pip3.9 install --no-cache-dir pika
RUN pip3.9 install --no-cache-dir pika tabulate
+12 −5
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ import uuid
import json
import sys

from tabulate import tabulate


class AMQPClient(object):

@@ -71,14 +73,19 @@ DESCRIPTION
            sys.exit("FATAL: Malformed response, storage acknowledge expected.\n")
        elif storeResponse["responseType"] == "STORE_ACK":
            storageList = storeResponse["storageList"]
            print("Choose one of the following storage locations:\n")
            print("----------------------------------------------------------------------")
            if not storageList:
                sys.exit("No storage point found. Please add a storage point using the 'vos_storage' command.")
            print("Choose one of the following storage locations:")
            print()
            print(tabulate(storageList, headers = "keys", tablefmt = "pretty"))
            print()
            #print("----------------------------------------------------------------------")
            storageIdList = []
            for st in storageList:
                storageIdList.append(st["storage_id"])
                print("[*] storage_id: {:<2d}   =>   hostname: {}".format(st['storage_id'], st['hostname']))
                #print("[*] storage_id: {:<2d}   =>   hostname: {}".format(st['storage_id'], st['hostname']))
            storageId = None
            print("----------------------------------------------------------------------\n")
            #print("----------------------------------------------------------------------\n")
            while not storageId in storageIdList:
                try:
                    storageId = input("Please, insert a storage id: ")
@@ -122,7 +129,7 @@ DESCRIPTION
        elif storeResponse["responseType"] == "ERROR":
            errorCode = storeResponse["errorCode"]
            errorMsg = storeResponse["errorMsg"]
            sys.exit(f"Error code: {errorCode}, Error message: {errorMsg}\n")
            sys.exit(f"Error code: {errorCode}\nError message: {errorMsg}\n")
        else:
            sys.exit("\nFATAL: Unknown response type.\n")

+24 −0
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@ import json
import os
import sys

from tabulate import tabulate


class AMQPClient(object):
  
@@ -81,6 +83,23 @@ class AMQPClient(object):
        else:
            sys.exit("\nFATAL: Unknown response type.\n")

    def list(self):
        storageRequest = { "requestType": "STORAGE_LST" }
        storageResponse = self.call(storageRequest)
        
        if "responseType" not in storageResponse:
            sys.exit("FATAL: Malformed response, storage acknowledge expected.\n")
        elif storageResponse["responseType"] == "STORAGE_LST_DONE":
            print()
            print(tabulate(storageResponse["storageList"], headers = "keys", tablefmt = "pretty"))
            print()
        elif storageResponse["responseType"] == "ERROR":
            errorCode = storageResponse["errorCode"]
            errorMsg = storageResponse["errorMsg"]
            sys.exit(f"\nError code: {errorCode}\nError message: {errorMsg}\n")
        else:
            sys.exit("\nFATAL: Unknown response type.\n")
            
    def help(self):
        sys.exit("""
NAME
@@ -97,6 +116,9 @@ DESCRIPTION

       add
           adds a storage point to the database.
           
       list
           prints the storage points list.
    """)

# Create new AMQPClient object
@@ -110,5 +132,7 @@ else:

if cmd == "add":
    vosStorageCli.add()
elif cmd == "list":
    vosStorageCli.list()
else:
    vosStorageCli.help()