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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
package ec2
import (
"launchpad.net/goamz/ec2"
"launchpad.net/goamz/s3"
"launchpad.net/juju-core/juju/environs"
"net/http"
)
type BootstrapState struct {
ZookeeperInstances []string
}
func LoadState(e environs.Environ) (*BootstrapState, error) {
s, err := e.(*environ).loadState()
if err != nil {
return nil, err
}
return &BootstrapState{s.ZookeeperInstances}, nil
}
func GroupName(e environs.Environ) string {
return e.(*environ).groupName()
}
func MachineGroupName(e environs.Environ, machineId int) string {
return e.(*environ).machineGroupName(machineId)
}
func AuthorizedKeys(path string) (string, error) {
return authorizedKeys(path)
}
func EnvironEC2(e environs.Environ) *ec2.EC2 {
return e.(*environ).ec2()
}
func DeleteStorageContent(s environs.Storage) error {
return s.(*storage).deleteAll()
}
func InstanceEC2(inst environs.Instance) *ec2.Instance {
return inst.(*instance).Instance
}
// BucketStorage returns a storage instance addressing
// an arbitrary s3 bucket.
func BucketStorage(b *s3.Bucket) environs.Storage {
return &storage{
bucket: b,
}
}
var origImagesHost = imagesHost
func init() {
// Make the images data accessible through the "file" protocol.
http.DefaultTransport.(*http.Transport).RegisterProtocol("file", http.NewFileTransport(http.Dir("images")))
}
func UseTestImageData(local bool) {
if local {
imagesHost = "file:"
} else {
imagesHost = origImagesHost
}
}
var originalShortAttempt = shortAttempt
var originalLongAttempt = longAttempt
// ShortTimeouts sets the timeouts to a short period as we
// know that the ec2test server doesn't get better with time,
// and this reduces the test time from 30s to 3s.
func ShortTimeouts(short bool) {
if short {
shortAttempt = attemptStrategy{
total: 0.25e9,
delay: 0.01e9,
}
longAttempt = shortAttempt
} else {
shortAttempt = originalShortAttempt
longAttempt = originalLongAttempt
}
}
func EC2ErrCode(err error) string {
return ec2ErrCode(err)
}
var ZkPortSuffix = zkPortSuffix
// FabricateInstance creates a new fictitious instance
// given an existing instance and a new id.
func FabricateInstance(inst environs.Instance, newId string) environs.Instance {
oldi := inst.(*instance)
newi := &instance{oldi.e, &ec2.Instance{}}
*newi.Instance = *oldi.Instance
newi.InstanceId = newId
return newi
}
|