-
Notifications
You must be signed in to change notification settings - Fork 1
/
compute_servergroup_v2.go
57 lines (48 loc) · 1.5 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package viettelidc
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
}
func expandComputeServerGroupV2RulesMaxServerPerHost(raw []interface{}) int {
for _, raw := range raw {
raw, ok := raw.(map[string]interface{})
if !ok {
return 0
}
v, ok := raw["max_server_per_host"].(int)
if !ok {
return 0
}
//nolint:staticcheck // we need the first element
return v
}
return 0
}