def SetupVirtualMachine(self): subutai.AddStatus("Setting up virtual machine") subutai.SetAction("INSTVM") rc = 0 subutai.AddStatus("Installing VM") if subutai.CheckVMExists(self.name) != 0: subutai.download("core.ova") while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setCoreProgress(subutai.GetBytesDownload()) self.progress.updateProgress() subutai.AddStatus("VM Image downloaded") self.progress.setCoreProgress(self.progress.getCoreSize()) self.progress.updateProgress() rc = subutai.VBoxS("import " + subutai.GetTmpDir().replace(" ", "+++") + "core.ova --vsys 0 --vmname " + self.name) if rc != 0: subutai.RaiseError("Failed to import Virtual Machine") return rc sleep(3) cpus = subutai.GetCoreNum() mem = subutai.GetMemSize() * 1024 subutai.VBox("modifyvm " + self.name + " --cpus " + str(cpus)) subutai.VBox("modifyvm " + self.name + " --memory " + str(mem)) return rc
def StartVirtualMachine(self): subutai.SetAction("STARTVM") rc = 0 if subutai.CheckVMRunning(self.name) != 0: rc = subutai.VBoxS("startvm --type headless " + self.name) if rc != 0: subutai.RaiseError("Failed to start Virtual Machine") return rc
def StopVirtualMachine(self): subutai.SetAction("STOPVM") subutai.SSHRun("sync && poweroff") subutai.log("info", "Stopping Virtual machine") sleep(15) rc = 0 if subutai.CheckVMRunning(self.name) == 0: sleep(15) if subutai.CheckVMRunning(self.name) == 0: rc = subutai.VBoxS("controlvm " + self.name + " poweroff soft") return rc
def setupVm(machineName): if subutai.CheckVMExists(machineName) != 0: subutai.download("core.ova") while subutai.isDownloadComplete() != 1: sleep(0.05) subutai.download("subutai_4.0.15_amd64-dev.snap") while subutai.isDownloadComplete() != 1: sleep(0.05) subutai.VBox("import /tmp/subutai/core.ova") subutai.VBox("modifyvm core --cpus 2") subutai.VBox("modifyvm core --nic1 nat") subutai.VBox("modifyvm core --cableconnected1 on") subutai.VBox( "modifyvm core --natpf1 ssh-fwd,tcp,,4567,,22 --natpf1 https-fwd,tcp,,9999,,8443" ) subutai.VBox("modifyvm core --rtcuseutc on") ret = subutai.VBoxS("modifyvm core --name " + machineName) if ret != 0: print(machineName + " is already exists") return
def setupVm(machineName, progress): subutai.log("info", "Setting up a VM") subutai.AddStatus("Installing VM") rc = 0 if subutai.CheckVMExists(machineName) != 0: subutai.download("core.ova") while subutai.isDownloadComplete() != 1: sleep(0.05) progress.setCoreProgress(subutai.GetBytesDownload()) progress.updateProgress() progress.setCoreProgress(progress.getCoreSize()) progress.updateProgress() rc = subutai.VBoxS("import " + subutai.GetTmpDir().replace(" ", "+++") + "core.ova --vsys 0 --vmname "+machineName) if rc != 0: return rc sleep(3) cpus = subutai.GetCoreNum() mem = subutai.GetMemSize() * 1024 subutai.VBox("modifyvm " + machineName + " --cpus " + str(cpus)) subutai.VBox("modifyvm " + machineName + " --memory " + str(mem)) subutai.VBox("modifyvm " + machineName + " --nic1 nat") subutai.VBox("modifyvm " + machineName + " --cableconnected1 on") subutai.VBox("modifyvm " + machineName + " --natpf1 ssh-fwd,tcp,,4567,,22 --natpf1 https-fwd,tcp,,9999,,8443") subutai.VBox("modifyvm " + machineName + " --rtcuseutc on") adapterName = subutai.GetVBoxHostOnlyInterface() if adapterName != 'undefined': subutai.VBox("modifyvm " + machineName + " --nic3 hostonly --hostonlyadapter3 " + adapterName) sleep(1) return rc
def reconfigureNic(machineName): print("Reconfiguring NIC on: " + machineName) subutai.VBox("controlvm " + machineName + " poweroff soft") gateway = subutai.GetDefaultRoutingInterface() print("Default gateway interface: '" + gateway + "'") bridged = subutai.GetVBoxBridgedInterface(gateway) print("Bridged interface: '" + bridged + "'") subutai.VBox("modifyvm " + machineName + ' --nic1 bridged --bridgeadapter1 ' + bridged) subutai.VBox("modifyvm " + machineName + " --nic2 nat") subutai.VBox("modifyvm " + machineName + " --cableconnected2 on") subutai.VBox( "modifyvm " + machineName + ' --natpf2 ssh-fwd,tcp,,4567,,22 --natpf2 https-fwd,tcp,,9999,,8443') ret = subutai.VBoxS("hostonlyif ipconfig vboxnet0 --ip 192.168.56.1") print("hostonlyif: " + str(ret)) if ret == 1: print("Creating hostonlyif") subutai.VBox("hostonlyif create") subutai.VBox("hostonlyif ipconfig vboxnet0 --ip 192.168.56.1") subutai.VBox( "dhcpserver add --ifname vboxnet0 --ip 192.168.56.1 --netmask 255.255.255.0 --lowerip 192.168.56.100 --upperip 192.168.56.200" ) subutai.VBox("dhcpserver modify --ifname vboxnet0 --enable") subutai.VBox("modifyvm " + machineName + " --nic3 hostonly --hostonlyadapter3 vboxnet0") subutai.VBox("startvm --type headless " + machineName) return