forked from docker/machine
/
store.go
47 lines (37 loc) · 1.03 KB
/
store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package persist
import (
"github.com/docker/machine/libmachine/host"
)
type Store interface {
// Exists returns whether a machine exists or not
Exists(name string) (bool, error)
// List returns a list of all hosts in the store
List() ([]string, error)
// Load loads a host by name
Load(name string) (*host.Host, error)
// Remove removes a machine from the store
Remove(name string) error
// Save persists a machine in the store
Save(host *host.Host) error
}
func LoadHosts(s Store, hostNames []string) ([]*host.Host, map[string]error) {
loadedHosts := []*host.Host{}
errors := map[string]error{}
for _, hostName := range hostNames {
h, err := s.Load(hostName)
if err != nil {
errors[hostName] = err
} else {
loadedHosts = append(loadedHosts, h)
}
}
return loadedHosts, errors
}
func LoadAllHosts(s Store) ([]*host.Host, map[string]error, error) {
hostNames, err := s.List()
if err != nil {
return nil, nil, err
}
loadedHosts, hostInError := LoadHosts(s, hostNames)
return loadedHosts, hostInError, nil
}