-
Notifications
You must be signed in to change notification settings - Fork 6
/
deploy.go
79 lines (63 loc) · 1.47 KB
/
deploy.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
package tweed
import (
"fmt"
)
func (c *Core) Provision(inst *Instance) (string, error) {
if inst.ID == "" {
return "", fmt.Errorf("no service instance id specified")
}
if c.Count(inst.Plan) >= inst.Plan.Tweed.Limit {
return "", fmt.Errorf("too many instances of this service have been provisioned")
}
t, err := inst.Provision()
if err != nil {
return "", err
}
if c.instances == nil {
c.instances = make(map[string]*Instance)
}
c.instances[inst.ID] = inst
return t.id, nil
}
func (c *Core) Bind(id, bid string) (string, error) {
if id == "" {
return "", fmt.Errorf("no service instance id specified")
}
if bid == "" {
return "", fmt.Errorf("no service instance binding id specified")
}
if inst, ok := c.instances[id]; ok {
t, err := inst.Bind(bid)
if err != nil {
return "", err
}
return t.id, nil
} else {
return "", fmt.Errorf("instance '%s' not found", id)
}
}
func (c *Core) Unbind(id, bid string) (string, error) {
if inst, ok := c.instances[id]; ok {
t, err := inst.Unbind(bid)
if err != nil {
return "", err
}
return t.id, nil
} else {
return "", fmt.Errorf("instance '%s' not found", id)
}
}
func (c *Core) Deprovision(id string) (string, bool, error) {
if inst, ok := c.instances[id]; ok {
if inst.IsGone() {
return "", true, nil
}
t, err := inst.Deprovision()
if err != nil {
return "", false, err
}
return t.id, false, nil
} else {
return "", false, fmt.Errorf("instance '%s' not found", id)
}
}