Ejemplo n.º 1
0
func Build(r *util.Repo, hypervisor string, image string, verbose bool) error {
	config, err := util.ReadConfig("Capstanfile")
	if err != nil {
		return err
	}
	fmt.Printf("Building %s...\n", image)
	err = os.MkdirAll(filepath.Dir(r.ImagePath(hypervisor, image)), 0777)
	if err != nil {
		return err
	}
	if config.RpmBase != nil {
		config.RpmBase.Download()
	}
	if config.Build != "" {
		args := strings.Fields(config.Build)
		cmd := exec.Command(args[0], args[1:]...)
		out, err := cmd.CombinedOutput()
		if err != nil {
			fmt.Println(string(out))
			return err
		}
	}
	err = checkConfig(config, r, hypervisor)
	if err != nil {
		return err
	}
	cmd := util.CopyFile(r.ImagePath(hypervisor, config.Base), r.ImagePath(hypervisor, image))
	_, err = cmd.Output()
	if err != nil {
		return err
	}
	err = qemu.SetArgs(r, hypervisor, image, "/tools/cpiod.so")
	if err != nil {
		return err
	}
	if config.RpmBase != nil {
		err = qemu.UploadRPM(r, hypervisor, image, config, verbose)
		if err != nil {
			return err
		}
	}
	err = qemu.UploadFiles(r, hypervisor, image, config, verbose)
	if err != nil {
		return err
	}
	err = qemu.SetArgs(r, hypervisor, image, config.Cmdline)
	if err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 2
0
func Build(r *util.Repo, image *core.Image, template *core.Template, verbose bool, mem string) error {
	if err := os.MkdirAll(filepath.Dir(r.ImagePath(image.Hypervisor, image.Name)), 0777); err != nil {
		return err
	}
	fmt.Printf("Building %s...\n", image.Name)
	if template.Build != "" {
		args := strings.Fields(template.Build)
		cmd := exec.Command(args[0], args[1:]...)
		out, err := cmd.CombinedOutput()
		if err != nil {
			fmt.Println(string(out))
			return err
		}
	}
	if err := checkConfig(template, r, image.Hypervisor); err != nil {
		return err
	}
	if template.RpmBase != nil {
		template.RpmBase.Download()
	}
	cmd := util.CopyFile(r.ImagePath(image.Hypervisor, template.Base), r.ImagePath(image.Hypervisor, image.Name))
	_, err := cmd.Output()
	if err != nil {
		return err
	}
	cmdline := "/tools/cpiod.so"
	if verbose {
		cmdline = "--verbose" + cmdline
	}
	if err := SetArgs(r, image.Hypervisor, image.Name, "/tools/cpiod.so"); err != nil {
		return err
	}
	if template.RpmBase != nil {
		if err := UploadRPM(r, image.Hypervisor, image.Name, template, verbose, mem); err != nil {
			return err
		}
	}
	if err := UploadFiles(r, image.Hypervisor, image.Name, template, verbose, mem); err != nil {
		return err
	}
	return SetArgs(r, image.Hypervisor, image.Name, template.Cmdline)
}
Ejemplo n.º 3
0
func LaunchVM(c *VMConfig) (*exec.Cmd, error) {
	if _, err := os.Stat(c.VMXFile); os.IsNotExist(err) {
		dir := c.InstanceDir
		err := os.MkdirAll(dir, 0777)
		if err != nil {
			fmt.Printf("mkdir failed: %s", dir)
			return nil, err
		}
		cmd := util.CopyFile(c.OriginalVMDK, c.Image)
		_, err = cmd.Output()
		if err != nil {
			fmt.Printf("cp failed: %s", c.OriginalVMDK)
			return nil, err
		}
		err = vmCreateVMXFile(c)
		if err != nil {
			fmt.Printf("Create VMXFile failed: %s", c.VMXFile)
			return nil, err
		}
	}

	StoreConfig(c)

	cmd, err := vmxRun("-T", "ws", "start", c.VMXFile, "nogui")
	if err != nil {
		return nil, err
	}

	conn, err := util.ConnectAndWait("unix", c.sockPath())
	if err != nil {
		return nil, err
	}

	done := make(chan bool)
	go io.Copy(conn, os.Stdin)
	go doRead(done, conn)

	// Wait until the serial connection is disconnected
	<-done

	return cmd, nil
}