Skip to content
Snippets Groups Projects
Select Git revision
  • 23a0c847746f186c63542d80e2b726a8899bda9c
  • main default protected
  • Kelvinrr-patch-3
  • radius_update
  • revert-616-apollo_pan
  • vims
  • 0.10
  • Kelvinrr-patch-2
  • revert-563-minirf_fix
  • Kelvinrr-patch-1
  • 0.9
  • acpaquette-patch-3
  • acpaquette-patch-2
  • acpaquette-patch-1
  • spiceql
  • ci-coverage
  • 0.10.0
  • 0.9.1
  • 0.9.0
  • 0.8.7
  • 0.8.8
  • 0.8.6
  • 0.8.3
  • 0.8.4
  • 0.8.5
  • 0.8.2
  • 0.8.1
  • 0.8.0
  • 0.7.3
  • 0.7.2
  • 0.7.1
  • 0.7.0
  • 0.6.5
  • 0.6.4
  • 0.6.3
  • 0.6.2
36 results

test_cassini_drivers.py

Blame
  • tape_client.py 3.38 KiB
    import json
    import os
    import paramiko
    import scp
    import sys
    
    from tape_task import TapeTask
    
    
    class TapeClient(object):
    
        # Constructor
        def __init__(self, host, port, user, password):
            self.host = host
            self.port = port
            self.user = user
            self.password = password
            self.client = paramiko.SSHClient()
            self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            self.scp = None
            self.taskList = []
        
        # Connects to the tape library frontend
        def connect(self):
            self.client.connect(self.host,
                                self.port, 
                                self.user, 
                                self.password)        
        
        # Returns the whole task list
        def getTaskList(self):
            stdin, stdout, stderr = self.client.exec_command("eeadm task list --json")
            exitCode = stdout.channel.recv_exit_status()
            if not exitCode:
                result = json.loads(stdout.readlines()[0].rstrip('\n'))
                #print(result)
                #print(len(result["payload"]))
                #print(result["payload"][0])
                for t 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"]
                    self.taskList.append(task)
                return self.taskList
            else:
                sys.exit("cmd_exit_code = FAILURE")
                
        # Copies files/dirs recursively by passing their absolute paths        
        def copy(self, srcPath, destPath):
            self.scp = scp.SCPClient(self.client.get_transport())
            print(f"Copying {srcPath} in {destPath}")
            if os.path.isdir(srcPath):
                self.scp.put(srcPath, recursive = True, remote_path = destPath)
            elif os.path.isfile(srcPath):
                self.scp.put(srcPath, destPath)
            else:
                sys.exit("FATAL: invalid file/dir.")
            self.scp.close()    
        
        # Closes the connection
        def disconnect(self):
            self.client.close()
    
        def getSize(self, fsMountPoint):
            cmd = "df " + fsMountPoint + " | tail -n +2"
            #out = subprocess.run(cmd, shell = True, capture_output = True)
            stdin, stdout, stderr = self.client.exec_command(cmd)
            #res = stdout.stdout.decode('UTF-8').rstrip('\n')
            res = stdout.readlines()[0]
            res = ' '.join(res.split()).split(' ')
            #print(res)
            total = res[1]
            used = res[2]
            available = res[3]
            return ( total, used, available)
            
    
    # Test
    #tc = TapeClient("192.168.56.101", 22, "root", "ibm")
    #tc.connect()
    #tc.copy("/home/curban/store/mydir", "/home/mydir")
    #tc.copy("/home/curban/store/foo2.txt", "/home/mydir/foo2.txt")
    #tl = tc.getTaskList()
    #fsSize = tc.getSize("/ia2_tape_stb_01")
    #print(fsSize)
    #tc.disconnect()
    #for i in tl:
    #    print(i.id)
    #    print('\n')