Skip to content

Instantly share code, notes, and snippets.

@dave-tucker
Created December 5, 2015 19:29
Show Gist options
  • Save dave-tucker/5e68ffe8d175330f15cf to your computer and use it in GitHub Desktop.
Save dave-tucker/5e68ffe8d175330f15cf 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"
"github.com/docker/machine/libmachine/persist"
)
func GetMachines() error {
api := libmachine.NewClient(mcndirs.GetBaseDir())
machines, err := api.List()
if err != nil {
return err
}
log.Infof("Loading hosts... ")
hosts, err := persist.LoadHosts(api, machines)
if err != nil {
return err
}
if len(hosts) < 1 {
return fmt.Errorf("no machines!")
}
log.Infof("Getting host IPs...")
for h := range hosts {
ip, err := hosts[h].Driver.GetIP()
if err != nil {
return err
}
log.Info("Machine: %s IP: %s", hosts[h].Name, ip)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment