-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
84 lines (65 loc) · 1.9 KB
/
client.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package client
import (
"github.com/cloudfoundry-incubator/garden"
"github.com/cloudfoundry-incubator/garden/client/connection"
)
type Client interface {
garden.Client
}
type client struct {
connection connection.Connection
}
func New(connection connection.Connection) Client {
return &client{
connection: connection,
}
}
func (client *client) Ping() error {
return client.connection.Ping()
}
func (client *client) Capacity() (garden.Capacity, error) {
return client.connection.Capacity()
}
func (client *client) Create(spec garden.ContainerSpec) (garden.Container, error) {
handle, err := client.connection.Create(spec)
if err != nil {
return nil, err
}
return newContainer(handle, client.connection), nil
}
func (client *client) Containers(properties garden.Properties) ([]garden.Container, error) {
handles, err := client.connection.List(properties)
if err != nil {
return nil, err
}
containers := []garden.Container{}
for _, handle := range handles {
containers = append(containers, newContainer(handle, client.connection))
}
return containers, nil
}
func (client *client) Destroy(handle string) error {
err := client.connection.Destroy(handle)
if err, ok := err.(connection.Error); ok && err.StatusCode == 404 {
return garden.ContainerNotFoundError{handle}
}
return err
}
func (client *client) BulkInfo(handles []string) (map[string]garden.ContainerInfoEntry, error) {
return client.connection.BulkInfo(handles)
}
func (client *client) BulkMetrics(handles []string) (map[string]garden.ContainerMetricsEntry, error) {
return client.connection.BulkMetrics(handles)
}
func (client *client) Lookup(handle string) (garden.Container, error) {
handles, err := client.connection.List(nil)
if err != nil {
return nil, err
}
for _, h := range handles {
if h == handle {
return newContainer(handle, client.connection), nil
}
}
return nil, garden.ContainerNotFoundError{handle}
}