示例#1
0
    def onSimulationBegins(self):
        self.bs.logger.setLevel(logging.ERROR)
        self.storageController = StorageController(self.bs)

        for machine in self.bs.machines["storage"]:
            storageId = machine["id"]
            storageName = machine["name"]
            storageSize = int(machine["properties"]["size_in_byte"])
            storage = Storage(storageId, storageName, storageSize)
            self.storageController.registerStorageSpace(storage)

        self.bs.wake_me_up_at(1000)
示例#2
0
class MouseRecorder:
    def __init__(self, storage_file):
        #Setting storage file.
        self.storage = StorageController(storage_file)

    # This is a mouse mouse even lister function.
    # It will be called when mouse is moved.
    def onMouseMove(self, x, y):
        # capture the coordinate at which button was clicked
        coordinate = (x, y)
        movement = {
            "source": "Mouse",
            "action": "Move",
            "coordinate": coordinate
        }
        print(movement)
        self.storage.store(movement)

    # This method will execute when mouse is clicked
    def onMouseClick(self, x, y, button, pressed):
        # capture if the botton is left("L") or right("R")
        mouse_button = "L" if button == mouse.Button.left else "R"
        # capture if button is pressed("Y") or released ("R")
        is_pressed = "Y" if pressed else "N"
        # capture the coordinate at which button was clicked
        coordinate = (x, y)
        movement = {
            "source": "Mouse",
            "action": "Click",
            "isPressed": is_pressed,
            "button": mouse_button,
            "coordinate": coordinate
        }
        print(movement)
        # store
        self.storage.store(movement)
示例#3
0
    def addStorageController(self, type, name=None):
        """Add a storage controller to the virtual machine

        type should be the bus type of the new controller. Must be one of Constants.StorageBus_IDE, Constants.StorageBus_SATA, Constants.StorageBus_SCSI, or Constants.StorageBus_Floppy

        name should be the name of the storage controller. If None, a name will be assigned.

        Returns StorageController instance for new controller.
        """
        if name is None:
            name = self._getNewStorageControllerName(type)
        with self.lock() as session:
            with VirtualBoxException.ExceptionHandler():
                mutableMachine = session.getMachine()
                controller = mutableMachine.getIMachine().addStorageController(name, type)
            session.saveSettings()
        return StorageController(controller)
示例#4
0
 def getStorageControllerByInstance(self, instance):
     """Return the StorageController with the given instance number"""
     with VirtualBoxException.ExceptionHandler():
         controller = self.getIMachine().getStorageControllerByInstance(instance)
     return StorageController(controller)
示例#5
0
 def getStorageControllerByName(self, name):
     """Return the StorageController with the given name"""
     with VirtualBoxException.ExceptionHandler():
         controller = self.getIMachine().getStorageControllerByName(name)
     return StorageController(controller)
示例#6
0
 def getStorageControllers(self):
     """Return array of StorageControllers attached to this VM"""
     return [StorageController(c) for c in self._getStorageControllers()]
示例#7
0
 def __init__(self, storage_file):
     #Setting storage file.
     self.storage = StorageController(storage_file)
示例#8
0
class StorageScheduler(BatsimScheduler):

    def myprint(self,msg):
        print("[{time}] {msg}".format(time=self.bs.time(), msg=msg))

    def __init__(self, options):
        self.options = options

    def onSimulationBegins(self):
        self.bs.logger.setLevel(logging.ERROR)
        self.storageController = StorageController(self.bs)

        for machine in self.bs.machines["storage"]:
            storageId = machine["id"]
            storageName = machine["name"]
            storageSize = int(machine["properties"]["size_in_byte"])
            storage = Storage(storageId, storageName, storageSize)
            self.storageController.registerStorageSpace(storage)

        self.bs.wake_me_up_at(1000)

    def onSimulationEnds(self):
        # Exporting the load from machines into a csv
        with open('imt_storages_load.json', 'w') as fp:
            json.dump(self.storageController.exportLoadLog(), fp)

        return super()

    def onJobSubmission(self, job):
        pass

    def onJobCompletion(self, job):
        self.storageController.logLoad(job.id, self.bs.time())

    def onNoMoreEvents(self):
        pass

    def onRequestedCall(self):
        # List of storage we will work with
        mainStorage = self.storageController.getStorageSpace(14)
        qBox1Storage = self.storageController.getStorageSpace(13)
        qBox2Storage = self.storageController.getStorageSpace(12)

        # Creating and storing a dataset as initialization
        dataset1 = Dataset(1, ONE_GIGA_BYTE)
        dataset2 = Dataset(2, ONE_GIGA_BYTE*10)
        dataset3 = Dataset(3, ONE_GIGA_BYTE*30)
        dataset4 = Dataset(4, ONE_GIGA_BYTE*30)
        dataset5 = Dataset(5, ONE_GIGA_BYTE*30)
        dataset6 = Dataset(6, ONE_GIGA_BYTE*30)
        dataset7 = Dataset(7, ONE_GIGA_BYTE*30)
        dataset8 = Dataset(8, ONE_GIGA_BYTE*30)
        mainStorage.storeDataset(dataset1)
        mainStorage.storeDataset(dataset2)
        mainStorage.storeDataset(dataset3)
        mainStorage.storeDataset(dataset4)
        mainStorage.storeDataset(dataset5)
        mainStorage.storeDataset(dataset6)
        mainStorage.storeDataset(dataset7)
        mainStorage.storeDataset(dataset8)

        # Moving the dataset and notify on finish
        self.storageController.doDataTransfer(dataset1, mainStorage, [qBox1Storage])

        self.storageController.doDataTransfer(dataset2, mainStorage, [qBox2Storage])

        self.storageController.doDataTransfer(dataset3, mainStorage, [qBox2Storage])

        self.storageController.doDataTransfer(dataset4, mainStorage, [qBox2Storage])

        self.storageController.doDataTransfer(dataset5, mainStorage, [qBox2Storage])

        self.storageController.doDataTransfer(dataset6, mainStorage, [qBox2Storage])

        self.storageController.doDataTransfer(dataset7, mainStorage, [qBox2Storage])

        self.storageController.doDataTransfer(dataset6, mainStorage, [qBox1Storage])

        self.storageController.doDataTransfer(dataset7, mainStorage, [qBox1Storage])

        self.bs.notify_submission_finished()