corrected concurent VM creation problem
authorBarthaM@N3SIM1218.D03.arc.local
Mon, 19 May 2014 15:39:55 +0100
changeset 15930947d377e7c
parent 158 316f9a5be7e5
child 161 588a83322e4e
corrected concurent VM creation problem
OpenSecurity/bin/vmmanager.pyw
     1.1 --- a/OpenSecurity/bin/vmmanager.pyw	Mon May 19 16:08:30 2014 +0200
     1.2 +++ b/OpenSecurity/bin/vmmanager.pyw	Mon May 19 15:39:55 2014 +0100
     1.3 @@ -28,6 +28,9 @@
     1.4  import urllib2
     1.5  DEBUG = True
     1.6  
     1.7 +
     1.8 +new_sdvm_lock = threading.Lock()
     1.9 +
    1.10  class VMManagerException(Exception):
    1.11      def __init__(self, value):
    1.12          self.value = value
    1.13 @@ -75,10 +78,10 @@
    1.14          # only proceed if we have a working background environment
    1.15          if self.backend_ok():
    1.16              self.cleanup()
    1.17 +            self.browsingManager = BrowsingManager(self)
    1.18 +            self.browsingManager.start()
    1.19              self.rsdHandler = DeviceHandler(self)
    1.20              self.rsdHandler.start()
    1.21 -            self.browsingManager = BrowsingManager(self)
    1.22 -            self.browsingManager.start()
    1.23          else:
    1.24              logger.critical(self.status_message)
    1.25      
    1.26 @@ -167,7 +170,7 @@
    1.27          return svdms
    1.28      
    1.29      # generate valid (not already existing SDVM name). necessary for creating a new VM
    1.30 -    def generateSDVMName(self):
    1.31 +    def genSDVMName(self):
    1.32          vms = self.listVM()
    1.33          for i in range(0,999):
    1.34              if(not self.vmRootName+str(i) in vms):
    1.35 @@ -254,7 +257,13 @@
    1.36          Cygwin.checkResult(Cygwin.vboxExecute('createvm --name ' + vm_name + ' --ostype Debian --register'))
    1.37          Cygwin.checkResult(Cygwin.vboxExecute('modifyvm ' + vm_name + ' --memory 512 --vram 10 --cpus 1 --usb on --usbehci on --nic1 hostonly --hostonlyadapter1 \"' + hostonly_if['Name'] + '\" --nic2 nat'))
    1.38          Cygwin.checkResult(Cygwin.vboxExecute('storagectl ' + vm_name + ' --name SATA --add sata --portcount 2'))
    1.39 -        return
    1.40 +
    1.41 +    #create new SecurityDVM with automatically generated name from template (thread safe)        
    1.42 +    def newSDVM(self):
    1.43 +        with new_sdvm_lock:
    1.44 +            vm_name = self.genSDVMName()
    1.45 +            self.createVM(vm_name)
    1.46 +        return vm_name
    1.47      
    1.48      # attach storage image to controller
    1.49      def storageAttach(self, vm_name):
    1.50 @@ -615,8 +624,7 @@
    1.51                  self.vmm.removeVM(self.vm_name)
    1.52              
    1.53              try:
    1.54 -                self.vm_name = self.vmm.generateSDVMName()
    1.55 -                self.vmm.createVM(self.vm_name)
    1.56 +                self.vm_name = self.vmm.newSDVM()
    1.57                  self.vmm.storageAttach(self.vm_name)
    1.58                  self.vmm.genCertificateISO(self.vm_name)
    1.59                  self.vmm.attachCertificateISO(self.vm_name)
    1.60 @@ -695,8 +703,7 @@
    1.61              new_ip = None
    1.62              for connected_device in self.connectedRSDs.values():
    1.63                  if (self.attachedRSDs and False) or (connected_device not in self.attachedRSDs.values()):
    1.64 -                    new_sdvm = self.vmm.generateSDVMName()
    1.65 -                    self.vmm.createVM(new_sdvm)
    1.66 +                    new_sdvm = self.vmm.newSDVM()
    1.67                      self.vmm.storageAttach(new_sdvm)
    1.68                      self.vmm.attachRSD(new_sdvm, connected_device)
    1.69                      self.vmm.startVM(new_sdvm)