Created
December 5, 2015 19:29
-
-
Save dave-tucker/5e68ffe8d175330f15cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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