added /sdvm_started notification edpoint and isSDVMStarted vmmanager method.
authormb
Tue, 10 Dec 2013 14:50:14 +0100
changeset 34fe5fb244f008
parent 32 1505c94059ab
child 35 ba1ca3e5870b
added /sdvm_started notification edpoint and isSDVMStarted vmmanager method.
changed VMManager to sinleton. retrieve with VMManager.getInstance()
OpenSecurity/bin/opensecurityd.py
OpenSecurity/bin/vmmanager.py
     1.1 --- a/OpenSecurity/bin/opensecurityd.py	Tue Dec 10 14:05:32 2013 +0100
     1.2 +++ b/OpenSecurity/bin/opensecurityd.py	Tue Dec 10 14:50:14 2013 +0100
     1.3 @@ -53,6 +53,7 @@
     1.4  """All the URLs we know mapping to class handler"""
     1.5  opensecurity_urls = (
     1.6      '/device_change',                   'os_device_change',     # http://localhost:8080/device_change                           GET
     1.7 +    '/sdvm_started',                    'os_sdvm_started',      # http://localhost:8080/sdvm_started                            GET
     1.8      '/browsing',                        'os_browsing',          # http://localhost:8080/browsing                                GET
     1.9      '/sdvms',                           'os_sdvms',             # http://localhost:8080/sdvms                                   GET, PUT
    1.10      '/sdvms/(.*)/application/(.*)',     'os_sdvm_application',  # http://localhost:8080/sdvms/[VMNAME]/application/[COMMAND]    GET
    1.11 @@ -70,7 +71,7 @@
    1.12  # vars
    1.13  
    1.14  # Global VMManager instance
    1.15 -gvm_mgr = VMManager()
    1.16 +gvm_mgr = VMManager.getInstance()
    1.17  
    1.18  
    1.19  # ------------------------------------------------------------
    1.20 @@ -99,6 +100,13 @@
    1.21          except:
    1.22              raise web.internalerror()
    1.23  
    1.24 +class os_sdvm_started:
    1.25 +    """OpenSecurity '/sdvm_started' handler"""
    1.26 +    
    1.27 +    def GET(self):
    1.28 +        remote_ip = web.ctx.environ['REMOTE_ADDR']
    1.29 +        gvm_mgr.putStartNotification(remote_ip)
    1.30 +        return "os_sdvm_started"
    1.31          
    1.32  class os_sdvm:
    1.33      """OpenSecurity '/sdvms/[VM]' handler
     2.1 --- a/OpenSecurity/bin/vmmanager.py	Tue Dec 10 14:05:32 2013 +0100
     2.2 +++ b/OpenSecurity/bin/vmmanager.py	Tue Dec 10 14:50:14 2013 +0100
     2.3 @@ -41,13 +41,32 @@
     2.4      systemProperties = None
     2.5      cygwin_path = 'c:\\cygwin64\\bin\\'
     2.6      vboxManage = 'VBoxManage'
     2.7 +    startNotifications = list()
     2.8 +    
     2.9 +    _instance = None
    2.10 +    #def __new__(cls, *args, **kwargs):
    2.11 +    #    if not cls._instance:
    2.12 +    #        cls._instance = super(VMManager, cls).__new__(cls, *args, **kwargs)
    2.13 +    #    return cls._instance
    2.14      
    2.15      def __init__(self):
    2.16          self.cygwin_path = os.path.join(Cygwin.root(), 'bin') + os.path.sep
    2.17          self.vboxManage = os.path.join(self.getVBoxManagePath(), 'VBoxManage')
    2.18          self.systemProperties = self.getSystemProperties()
    2.19          return
    2.20 -         
    2.21 +    
    2.22 +    @staticmethod
    2.23 +    def getInstance():
    2.24 +        if VMManager._instance == None:
    2.25 +            VMManager._instance = VMManager()
    2.26 +        return VMManager._instance
    2.27 +    
    2.28 +    def putStartNotification(self, ip):
    2.29 +        self.startNotifications.append(ip)
    2.30 +    
    2.31 +    def isSDVMStarted(self, ip):
    2.32 +        return self.startNotifications.contains(ip)
    2.33 +             
    2.34      def execute(self, cmd):
    2.35          if DEBUG:
    2.36              print('trying to launch: ' + cmd)
    2.37 @@ -117,7 +136,7 @@
    2.38                                          re.search(r"\((?P<rev>[0-9A-Fa-f]+)\)", props['Revision']).groupdict()['rev'] )
    2.39                  rsds[props['UUID']] = usb_filter;
    2.40                  if DEBUG:
    2.41 -                    print filter
    2.42 +                    print usb_filter
    2.43          return rsds
    2.44  
    2.45      # list all existing VMs registered with VBox
    2.46 @@ -162,11 +181,11 @@
    2.47          #self.execute(cmd)
    2.48          #cmd = 'vboxmanage hostonlyif create'
    2.49          #self.execute(cmd)
    2.50 -        cmd = 'vboxmanage hostonlyif ipconfig \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.1 --netmask 255.255.255.0'
    2.51 +        cmd = 'VBoxManage hostonlyif ipconfig \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.1 --netmask 255.255.255.0'
    2.52          self.execute(cmd)
    2.53          #cmd = 'vboxmanage dhcpserver add'
    2.54          #self.execute(cmd)
    2.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'
    2.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'
    2.57          self.execute(cmd)
    2.58      
    2.59      #create new virtual machine instance based on template vm named SecurityDVM (\SecurityDVM\SecurityDVM.vmdk)
    2.60 @@ -320,23 +339,20 @@
    2.61          return self.execute(cmd)
    2.62          
    2.63      
    2.64 -if __name__ == '__main__':
    2.65 -    man = VMManager()
    2.66 -    man.cygwin_path = 'c:\\cygwin64\\bin\\'
    2.67 +#if __name__ == '__main__':
    2.68 +    #man = VMManager()
    2.69 +    #man.cygwin_path = 'c:\\cygwin64\\bin\\'
    2.70      #man.handleDeviceChange()
    2.71      #print man.listSDVM()
    2.72      #man.configureHostNetworking()
    2.73 -    new_vm = man.generateSDVMName()
    2.74 -    man.createVM(new_vm)
    2.75 -    man.genCertificateISO(new_vm)
    2.76 -    man.attachCertificateISO(new_vm)
    2.77 +    #new_vm = man.generateSDVMName()
    2.78 +    #man.createVM(new_vm)
    2.79 +    #man.genCertificateISO(new_vm)
    2.80 +    #man.attachCertificateISO(new_vm)
    2.81      
    2.82      #man.attachCertificateISO(vm_name)
    2.83      #man.sshGuestExecute(vm_name, "ls")
    2.84      #man.sshGuestX11Execute(vm_name, "iceweasel")
    2.85      #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""
    2.86      #man.execute(cmd)
    2.87 -    
    2.88 -    
    2.89 -
    2.90 -    
    2.91 +    
    2.92 \ No newline at end of file