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 reconfigureNic(machineName): subutai.AddStatus("Configuring Network") subutai.log("info", "Reconfiguring NIC") gateway = subutai.GetDefaultRoutingInterface() bridged = subutai.GetVBoxBridgedInterface(gateway) bridged = bridged.replace(' ', '+++') 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') adapterName = subutai.GetVBoxHostOnlyInterface() adapterName = adapterName.replace(' ', '+++') ret = subutai.VBoxS("hostonlyif ipconfig " + adapterName + " --ip 192.168.56.1") if ret == 1: subutai.VBox("hostonlyif create") subutai.VBox("hostonlyif ipconfig " + adapterName + " --ip 192.168.56.1") out = subutai.VBox("list dhcpservers") if out == '': subutai.VBox("dhcpserver add --ifname " + adapterName + " --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 " + adapterName + " --enable") subutai.VBox("modifyvm " + machineName + " --nic3 hostonly --hostonlyadapter3 " + adapterName) return
def installSnapFromStore(): subutai.AddStatus("Installing Subutai") subutai.log("info", "Installing subutai snap") subutai.SSHRun("sudo snap install --beta --devmode subutai-dev") out = subutai.SSHRunOut("which subutai-dev >/dev/null; echo $?") if out != '0': return 55 return 0
def installSnapFromStore(): subutai.AddStatus("Installing Subutai") subutai.log("info", "Installing subutai snap") subutai.SSHRun("sudo snap install --beta --devmode subutai-dev > /tmp/subutai-snap.log 2>&1") sleep(5) out = subutai.SSHRunOut("which subutai-dev >/dev/null; echo $?") if out != '0': return 55 return 0
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 reconfigureNic(machineName): subutai.AddStatus("Configuring Network") subutai.log("info", "Reconfiguring NIC") gateway = subutai.GetDefaultRoutingInterface() bridged = subutai.GetVBoxBridgedInterface(gateway) 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') adapterName = subutai.GetVBoxHostOnlyInterface() if adapterName != 'undefined': subutai.VBox("modifyvm " + machineName + " --nic3 hostonly --hostonlyadapter3 " + adapterName) 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 setupVm(machineName, progress): rc = 0 subutai.log("info", "Setting up a VM") subutai.AddStatus("Installing VM") if subutai.CheckVMExists(machineName) != 0: subutai.download("core.ova") while subutai.isDownloadComplete() != 1: sleep(0.05) progress.setCoreProgress(subutai.GetBytesDownload()) progress.updateProgress() subutai.AddStatus("Virtual Machine Image file downloaded") 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() adapterName = adapterName.replace(' ', '+++') subutai.VBox("modifyvm " + machineName + " --nic3 hostonly --hostonlyadapter3 " + adapterName) sleep(1) return rc
def waitSSH(): subutai.log("info", "Waiting for machine to bring SSH") attempts = 0 while subutai.TestSSH() != 0: sleep(1) attempts = attempts + 1 if attempts == 30: subutai.log("error", "SSH timeout for 30 second") return -1 subutai.log("info", "SSH Connected") return 0
def waitSSH(): subutai.log("info", "Waiting for machine to bring SSH") attempts = 0 while subutai.TestSSH() != 0: sleep(1) attempts = attempts + 1 if attempts == 30: subutai.log("error", "SSH timeout for 30 second") return 34 attempts = 0 out = '' while out == '': out = subutai.SSHRunOut("uptime") attempts = attempts + 1 if attempts >= 30: subutai.RaiseError("SSH connection failed after 30 attempts") subutai.log("error", "SSH timeout for 30 second") return 35 subutai.log("info", "SSH Connected") return 0
def SetupSSH(self): subutai.SetAction("SETUPSSH") subutai.log("info", "Setting up SSH") subutai.SSHRun("mkdir -p /home/subutai/.ssh") subutai.InstallSSHKey() return 0
def SetupAlias(self): subutai.SetAction("SETALIAS") subutai.log("info", "Setting Alias") subutai.SSHRun("sudo bash -c 'snap alias subutai-dev subutai'") return 0
def initBtrfs(): subutai.log("info", "Initializing BTRFS") subutai.AddStatus("Initializing BTRFS") subutai.SSHRun("sudo subutai-dev.btrfsinit /dev/sdb") return
def setupSSH(): subutai.log("info", "Setting up SSH") subutai.SSHRun("mkdir -p /home/subutai/.ssh") subutai.InstallSSHKey() return
def setAlias(): subutai.log("info", "Setting Alias") subutai.SSHRun("sudo bash -c 'snap alias subutai-dev subutai'") return
def startVm(machineName): subutai.log("info", "Starting virtual machine") if subutai.CheckVMRunning(machineName) != 0: subutai.VBox("startvm --type headless " + machineName) return