api: starting on allocs

This commit is contained in:
Ryan Uber
2015-09-08 15:37:07 -07:00
parent 6ff44fa0c4
commit bf548e7947
2 changed files with 57 additions and 0 deletions

37
api/allocs.go Normal file
View File

@@ -0,0 +1,37 @@
package api
// Allocs is used to query the alloc-related endpoints.
type Allocs struct {
client *Client
}
// Allocs returns a handle on the allocs endpoints.
func (c *Client) Allocs() *Allocs {
return &Allocs{client: c}
}
// List returns a list of all of the allocations.
func (a *Allocs) List() ([]*Alloc, error) {
var resp []*Alloc
_, err := a.client.query("/v1/allocations", &resp, nil)
if err != nil {
return nil, err
}
return resp, nil
}
// Alloc is used for serialization of allocations.
type Alloc struct {
ID string
EvalID string
Name string
NodeID string
JobID string
TaskGroup string
DesiredStatus string
DesiredDescription string
ClientStatus string
ClientDescription string
CreateIndex uint64
ModifyIndex uint64
}

20
api/allocs_test.go Normal file
View File

@@ -0,0 +1,20 @@
package api
import (
"testing"
)
func TestAllocs_List(t *testing.T) {
c, s := makeClient(t, nil, nil)
defer s.Stop()
a := c.Allocs()
// Querying when no allocs exist returns nothing
allocs, err := a.List()
if err != nil {
t.Fatalf("err: %s", err)
}
if n := len(allocs); n != 0 {
t.Fatalf("expected 0 allocs, got: %d", n)
}
}