# HG changeset patch # User mb # Date 1386687744 -3600 # Node ID cc6abcf9108b2dd6b06a49ed5475fb34d9424660 # Parent ba1ca3e5870b14624992d9ff9c25835fe262f572 corrections in vmmanager diff -r ba1ca3e5870b -r cc6abcf9108b OpenSecurity/bin/vmmanager.py --- a/OpenSecurity/bin/vmmanager.py Tue Dec 10 14:56:11 2013 +0100 +++ b/OpenSecurity/bin/vmmanager.py Tue Dec 10 16:02:24 2013 +0100 @@ -11,6 +11,7 @@ import re import _winreg from cygwin import Cygwin +import threading DEBUG = True @@ -212,10 +213,10 @@ #remove VM from the system. should be used on VMs returned by listSDVMs def removeVM(self, vm_name): print('removing ' + vm_name) - cmd = 'VBoxManage unregistervm', vm_name, '--delete' + cmd = 'VBoxManage unregistervm ' + vm_name + ' --delete' print self.execute(cmd) machineFolder = self.getDefaultMachineFolder() - cmd = self.cygwin_path+'bash.exe --login -c \"rm -rf ' + machineFolder + '\\' + vm_name + '*\"' + cmd = self.cygwin_path + 'bash.exe --login -c \"rm -rf ' + machineFolder + '\\' + vm_name + '*\"' print self.execute(cmd) # start VM @@ -293,24 +294,30 @@ result = self.execute(cmd) return result + handleDeviceChangeLock = threading.Lock() + # handles device change events def handleDeviceChange(self): - attached_devices = self.getAttachedRSDs() - connected_devices = self.listRSDS() - for vm_name in attached_devices.keys(): - if connected_devices and attached_devices[vm_name] not in connected_devices.values(): - # self.netUse(vm_name) - self.stopVM(vm_name) - self.removeVM(vm_name) - - attached_devices = self.getAttachedRSDs() - for connected_device in connected_devices.values(): - if attached_devices or connected_device not in attached_devices.values(): - new_sdvm = self.generateSDVMName() - self.createVM(new_sdvm) - self.attachRSD(new_sdvm, connected_device) - self.startVM(new_sdvm) - self.netUse(new_sdvm) + if VMManager.handleDeviceChangeLock.acquire(True): + #destroy unused vms + attached_devices = self.getAttachedRSDs() + connected_devices = self.listRSDS() + for vm_name in attached_devices.keys(): + if attached_devices[vm_name] not in connected_devices.values(): + # self.netUnUse(vm_name) + self.stopVM(vm_name) + self.removeVM(vm_name) + #create new vm for attached device if any + attached_devices = self.getAttachedRSDs() + for connected_device in connected_devices.values(): + if (attached_devices and False) or (connected_device not in attached_devices.values()): + new_sdvm = self.generateSDVMName() + self.createVM(new_sdvm) + self.attachRSD(new_sdvm, connected_device) + self.startVM(new_sdvm) + + #self.netUse(new_sdvm) + VMManager.handleDeviceChangeLock.release() def handleBrowsingRequest(self): new_sdvm = self.generateSDVMName()