Commit 769858dc authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added 'getPoolList()' method + minor changes.

parent adcd6ac3
Loading
Loading
Loading
Loading
Loading
+60 −17
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import uuid

from config import Config
from redis_log_handler import RedisLogHandler
from tape_pool import TapePool
from tape_task import TapeTask


@@ -28,6 +29,7 @@ class TapeClient(object):
        self.client.load_system_host_keys()
        self.scp = None
        self.taskList = []
        self.poolList = []
    
    def connect(self):
        """Connects to the tape library frontend."""
@@ -36,6 +38,42 @@ class TapeClient(object):
                            username = self.user,
                            pkey = self.key)
    
    def getPoolList(self):
        """Returns a list of 'TapePool' objects."""
        stdin, stdout, stderr = self.client.exec_command(f"{self.EEADM} pool list --json")
        exitCode = stdout.channel.recv_exit_status()
        if not exitCode:
            result = json.loads(stdout.readlines()[0].rstrip('\n'))
            for el in result:
                pool = TapePool()
                pool.id = el["id"]
                pool.name = el["name"]
                pool.mediaRestriction = el["media_restriction"]
                pool.capacity = el["capacity"]
                pool.usedSpace = el["used_space"]
                pool.freeSpace = el["free_space"]
                pool.reclaimableSpace = el["reclaimable_space"]
                pool.activeSpace = el["active_space"]
                pool.nonAppendableSpace = el["non_appendable_space"]
                pool.numOfTapes = el["num_of_tapes"]
                pool.formatClass = el["format_class"]
                pool.libraryName = el["library_name"]
                pool.libraryId = el["library_id"]
                pool.nodeGroupName = el["nodegroup_name"]
                pool.deviceType = el["device_type"]
                pool.worm = el["worm"]
                pool.fillPolicy = el["fill_policy"]
                pool.owner = el["owner"]
                pool.mountLimit = el["mount_limit"]
                pool.lowSpaceWarningEnable = el["low_space_warning_enable"]
                pool.lowSpaceWarningThreshold = el["low_space_warning_threshold"]
                pool.noSpaceWarningEnable = el["no_space_warning_enable"]
                pool.mode = el["mode"]
                self.poolList.append(task)
            return self.poolList.copy()
        else:
            sys.exit("cmd_exit_code = FAILURE")
    
    def getTaskList(self):
        """Returns the whole task list."""
        stdin, stdout, stderr = self.client.exec_command(f"{self.EEADM} task list --json")
@@ -45,24 +83,24 @@ class TapeClient(object):
            #print(result)
            #print(len(result["payload"]))
            #print(result["payload"][0])
            for t in result["payload"]:
            for el in result["payload"]:
                task = TapeTask()
                task.inUseTapes = t["inuse_tapes"]
                task.inUsePools = t["inuse_pools"]
                task.inUseNodeGroups = t["inuse_node_groups"]
                task.inUseDrives = t["inuse_drives"]
                task.cmdParam = t["cmd_param"]
                task.result = t["result"]
                task.status = t["status"]
                task.completedTime = t["completed_time"]
                task.startedTime = t["started_time"]
                task.createdTime = t["created_time"]
                task.setInUseLibs = t["inuse_libs"]
                task.type = t["type"]
                task.taskId = t["task_id"]
                task.id = t["id"]
                task.inUseTapes = el["inuse_tapes"]
                task.inUsePools = el["inuse_pools"]
                task.inUseNodeGroups = el["inuse_node_groups"]
                task.inUseDrives = el["inuse_drives"]
                task.cmdParam = el["cmd_param"]
                task.result = el["result"]
                task.status = el["status"]
                task.completedTime = el["completed_time"]
                task.startedTime = el["started_time"]
                task.createdTime = el["created_time"]
                task.setInUseLibs = el["inuse_libs"]
                task.type = el["type"]
                task.taskId = el["task_id"]
                task.id = el["id"]
                self.taskList.append(task)
            return self.taskList
            return self.taskList.copy()
        else:
            sys.exit("cmd_exit_code = FAILURE")
            
@@ -138,10 +176,15 @@ class TapeClient(object):
        return exitCode
    
    def disconnect(self):
        """Closes the connection."""
        """Performs a cleanup and closes the connection."""
        self.taskList.clear()
        self.poolList.clear()
        self.client.close()

    def getSize(self, fsMountPoint):
        """
        DEPRECATED
        """
        cmd = f"df {fsMountPoint} | tail -n +2"
        #out = subprocess.run(cmd, shell = True, capture_output = True)
        stdin, stdout, stderr = self.client.exec_command(cmd)