/
compute_servergroup_v2.go
41 lines (33 loc) · 1.18 KB
/
compute_servergroup_v2.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
package openstack
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups"
)
const (
antiAffinityPolicy = "anti-affinity"
affinityPolicy = "affinity"
)
// ServerGroupCreateOpts is a custom ServerGroup struct to include the
// ValueSpecs field.
type ComputeServerGroupV2CreateOpts struct {
servergroups.CreateOpts
ValueSpecs map[string]string `json:"value_specs,omitempty"`
}
// ToServerGroupCreateMap casts a CreateOpts struct to a map.
// It overrides routers.ToServerGroupCreateMap to add the ValueSpecs field.
func (opts ComputeServerGroupV2CreateOpts) ToServerGroupCreateMap() (map[string]interface{}, error) {
return BuildRequest(opts, "server_group")
}
func expandComputeServerGroupV2Policies(client *gophercloud.ServiceClient, raw []interface{}) []string {
policies := make([]string, len(raw))
for i, v := range raw {
client.Microversion = "2.15"
policy := v.(string)
policies[i] = policy
// Set microversion for legacy policies to empty to not change behaviour for those policies
if policy == antiAffinityPolicy || policy == affinityPolicy {
client.Microversion = ""
}
}
return policies
}