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 stopVm(machineName): subutai.SSHRun("sync") subutai.log("info", "Stopping Virtual machine") if subutai.CheckVMRunning(machineName) == 0: subutai.VBox("controlvm " + machineName + " poweroff soft") return
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 subutaistart(): coreFile = "core.ova" vboxFile = "VirtualBox.pkg" ubuntuFile = "ubuntu16-subutai-template_4.0.0_amd64.tar.gz" openjreFile = "openjre16-subutai-template_4.0.0_amd64.tar.gz" mngFile = "management" progress = subuco.Progress(coreFile, vboxFile, ubuntuFile, openjreFile, mngFile) tmpDir = subutai.GetTmpDir() installDir = subutai.GetInstallDir() rc = subup.InstallPeerPrerequisites(tmpDir, installDir, progress) if rc != 0: subutai.RaiseError("Failed to install prerequisites") sleep(10) return 29 sleep(3) subup.CleanSSHKeys() subutai.SetSSHCredentials("subutai", "ubuntai", "127.0.0.1", 4567) peer = subuco.SubutaiPeer(subup.GetVirtualMachineName(), progress, ubuntuFile, openjreFile, mngFile) if peer.SetupVirtualMachine() != 0: sleep(10) subutai.Shutdown() return peer.ConfigureNetwork() rc = peer.StartVirtualMachine() subutai.AddStatus("Waiting for peer to start and initialize") sleep(40) if subutai.CheckVMRunning(peer.GetName()) != 0: peer.StartVirtualMachine() sleep(50) if subutai.CheckVMRunning(peer.GetName()) != 0: subutai.RaiseError("Aborting") sleep(15) subutai.Shutdown() return 21 progress.spin() rc = peer.WaitSSH() if rc != 0: sleep(10) subutai.Shutdown() return rc peer.SetupSSH() rc = peer.waitForNetwork() if rc != 0: sleep(10) return rc rc = peer.InstallSnap() if rc != 0: subutai.RaiseError("Failed to install Subutai. Aborting") sleep(10) subutai.Shutdown() return rc peer.InitBTRFS() peer.SetupAlias() peer.RetrievePeerIP() progress.unspin() peer.InstallUbuntu() peer.installOpenJRE() peer.installManagement() peer.WaitPeerResponse() subutai.SetProgress(1.0) subutai.Shutdown() return 0
def stopVm(machineName): if subutai.CheckVMRunning(machineName) != 0: subutai.VBox("controlvm " + machineName + " poweroff soft") return
def startVm(machineName): if subutai.CheckVMRunning(machineName) != 0: subutai.VBox("startvm --type headless " + machineName) return
def subutaistart(): coreFile = "core.ova" vboxFile = "VirtualBox.pkg" progress = subuco.Progress() progress.setCore(coreFile) progress.setVBox(vboxFile) progress.calculateTotal() tmpDir = subutai.GetTmpDir() installDir = subutai.GetInstallDir() rc = subup.InstallPeerPrerequisites(tmpDir, installDir, progress) if rc != 0: subutai.RaiseError("Failed to install prerequisites") sleep(10) return 29 sleep(3) subup.CleanSSHKeys() subutai.SetSSHCredentials("subutai", "ubuntai", "127.0.0.1", 4567) peer = subuco.SubutaiPeer(subup.GetVirtualMachineName(), progress, "", "", "") if peer.SetupVirtualMachine() != 0: sleep(10) subutai.Shutdown() return peer.ConfigureNetwork() rc = peer.StartVirtualMachine() subutai.AddStatus("Waiting for RH to start and initialize") sleep(40) if subutai.CheckVMRunning(peer.GetName()) != 0: peer.StartVirtualMachine() sleep(50) if subutai.CheckVMRunning(peer.GetName()) != 0: subutai.RaiseError("Aborting") sleep(15) subutai.Shutdown() return 21 progress.spin() rc = peer.WaitSSH() if rc != 0: sleep(10) subutai.Shutdown() return rc peer.SetupSSH() rc = peer.WaitForNetwork() if rc != 0: sleep(10) return rc rc = peer.InstallSnap() if rc != 0: subutai.RaiseError("Failed to install Subutai. Aborting") sleep(10) subutai.Shutdown() return rc peer.InitBTRFS() peer.SetupAlias() peer.RetrievePeerIP() progress.unspin() subutai.SetProgress(1.0) subutai.Shutdown() return 0
def startVm(machineName): subutai.log("info", "Starting virtual machine") if subutai.CheckVMRunning(machineName) != 0: subutai.VBox("startvm --type headless " + machineName) return
def subutaistart(): tmpDir = subutai.GetTmpDir() installDir = subutai.GetInstallDir() m = hashlib.md5() m.update(datetime.datetime.now().isoformat().encode('utf-8')) machineName = "subutai-ld-" + m.hexdigest()[:5] coreFile = "core.ova" vboxFile = "virtualbox-5.1_xenial_amd64.deb" vnum = subutai.GetOSVersionNumber() if vnum == "16.10": vboxFile = "virtualbox-5.1_yakkety_amd64.deb" elif vnum == "17.04": vboxFile = "virtualbox-5.1_zesty_amd64.deb" ubuntuFile = "ubuntu16-subutai-template_4.0.0_amd64.tar.gz" openjreFile = "openjre16-subutai-template_4.0.0_amd64.tar.gz" mngFile = "management" progress = Progress(coreFile, vboxFile, ubuntuFile, openjreFile, mngFile) rc = installVBox(vboxFile, tmpDir, installDir, progress) if rc != 0: sleep(10) return rc call(['ssh-keygen', '-R', '[127.0.0.1]:4567']) subutai.SetSSHCredentials("subutai", "ubuntai", "127.0.0.1", 4567) enableHostonlyif() if setupVm(machineName, progress) != 0: subutai.RaiseError("Failed to install Virtual Machine. See the logs for details") subutai.Shutdown() return startVm(machineName) subutai.AddStatus("Waiting for peer to start and initialize") sleep(40) if subutai.CheckVMRunning(machineName) != 0: subutai.AddStatus("Failed to start VM. Retrying") startVm(machineName) sleep(50) if subutai.CheckVMRunning(machineName) != 0: subutai.RaiseError("Failed to start VM. Aborting") sleep(15) return 21 rc = waitSSH() if rc != 0: return rc setupSSH() rc = waitForNetwork() if rc != 0: sleep(10) return rc rc = installSnapFromStore() if rc != 0: subutai.RaiseError("Failed to install Subutai. Aborting") sleep(10) subutai.Shutdown() return rc initBtrfs() setAlias() peerip = GetPeerIP() installUbuntu(ubuntuFile, progress) installOpenjre(openjreFile, progress) installManagement(mngFile, progress) WaitForPeer(peerip) sleep(3) stopVm(machineName) sleep(5) if subutai.CheckVMRunning(machineName) == 0: subutai.AddStatus("Failed to stop VM. Retrying") stopVm(machineName) sleep(20) if subutai.CheckVMRunning(machineName) == 0: subutai.RaiseError("Failed to stop VM. Retrying") sleep(20) return 22 reconfigureNic(machineName) sleep(3) startVm(machineName) sleep(10) if subutai.CheckVMRunning(machineName) != 0: subutai.AddStatus("Failed to start VM. Retrying") startVm(machineName) sleep(50) if subutai.CheckVMRunning(machineName) != 0: subutai.RaiseError("Failed to start VM. Aborting") sleep(15) return 21 subutai.SetProgress(1.0) subutai.Shutdown() return 0