-
Notifications
You must be signed in to change notification settings - Fork 15
/
name_factory.go
78 lines (71 loc) · 2.47 KB
/
name_factory.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
package integration_tests
import (
"fmt"
"strings"
)
//Names ...
type Names struct {
Buckets []string
Volumes []string
Shares []string
Hosts []string
Networks []string
Clusters []string
}
func GetNames(coreString string, nbBukets int, nbVolumes int, nbShares int, nbHosts int, nbNetworks int, nbClusters int) Names {
coreString = strings.ToLower(coreString)
names := Names{
Buckets: []string{},
Volumes: []string{},
Shares: []string{},
Hosts: []string{},
Networks: []string{},
Clusters: []string{},
}
for i := 1; i <= nbBukets; i++ {
names.Buckets = append(names.Buckets, fmt.Sprintf("%s-bucket-%d", coreString, i))
}
for i := 1; i <= nbVolumes; i++ {
names.Volumes = append(names.Volumes, fmt.Sprintf("%s-volume-%d", coreString, i))
}
for i := 1; i <= nbShares; i++ {
names.Shares = append(names.Shares, fmt.Sprintf("%s-share-%d", coreString, i))
}
for i := 1; i <= nbHosts; i++ {
names.Hosts = append(names.Hosts, fmt.Sprintf("%s-host-%d", coreString, i))
}
for i := 1; i <= nbNetworks; i++ {
names.Networks = append(names.Networks, fmt.Sprintf("%s-network-%d", coreString, i))
}
for i := 1; i <= nbClusters; i++ {
names.Clusters = append(names.Clusters, fmt.Sprintf("%s-cluster-%d", coreString, i))
}
return names
}
func (names *Names) TearDown() {
//TODO is it possible to suppress a non empty bucket?
for _, bucketName := range names.Buckets {
_, _ = GetTaggedOutput(fmt.Sprintf("safescale bucket delete %s", bucketName), "Teardown: ")
}
for _, volumeName := range names.Volumes {
for _, hostName := range names.Hosts {
_, _ = GetTaggedOutput(fmt.Sprintf("safescale volume detach %s %s", volumeName, hostName), "Teardown: ")
}
_, _ = GetTaggedOutput(fmt.Sprintf("safescale volume delete %s", volumeName), "Teardown: ")
}
for _, shareName := range names.Shares {
for _, hostName := range names.Hosts {
_, _ = GetTaggedOutput(fmt.Sprintf("safescale share umount %s %s", shareName, hostName), "Teardown: ")
}
_, _ = GetTaggedOutput(fmt.Sprintf("safescale share delete %s", shareName), "Teardown: ")
}
for _, hostName := range names.Hosts {
_, _ = GetTaggedOutput(fmt.Sprintf("safescale host delete %s", hostName), "Teardown: ")
}
for _, networkName := range names.Networks {
_, _ = GetTaggedOutput(fmt.Sprintf("safescale network delete %s", networkName), "Teardown: ")
}
for _, clusterName := range names.Clusters {
_, _ = GetTaggedOutput(fmt.Sprintf("safescale cluster delete --yes %s", clusterName), "Teardown: ")
}
}