# HG changeset patch # User mb # Date 1386683414 -3600 # Node ID fe5fb244f008a9d66587e8372ca1c4dbd1d7dc4b # Parent 1505c94059ab567e8eaab2a590db7652a5efd7ef added /sdvm_started notification edpoint and isSDVMStarted vmmanager method. changed VMManager to sinleton. retrieve with VMManager.getInstance() diff -r 1505c94059ab -r fe5fb244f008 OpenSecurity/bin/opensecurityd.py --- a/OpenSecurity/bin/opensecurityd.py Tue Dec 10 14:05:32 2013 +0100 +++ b/OpenSecurity/bin/opensecurityd.py Tue Dec 10 14:50:14 2013 +0100 @@ -53,6 +53,7 @@ """All the URLs we know mapping to class handler""" opensecurity_urls = ( '/device_change', 'os_device_change', # http://localhost:8080/device_change GET + '/sdvm_started', 'os_sdvm_started', # http://localhost:8080/sdvm_started GET '/browsing', 'os_browsing', # http://localhost:8080/browsing GET '/sdvms', 'os_sdvms', # http://localhost:8080/sdvms GET, PUT '/sdvms/(.*)/application/(.*)', 'os_sdvm_application', # http://localhost:8080/sdvms/[VMNAME]/application/[COMMAND] GET @@ -70,7 +71,7 @@ # vars # Global VMManager instance -gvm_mgr = VMManager() +gvm_mgr = VMManager.getInstance() # ------------------------------------------------------------ @@ -99,6 +100,13 @@ except: raise web.internalerror() +class os_sdvm_started: + """OpenSecurity '/sdvm_started' handler""" + + def GET(self): + remote_ip = web.ctx.environ['REMOTE_ADDR'] + gvm_mgr.putStartNotification(remote_ip) + return "os_sdvm_started" class os_sdvm: """OpenSecurity '/sdvms/[VM]' handler diff -r 1505c94059ab -r fe5fb244f008 OpenSecurity/bin/vmmanager.py --- a/OpenSecurity/bin/vmmanager.py Tue Dec 10 14:05:32 2013 +0100 +++ b/OpenSecurity/bin/vmmanager.py Tue Dec 10 14:50:14 2013 +0100 @@ -41,13 +41,32 @@ systemProperties = None cygwin_path = 'c:\\cygwin64\\bin\\' vboxManage = 'VBoxManage' + startNotifications = list() + + _instance = None + #def __new__(cls, *args, **kwargs): + # if not cls._instance: + # cls._instance = super(VMManager, cls).__new__(cls, *args, **kwargs) + # return cls._instance def __init__(self): self.cygwin_path = os.path.join(Cygwin.root(), 'bin') + os.path.sep self.vboxManage = os.path.join(self.getVBoxManagePath(), 'VBoxManage') self.systemProperties = self.getSystemProperties() return - + + @staticmethod + def getInstance(): + if VMManager._instance == None: + VMManager._instance = VMManager() + return VMManager._instance + + def putStartNotification(self, ip): + self.startNotifications.append(ip) + + def isSDVMStarted(self, ip): + return self.startNotifications.contains(ip) + def execute(self, cmd): if DEBUG: print('trying to launch: ' + cmd) @@ -117,7 +136,7 @@ re.search(r"\((?P[0-9A-Fa-f]+)\)", props['Revision']).groupdict()['rev'] ) rsds[props['UUID']] = usb_filter; if DEBUG: - print filter + print usb_filter return rsds # list all existing VMs registered with VBox @@ -162,11 +181,11 @@ #self.execute(cmd) #cmd = 'vboxmanage hostonlyif create' #self.execute(cmd) - cmd = 'vboxmanage hostonlyif ipconfig \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.1 --netmask 255.255.255.0' + cmd = 'VBoxManage hostonlyif ipconfig \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.1 --netmask 255.255.255.0' self.execute(cmd) #cmd = 'vboxmanage dhcpserver add' #self.execute(cmd) - 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' + 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' self.execute(cmd) #create new virtual machine instance based on template vm named SecurityDVM (\SecurityDVM\SecurityDVM.vmdk) @@ -320,23 +339,20 @@ return self.execute(cmd) -if __name__ == '__main__': - man = VMManager() - man.cygwin_path = 'c:\\cygwin64\\bin\\' +#if __name__ == '__main__': + #man = VMManager() + #man.cygwin_path = 'c:\\cygwin64\\bin\\' #man.handleDeviceChange() #print man.listSDVM() #man.configureHostNetworking() - new_vm = man.generateSDVMName() - man.createVM(new_vm) - man.genCertificateISO(new_vm) - man.attachCertificateISO(new_vm) + #new_vm = man.generateSDVMName() + #man.createVM(new_vm) + #man.genCertificateISO(new_vm) + #man.attachCertificateISO(new_vm) #man.attachCertificateISO(vm_name) #man.sshGuestExecute(vm_name, "ls") #man.sshGuestX11Execute(vm_name, "iceweasel") #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\"" #man.execute(cmd) - - - - + \ No newline at end of file