Skip to content

Commit 201e932

Browse files
committed
Return summaries from list flavors
* ListFlavors returns Flavor * ListFlavorSummaries returns FlavorSummary * Server has a FlavorReference
1 parent f622ab9 commit 201e932

12 files changed

Lines changed: 52 additions & 43 deletions

File tree

src/corelib/Compute/v2_1/ComputeApiBuilder.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,33 +470,33 @@ protected ComputeApiBuilder(IServiceType serviceType, IAuthenticationProvider au
470470
}
471471

472472
/// <summary />
473-
public virtual async Task<T> ListFlavorsAsync<T>(CancellationToken cancellationToken = default(CancellationToken))
473+
public virtual async Task<T> ListFlavorSummariesAsync<T>(CancellationToken cancellationToken = default(CancellationToken))
474474
where T : IEnumerable<IServiceResource>
475475
{
476-
return await BuildListFlavorsAsync(cancellationToken)
476+
return await BuildListFlavorSummariesAsync(cancellationToken)
477477
.SendAsync()
478478
.ReceiveJson<T>()
479479
.PropogateOwnerToChildren(this);
480480
}
481481

482482
/// <summary />
483-
public virtual Task<PreparedRequest> BuildListFlavorsAsync(CancellationToken cancellationToken = default(CancellationToken))
483+
public virtual Task<PreparedRequest> BuildListFlavorSummariesAsync(CancellationToken cancellationToken = default(CancellationToken))
484484
{
485485
return Endpoint.PrepareListResourcesRequest("flavors", cancellationToken);
486486
}
487487

488488
/// <summary />
489-
public virtual async Task<T> ListFlavorDetailsAsync<T>(CancellationToken cancellationToken = default(CancellationToken))
489+
public virtual async Task<T> ListFlavorsAsync<T>(CancellationToken cancellationToken = default(CancellationToken))
490490
where T : IEnumerable<IServiceResource>
491491
{
492-
return await BuildListFlavorDetailsAsync(cancellationToken)
492+
return await BuildListFlavorsAsync(cancellationToken)
493493
.SendAsync()
494494
.ReceiveJson<T>()
495495
.PropogateOwnerToChildren(this);
496496
}
497497

498498
/// <summary />
499-
public virtual Task<PreparedRequest> BuildListFlavorDetailsAsync(CancellationToken cancellationToken = default(CancellationToken))
499+
public virtual Task<PreparedRequest> BuildListFlavorsAsync(CancellationToken cancellationToken = default(CancellationToken))
500500
{
501501
return Endpoint.PrepareListResourcesRequest("flavors/detail", cancellationToken);
502502
}

src/corelib/Compute/v2_1/ComputeService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,16 @@ public ComputeService(IAuthenticationProvider authenticationProvider, string reg
195195
return _computeApi.GetFlavorAsync<Flavor>(flavorId, cancellationToken);
196196
}
197197

198-
/// <inheritdoc cref="ComputeApiBuilder.ListFlavorsAsync{T}" />
199-
public async Task<IEnumerable<FlavorReference>> ListFlavorsAsync(CancellationToken cancellationToken = default(CancellationToken))
198+
/// <inheritdoc cref="ComputeApiBuilder.ListFlavorSummariesAsync{T}" />
199+
public async Task<IEnumerable<FlavorSummary>> ListFlavorSummariesAsync(CancellationToken cancellationToken = default(CancellationToken))
200200
{
201-
return await _computeApi.ListFlavorsAsync<FlavorReferenceCollection>(cancellationToken);
201+
return await _computeApi.ListFlavorSummariesAsync<FlavorSummaryCollection>(cancellationToken);
202202
}
203203

204-
/// <inheritdoc cref="ComputeApiBuilder.ListFlavorDetailsAsync{T}" />
205-
public async Task<IEnumerable<Flavor>> ListFlavorDetailsAsync(CancellationToken cancellationToken = default(CancellationToken))
204+
/// <inheritdoc cref="ComputeApiBuilder.ListFlavorsAsync{T}" />
205+
public async Task<IEnumerable<Flavor>> ListFlavorsAsync(CancellationToken cancellationToken = default(CancellationToken))
206206
{
207-
return await _computeApi.ListFlavorDetailsAsync<FlavorCollection>(cancellationToken);
207+
return await _computeApi.ListFlavorsAsync<FlavorCollection>(cancellationToken);
208208
}
209209

210210
#endregion

src/corelib/Compute/v2_1/ComputeServiceExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,16 @@ public static Flavor GetFlavor(this ComputeService service, Identifier flavorId)
176176
return service.GetFlavorAsync(flavorId).ForceSynchronous();
177177
}
178178

179-
/// <inheritdoc cref="ComputeService.ListFlavorsAsync" />
180-
public static IEnumerable<FlavorReference> ListFlavors(this ComputeService service)
179+
/// <inheritdoc cref="ComputeService.ListFlavorSummariesAsync" />
180+
public static IEnumerable<FlavorSummary> ListFlavorSummaries(this ComputeService service)
181181
{
182-
return service.ListFlavorsAsync().ForceSynchronous();
182+
return service.ListFlavorSummariesAsync().ForceSynchronous();
183183
}
184184

185-
/// <inheritdoc cref="ComputeService.ListFlavorDetailsAsync" />
186-
public static IEnumerable<Flavor> ListFlavorDetails(this ComputeService service)
185+
/// <inheritdoc cref="ComputeService.ListFlavorsAsync" />
186+
public static IEnumerable<Flavor> ListFlavors(this ComputeService service)
187187
{
188-
return service.ListFlavorDetailsAsync().ForceSynchronous();
188+
return service.ListFlavorsAsync().ForceSynchronous();
189189
}
190190
#endregion
191191

src/corelib/Compute/v2_1/Flavor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace OpenStack.Compute.v2_1
55
{
66
/// <summary />
77
[JsonConverterWithConstructor(typeof(RootWrapperConverter), "flavor")]
8-
public class Flavor : FlavorReference
8+
public class Flavor : FlavorSummary
99
{
1010
/// <summary />
1111
[JsonProperty("disk")]

src/corelib/Compute/v2_1/FlavorReference.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ public class FlavorReference : IHaveExtraData, IServiceResource
1515
[JsonProperty("id")]
1616
public Identifier Id { get; set; }
1717

18-
/// <summary /> // In some cases, only the id is populated. Use GetFlavor if Name is null.
19-
[JsonProperty("name")]
20-
public string Name { get; set; }
21-
2218
/// <summary />
2319
[JsonExtensionData]
2420
IDictionary<string, JToken> IHaveExtraData.Data { get; set; } = new Dictionary<string, JToken>();
2521

2622
object IServiceResource.Owner { get; set; }
2723

2824
/// <inheritdoc cref="ComputeApiBuilder.GetFlavorAsync{T}" />
29-
/// <exception cref="InvalidOperationException">When the <see cref="FlavorReference"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
25+
/// <exception cref="InvalidOperationException">When the <see cref="FlavorSummary"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
3026
public Task<Flavor> GetFlavorAsync(CancellationToken cancellationToken = default(CancellationToken))
3127
{
3228
var owner = this.GetOwnerOrThrow<ComputeApiBuilder>();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Newtonsoft.Json;
2+
3+
namespace OpenStack.Compute.v2_1
4+
{
5+
/// <summary />
6+
public class FlavorSummary : FlavorReference
7+
{
8+
/// <summary /> // In some cases, only the id is populated. Use GetFlavor if Name is null.
9+
[JsonProperty("name")]
10+
public string Name { get; set; }
11+
}
12+
}

src/corelib/Compute/v2_1/Serialization/FlavorCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public class FlavorCollection<T> : ResourceCollection<T>
1919
}
2020

2121
/// <summary>
22-
/// Represents a collection of references to flavor resources of the <see cref="ComputeService"/>.
22+
/// Represents a collection of flavor summary resources of the <see cref="ComputeService"/>.
2323
/// </summary>
2424
/// <exclude />
25-
public class FlavorReferenceCollection : FlavorCollection<FlavorReference>
25+
public class FlavorSummaryCollection : FlavorCollection<FlavorSummary>
2626
{ }
2727

2828
/// <inheritdoc cref="FlavorCollection{T}" />

src/corelib/OpenStack.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<Compile Include="Compute\v2_1\Actions\StopServerRequest.cs" />
9898
<Compile Include="Compute\v2_1\AddressType.cs" />
9999
<Compile Include="Compute\v2_1\Flavor.cs" />
100+
<Compile Include="Compute\v2_1\FlavorReference.cs" />
100101
<Compile Include="Compute\v2_1\ImageMetadataExtensions.cs" />
101102
<Compile Include="Compute\v2_1\ImageExtensions.cs" />
102103
<Compile Include="Compute\v2_1\Image.cs" />
@@ -150,7 +151,7 @@
150151
<Compile Include="Compute\v2_1\ServerBlockDeviceMapping.cs" />
151152
<Compile Include="Compute\v2_1\ServerCreateDefinition.cs" />
152153
<Compile Include="Compute\v2_1\DiskConfiguration.cs" />
153-
<Compile Include="Compute\v2_1\FlavorReference.cs" />
154+
<Compile Include="Compute\v2_1\FlavorSummary.cs" />
154155
<Compile Include="Compute\v2_1\ImageReference.cs" />
155156
<Compile Include="Compute\v2_1\KeyPairSummary.cs" />
156157
<Compile Include="Compute\v2_1\KeyPairDefinition.cs" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private async Task<Identifier> GetDefaultFlavor()
108108
{
109109
if (_defaultFlavor == null)
110110
{
111-
var flavors = await _compute.ListFlavorsAsync();
111+
var flavors = await _compute.ListFlavorSummariesAsync();
112112
_defaultFlavor = flavors.First(x => x.Name == "m1.tiny").Id;
113113
}
114114
return _defaultFlavor;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public void Dispose()
3333
}
3434

3535
[Fact]
36-
public async Task ListFlavorsTest()
36+
public async Task ListFlavorSummariesTest()
3737
{
38-
var results = await _compute.ListFlavorsAsync();
38+
var results = await _compute.ListFlavorSummariesAsync();
3939

4040
Assert.NotNull(results);
4141
Assert.All(results, result => Assert.NotNull(result.Id));
@@ -45,7 +45,7 @@ public async Task ListFlavorsTest()
4545
[Fact]
4646
public async Task GetFlavorTest()
4747
{
48-
var results = await _compute.ListFlavorsAsync();
48+
var results = await _compute.ListFlavorSummariesAsync();
4949

5050
var flavorRef = results.FirstOrDefault(x => x.Name == "m1.tiny");
5151
var flavor = await flavorRef.GetFlavorAsync();
@@ -60,9 +60,9 @@ public async Task GetFlavorTest()
6060
}
6161

6262
[Fact]
63-
public async Task ListFlavorDetailsTest()
63+
public async Task ListFlavorsTest()
6464
{
65-
var results = await _compute.ListFlavorDetailsAsync();
65+
var results = await _compute.ListFlavorsAsync();
6666

6767
Assert.NotNull(results);
6868
Assert.True(results.Any());

0 commit comments

Comments
 (0)