Skip to content

Commit 789d07e

Browse files
committed
schedulerhints: support DifferentCell filter
The TargetCell filter from cells v1 is supported in the code base but support for the DifferentCell filter was never added. DifferentCell filter is part of cells v1 but for anyone still using cells v1 this is useful. Originally part of OpenStack with openstack/nova@596ee87
1 parent 77b238f commit 789d07e

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

openstack/compute/v2/extensions/schedulerhints/requests.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type SchedulerHints struct {
3131
// TargetCell specifies a cell name where the instance will be placed.
3232
TargetCell string `json:"target_cell,omitempty"`
3333

34+
// DifferentCell specifies cells names where an instance should not be placed.
35+
DifferentCell []string `json:"different_cell,omitempty"`
36+
3437
// BuildNearHostIP specifies a subnet of compute nodes to host the instance.
3538
BuildNearHostIP string
3639

@@ -124,6 +127,10 @@ func (opts SchedulerHints) ToServerSchedulerHintsCreateMap() (map[string]interfa
124127
sh["target_cell"] = opts.TargetCell
125128
}
126129

130+
if len(opts.DifferentCell) > 0 {
131+
sh["different_cell"] = opts.DifferentCell
132+
}
133+
127134
if opts.BuildNearHostIP != "" {
128135
if _, _, err := net.ParseCIDR(opts.BuildNearHostIP); err != nil {
129136
err := gophercloud.ErrInvalidInput{}

openstack/compute/v2/extensions/schedulerhints/testing/requests_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ func TestCreateOpts(t *testing.T) {
2525
"a0cf03a5-d921-4877-bb5c-86d26cf818e1",
2626
"8c19174f-4220-44f0-824a-cd1eeef10287",
2727
},
28-
Query: []interface{}{"=", "$free_ram_mb", "1024"},
29-
TargetCell: "foobar",
28+
Query: []interface{}{"=", "$free_ram_mb", "1024"},
29+
TargetCell: "foobar",
30+
DifferentCell: []string{
31+
"bazbar",
32+
"barbaz",
33+
},
3034
BuildNearHostIP: "192.168.1.1/24",
3135
AdditionalProperties: map[string]interface{}{"reservation": "a0cf03a5-d921-4877-bb5c-86d26cf818e1"},
3236
}
@@ -55,6 +59,10 @@ func TestCreateOpts(t *testing.T) {
5559
],
5660
"query": "[\"=\",\"$free_ram_mb\",\"1024\"]",
5761
"target_cell": "foobar",
62+
"different_cell": [
63+
"bazbar",
64+
"barbaz"
65+
],
5866
"build_near_host_ip": "192.168.1.1",
5967
"cidr": "/24",
6068
"reservation": "a0cf03a5-d921-4877-bb5c-86d26cf818e1"
@@ -83,8 +91,12 @@ func TestCreateOptsWithComplexQuery(t *testing.T) {
8391
"a0cf03a5-d921-4877-bb5c-86d26cf818e1",
8492
"8c19174f-4220-44f0-824a-cd1eeef10287",
8593
},
86-
Query: []interface{}{"and", []string{"=", "$free_ram_mb", "1024"}, []string{"=", "$free_disk_mb", "204800"}},
87-
TargetCell: "foobar",
94+
Query: []interface{}{"and", []string{"=", "$free_ram_mb", "1024"}, []string{"=", "$free_disk_mb", "204800"}},
95+
TargetCell: "foobar",
96+
DifferentCell: []string{
97+
"bazbar",
98+
"barbaz",
99+
},
88100
BuildNearHostIP: "192.168.1.1/24",
89101
AdditionalProperties: map[string]interface{}{"reservation": "a0cf03a5-d921-4877-bb5c-86d26cf818e1"},
90102
}
@@ -113,6 +125,10 @@ func TestCreateOptsWithComplexQuery(t *testing.T) {
113125
],
114126
"query": "[\"and\",[\"=\",\"$free_ram_mb\",\"1024\"],[\"=\",\"$free_disk_mb\",\"204800\"]]",
115127
"target_cell": "foobar",
128+
"different_cell": [
129+
"bazbar",
130+
"barbaz"
131+
],
116132
"build_near_host_ip": "192.168.1.1",
117133
"cidr": "/24",
118134
"reservation": "a0cf03a5-d921-4877-bb5c-86d26cf818e1"

0 commit comments

Comments
 (0)