Skip to content

Commit 3cfc684

Browse files
committed
Isolate ComputeApiBuilder to Serialization/ComputeApi
Hide stuff that a "regular user" doesn't need to use and cleanup the name to better reflect its purpose. Service -> Api -> Endpoint
1 parent 14baf25 commit 3cfc684

28 files changed

Lines changed: 222 additions & 210 deletions

src/corelib/Compute/v2_1/ComputeService.cs

Lines changed: 72 additions & 72 deletions
Large diffs are not rendered by default.

src/corelib/Compute/v2_1/FlavorReference.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using Newtonsoft.Json;
66
using Newtonsoft.Json.Linq;
7+
using OpenStack.Compute.v2_1.Serialization;
78
using OpenStack.Serialization;
89

910
namespace OpenStack.Compute.v2_1
@@ -21,11 +22,11 @@ public class FlavorReference : IHaveExtraData, IServiceResource
2122

2223
object IServiceResource.Owner { get; set; }
2324

24-
/// <inheritdoc cref="ComputeApiBuilder.GetFlavorAsync{T}" />
25+
/// <inheritdoc cref="ComputeApi.GetFlavorAsync{T}" />
2526
/// <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>
2627
public Task<Flavor> GetFlavorAsync(CancellationToken cancellationToken = default(CancellationToken))
2728
{
28-
var owner = this.GetOwnerOrThrow<ComputeApiBuilder>();
29+
var owner = this.GetOwnerOrThrow<ComputeApi>();
2930
return owner.GetFlavorAsync<Flavor>(Id, cancellationToken);
3031
}
3132
}

src/corelib/Compute/v2_1/Image.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using Newtonsoft.Json;
7+
using OpenStack.Compute.v2_1.Serialization;
78
using OpenStack.Serialization;
89

910
namespace OpenStack.Compute.v2_1
@@ -70,11 +71,11 @@ public ImageType Type
7071
}
7172
}
7273

73-
/// <inheritdoc cref="ComputeApiBuilder.WaitForImageStatusAsync{TImage,TStatus}" />
74+
/// <inheritdoc cref="ComputeApi.WaitForImageStatusAsync{TImage,TStatus}" />
7475
/// <exception cref="InvalidOperationException">When this instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
7576
public async Task WaitForStatus(ImageStatus status, TimeSpan? refreshDelay = null, TimeSpan? timeout = null, IProgress<bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
7677
{
77-
var owner = this.GetOwnerOrThrow<ComputeApiBuilder>();
78+
var owner = this.GetOwnerOrThrow<ComputeApi>();
7879
var result = await owner.WaitForImageStatusAsync<Image, ImageStatus>(Id, status, refreshDelay, timeout, progress, cancellationToken).ConfigureAwait(false);
7980
result.CopyProperties(this);
8081
}
@@ -85,7 +86,7 @@ public ImageType Type
8586
return WaitForStatus(ImageStatus.Active, refreshDelay, timeout, progress, cancellationToken);
8687
}
8788

88-
/// <inheritdoc cref="ComputeApiBuilder.WaitUntilImageIsDeletedAsync{TImage,TStatus}" />
89+
/// <inheritdoc cref="ComputeApi.WaitUntilImageIsDeletedAsync{TImage,TStatus}" />
8990
/// <exception cref="InvalidOperationException">When this instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
9091
public override async Task WaitUntilDeletedAsync(TimeSpan? refreshDelay = null, TimeSpan? timeout = null, IProgress<bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
9192
{

src/corelib/Compute/v2_1/ImageMetadata.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Newtonsoft.Json;
77
using Newtonsoft.Json.Linq;
8+
using OpenStack.Compute.v2_1.Serialization;
89
using OpenStack.Serialization;
910

1011
namespace OpenStack.Compute.v2_1
@@ -52,7 +53,7 @@ protected void AssertImageIsSet([CallerMemberName]string callerName = "")
5253
public async Task CreateAsync(string key, string value, CancellationToken cancellationToken = default(CancellationToken))
5354
{
5455
AssertImageIsSet();
55-
var compute = this.GetOwnerOrThrow<ComputeApiBuilder>();
56+
var compute = this.GetOwnerOrThrow<ComputeApi>();
5657
await compute.CreateImagMetadataAsync(Image.Id, key, value, cancellationToken);
5758
this[key] = value;
5859
}
@@ -61,7 +62,7 @@ protected void AssertImageIsSet([CallerMemberName]string callerName = "")
6162
public async Task UpdateAsync(bool overwrite = false, CancellationToken cancellationToken = default(CancellationToken))
6263
{
6364
AssertImageIsSet();
64-
var compute = this.GetOwnerOrThrow<ComputeApiBuilder>();
65+
var compute = this.GetOwnerOrThrow<ComputeApi>();
6566
var results = await compute.UpdateImageMetadataAsync<ImageMetadata>(Image.Id, this, overwrite, cancellationToken);
6667
Clear();
6768
foreach (var result in results)
@@ -77,7 +78,7 @@ protected void AssertImageIsSet([CallerMemberName]string callerName = "")
7778
return;
7879

7980
AssertImageIsSet();
80-
var compute = this.GetOwnerOrThrow<ComputeApiBuilder>();
81+
var compute = this.GetOwnerOrThrow<ComputeApi>();
8182
await compute.DeleteImageMetadataAsync(Image.Id, key, cancellationToken);
8283
Remove(key);
8384
}

src/corelib/Compute/v2_1/ImageReference.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using Newtonsoft.Json;
66
using Newtonsoft.Json.Linq;
7+
using OpenStack.Compute.v2_1.Serialization;
78
using OpenStack.Serialization;
89

910
namespace OpenStack.Compute.v2_1
@@ -21,43 +22,43 @@ public class ImageReference : IHaveExtraData, IServiceResource
2122

2223
object IServiceResource.Owner { get; set; }
2324

24-
/// <inheritdoc cref="ComputeApiBuilder.GetImageAsync{T}" />
25+
/// <inheritdoc cref="ComputeApi.GetImageAsync{T}" />
2526
/// <exception cref="InvalidOperationException">When the <see cref="ImageReference"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
2627
public Task<Image> GetImageAsync(CancellationToken cancellationToken = default(CancellationToken))
2728
{
28-
var owner = this.GetOwnerOrThrow<ComputeApiBuilder>();
29+
var owner = this.GetOwnerOrThrow<ComputeApi>();
2930
return owner.GetImageAsync<Image>(Id, cancellationToken);
3031
}
3132

32-
/// <inheritdoc cref="ComputeApiBuilder.GetImageMetadataAsync{T}" />
33+
/// <inheritdoc cref="ComputeApi.GetImageMetadataAsync{T}" />
3334
/// <exception cref="InvalidOperationException">When the <see cref="ImageReference"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
3435
public Task<ImageMetadata> GetMetadataAsync(CancellationToken cancellationToken = default(CancellationToken))
3536
{
36-
var owner = this.GetOwnerOrThrow<ComputeApiBuilder>();
37+
var owner = this.GetOwnerOrThrow<ComputeApi>();
3738
return owner.GetImageMetadataAsync<ImageMetadata>(Id, cancellationToken);
3839
}
3940

40-
/// <inheritdoc cref="ComputeApiBuilder.GetImageMetadataItemAsync" />
41+
/// <inheritdoc cref="ComputeApi.GetImageMetadataItemAsync" />
4142
/// <exception cref="InvalidOperationException">When the <see cref="ImageReference"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
4243
public Task<string> GetMetadataItemAsync(string key, CancellationToken cancellationToken = default(CancellationToken))
4344
{
44-
var owner = this.GetOwnerOrThrow<ComputeApiBuilder>();
45+
var owner = this.GetOwnerOrThrow<ComputeApi>();
4546
return owner.GetImageMetadataItemAsync(Id, key, cancellationToken);
4647
}
4748

48-
/// <inheritdoc cref="ComputeApiBuilder.DeleteImageAsync" />
49+
/// <inheritdoc cref="ComputeApi.DeleteImageAsync" />
4950
/// <exception cref="InvalidOperationException">When the <see cref="Server"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
5051
public virtual async Task DeleteAsync(CancellationToken cancellationToken = default(CancellationToken))
5152
{
52-
var owner = this.GetOwnerOrThrow<ComputeApiBuilder>();
53+
var owner = this.GetOwnerOrThrow<ComputeApi>();
5354
await owner.DeleteImageAsync(Id, cancellationToken);
5455
}
5556

56-
/// <inheritdoc cref="ComputeApiBuilder.WaitUntilImageIsDeletedAsync{TImage,TStatus}" />
57+
/// <inheritdoc cref="ComputeApi.WaitUntilImageIsDeletedAsync{TImage,TStatus}" />
5758
/// <exception cref="InvalidOperationException">When this instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
5859
public virtual async Task WaitUntilDeletedAsync(TimeSpan? refreshDelay = null, TimeSpan? timeout = null, IProgress<bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
5960
{
60-
var owner = this.GetOwnerOrThrow<ComputeApiBuilder>();
61+
var owner = this.GetOwnerOrThrow<ComputeApi>();
6162
await owner.WaitUntilImageIsDeletedAsync<Image, ImageStatus>(Id, null, refreshDelay, timeout, progress, cancellationToken).ConfigureAwait(false);
6263
}
6364
}

src/corelib/Compute/v2_1/KeyPairSummary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public class KeyPairSummary : IHaveExtraData, IServiceResource
3030

3131
object IServiceResource.Owner { get; set; }
3232

33-
/// <inheritdoc cref="ComputeApiBuilder.DeleteKeyPairAsync" />
33+
/// <inheritdoc cref="ComputeApi.DeleteKeyPairAsync" />
3434
public Task DeleteAsync(CancellationToken cancellationToken = default(CancellationToken))
3535
{
36-
var compute = this.GetOwnerOrThrow<ComputeApiBuilder>();
36+
var compute = this.GetOwnerOrThrow<ComputeApi>();
3737
return compute.DeleteKeyPairAsync(Name, cancellationToken);
3838
}
3939
}

src/corelib/Compute/v2_1/SecurityGroup.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using Newtonsoft.Json;
7+
using OpenStack.Compute.v2_1.Serialization;
78
using OpenStack.Serialization;
89

910
namespace OpenStack.Compute.v2_1
@@ -30,22 +31,22 @@ public SecurityGroup()
3031
[JsonProperty("rules")]
3132
public IList<SecurityGroupRule> Rules { get; set; }
3233

33-
/// <inheritdoc cref="ComputeApiBuilder.UpdateSecurityGroupAsync{T}" />
34+
/// <inheritdoc cref="ComputeApi.UpdateSecurityGroupAsync{T}" />
3435
/// <exception cref="InvalidOperationException">When the <see cref="Server"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
3536
public async Task UpdateAsync(CancellationToken cancellationToken = default(CancellationToken))
3637
{
37-
var compute = this.GetOwnerOrThrow<ComputeApiBuilder>();
38+
var compute = this.GetOwnerOrThrow<ComputeApi>();
3839
var request = new SecurityGroupDefinition(Name, Description);
3940

4041
var result = await compute.UpdateSecurityGroupAsync<SecurityGroup>(Id, request, cancellationToken);
4142
result.CopyProperties(this);
4243
}
4344

44-
/// <inheritdoc cref="ComputeApiBuilder.CreateSecurityGroupRuleAsync{T}" />
45+
/// <inheritdoc cref="ComputeApi.CreateSecurityGroupRuleAsync{T}" />
4546
/// <exception cref="InvalidOperationException">When the <see cref="Server"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
4647
public async Task<SecurityGroupRule> AddRuleAsync(SecurityGroupRuleDefinition rule, CancellationToken cancellationToken = default(CancellationToken))
4748
{
48-
var compute = this.GetOwnerOrThrow<ComputeApiBuilder>();
49+
var compute = this.GetOwnerOrThrow<ComputeApi>();
4950
rule.GroupId = Id;
5051

5152
var result = await compute.CreateSecurityGroupRuleAsync<SecurityGroupRule>(rule, cancellationToken);

src/corelib/Compute/v2_1/SecurityGroupReference.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private async Task<SecurityGroup> LoadSecurityGroup(CancellationToken cancellati
2929
if (securityGroup != null)
3030
return securityGroup;
3131

32-
var owner = this.GetOwnerOrThrow<ComputeApiBuilder>();
32+
var owner = this.GetOwnerOrThrow<ComputeApi>();
3333

3434
// In some cases, such as when working with the groups on a server, we only have the name and not the id
3535
var groups = await owner.ListSecurityGroupsAsync<SecurityGroupCollection>(cancellationToken: cancellationToken);
@@ -40,18 +40,18 @@ private async Task<SecurityGroup> LoadSecurityGroup(CancellationToken cancellati
4040
return securityGroup;
4141
}
4242

43-
/// <inheritdoc cref="ComputeApiBuilder.GetSecurityGroupAsync{T}" />
43+
/// <inheritdoc cref="ComputeApi.GetSecurityGroupAsync{T}" />
4444
/// <exception cref="InvalidOperationException">When this instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
4545
public async Task<SecurityGroup> GetSecurityGroupAsync(CancellationToken cancellationToken = default(CancellationToken))
4646
{
4747
return await LoadSecurityGroup(cancellationToken);
4848
}
4949

50-
/// <inheritdoc cref="ComputeApiBuilder.DeleteSecurityGroupAsync" />
50+
/// <inheritdoc cref="ComputeApi.DeleteSecurityGroupAsync" />
5151
/// <exception cref="InvalidOperationException">When this instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
5252
public async Task DeleteAsync(CancellationToken cancellationToken = default(CancellationToken))
5353
{
54-
var owner = this.GetOwnerOrThrow<ComputeApiBuilder>();
54+
var owner = this.GetOwnerOrThrow<ComputeApi>();
5555
var securityGroup = await LoadSecurityGroup(cancellationToken);
5656

5757
await owner.DeleteSecurityGroupAsync(securityGroup.Id, cancellationToken);

src/corelib/Compute/v2_1/SecurityGroupRule.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using Newtonsoft.Json;
66
using Newtonsoft.Json.Linq;
7+
using OpenStack.Compute.v2_1.Serialization;
78
using OpenStack.Serialization;
89

910
namespace OpenStack.Compute.v2_1
@@ -54,11 +55,11 @@ public string CIDR
5455

5556
object IServiceResource.Owner { get; set; }
5657

57-
/// <inheritdoc cref="ComputeApiBuilder.DeleteSecurityGroupRuleAsync" />
58+
/// <inheritdoc cref="ComputeApi.DeleteSecurityGroupRuleAsync" />
5859
/// <exception cref="InvalidOperationException">When this instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
5960
public async Task DeleteAsync(CancellationToken cancellationToken = default(CancellationToken))
6061
{
61-
var owner = this.GetOwnerOrThrow<ComputeApiBuilder>();
62+
var owner = this.GetOwnerOrThrow<ComputeApi>();
6263
await owner.DeleteSecurityGroupRuleAsync(Id, cancellationToken);
6364
}
6465

src/corelib/Compute/v2_1/ComputeApiBuilder.cs renamed to src/corelib/Compute/v2_1/Serialization/ComputeApi.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
using OpenStack.Authentication;
1212
using OpenStack.Serialization;
1313

14-
namespace OpenStack.Compute.v2_1
14+
namespace OpenStack.Compute.v2_1.Serialization
1515
{
1616
/// <summary>
1717
/// Builds requests to the Compute API which can be further customized and then executed.
1818
/// <para>Intended for custom implementations.</para>
1919
/// </summary>
2020
/// <exclude />
2121
/// <seealso href="http://developer.openstack.org/api-ref-compute-v2.1.html">OpenStack Compute API v2.1 Overview</seealso>
22-
public class ComputeApiBuilder
22+
public class ComputeApi
2323
{
2424
/// <summary />
2525
protected readonly IAuthenticationProvider AuthenticationProvider;
@@ -33,25 +33,25 @@ public class ComputeApiBuilder
3333
protected readonly ServiceEndpoint Endpoint;
3434

3535
/// <summary>
36-
/// Initializes a new instance of the <see cref="ComputeApiBuilder"/> class.
36+
/// Initializes a new instance of the <see cref="ComputeApi"/> class.
3737
/// </summary>
3838
/// <param name="serviceType">The service type for the desired compute provider.</param>
3939
/// <param name="authenticationProvider">The authentication provider.</param>
4040
/// <param name="region">The region.</param>
4141
/// <param name="useInternalUrl">if set to <c>true</c> uses the internal URLs specified in the ServiceCatalog, otherwise the public URLs are used.</param>
42-
public ComputeApiBuilder(IServiceType serviceType, IAuthenticationProvider authenticationProvider, string region, bool useInternalUrl)
42+
public ComputeApi(IServiceType serviceType, IAuthenticationProvider authenticationProvider, string region, bool useInternalUrl)
4343
: this(serviceType, authenticationProvider, region, useInternalUrl, "2.1")
4444
{ }
4545

4646
/// <summary>
47-
/// Initializes a new instance of the <see cref="ComputeApiBuilder"/> class.
47+
/// Initializes a new instance of the <see cref="ComputeApi"/> class.
4848
/// </summary>
4949
/// <param name="serviceType">The service type for the desired compute provider.</param>
5050
/// <param name="authenticationProvider">The authentication provider.</param>
5151
/// <param name="useInternalUrl">if set to <c>true</c> uses the internal URLs specified in the ServiceCatalog, otherwise the public URLs are used.</param>
5252
/// <param name="region">The region.</param>
5353
/// <param name="microversion">The requested API microversion.</param>
54-
protected ComputeApiBuilder(IServiceType serviceType, IAuthenticationProvider authenticationProvider, string region, bool useInternalUrl, string microversion)
54+
protected ComputeApi(IServiceType serviceType, IAuthenticationProvider authenticationProvider, string region, bool useInternalUrl, string microversion)
5555
{
5656
if (serviceType == null)
5757
throw new ArgumentNullException("serviceType");

0 commit comments

Comments
 (0)