# HG changeset patch # User mb # Date 1386679813 -3600 # Node ID 79ed9495fa88f4643db3067f7634d65c78c1ad72 # Parent 3f564e1673bb5a88e0c9b93cd85024c4d45e5689 singleton in VMManager. get using VMManager.getInstance() diff -r 3f564e1673bb -r 79ed9495fa88 OpenSecurity/bin/opensecurityd.py --- a/OpenSecurity/bin/opensecurityd.py Mon Dec 09 14:44:41 2013 +0100 +++ b/OpenSecurity/bin/opensecurityd.py Tue Dec 10 13:50:13 2013 +0100 @@ -66,8 +66,7 @@ # vars # Global VMManager instance -gvm_mgr = VMManager() - +gvm_mgr = VMManager.getInstance() # ------------------------------------------------------------ # code @@ -85,6 +84,7 @@ def GET(self): # self.request get address + print "os_sdvm_started" return "os_sdvm_started" class os_sdvm: diff -r 3f564e1673bb -r 79ed9495fa88 OpenSecurity/bin/vmmanager.py --- a/OpenSecurity/bin/vmmanager.py Mon Dec 09 14:44:41 2013 +0100 +++ b/OpenSecurity/bin/vmmanager.py Tue Dec 10 13:50:13 2013 +0100 @@ -42,12 +42,25 @@ cygwin_path = 'c:\\cygwin64\\bin\\' vboxManage = 'VBoxManage' + _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') self.vboxManage = os.path.join(self.getVBoxManagePath(), 'VBoxManage') self.systemProperties = self.getSystemProperties() return - + + #@classmethod + @staticmethod + def getInstance(): + if VMManager._instance == None: + VMManager._instance = VMManager() + return VMManager._instance + def execute(self, cmd): if DEBUG: print('trying to launch: ' + cmd) @@ -117,7 +130,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 +175,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) @@ -319,23 +332,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