1.1 --- a/OpenSecurity/bin/vmmanager.pyw Thu May 22 12:17:57 2014 +0200
1.2 +++ b/OpenSecurity/bin/vmmanager.pyw Thu May 22 16:01:28 2014 +0100
1.3 @@ -78,10 +78,7 @@
1.4 # only proceed if we have a working background environment
1.5 if self.backend_ok():
1.6 self.cleanup()
1.7 - self.browsingManager = BrowsingManager(self)
1.8 - self.browsingManager.start()
1.9 - self.rsdHandler = DeviceHandler(self)
1.10 - self.rsdHandler.start()
1.11 + self.start()
1.12 else:
1.13 logger.critical(self.status_message)
1.14
1.15 @@ -122,18 +119,34 @@
1.16 self.status_message = 'All is ok.'
1.17
1.18 return True
1.19 -
1.20 -
1.21 - def cleanup(self):
1.22 +
1.23 + def stop(self):
1.24 if self.rsdHandler != None:
1.25 self.rsdHandler.stop()
1.26 self.rsdHandler.join()
1.27 + self.rsdHandler = None
1.28 +
1.29 + if self.browsingManager != None:
1.30 + self.browsingManager.stop()
1.31 + self.browsingManager.join()
1.32 + self.browsingManager = None
1.33 +
1.34 + def start(self):
1.35 + self.stop()
1.36 + self.browsingManager = BrowsingManager(self)
1.37 + self.browsingManager.start()
1.38 + self.rsdHandler = DeviceHandler(self)
1.39 + self.rsdHandler.start()
1.40 +
1.41 +
1.42 + def cleanup(self):
1.43 + self.stop()
1.44 drives = self.getNetworkDrives()
1.45 for drive in drives.keys():
1.46 try:
1.47 result = urllib2.urlopen('http://127.0.0.1:8090/netumount?'+'drive_letter='+drive).readline()
1.48 except urllib2.URLError:
1.49 - logger.error("Network drive disconnect failed. OpenSecurity Tray client not running.")
1.50 + logger.info("Network drive disconnect skipped. OpenSecurity Tray client not started yet.")
1.51
1.52 for vm in self.listSDVM():
1.53 self.poweroffVM(vm)
1.54 @@ -291,18 +304,7 @@
1.55 def changeStorageType(self, filename, storage_type):
1.56 Cygwin.checkResult(Cygwin.vboxExecute('modifyhd \"' + filename + '\" --type ' + storage_type))
1.57
1.58 - # list storage snaphots for VM
1.59 - def updateTemplate(self):
1.60 -
1.61 - self.cleanup()
1.62 - self.poweroffVM('SecurityDVM')
1.63 - self.waitShutdown('SecurityDVM')
1.64 -
1.65 - # check for updates
1.66 - self.genCertificateISO('SecurityDVM')
1.67 - self.attachCertificateISO('SecurityDVM')
1.68 -
1.69 - self.storageDetach('SecurityDVM')
1.70 + def removeSnapshots(self, vm_name):
1.71 results = Cygwin.checkResult(Cygwin.vboxExecute('list hdds'))[1]
1.72 results = results.replace('Parent UUID', 'Parent')
1.73 items = list( "UUID:"+result for result in results.split('UUID:') if result != '')
1.74 @@ -316,8 +318,7 @@
1.75 props[k] = v;
1.76 snaps[props['UUID']] = props
1.77
1.78 -
1.79 - template_storage = self.machineFolder + '\SecurityDVM\SecurityDVM.vmdk'
1.80 + template_storage = self.machineFolder + '\\' + vm_name + '\\' + vm_name + '.vmdk'
1.81
1.82 # find template uuid
1.83 template_uuid = ''
1.84 @@ -333,7 +334,23 @@
1.85 logger.debug('removing snapshot ' + hdd['UUID'])
1.86 Cygwin.checkResult(Cygwin.vboxExecute('closemedium disk {' + hdd['UUID'] + '} --delete'))#[1]
1.87 # parse result 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
1.88 +
1.89 + # list storage snaphots for VM
1.90 + def updateTemplate(self):
1.91 + self.stop()
1.92 + self.cleanup()
1.93 + self.poweroffVM('SecurityDVM')
1.94 + self.waitShutdown('SecurityDVM')
1.95
1.96 + # check for updates
1.97 + self.genCertificateISO('SecurityDVM')
1.98 + self.attachCertificateISO('SecurityDVM')
1.99 +
1.100 + self.storageDetach('SecurityDVM')
1.101 + self.removeSnapshots('SecurityDVM')
1.102 +
1.103 + template_storage = self.machineFolder + '\\' + 'SecurityDVM' + '\\' + 'SecurityDVM' + '.vmdk'
1.104 + #TODO:// modify to take vm name as argument
1.105 self.changeStorageType(template_storage,'normal')
1.106 self.storageAttach('SecurityDVM')
1.107 self.startVM('SecurityDVM')
1.108 @@ -346,13 +363,18 @@
1.109 self.storageDetach('SecurityDVM')
1.110 self.changeStorageType(template_storage,'immutable')
1.111 self.storageAttach('SecurityDVM')
1.112 - self.rsdHandler = DeviceHandler(self)
1.113 - self.rsdHandler.start()
1.114 +
1.115 + self.start()
1.116
1.117 #remove VM from the system. should be used on VMs returned by listSDVMs
1.118 def removeVM(self, vm_name):
1.119 logger.info('Removing ' + vm_name)
1.120 Cygwin.checkResult(Cygwin.vboxExecute('unregistervm ' + vm_name + ' --delete'))
1.121 + #TODO:// try to close medium if still existing
1.122 + #Cygwin.checkResult(Cygwin.vboxExecute('closemedium disk {' + hdd['UUID'] + '} --delete'))#[1]
1.123 + self.removeVMFolder(vm_name)
1.124 +
1.125 + def removeVMFolder(self, vm_name):
1.126 machineFolder = Cygwin.cygPath(self.machineFolder)
1.127 Cygwin.checkResult(Cygwin.bashExecute('/usr/bin/rm -rf \\\"' + machineFolder + '/' + vm_name + '\\\"'))
1.128
1.129 @@ -629,7 +651,10 @@
1.130 self.vmm = vmmanager
1.131 self.restart = threading.Event()
1.132 self.started = threading.Event()
1.133 -
1.134 +
1.135 + def stop(self):
1.136 + self.running = False
1.137 + self.restart.set()
1.138
1.139 def run(self):
1.140 while self.running: