Commit 90e30695 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added 'getHSMFileSystemFreeSpace()' method.

parent 79040bad
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ from config import Config
from exceptions import ScpInvalidFileException
from exceptions import TapeClientException
from redis_log_handler import RedisLogHandler
from system_utils import SystemUtils


class TapeClient(object):
@@ -40,6 +41,7 @@ class TapeClient(object):
        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self.keyFile = keyFile
        self.scp = None
        self.systemUtils = SystemUtils()
        self.HSMFilesystemList = []

    def connect(self):
@@ -91,6 +93,23 @@ class TapeClient(object):
            else:
                raise TapeClientException(cmd, exitCode, stderr)

    def getHSMFileSystemFreeSpace(self, HSMFilesystem):
        "Returns the free space in bytes for a given HSM filesystem."
        cmd = f"{self.DSMDF} -detail {HSMFilesystem} | grep "Free Size" | awk '{ print $3 }'"
        try:
            stdin, stdout, stderr = self.client.exec_command(cmd)
        except Exception:
            self.logger.exception(f"Unable to execute command: '{cmd}'")
            raise
        else:
            exitCode = stdout.channel.recv_exit_status()
            if not exitCode:
                result = stdout.readlines()[0].rstrip('\n') + " KB"
                freeSpace = self.systemUtils.convertSizeToBytes(result)
                return freeSpace
            else:
                raise TapeClientException(cmd, exitCode, stderr)

    def migrate(self, fileList, tapeHSMFilesystem, jobId):
        """
        Migrates to tape all files whose absolute path is