This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
store.go
58 lines (47 loc) · 1.95 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
48
49
50
51
52
53
54
55
56
57
58
package store
import (
"context"
"github.com/docker/stacks/pkg/interfaces"
"github.com/docker/stacks/pkg/types"
)
// StackStore is an implementation of the types.StackStore interface,
// which provides for the storage and retrieval of Stack objects from the
// swarmkit object store.
type StackStore struct {
client ResourcesClient
}
// New creates a new StackStore using the provided client.
func New(client ResourcesClient) *StackStore {
return &StackStore{
client: client,
}
}
// AddStack creates a new Stack object in the swarmkit data store. It returns
// the ID of the new object if successful, or an error otherwise.
func (s *StackStore) AddStack(stackSpec types.StackSpec) (string, error) {
return AddStack(context.TODO(), s.client, stackSpec)
}
// UpdateStack updates an existing Stack object
func (s *StackStore) UpdateStack(id string, stackSpec types.StackSpec, version uint64) error {
return UpdateStack(context.TODO(), s.client, id, stackSpec, version)
}
// UpdateSnapshotStack updates an existing SnapshotStack object
func (s *StackStore) UpdateSnapshotStack(id string, snapshotStack interfaces.SnapshotStack, version uint64) (interfaces.SnapshotStack, error) {
return UpdateSnapshotStack(context.TODO(), s.client, id, snapshotStack, version)
}
// DeleteStack removes the stacks with the given ID.
func (s *StackStore) DeleteStack(id string) error {
return DeleteStack(context.TODO(), s.client, id)
}
// GetStack retrieves and returns an exist types.Stack object by ID.
func (s *StackStore) GetStack(id string) (types.Stack, error) {
return GetStack(context.TODO(), s.client, id)
}
// GetSnapshotStack retrieves and returns an exist types.Stack object by ID.
func (s *StackStore) GetSnapshotStack(id string) (interfaces.SnapshotStack, error) {
return GetSnapshotStack(context.TODO(), s.client, id)
}
// ListStacks lists all available stack objects
func (s *StackStore) ListStacks() ([]types.Stack, error) {
return ListStacks(context.TODO(), s.client)
}