def waitForInstallCompleteAndFirstBoot(self): # Install is complete when the guest shuts down # Using the signalling mechanism to monitor for installation complete. if xenrt.TEC().lookup("EXTRA_TIME", False, boolean=True): installtime = 7200 else: installtime = 3600 xenrt.waitForFile("%s/.xenrtsuccess" % (self.nfsdir.path()), installtime, desc="RHEL based installation") if self.distro.startswith("rhel7") or self.distro.startswith( "centos7") or self.distro.startswith( "oel7") or self.distro.startswith("fedora"): # This is likely to be a force stop, so we'll sleep to allow the disk to sync xenrt.sleep(60) self.parent._osParent_stop() self.parent._osParent_pollPowerState(xenrt.PowerState.down, timeout=1800) if self.installMethod == xenrt.InstallMethod.IsoWithAnswerFile: self.cleanupIsoAnswerfile() self.parent._osParent_ejectIso() self.parent._osParent_start() self.waitForBoot(600)
def waitForIPXEStamp(self, machine, forceip=None): if forceip: filename = "%s/%s.stamp" % (self._getIPXEDir(), forceip) else: filename = "%s/%s.stamp" % (self._getIPXEDir(), machine.pxeipaddr) self._rmtree(filename) xenrt.waitForFile(filename, 1800, desc="Waiting for iPXE config to be accessed on !%s" % (machine.name))
def waitForIPXEStamp(self, machine, forceip=None): if forceip: filename = "%s/%s.stamp" % (self._getIPXEDir(), forceip) else: filename = "%s/%s.stamp" % (self._getIPXEDir(), machine.pxeipaddr) self._rmtree(filename) xenrt.waitForFile( filename, 1800, desc="Waiting for iPXE config to be accessed on !%s" % (machine.name))
def waitForInstallCompleteAndFirstBoot(self): # Install is complete when the guest shuts down # Using the signalling mechanism to monitor for installation complete. if xenrt.TEC().lookup("EXTRA_TIME", False, boolean=True): installtime = 7200 else: installtime = 3600 xenrt.waitForFile("%s/.xenrtsuccess" % (self.nfsdir.path()), installtime, desc="RHEL based installation") if self.distro.startswith("rhel7") or self.distro.startswith("centos7") or self.distro.startswith("oel7") or self.distro.startswith("fedora"): # This is likely to be a force stop, so we'll sleep to allow the disk to sync xenrt.sleep(60) self.parent._osParent_stop() self.parent._osParent_pollPowerState(xenrt.PowerState.down, timeout=1800) if self.installMethod == xenrt.InstallMethod.IsoWithAnswerFile: self.cleanupIsoAnswerfile() self.parent._osParent_ejectIso() self.parent._osParent_start() self.waitForBoot(600)
def waitForInstallCompleteAndFirstBoot(self): # Install is complete when the guest shuts down # Using the signalling mechanism to monitor for installation complete. if xenrt.TEC().lookup("EXTRA_TIME", False, boolean=True): installtime = 7200 else: installtime = 3600 xenrt.waitForFile("%s/.xenrtsuccess" % (self.nfsdir.path()), installtime, desc="SUSE based installation") if 'sles10' in self.distro: xenrt.TEC().logverbose("Sleeping for 240secs before removing iso") xenrt.sleep(240) else: self.parent._osParent_stop() self.parent._osParent_pollPowerState(xenrt.PowerState.down, timeout=1800) if self.installMethod == xenrt.InstallMethod.IsoWithAnswerFile: self.cleanupIsoAnswerfile() self.parent._osParent_ejectIso() if not 'sles10' in self.distro: self.parent._osParent_startOS() self.waitForBoot(600)
def install(self, cd=None, primarydisk=None, guestdisks=["sda"], source="url", timezone="UTC", interfaces=[(None, "yes", "dhcp", None, None, None)], ntpserver=None, nameserver=None, hostname=None, installSRType=None, bootloader=None, overlay=None, suppackcds=None): xenrt.TEC().progress("Installing ESXi %s" % self.esxiVersion) workdir = xenrt.TEC().getWorkdir() # Get a PXE directory to put boot files in pxe = xenrt.PXEBoot() # Create an NFS directory for images, signals, etc. nfsdir = xenrt.NFSDirectory() isoname = "/usr/groups/xenrt/esx/ESXi-%s.iso" % self.esxiVersion esxiso = xenrt.TEC().getFile(isoname) if not esxiso: raise xenrt.XRTError("Couldn't find ISO %s" % (isoname)) mount = xenrt.rootops.MountISO(esxiso) mountpoint = mount.getMount() pxe.copyIn("%s/*" % (mountpoint)) # create kickstart file ksname = "kickstart-%s.cfg" % (self.getName()) kspath = "%s/%s" % (workdir, ksname) ks = file(kspath, "w") kstext = """ vmaccepteula rootpw %s clearpart --alldrives --overwritevmfs install --firstdisk --overwritevmfs network --bootproto=dhcp --device=vmnic0 %%firstboot --interpreter=busybox vim-cmd hostsvc/enable_ssh vim-cmd hostsvc/start_ssh vim-cmd hostsvc/enable_esx_shell vim-cmd hostsvc/start_esx_shell esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1 esxcli network firewall set --enabled false esxcli network vswitch standard policy security set --allow-promiscuous true -v vSwitch0 esxcli system settings advanced set -i 1 -o /Misc/LogToSerial esxcli system settings advanced set -i 115200 -o /Misc/SerialBaudRate esxcli system settings advanced set -i 1 -o /Misc/DebugLogToSerial esxcli system settings advanced set -s NONE -o /Misc/LogPort esxcli system settings advanced set -s COM1 -o /Misc/LogPort %%post --interpreter=busybox exec < /dev/console > /dev/console 2> /dev/console touch /vmfs/volumes/remote-install-location/.xenrtsuccess sleep 30 reboot """ % xenrt.TEC().lookup("ROOT_PASSWORD") ks.write(kstext) ks.close() nfsdir.copyIn(kspath) xenrt.TEC().copyToLogDir(kspath, target=ksname) # tweak mboot config file origbootcfg = file("%s/%s" % (mountpoint, "boot.cfg"), "r") bootcfgpath = "%s/%s" % (workdir, "boot.cfg") bootcfg = file(bootcfgpath, "w") bootcfgtext = origbootcfg.read() bootcfgtext = re.sub(r"/", r"", bootcfgtext) # get rid of all absolute paths... bootcfgtext += "prefix=%s" % pxe.makeBootPath( "") # ... and use our PXE path as a prefix instead bootcfgtext = re.sub( r"--- useropts\.gz", r"", bootcfgtext ) # this file seems to cause only trouble, and getting rid of it seems to have no side effects... bootcfgtext = re.sub(r"--- jumpstrt\.gz", r"", bootcfgtext) # this file (in ESXi 5.5) is similar if self.esxiVersion < "5.5": deferToolsPackInstallation = False else: bootcfgtext2 = re.sub( r"--- tools.t00", r"", bootcfgtext ) # this file is too large to get over netboot from atftpd (as used in CBGLAB01), so we will install it after host-installation deferToolsPackInstallation = (bootcfgtext2 <> bootcfgtext) bootcfgtext = bootcfgtext2 bootcfgtext = re.sub( r"(kernelopt=.*)", r"\1 debugLogToSerial=1 logPort=com1 ks=%s" % ("nfs://%s%s" % (nfsdir.getHostAndPath(ksname))), bootcfgtext) bootcfg.write(bootcfgtext) bootcfg.close() origbootcfg.close() # remove the old boot.cfg (as it is read-only, it won't let you update in place) os.remove(os.path.join(pxe.path(), "boot.cfg")) pxe.copyIn(bootcfgpath) xenrt.TEC().copyToLogDir(bootcfgpath, target="bootcfg-%s.cfg" % (self.getName())) # add boot entry # NB: we are not actually booting a linux kernel pxecfg = pxe.addEntry("esx", default=1, boot="linux") pxecfg.linuxSetKernel("mboot.c32") pxecfg.linuxArgsKernelAdd("-c %s" % pxe.makeBootPath("boot.cfg")) chain = self.getChainBoot() if chain: pxe.addEntry("local", boot="chainlocal", options=chain) else: pxe.addEntry("local", boot="local") # Set up PXE for installer boot pxefile = pxe.writeOut(self.machine) pfname = os.path.basename(pxefile) xenrt.TEC().copyToLogDir(pxefile, target="%s.pxe.txt" % (pfname)) # Reboot the host into the installer self.machine.powerctl.cycle() xenrt.TEC().progress("Rebooted host to start installation.") # Monitor for installation complete xenrt.waitForFile("%s/.xenrtsuccess" % (nfsdir.path()), 1800, desc="Installer boot on !%s" % (self.getName())) # Boot the local disk - we need to update this before the machine # reboots after setting the signal flag. pxe.setDefault("local") pxe.writeOut(self.machine) xenrt.sleep(30) self.waitForSSH(900, desc="Host boot (!%s)" % (self.getName())) # If we skipped tools.t00 above due to tftp issues, install it now. It's just a .tar.gz file. if deferToolsPackInstallation: xenrt.TEC().progress("Manually installing tools.t00") toolsFile = "%s/tools.t00" % (mountpoint) # Use the first-named datastore to temporarily dump the file. (Alternatively, could use /tardisks?) firstDatastore = self.getDefaultDatastore() destFilePath = "/vmfs/volumes/%s/tools.t00" % (firstDatastore) sftp = self.sftpClient() try: sftp.copyTo(toolsFile, destFilePath) finally: sftp.close() self.execdom0("tar xvfz %s -C /locker/packages" % (destFilePath)) self.execdom0("rm -f %s" % (destFilePath)) # We're done with the ISO now mount.unmount() nfsdir.remove() self.installSRType = installSRType xenrt.TEC().progress("Completed installation of ESXi host")
def waitForIsoAnswerfileAccess(self): installIP = self.getIP(trafficType="OUTBOUND", timeout=600) path = "%s/%s" % (xenrt.TEC().lookup("GUESTFILE_BASE_PATH"), installIP) filename = "%s/kickstart.stamp" % path xenrt.waitForFile(filename, 1800)
def install(self): f = xenrt.TEC().getFile("/usr/groups/xenrt/oraclevm/%s/ovm.iso" % (self.productVersion)) d = xenrt.NFSDirectory() m = xenrt.MountISO(f) d.copyIn("%s/*" % m.getMount()) m.unmount() host, path = d.getHostAndPath("") pw = crypt.crypt(xenrt.TEC().lookup("ROOT_PASSWORD"), "Xa") ksd = xenrt.NFSDirectory() ks="""lang en_US #langsupport en_US keyboard us #mouse genericusb timezone --utc America/Los_Angeles rootpw --iscrypted %s bootloader --location=mbr install nfs --server %s --dir %s clearpart --all --initlabel part /boot --fstype ext3 --size 512 --ondisk sda part swap --size 4096 --ondisk sda part / --fstype ext3 --size 1 --grow --ondisk sda network --bootproto dhcp --device eth0 ovsagent --iscrypted %s ovsmgmntif eth0 auth --useshadow --enablemd5 firewall --disabled #Do not configure the X Window System skipx text %%packages @Everything %%pre dd if=/dev/zero of=/dev/sda bs=1024 count=1024 %%post --nochroot %%post mkdir /tmp/xenrttmpmount mount -onolock -t nfs %s /tmp/xenrttmpmount touch /tmp/xenrttmpmount/.xenrtsuccess umount /tmp/xenrttmpmount """ % (pw, host, path, pw, ksd.getMountURL("")) with open("%s/ks.cfg" % ksd.path(), "w") as f: f.write(ks) pxe = xenrt.PXEBoot() pxe.addEntry("local", boot="local") serport = self.lookup("SERIAL_CONSOLE_PORT", "0") serbaud = self.lookup("SERIAL_CONSOLE_BAUD", "115200") comport = str(int(serport) + 1) if self.lookup("PXE_NO_SERIAL", False, boolean=True): pxe.setSerial(None,None) else: pxe.setSerial(serport, serbaud) chain = self.getChainBoot() if chain: pxe.addEntry("local", boot="chainlocal", options=chain) else: pxe.addEntry("local", boot="local") pxe.copyIn("%s/images/pxeboot/vmlinuz" % d.path()) pxe.copyIn("%s/images/pxeboot/initrd.img" % d.path()) install = pxe.addEntry("ovminstall", boot="linux") install.linuxSetKernel("%s/vmlinuz" % pxe.path()) install.linuxArgsKernelAdd("initrd=%s" % install.cfg.makeBootPath("%s/initrd.img" % pxe.path())) install.linuxArgsKernelAdd("load_ramdisk=1") install.linuxArgsKernelAdd("network") install.linuxArgsKernelAdd("mem=32g") install.linuxArgsKernelAdd("console=ttyS0,115200") install.linuxArgsKernelAdd("ks=nfs:%sks.cfg" % ksd.getMountURL("")) install.linuxArgsKernelAdd("ksdevice=eth0") pxe.setDefault("ovminstall") pxe.writeOut(self.machine) self.machine.powerctl.cycle() xenrt.waitForFile("%s/.xenrtsuccess" % ksd.path(), 3600, desc="Installer boot on !%s" % (self.getName())) xenrt.sleep(30) pxe.setDefault("local") pxe.writeOut(self.machine) self.machine.powerctl.cycle() self.waitForSSH(1800, desc="Host boot (!%s)" % (self.getName()))
def install(self): f = xenrt.TEC().getFile("/usr/groups/xenrt/oraclevm/%s/ovm.iso" % (self.productVersion)) d = xenrt.NFSDirectory() m = xenrt.MountISO(f) d.copyIn("%s/*" % m.getMount()) m.unmount() host, path = d.getHostAndPath("") pw = crypt.crypt(xenrt.TEC().lookup("ROOT_PASSWORD"), "Xa") ksd = xenrt.NFSDirectory() ks = """lang en_US #langsupport en_US eula Accepted keyboard us #mouse genericusb timezone --utc America/Los_Angeles rootpw --iscrypted %s zerombr bootloader --location=mbr install nfs --server %s --dir %s clearpart --all part /boot --fstype ext3 --size 512 --ondisk sda part swap --size 4096 --ondisk sda part / --fstype ext3 --size 1 --grow --ondisk sda network --bootproto dhcp --device eth0 ovsagent --iscrypted %s ovsmgmntif eth0 auth --useshadow --enablemd5 firewall --disabled #Do not configure the X Window System skipx text %%packages @Everything %%pre dd if=/dev/zero of=/dev/sda bs=1024 count=1024 %%post --nochroot %%post mkdir /tmp/xenrttmpmount mount -onolock -t nfs %s /tmp/xenrttmpmount touch /tmp/xenrttmpmount/.xenrtsuccess umount /tmp/xenrttmpmount """ % (pw, host, path, pw, ksd.getMountURL("")) with open("%s/ks.cfg" % ksd.path(), "w") as f: f.write(ks) pxe = xenrt.PXEBoot() pxe.addEntry("local", boot="local") serport = self.lookup("SERIAL_CONSOLE_PORT", "0") serbaud = self.lookup("SERIAL_CONSOLE_BAUD", "115200") comport = str(int(serport) + 1) if self.lookup("PXE_NO_SERIAL", False, boolean=True): pxe.setSerial(None, None) else: pxe.setSerial(serport, serbaud) chain = self.getChainBoot() if chain: pxe.addEntry("local", boot="chainlocal", options=chain) else: pxe.addEntry("local", boot="local") pxe.copyIn("%s/isolinux/xen.gz" % d.path()) pxe.copyIn("%s/isolinux/vmlinuz" % d.path()) pxe.copyIn("%s/isolinux/initrd.img" % d.path()) install = pxe.addEntry("ovminstall", boot="mboot") install.mbootSetKernel("%s/xen.gz" % pxe.path()) install.mbootSetModule1("%s/vmlinuz" % pxe.path()) install.mbootSetModule2("%s/initrd.img" % pxe.path()) install.mbootArgsModule1Add("ks=nfs:%sks.cfg" % ksd.getMountURL("")) install.mbootArgsModule1Add("ksdevice=eth0") install.mbootArgsModule1Add("ip=dhcp") #install.mbootArgsKernelAdd("com%s=%s,8n1" % (comport, serbaud)) #install.mbootArgsModule1Add("console=tty0") #install.mbootArgsModule1Add("console=ttyS%s,%sn8" % (serport, serbaud)) pxe.setDefault("ovminstall") pxe.writeOut(self.machine) self.machine.powerctl.cycle() xenrt.waitForFile("%s/.xenrtsuccess" % ksd.path(), 3600, desc="Installer boot on !%s" % (self.getName())) xenrt.sleep(30) pxe.setDefault("local") pxe.writeOut(self.machine) self.machine.powerctl.cycle() self.waitForSSH(1800, desc="Host boot (!%s)" % (self.getName()))
def install(self, cd=None, primarydisk=None, guestdisks=["sda"], source="url", timezone="UTC", interfaces=[(None, "yes", "dhcp", None, None, None)], ntpserver=None, nameserver=None, hostname=None, installSRType=None, bootloader=None, overlay=None, suppackcds=None): xenrt.TEC().progress("Installing ESXi %s" % self.esxiVersion) workdir = xenrt.TEC().getWorkdir() # Get a PXE directory to put boot files in pxe = xenrt.PXEBoot() # Create an NFS directory for images, signals, etc. nfsdir = xenrt.NFSDirectory() isoname = "/usr/groups/xenrt/esx/ESXi-%s.iso" % self.esxiVersion esxiso = xenrt.TEC().getFile(isoname) if not esxiso: raise xenrt.XRTError("Couldn't find ISO %s" % (isoname)) mount = xenrt.rootops.MountISO(esxiso) mountpoint = mount.getMount() pxe.copyIn("%s/*" % (mountpoint)) # create kickstart file ksname = "kickstart-%s.cfg" % (self.getName()) kspath = "%s/%s" % (workdir, ksname) ks = file(kspath, "w") kstext = """ vmaccepteula rootpw %s clearpart --alldrives --overwritevmfs install --firstdisk --overwritevmfs network --bootproto=dhcp --device=vmnic0 %%firstboot --interpreter=busybox vim-cmd hostsvc/enable_ssh vim-cmd hostsvc/start_ssh vim-cmd hostsvc/enable_esx_shell vim-cmd hostsvc/start_esx_shell esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1 esxcli network firewall set --enabled false esxcli network vswitch standard policy security set --allow-promiscuous true -v vSwitch0 esxcli system settings advanced set -i 1 -o /Misc/LogToSerial esxcli system settings advanced set -i 115200 -o /Misc/SerialBaudRate esxcli system settings advanced set -i 1 -o /Misc/DebugLogToSerial esxcli system settings advanced set -s NONE -o /Misc/LogPort esxcli system settings advanced set -s COM1 -o /Misc/LogPort %%post --interpreter=busybox exec < /dev/console > /dev/console 2> /dev/console touch /vmfs/volumes/remote-install-location/.xenrtsuccess sleep 30 reboot """ % xenrt.TEC().lookup("ROOT_PASSWORD") ks.write(kstext) ks.close() nfsdir.copyIn(kspath) xenrt.TEC().copyToLogDir(kspath, target=ksname) # tweak mboot config file origbootcfg = file("%s/%s" % (mountpoint, "boot.cfg"), "r") bootcfgpath = "%s/%s" % (workdir, "boot.cfg") bootcfg = file(bootcfgpath, "w") bootcfgtext = origbootcfg.read() bootcfgtext = re.sub(r"/", r"", bootcfgtext) # get rid of all absolute paths... bootcfgtext += "prefix=%s" % pxe.makeBootPath("") # ... and use our PXE path as a prefix instead bootcfgtext = re.sub(r"--- useropts\.gz", r"", bootcfgtext) # this file seems to cause only trouble, and getting rid of it seems to have no side effects... bootcfgtext = re.sub(r"--- jumpstrt\.gz", r"", bootcfgtext) # this file (in ESXi 5.5) is similar if self.esxiVersion < "5.5": deferToolsPackInstallation = False else: bootcfgtext2 = re.sub(r"--- tools.t00", r"", bootcfgtext) # this file is too large to get over netboot from atftpd (as used in CBGLAB01), so we will install it after host-installation deferToolsPackInstallation = (bootcfgtext2 <> bootcfgtext) bootcfgtext = bootcfgtext2 bootcfgtext = re.sub(r"(kernelopt=.*)", r"\1 debugLogToSerial=1 logPort=com1 ks=%s" % ("nfs://%s%s" % (nfsdir.getHostAndPath(ksname))), bootcfgtext) bootcfg.write(bootcfgtext) bootcfg.close() origbootcfg.close() # remove the old boot.cfg (as it is read-only, it won't let you update in place) os.remove(os.path.join(pxe.path(), "boot.cfg")) pxe.copyIn(bootcfgpath) xenrt.TEC().copyToLogDir(bootcfgpath, target="bootcfg-%s.cfg" % (self.getName())) # add boot entry # NB: we are not actually booting a linux kernel pxecfg = pxe.addEntry("esx", default=1, boot="linux") pxecfg.linuxSetKernel("mboot.c32") pxecfg.linuxArgsKernelAdd("-c %s" % pxe.makeBootPath("boot.cfg")) chain = self.getChainBoot() if chain: pxe.addEntry("local", boot="chainlocal", options=chain) else: pxe.addEntry("local", boot="local") # Set up PXE for installer boot pxefile = pxe.writeOut(self.machine) pfname = os.path.basename(pxefile) xenrt.TEC().copyToLogDir(pxefile,target="%s.pxe.txt" % (pfname)) # Reboot the host into the installer self.machine.powerctl.cycle() xenrt.TEC().progress("Rebooted host to start installation.") # Monitor for installation complete xenrt.waitForFile("%s/.xenrtsuccess" % (nfsdir.path()), 1800, desc="Installer boot on !%s" % (self.getName())) # Boot the local disk - we need to update this before the machine # reboots after setting the signal flag. pxe.setDefault("local") pxe.writeOut(self.machine) xenrt.sleep(30) self.waitForSSH(900, desc="Host boot (!%s)" % (self.getName())) # If we skipped tools.t00 above due to tftp issues, install it now. It's just a .tar.gz file. if deferToolsPackInstallation: xenrt.TEC().progress("Manually installing tools.t00") toolsFile = "%s/tools.t00" % (mountpoint) # Use the first-named datastore to temporarily dump the file. (Alternatively, could use /tardisks?) firstDatastore = self.getDefaultDatastore() destFilePath = "/vmfs/volumes/%s/tools.t00" % (firstDatastore) sftp = self.sftpClient() try: sftp.copyTo(toolsFile, destFilePath) finally: sftp.close() self.execdom0("tar xvfz %s -C /locker/packages" % (destFilePath)) self.execdom0("rm -f %s" % (destFilePath)) # We're done with the ISO now mount.unmount() nfsdir.remove() self.installSRType = installSRType xenrt.TEC().progress("Completed installation of ESXi host")