OpenSecurity/bin/vmmanager.py
changeset 34 fe5fb244f008
parent 31 d95fe93d7a83
child 35 ba1ca3e5870b
     1.1 --- a/OpenSecurity/bin/vmmanager.py	Tue Dec 10 14:04:11 2013 +0100
     1.2 +++ b/OpenSecurity/bin/vmmanager.py	Tue Dec 10 14:50:14 2013 +0100
     1.3 @@ -41,13 +41,32 @@
     1.4      systemProperties = None
     1.5      cygwin_path = 'c:\\cygwin64\\bin\\'
     1.6      vboxManage = 'VBoxManage'
     1.7 +    startNotifications = list()
     1.8 +    
     1.9 +    _instance = None
    1.10 +    #def __new__(cls, *args, **kwargs):
    1.11 +    #    if not cls._instance:
    1.12 +    #        cls._instance = super(VMManager, cls).__new__(cls, *args, **kwargs)
    1.13 +    #    return cls._instance
    1.14      
    1.15      def __init__(self):
    1.16          self.cygwin_path = os.path.join(Cygwin.root(), 'bin') + os.path.sep
    1.17          self.vboxManage = os.path.join(self.getVBoxManagePath(), 'VBoxManage')
    1.18          self.systemProperties = self.getSystemProperties()
    1.19          return
    1.20 -         
    1.21 +    
    1.22 +    @staticmethod
    1.23 +    def getInstance():
    1.24 +        if VMManager._instance == None:
    1.25 +            VMManager._instance = VMManager()
    1.26 +        return VMManager._instance
    1.27 +    
    1.28 +    def putStartNotification(self, ip):
    1.29 +        self.startNotifications.append(ip)
    1.30 +    
    1.31 +    def isSDVMStarted(self, ip):
    1.32 +        return self.startNotifications.contains(ip)
    1.33 +             
    1.34      def execute(self, cmd):
    1.35          if DEBUG:
    1.36              print('trying to launch: ' + cmd)
    1.37 @@ -117,7 +136,7 @@
    1.38                                          re.search(r"\((?P<rev>[0-9A-Fa-f]+)\)", props['Revision']).groupdict()['rev'] )
    1.39                  rsds[props['UUID']] = usb_filter;
    1.40                  if DEBUG:
    1.41 -                    print filter
    1.42 +                    print usb_filter
    1.43          return rsds
    1.44  
    1.45      # list all existing VMs registered with VBox
    1.46 @@ -162,11 +181,11 @@
    1.47          #self.execute(cmd)
    1.48          #cmd = 'vboxmanage hostonlyif create'
    1.49          #self.execute(cmd)
    1.50 -        cmd = 'vboxmanage hostonlyif ipconfig \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.1 --netmask 255.255.255.0'
    1.51 +        cmd = 'VBoxManage hostonlyif ipconfig \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.1 --netmask 255.255.255.0'
    1.52          self.execute(cmd)
    1.53          #cmd = 'vboxmanage dhcpserver add'
    1.54          #self.execute(cmd)
    1.55 -        cmd = 'vboxmanage dhcpserver modify --ifname \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.1 --netmask 255.255.255.0 --lowerip 192.168.56.100 --upperip 192.168.56.255'
    1.56 +        cmd = 'VBoxManage dhcpserver modify --ifname \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.100 --netmask 255.255.255.0 --lowerip 192.168.56.101 --upperip 192.168.56.200'
    1.57          self.execute(cmd)
    1.58      
    1.59      #create new virtual machine instance based on template vm named SecurityDVM (\SecurityDVM\SecurityDVM.vmdk)
    1.60 @@ -320,23 +339,20 @@
    1.61          return self.execute(cmd)
    1.62          
    1.63      
    1.64 -if __name__ == '__main__':
    1.65 -    man = VMManager()
    1.66 -    man.cygwin_path = 'c:\\cygwin64\\bin\\'
    1.67 +#if __name__ == '__main__':
    1.68 +    #man = VMManager()
    1.69 +    #man.cygwin_path = 'c:\\cygwin64\\bin\\'
    1.70      #man.handleDeviceChange()
    1.71      #print man.listSDVM()
    1.72      #man.configureHostNetworking()
    1.73 -    new_vm = man.generateSDVMName()
    1.74 -    man.createVM(new_vm)
    1.75 -    man.genCertificateISO(new_vm)
    1.76 -    man.attachCertificateISO(new_vm)
    1.77 +    #new_vm = man.generateSDVMName()
    1.78 +    #man.createVM(new_vm)
    1.79 +    #man.genCertificateISO(new_vm)
    1.80 +    #man.attachCertificateISO(new_vm)
    1.81      
    1.82      #man.attachCertificateISO(vm_name)
    1.83      #man.sshGuestExecute(vm_name, "ls")
    1.84      #man.sshGuestX11Execute(vm_name, "iceweasel")
    1.85      #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""
    1.86      #man.execute(cmd)
    1.87 -    
    1.88 -    
    1.89 -
    1.90 -    
    1.91 +    
    1.92 \ No newline at end of file