forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenstack_util.go
52 lines (47 loc) · 1.41 KB
/
openstack_util.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
package cloud
import (
"github.com/evergreen-ci/evergreen/model/host"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
)
const (
// OSStatusActive means the instance is currently running.
OSStatusActive = "ACTIVE"
// OSStatusInProgress means the instance is currently running and processing a request.
OSStatusInProgress = "IN_PROGRESS"
// OSStatusShutOff means the instance has been temporarily stopped.
OSStatusShutOff = "SHUTOFF"
// OSStatusBuilding means the instance is starting up.
OSStatusBuilding = "BUILD"
)
func osStatusToEvgStatus(status string) CloudStatus {
// Note: There is no equivalent to the 'terminated' cloud status since instances are no
// longer detectable once they have been terminated.
switch status {
case OSStatusActive:
return StatusRunning
case OSStatusInProgress:
return StatusRunning
case OSStatusShutOff:
return StatusStopped
case OSStatusBuilding:
return StatusInitializing
default:
return StatusUnknown
}
}
func getSpawnOptions(h *host.Host, s *openStackSettings) servers.CreateOpts {
return servers.CreateOpts{
Name: h.Id,
ImageName: s.ImageName,
FlavorName: s.FlavorName,
SecurityGroups: []string{s.SecurityGroup},
Metadata: makeMapFromTags(makeTags(h)),
}
}
func makeMapFromTags(tags []host.Tag) map[string]string {
new := make(map[string]string)
for _, tag := range tags {
new[tag.Key] = tag.Value
}
return new
}