Skip to content

Commit d6dc7ff

Browse files
committed
Allow filtering servers by their metadata
1 parent 2ff897d commit d6dc7ff

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/corelib/Compute/v2_1/ServerListOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ namespace OpenStack.Compute.v2_1
66
/// <summary />
77
public class ServerListOptions : PageOptions
88
{
9+
/// <summary />
10+
public ServerListOptions()
11+
{
12+
Metadata = new Dictionary<string, string>();
13+
}
14+
915
/// <summary />
1016
public DateTimeOffset? UpdatedAfter { get; set; }
1117

@@ -21,6 +27,9 @@ public class ServerListOptions : PageOptions
2127
/// <summary />
2228
public ServerStatus Status { get; set; }
2329

30+
/// <summary />
31+
public IDictionary<string, string> Metadata { get; set; }
32+
2433
/// <summary />
2534
protected override IDictionary<string, object> BuildQueryString()
2635
{
@@ -30,6 +39,7 @@ protected override IDictionary<string, object> BuildQueryString()
3039
queryString["flavor"] = FlavorId;
3140
queryString["name"] = Name;
3241
queryString["status"] = Status;
42+
queryString["metadata"] = Metadata;
3343

3444
return queryString;
3545
}

src/testing/integration/Compute/v2_1/ServerTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,27 @@ public async Task FindServersTest()
148148
{
149149
var servers = await _testData.CreateServers();
150150
await Task.WhenAll(servers.Select(x => x.WaitUntilActiveAsync()));
151+
152+
var serverWithMetadata = servers.First();
153+
var fooValue = Guid.NewGuid().ToString();
154+
await serverWithMetadata.Metadata.CreateAsync("foo", fooValue);
155+
151156
var serversNames = new HashSet<string>(servers.Select(s => s.Name));
152157

153158
var results = await _compute.ListServerSummariesAsync(new ServerListOptions {Name = "ci-*"});
154159
var resultNames = new HashSet<string>(results.Select(s => s.Name));
155160

156161
Assert.Subset(resultNames, serversNames);
162+
163+
Trace.WriteLine("Filtering servers by their metadata...");
164+
results = await _compute.ListServerSummariesAsync(new ServerListOptions
165+
{
166+
Metadata =
167+
{
168+
{"foo", fooValue}
169+
}
170+
});
171+
Assert.Equal(1, results.Count());
157172
}
158173

159174
[Fact]

src/testing/unit/Compute/v2_1/ServerTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ public void SerializeServerWithoutSchedulerHints()
4444
Assert.Equal(expectedJson, json);
4545
}
4646

47+
[Fact]
48+
public void SerializeListServerOptionsInUrl()
49+
{
50+
using (var httpTest = new HttpTest())
51+
{
52+
httpTest.RespondWithJson(new ServerSummaryCollection());
53+
_compute.ListServerSummaries(new ServerListOptions());
54+
httpTest.ShouldNotHaveCalled("*metadata*");
55+
}
56+
}
57+
4758
[Fact]
4859
public void CreateServer()
4960
{

0 commit comments

Comments
 (0)