Пример #1
0
 def unforward(self, port):
     # Remove a forwarding rule.
     local_port = port + 10000
     debug("unforwarding: localhost:{} -> {}:{}", local_port, self.name,
           port)
     self.ctl("hostfwd_remove tcp:127.0.0.1:%s-:%s" % (local_port, port))
     port_path = CTL_DIR + "/port.%s" % port
     if os.path.exists(port_path):
         rm(port_path)
Пример #2
0
 def delete(self):
     # Delete the VM image.
     if self.missing():
         raise fail("VM is not built: {}", self.name)
     if self.running():
         raise fail("VM is running: {}", self.name)
     log("deleting VM: {}", self.name)
     rm(self.img_path)
     if os.path.exists(self.ctl_path):
         rm(self.ctl_path)
Пример #3
0
 def start(self):
     # Start a VM.
     if self.missing():
         raise fail("VM is not built: {}", self.name)
     if self.running():
         raise fail("VM is already running: {}", self.name)
     log("starting VM: {}", self.name)
     for filename in glob.glob(CTL_DIR + "/port.*"):
         name = open(filename).read().strip()
         if name == self.name:
             rm(filename)
     if self.state:
         self.kvm("-daemonize -loadvm %s" % self.state)
     else:
         self.kvm("-daemonize -snapshot")
Пример #4
0
def CLEAN():
    """delete generated files

    This task deletes generated files.
    """
    if os.path.exists("./build"):
        rmtree("./build")
    if os.path.exists("./dist"):
        rmtree("./dist")
    for dirpath, dirnames, filenames in os.walk("."):
        for filename in filenames:
            if filename.endswith(".pyc") or filename.endswith(".pyo"):
                filename = os.path.join(dirpath, filename)
                rm(filename)
        for dirname in dirnames:
            if dirname == "vendor":
                dirname = os.path.join(dirpath, dirname)
                rmtree(dirname)
    for filename in glob.glob("./HTSQL-*"):
        if os.path.isdir(filename):
            rmtree(filename)
Пример #5
0
 def build(self):
     super(LinuxBenchVM, self).build()
     parent_vm = VM.find(self.parent)
     if parent_vm.missing():
         parent_vm.build()
     if parent_vm.running():
         raise fail("unable to copy VM while it is running: {}",
                    parent_vm.name)
     log("building VM: `{}`...", self.name)
     start_time = datetime.datetime.now()
     try:
         sh("qemu-img create -b %s.qcow2 -f qcow2 %s.qcow2" %
            (parent_vm.name, self.name),
            cd=IMG_DIR)
         self.kvm("-daemonize")
         time.sleep(60.0)
         self.put(DATA_ROOT + "/vm/%s-update.sh" % self.name,
                  "/root/update.sh")
         self.run("/root/update.sh")
         self.run("rm /root/update.sh")
         self.run("shutdown")
         self.wait()
         #self.compress(parent_vm.name)
         self.kvm("-daemonize")
         time.sleep(60.0)
         self.ctl("savevm %s" % self.state)
         self.ctl("quit")
         self.wait()
     except:
         if self.running():
             self.ctl("quit")
             self.wait()
         if os.path.exists(self.img_path):
             rm(self.img_path)
         raise
     stop_time = datetime.datetime.now()
     log("VM is built successfully: `{}` ({})", self.name,
         stop_time - start_time)
Пример #6
0
 def build(self):
     super(WindowsBenchVM, self).build()
     parent_vm = VM.find(self.parent)
     if parent_vm.missing():
         parent_vm.build()
     if parent_vm.running():
         raise fail("unable to copy VM while it is running: {}",
                    parent_vm.name)
     log("building VM: `{}`...", self.name)
     start_time = datetime.datetime.now()
     try:
         cp(parent_vm.img_path, self.img_path)
         self.kvm("-daemonize")
         time.sleep(120.0)
         self.put(DATA_ROOT + "/vm/%s-update.cmd" % self.name,
                  "/cygdrive/c/INSTALL/UPDATE.CMD")
         self.run(
             "reg add 'HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce'"
             " /v %s /t REG_SZ /d 'C:\INSTALL\UPDATE.CMD' /f" % self.name)
         self.run("shutdown /r /t 0 /f")
         self.wait()
         #self.compress(parent_vm.name)
         self.kvm("-daemonize")
         time.sleep(120.0)
         self.ctl("savevm %s" % self.state)
         self.ctl("quit")
         self.wait()
     except:
         if self.running():
             self.ctl("quit")
             self.wait()
         if os.path.exists(self.img_path):
             rm(self.img_path)
         raise
     stop_time = datetime.datetime.now()
     log("VM is built successfully: `{}` ({})", self.name,
         stop_time - start_time)
Пример #7
0
 def build(self):
     super(DebianTemplateVM, self).build()
     log("building VM: `{}`...", self.name)
     start_time = datetime.datetime.now()
     src_iso_path = getattr(env, self.iso_env)
     if not (src_iso_path and os.path.isfile(src_iso_path)):
         src_iso_path = self.download(self.iso_urls)
     unpack_path = TMP_DIR + "/" + self.name
     if os.path.exists(unpack_path):
         rmtree(unpack_path)
     self.unpack_iso(src_iso_path, unpack_path)
     cp(DATA_ROOT + "/vm/%s-isolinux.cfg" % self.name,
        unpack_path + "/isolinux/isolinux.cfg")
     cp(DATA_ROOT + "/vm/%s-preseed.cfg" % self.name,
        unpack_path + "/preseed.cfg")
     cp(DATA_ROOT + "/vm/%s-install.sh" % self.name,
        unpack_path + "/install.sh")
     cp(CTL_DIR + "/identity.pub", unpack_path + "/identity.pub")
     sh(
         "md5sum"
         " `find ! -name \"md5sum.txt\""
         " ! -path \"./isolinux/*\" -follow -type f` > md5sum.txt",
         cd=unpack_path)
     iso_path = TMP_DIR + "/%s.iso" % self.name
     if os.path.exists(iso_path):
         rm(iso_path)
     sh("mkisofs -o %s"
        " -q -r -J -no-emul-boot -boot-load-size 4 -boot-info-table"
        " -b isolinux/isolinux.bin -c isolinux/boot.cat %s" %
        (iso_path, unpack_path))
     rmtree(unpack_path)
     try:
         self.kvm_img()
         self.kvm("-cdrom %s -boot d" % iso_path)
         rm(iso_path)
         self.compress()
     except:
         if os.path.exists(self.img_path):
             rm(self.img_path)
         raise
     stop_time = datetime.datetime.now()
     log("VM is built successfully: `{}` ({})", self.name,
         stop_time - start_time)
Пример #8
0
 def build(self):
     super(CentOSTemplateVM, self).build()
     log("building VM: `{}`...", self.name)
     start_time = datetime.datetime.now()
     src_iso_path = env.centos_iso
     if not (src_iso_path and os.path.isfile(src_iso_path)):
         src_iso_path = self.download(CENTOS_ISO_URLS)
     unpack_path = TMP_DIR + "/" + self.name
     if os.path.exists(unpack_path):
         rmtree(unpack_path)
     self.unpack_iso(src_iso_path, unpack_path)
     cp(DATA_ROOT + "/vm/%s-isolinux.cfg" % self.name,
        unpack_path + "/isolinux/isolinux.cfg")
     cp(DATA_ROOT + "/vm/%s-ks.cfg" % self.name, unpack_path + "/ks.cfg")
     cp(DATA_ROOT + "/vm/%s-install.sh" % self.name,
        unpack_path + "/install.sh")
     cp(CTL_DIR + "/identity.pub", unpack_path + "/identity.pub")
     iso_path = TMP_DIR + "/%s.iso" % self.name
     if os.path.exists(iso_path):
         rm(iso_path)
     sh("mkisofs -o %s"
        " -q -r -J -T -no-emul-boot -boot-load-size 4 -boot-info-table"
        " -b isolinux/isolinux.bin -c isolinux/boot.cat %s" %
        (iso_path, unpack_path))
     rmtree(unpack_path)
     try:
         self.kvm_img()
         self.kvm("-cdrom %s -boot d" % iso_path)
         rm(iso_path)
         self.compress()
     except:
         if os.path.exists(self.img_path):
             rm(self.img_path)
         raise
     stop_time = datetime.datetime.now()
     log("VM is built successfully: `{}` ({})",
         (self.name, stop_time - start_time))
Пример #9
0
 def build(self):
     super(WindowsTemplateVM, self).build()
     log("building VM: `{}`...", self.name)
     start_time = datetime.datetime.now()
     src_iso_path = env.windows_iso
     if not (src_iso_path and os.path.isfile(src_iso_path)):
         src_iso_path = None
         output = pipe("locate %s || true" % " ".join(WINDOWS_ISO_FILES))
         for line in output.splitlines():
             if os.path.exists(line):
                 src_iso_path = line
                 break
     if src_iso_path is None:
         log("unable to find an ISO image for Windows XP or Windows 2003")
         src_iso_path = prompt("enter path to an ISO image:")
         if not (src_iso_path and os.path.isfile(src_iso_path)):
             raise fail("invalid path: %s" % src_iso_path)
     key_regexp = re.compile(r'^\w{5}-\w{5}-\w{5}-\w{5}-\w{5}$')
     key = env.windows_key
     if not (key and key_regexp.match(key)):
         key = None
         key_path = os.path.splitext(src_iso_path)[0] + ".key"
         if os.path.isfile(key_path):
             key = open(key_path).readline().strip()
             if not key_regexp.match(key):
                 key = None
     if key is None:
         log("unable to find a Windows product key")
         key = prompt("enter product key:")
         if not key_regexp.match(key):
             raise fail("invalid product key: {}", key)
     wget_path = self.download(WGET_EXE_URLS)
     unpack_path = TMP_DIR + "/" + self.name
     boot_path = unpack_path + "/eltorito.img"
     if os.path.exists(unpack_path):
         rmtree(unpack_path)
     self.unpack_iso(src_iso_path, unpack_path)
     self.unpack_iso_boot(src_iso_path, boot_path)
     sif_template_path = DATA_ROOT + "/vm/%s-winnt.sif" % self.name
     sif_path = unpack_path + "/I386/WINNT.SIF"
     debug("translating: {} => {}", sif_template_path, sif_path)
     sif_template = open(sif_template_path).read()
     sif = sif_template.replace("#####-#####-#####-#####-#####", key)
     assert sif != sif_template
     open(sif_path, 'w').write(sif)
     install_path = unpack_path + "/$OEM$/$1/INSTALL"
     mktree(install_path)
     cp(wget_path, install_path)
     cp(CTL_DIR + "/identity.pub", install_path)
     cp(DATA_ROOT + "/vm/%s-install.cmd" % self.name,
        install_path + "/INSTALL.CMD")
     iso_path = TMP_DIR + "/%s.iso" % self.name
     if os.path.exists(iso_path):
         rm(iso_path)
     sh("mkisofs -o %s -q -iso-level 2 -J -l -D -N"
        " -joliet-long -relaxed-filenames -no-emul-boot"
        " -boot-load-size 4 -b eltorito.img %s" % (iso_path, unpack_path))
     rmtree(unpack_path)
     try:
         self.kvm_img()
         self.kvm("-cdrom %s -boot d" % iso_path)
         rm(iso_path)
         self.compress()
     except:
         if os.path.exists(self.img_path):
             rm(self.img_path)
         raise
     stop_time = datetime.datetime.now()
     log("VM is built successfully: `{}` ({})", self.name,
         stop_time - start_time)