-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
77 lines (64 loc) · 1.89 KB
/
utils.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
package broker
import (
"errors"
"github.com/pivotal-cf/brokerapi"
"strconv"
"strings"
)
func (b *Broker) instanceExists(instID string) bool {
_, err := b.S3.GetObjectInfo(b.BrokerConfig.BucketName, b.getInstanceObjName(instID))
return err == nil
}
func (b *Broker) bindingExists(instID string, bindID string) bool {
_, err := b.S3.GetObjectInfo(b.BrokerConfig.BucketName, b.getBindObjName(instID, bindID))
return err == nil
}
//Returns the number of provisioned instances
func (b *Broker) provisionCount() int {
objs, done := b.S3.GetObjects(b.BrokerConfig.BucketName, b.BrokerConfig.InstancePrefix, false)
defer close(done)
count := 0
for range objs {
count++
}
return count
}
//Returns true if the provisioned instance has any binds
func (b *Broker) hasBinds(instID string) bool {
objs, done := b.S3.GetObjects(b.BrokerConfig.BucketName, b.getInstanceObjName(instID)+"/", false)
defer close(done)
for range objs {
return true
}
return false
}
func (b *Broker) getPlan(planID string) (*brokerapi.ServicePlan, error) {
for _, p := range b.ServiceConfig[0].Plans {
if p.ID == planID {
return &p, nil
}
}
return nil, errors.New("Plan with ID '" + planID + "' not found")
}
func (b *Broker) getPlanQuota(planID string) (int, error) {
p, err := b.getPlan(planID)
if err != nil {
return -1, err
}
i, err := strconv.Atoi(p.Metadata.AdditionalMetadata["quotaMB"].(string))
if err != nil {
return -1, err
}
return i, nil
}
func createTenantID(instanceID string) string {
return strings.Replace(instanceID, "-", "", -1)
}
//Converts the instance ID into the object name format
func (b *Broker) getInstanceObjName(instID string) string {
return b.BrokerConfig.InstancePrefix + instID
}
//Converts the instance and binding IDs into the object name format
func (b *Broker) getBindObjName(instID string, bindID string) string {
return b.BrokerConfig.InstancePrefix + instID + "/" + bindID
}