Skip to content

Instantly share code, notes, and snippets.

@dave-tucker
Created December 5, 2015 22:16
Show Gist options
  • Save dave-tucker/b7928cfbe1c8a4549858 to your computer and use it in GitHub Desktop.
Save dave-tucker/b7928cfbe1c8a4549858 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/docker/machine/commands/mcndirs"
"github.com/docker/machine/libmachine"
)
func GetMachines() error {
api := libmachine.GetDefaultStore()
api.Path = mcndirs.GetBaseDir()
log.Info("Listing machines")
machines, err := api.List()
if err != nil {
return err
}
if len(machines) == 0 {
return fmt.Errorf("no machines!")
}
log.Info("Getting host IPs...")
for m := range machines {
ip, err := machines[m].Driver.GetIP()
if err != nil {
return err
}
log.Infof("IP: %s", ip)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment