func (c *RebuildCommand) Execute(args []string) error { var cfg *config.Config steps := Steps{ { "Reading configuration", func() error { cfg, err := config.New(os.ExpandEnv("$USER")) if err != nil { return err } return cfg.Load() }, }, { "Rebuilding disk image", func() error { if cfg.DiskSize != c.Disk { cfg.DiskSize = c.Disk err := cfg.Save() if err != nil { return err } } d := disk.New(cfg) d.Detach() return d.Create() }, }, } return Spin(steps) }
func (v *VM) Start() (chan error, error) { d := disk.New(v.config) err := d.Attach() if err != nil { return nil, err } dev, err := d.RawDevice() if err != nil { return nil, err } sshBytes, err := ioutil.ReadFile(filepath.Join(v.config.Dir, "key.pub")) if err != nil { return nil, err } sshKey := base64.StdEncoding.EncodeToString(sshBytes) cmdline := fmt.Sprintf("console=ttyS0 hostname=dlite uuid=%s dns_server=%s user_name=%s user_id=%d ssh_key=%s docker_version=%s docker_extra=%s", v.config.Uuid, v.config.DNSServer, v.config.Username, v.config.Uid, sshKey, v.config.DockerVersion, v.config.Extra, ) args := []string{ "-A", "-c", fmt.Sprintf("%d", v.config.CpuCount), "-m", fmt.Sprintf("%dG", v.config.Memory), "-s", "0:0,hostbridge", "-l", "com1,autopty", "-s", "31,lpc", "-s", "2:0,virtio-net", "-s", fmt.Sprintf("4,ahci-hd,%s", dev), "-U", v.config.Uuid, "-f", fmt.Sprintf("kexec,%s,%s,%s", filepath.Join(v.config.Dir, "bzImage"), filepath.Join(v.config.Dir, "rootfs.cpio.xz"), cmdline), } pty := make(chan string) done := make(chan error) go func(args []string, pty chan string, done chan error) { done <- xhyve.Run(args, pty) }(args, pty, done) v.tty = <-pty return done, os.Chown(v.tty, v.config.Uid, v.config.Gid) }
func (c *InstallCommand) Execute(args []string) error { versionMsg := "the latest version" if c.Version != "" { versionMsg = "version " + c.Version } fmt.Printf(` The install command will make the following changes to your system: - Create a '.dlite' directory in your home - Create a %d GiB sparse disk image in the '.dlite' directory - Download %s of DhyveOS to the '.dlite' directory - Create a 'config.json' file in the '.dlite' directory - Create a new SSH key pair in the '.dlite' directory for the vm - Create a launchd agent in '/Library/LaunchDaemons' used to run the privileged daemon - Store logs from the daemon in '/Library/Logs' - Create a launchd agent in '~/Library/LaunchAgents' used to start the privileged daemon under this user's context `, c.Disk, versionMsg) fmt.Print("Would you like to continue? (Y/n): ") reader := bufio.NewReader(os.Stdin) response, err := reader.ReadString('\n') if err != nil { return err } response = strings.ToLower(strings.TrimSpace(response)) if response == "n" || response == "no" { return fmt.Errorf("Aborted install due to user input") } if response != "" && response != "y" && response != "yes" { return fmt.Errorf("Aborted install due to invalid user input") } var cfg *config.Config steps := Steps{ { "Creating configuration", func() error { cfg, err := config.New(os.ExpandEnv("$USER")) if err != nil { return err } if c.DockerVersion == "" { latest, err := docker.Latest() if err != nil { return err } c.DockerVersion = latest } if c.Cpus == 0 { c.Cpus = runtime.NumCPU() } cfg.CpuCount = c.Cpus cfg.DockerVersion = c.DockerVersion cfg.Uuid = uuid.NewV1().String() cfg.Memory = c.Memory cfg.Hostname = c.Hostname cfg.DockerVersion = c.DockerVersion cfg.Extra = c.Extra cfg.DNSServer = c.DNSServer cfg.DiskSize = c.Disk cfg.Route = c.Route return cfg.Save() }, }, { "Building disk image", func() error { d := disk.New(cfg) d.Detach() return d.Create() }, }, { "Downloading OS", func() error { var vers dliteos.Version var err error if c.Version == "" { vers, err = dliteos.Latest() } else { vers, err = dliteos.Specific(c.Version) } if err != nil { return err } return dliteos.Download(cfg.Dir, vers) }, }, { "Generating SSH key", func() error { s := ssh.New(cfg) return s.Generate() }, }, } return Spin(steps) }