singleton in VMManager. get using VMManager.getInstance()
authormb
Tue, 10 Dec 2013 13:50:13 +0100
changeset 3379ed9495fa88
parent 29 3f564e1673bb
child 35 ba1ca3e5870b
singleton in VMManager. get using VMManager.getInstance()
OpenSecurity/bin/opensecurityd.py
OpenSecurity/bin/vmmanager.py
     1.1 --- a/OpenSecurity/bin/opensecurityd.py	Mon Dec 09 14:44:41 2013 +0100
     1.2 +++ b/OpenSecurity/bin/opensecurityd.py	Tue Dec 10 13:50:13 2013 +0100
     1.3 @@ -66,8 +66,7 @@
     1.4  # vars
     1.5  
     1.6  # Global VMManager instance
     1.7 -gvm_mgr = VMManager()
     1.8 -
     1.9 +gvm_mgr = VMManager.getInstance()
    1.10  
    1.11  # ------------------------------------------------------------
    1.12  # code
    1.13 @@ -85,6 +84,7 @@
    1.14      
    1.15      def GET(self):
    1.16          # self.request get address
    1.17 +        print "os_sdvm_started"
    1.18          return "os_sdvm_started"
    1.19  
    1.20  class os_sdvm:
     2.1 --- a/OpenSecurity/bin/vmmanager.py	Mon Dec 09 14:44:41 2013 +0100
     2.2 +++ b/OpenSecurity/bin/vmmanager.py	Tue Dec 10 13:50:13 2013 +0100
     2.3 @@ -42,12 +42,25 @@
     2.4      cygwin_path = 'c:\\cygwin64\\bin\\'
     2.5      vboxManage = 'VBoxManage'
     2.6      
     2.7 +    _instance = None
     2.8 +    #def __new__(cls, *args, **kwargs):
     2.9 +    #    if not cls._instance:
    2.10 +    #        cls._instance = super(VMManager, cls).__new__(cls, *args, **kwargs)
    2.11 +    #    return cls._instance
    2.12 +    
    2.13      def __init__(self):
    2.14          self.cygwin_path = os.path.join(Cygwin.root(), 'bin')
    2.15          self.vboxManage = os.path.join(self.getVBoxManagePath(), 'VBoxManage')
    2.16          self.systemProperties = self.getSystemProperties()
    2.17          return
    2.18 -         
    2.19 +    
    2.20 +    #@classmethod
    2.21 +    @staticmethod
    2.22 +    def getInstance():
    2.23 +        if VMManager._instance == None:
    2.24 +            VMManager._instance = VMManager()
    2.25 +        return VMManager._instance
    2.26 +             
    2.27      def execute(self, cmd):
    2.28          if DEBUG:
    2.29              print('trying to launch: ' + cmd)
    2.30 @@ -117,7 +130,7 @@
    2.31                                          re.search(r"\((?P<rev>[0-9A-Fa-f]+)\)", props['Revision']).groupdict()['rev'] )
    2.32                  rsds[props['UUID']] = usb_filter;
    2.33                  if DEBUG:
    2.34 -                    print filter
    2.35 +                    print usb_filter
    2.36          return rsds
    2.37  
    2.38      # list all existing VMs registered with VBox
    2.39 @@ -162,11 +175,11 @@
    2.40          #self.execute(cmd)
    2.41          #cmd = 'vboxmanage hostonlyif create'
    2.42          #self.execute(cmd)
    2.43 -        cmd = 'vboxmanage hostonlyif ipconfig \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.1 --netmask 255.255.255.0'
    2.44 +        cmd = 'VBoxManage hostonlyif ipconfig \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.1 --netmask 255.255.255.0'
    2.45          self.execute(cmd)
    2.46          #cmd = 'vboxmanage dhcpserver add'
    2.47          #self.execute(cmd)
    2.48 -        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'
    2.49 +        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'
    2.50          self.execute(cmd)
    2.51      
    2.52      #create new virtual machine instance based on template vm named SecurityDVM (\SecurityDVM\SecurityDVM.vmdk)
    2.53 @@ -319,23 +332,20 @@
    2.54          return self.execute(cmd)
    2.55          
    2.56      
    2.57 -if __name__ == '__main__':
    2.58 -    man = VMManager()
    2.59 -    man.cygwin_path = 'c:\\cygwin64\\bin\\'
    2.60 +#if __name__ == '__main__':
    2.61 +    #man = VMManager()
    2.62 +    #man.cygwin_path = 'c:\\cygwin64\\bin\\'
    2.63      #man.handleDeviceChange()
    2.64      #print man.listSDVM()
    2.65      #man.configureHostNetworking()
    2.66 -    new_vm = man.generateSDVMName()
    2.67 -    man.createVM(new_vm)
    2.68 -    man.genCertificateISO(new_vm)
    2.69 -    man.attachCertificateISO(new_vm)
    2.70 +    #new_vm = man.generateSDVMName()
    2.71 +    #man.createVM(new_vm)
    2.72 +    #man.genCertificateISO(new_vm)
    2.73 +    #man.attachCertificateISO(new_vm)
    2.74      
    2.75      #man.attachCertificateISO(vm_name)
    2.76      #man.sshGuestExecute(vm_name, "ls")
    2.77      #man.sshGuestX11Execute(vm_name, "iceweasel")
    2.78      #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""
    2.79      #man.execute(cmd)
    2.80 -    
    2.81 -    
    2.82 -
    2.83 -    
    2.84 +    
    2.85 \ No newline at end of file