Ejemplo n.º 1
0
func main() {
	libmachine.SetDebug(true)

	log.SetOutWriter(os.Stdout)
	log.SetErrWriter(os.Stderr)

	// returns the familiar store at $HOME/.docker/machine
	store := libmachine.GetDefaultStore()

	// over-ride this for now (don't want to muck with my default store)
	store.Path = "/tmp/automatic"

	hostName := "myfunhost"

	// Set some options on the provider...
	driver := virtualbox.NewDriver(hostName, "/tmp/automatic")
	driver.CPU = 2
	driver.Memory = 2048

	h, err := store.NewHost(driver)
	if err != nil {
		log.Fatal(err)
	}

	h.HostOptions.EngineOptions.StorageDriver = "overlay"

	if err := libmachine.Create(store, h); err != nil {
		log.Fatal(err)
	}

	out, err := h.RunSSHCommand("df -h")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Results of your disk space query:\n%s\n", out)

	fmt.Println("Powering down machine now...")
	if err := h.Stop(); err != nil {
		log.Fatal(err)
	}
}
Ejemplo n.º 2
0
func main() {
	if len(os.Args) != 2 {
		bail()
	}

	libmachine.SetDebug(true)

	errR, errW := io.Pipe()
	errTracker := &FancyTracker{
		r: errR,
		w: os.Stderr,
	}

	outR, outW := io.Pipe()
	outTracker := &FancyTracker{
		r: outR,
		w: os.Stdout,
	}

	go errTracker.Track()
	go outTracker.Track()

	dmlog.SetOutWriter(errW)
	dmlog.SetErrWriter(outW)

	store := libmachine.GetDefaultStore()
	store.Path = "./store"

	hostName := "mobydick"

	data, err := ioutil.ReadFile("moby.yml")
	if err != nil {
		log.Fatal(err)
	}

	switch os.Args[1] {
	case "up":
		driver, err := drivermaker.NewDriver("digitalocean", hostName, "./store")
		if err != nil {
			log.Fatal(err)
		}

		h, err := store.NewHost(driver)
		if err != nil {
			log.Fatal(err)
		}

		if err := yaml.Unmarshal(data, h); err != nil {
			log.Fatal(err)
		}

		castedDriver, ok := driver.(*digitalocean.Driver)
		if !ok {
			log.Fatal("Fatal error, shoud be able to cast to driver type \"digitalocean\".")
		}

		driverWrapper := DriverWrapper{castedDriver}

		if err := yaml.Unmarshal(data, &driverWrapper); err != nil {
			log.Fatal(err)
		}

		h.Driver = driverWrapper.DriverOptions
		spew.Dump(h)

		if err := libmachine.Create(store, h); err != nil {
			log.Fatal(err)
		}
	case "apply":
		h, err := store.Get(hostName)
		if err != nil {
			log.Fatal(err)
		}

		spew.Dump(h)

		if err := yaml.Unmarshal(data, h); err != nil {
			log.Fatal(err)
		}

		if err := h.Provision(); err != nil {
			log.Fatal(err)
		}
	default:
		bail()
	}

}