Skip to content

Commit a1261e2

Browse files
committed
Enable paging/filtering flavors
1 parent c811322 commit a1261e2

6 files changed

Lines changed: 75 additions & 29 deletions

File tree

src/corelib/Compute/v2_1/ComputeService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@ public ComputeService(IAuthenticationProvider authenticationProvider, string reg
222222
}
223223

224224
/// <inheritdoc cref="ComputeApi.ListFlavorSummariesAsync{T}" />
225-
public async Task<IEnumerable<FlavorSummary>> ListFlavorSummariesAsync(CancellationToken cancellationToken = default(CancellationToken))
225+
public async Task<IPage<FlavorSummary>> ListFlavorSummariesAsync(FlavorListOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
226226
{
227-
return await _computeApi.ListFlavorSummariesAsync<FlavorSummaryCollection>(cancellationToken).ConfigureAwait(false);
227+
return await _computeApi.ListFlavorSummariesAsync<FlavorSummaryCollection>(options, cancellationToken).ConfigureAwait(false);
228228
}
229229

230230
/// <inheritdoc cref="ComputeApi.ListFlavorsAsync{T}" />
231-
public async Task<IEnumerable<Flavor>> ListFlavorsAsync(CancellationToken cancellationToken = default(CancellationToken))
231+
public async Task<IPage<Flavor>> ListFlavorsAsync(FlavorListOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
232232
{
233-
return await _computeApi.ListFlavorsAsync<FlavorCollection>(cancellationToken).ConfigureAwait(false);
233+
return await _computeApi.ListFlavorsAsync<FlavorCollection>(options, cancellationToken).ConfigureAwait(false);
234234
}
235235

236236
#endregion
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections.Generic;
2+
3+
namespace OpenStack.Compute.v2_1
4+
{
5+
/// <summary>
6+
/// Optional filter and paging options when listing flavors.
7+
/// </summary>
8+
public class FlavorListOptions : PageOptions
9+
{
10+
/// <summary>
11+
/// The minimum disk size provided by the flavor.
12+
/// </summary>
13+
public int? MininumDiskSize { get; set; }
14+
15+
/// <summary>
16+
/// The minimum amount of RAM provided by the flavor.
17+
/// </summary>
18+
public int? MininumMemorySize { get; set; }
19+
20+
/// <summary />
21+
protected override IDictionary<string, object> BuildQueryString()
22+
{
23+
var queryString = base.BuildQueryString();
24+
queryString["minDisk"] = MininumDiskSize;
25+
queryString["minRam"] = MininumMemorySize;
26+
27+
return queryString;
28+
}
29+
}
30+
}

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -858,47 +858,57 @@ protected ComputeApi(IServiceType serviceType, IAuthenticationProvider authentic
858858
/// <summary>
859859
/// Lists summary information for available flavors.
860860
/// </summary>
861-
/// <typeparam name="T">The return type.</typeparam>
861+
/// <typeparam name="TPage">The return type.</typeparam>
862+
/// <param name="queryString">Options for paging and filtering.</param>
862863
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
863-
public virtual async Task<T> ListFlavorSummariesAsync<T>(CancellationToken cancellationToken = default(CancellationToken))
864-
where T : IEnumerable<IServiceResource>
864+
public virtual async Task<TPage> ListFlavorSummariesAsync<TPage>(IQueryStringBuilder queryString, CancellationToken cancellationToken = default(CancellationToken))
865+
where TPage : IPageBuilder<TPage>, IEnumerable<IServiceResource>
865866
{
866-
return await BuildListFlavorSummariesRequest(cancellationToken)
867-
.SendAsync()
868-
.ReceiveJson<T>()
867+
Url initialRequestUrl = await BuildListFlavorSummariesURL(queryString, cancellationToken).ConfigureAwait(false);
868+
return await Endpoint.GetResourcePageAsync<TPage>(initialRequestUrl, cancellationToken)
869869
.PropogateOwnerToChildren(this).ConfigureAwait(false);
870870
}
871871

872872
/// <summary>
873873
/// Builds the <see cref="ListFlavorSummariesAsync{T}"/> request.
874874
/// </summary>
875+
/// <param name="queryString">Options for paging and filtering.</param>
875876
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
876-
public virtual Task<PreparedRequest> BuildListFlavorSummariesRequest(CancellationToken cancellationToken = default(CancellationToken))
877+
public virtual async Task<Url> BuildListFlavorSummariesURL(IQueryStringBuilder queryString, CancellationToken cancellationToken = default(CancellationToken))
877878
{
878-
return Endpoint.PrepareListResourcesRequest("flavors", cancellationToken);
879+
Url endpoint = await Endpoint.GetEndpoint(cancellationToken).ConfigureAwait(false);
880+
881+
return endpoint
882+
.AppendPathSegment("flavors")
883+
.SetQueryParams(queryString?.Build());
879884
}
880885

881886
/// <summary>
882887
/// Lists available flavors.
883888
/// </summary>
884-
/// <typeparam name="T">The return type.</typeparam>
889+
/// <typeparam name="TPage">The return type.</typeparam>
890+
/// <param name="queryString">Options for paging and filtering.</param>
885891
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
886-
public virtual async Task<T> ListFlavorsAsync<T>(CancellationToken cancellationToken = default(CancellationToken))
887-
where T : IEnumerable<IServiceResource>
892+
public virtual async Task<TPage> ListFlavorsAsync<TPage>(IQueryStringBuilder queryString, CancellationToken cancellationToken = default(CancellationToken))
893+
where TPage : IPageBuilder<TPage>, IEnumerable<IServiceResource>
888894
{
889-
return await BuildListFlavorsRequest(cancellationToken)
890-
.SendAsync()
891-
.ReceiveJson<T>()
895+
Url initialRequestUrl = await BuildListFlavorsURL(queryString, cancellationToken).ConfigureAwait(false);
896+
return await Endpoint.GetResourcePageAsync<TPage>(initialRequestUrl, cancellationToken)
892897
.PropogateOwnerToChildren(this).ConfigureAwait(false);
893898
}
894899

895900
/// <summary>
896-
/// Builds the <see cref="ListFlavorsAsync{T}"/> request.
901+
/// Builds the <see cref="ListFlavorsAsync{T}"/> URL.
897902
/// </summary>
903+
/// <param name="queryString">Options for paging and filtering.</param>
898904
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
899-
public virtual Task<PreparedRequest> BuildListFlavorsRequest(CancellationToken cancellationToken = default(CancellationToken))
905+
public virtual async Task<Url> BuildListFlavorsURL(IQueryStringBuilder queryString, CancellationToken cancellationToken = default(CancellationToken))
900906
{
901-
return Endpoint.PrepareListResourcesRequest("flavors/detail", cancellationToken);
907+
Url endpoint = await Endpoint.GetEndpoint(cancellationToken).ConfigureAwait(false);
908+
909+
return endpoint
910+
.AppendPathSegment("flavors/detail")
911+
.SetQueryParams(queryString?.Build());
902912
}
903913

904914
#endregion

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,28 @@ namespace OpenStack.Compute.v2_1.Serialization
88
/// Represents a collection of flavor resources of the <see cref="ComputeService"/>.
99
/// </summary>
1010
/// <exclude />
11-
public class FlavorCollection<T> : ResourceCollection<T>
12-
where T : IServiceResource
11+
public class FlavorCollection<TPage, TItem> : Page<TPage, TItem, PageLink>
12+
where TPage : FlavorCollection<TPage, TItem>
13+
where TItem : IServiceResource
1314
{
14-
/// <summary />
15+
/// <summary/>
1516
[JsonProperty("flavors")]
16-
protected IList<T> Flavors => Items;
17+
protected IList<TItem> Flavors => Items;
18+
19+
/// <summary/>
20+
[JsonProperty("flavors_links")]
21+
protected IList<PageLink> FlavorLinks => Links;
1722
}
1823

1924
/// <summary>
2025
/// Represents a collection of flavor summary resources of the <see cref="ComputeService"/>.
2126
/// </summary>
2227
/// <exclude />
23-
public class FlavorSummaryCollection : FlavorCollection<FlavorSummary>
28+
public class FlavorSummaryCollection : FlavorCollection<FlavorSummaryCollection, FlavorSummary>
2429
{ }
2530

26-
/// <inheritdoc cref="FlavorCollection{T}" />
31+
/// <inheritdoc cref="FlavorCollection{TPage, TItem}" />
2732
/// <exclude />
28-
public class FlavorCollection : FlavorCollection<Flavor>
33+
public class FlavorCollection : FlavorCollection<FlavorCollection, Flavor>
2934
{ }
3035
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ImageCollection<TPage, TItem> : Page<TPage, TItem, PageLink>
2828
public class ImageSummaryCollection : ImageCollection<ImageSummaryCollection, ImageSummary>
2929
{ }
3030

31-
/// <inheritdoc cref="FlavorCollection{T}" />
31+
/// <inheritdoc cref="ImageCollection{TPage, TItem}" />
3232
/// <exclude />
3333
public class ImageCollection : ImageCollection<ImageCollection, Image>
3434
{ }

src/corelib/OpenStack.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<Compile Include="Compute\v2_1\AddressType.cs" />
9898
<Compile Include="Compute\v2_1\Flavor.cs" />
9999
<Compile Include="Compute\v2_1\FlavorReference.cs" />
100+
<Compile Include="Compute\v2_1\FlavorListOptions.cs" />
100101
<Compile Include="Compute\v2_1\NamespaceDoc.cs" />
101102
<Compile Include="Compute\v2_1\Operator\ComputeServiceExtensions.cs" />
102103
<Compile Include="Compute\v2_1\Operator\EvacuateServerRequest.cs" />

0 commit comments

Comments
 (0)