def get_scsi_test_unit_ready(self): """:returns: True if the device is ready """ from infi.asi.cdb.tur import TestUnitReadyCommand from infi.asi.coroutines.sync_adapter import sync_wait with self.asi_context() as asi: command = TestUnitReadyCommand() return sync_wait(command.execute(asi))
def get_scsi_test_unit_ready(self): """Returns True if the device is ready, False if got NOT_READY check condition """ from infi.asi.cdb.tur import TestUnitReadyCommand from infi.asi.coroutines.sync_adapter import sync_wait from infi.asi import AsiCheckConditionError with self.asi_context() as asi: try: command = TestUnitReadyCommand() return sync_wait(command.execute(asi)) except AsiCheckConditionError, e: (key, code) = (e.sense_obj.sense_key, e.sense_obj.additional_sense_code.code_name) if key in ('NOT_READY', 'ILLEGAL_REQUEST'): return False raise
def do_test_unit_ready(sg_device): from infi.asi.cdb.tur import TestUnitReadyCommand try: cdb = TestUnitReadyCommand() return do_scsi_cdb(sg_device, cdb) except ScsiCheckConditionError as error: (key, code) = (error.sense_key, error.code_name) if key in ('NOT_READY', "ILLEGAL_REQUEST"): return False raise except AsiReservationConflictError: return True
import sys from infi.asi import create_platform_command_executer from infi.asi.cdb.tur import TestUnitReadyCommand from infi.asi.coroutines.sync_adapter import sync_wait from infi.asi import create_os_file from infi.exceptools import print_exc if len(sys.argv) != 2: sys.stderr.write("usage: %s device_name\n" % sys.argv[0]) sys.exit(1) path = sys.argv[1] f = create_os_file(path) try: executer = create_platform_command_executer(f) tur = TestUnitReadyCommand() data = sync_wait(tur.execute(executer)) print(data) f.close() except: print_exc()