mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 10:55:42 +03:00
api: starting on allocs
This commit is contained in:
37
api/allocs.go
Normal file
37
api/allocs.go
Normal 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
20
api/allocs_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user