Skip to content

Commit e06068b

Browse files
committed
Move Evacuate server to Operator namespace
1 parent ca7e34c commit e06068b

14 files changed

Lines changed: 146 additions & 75 deletions

src/corelib/Compute/v2_1/ComputeService.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,6 @@ public ComputeService(IAuthenticationProvider authenticationProvider, string reg
140140
return _computeApi.RebootServerAsync(serverId, request, cancellationToken);
141141
}
142142

143-
/// <inheritdoc cref="ComputeApi.EvacuateServerAsync" />
144-
public Task EvacuateServerAsync(Identifier serverId, EvacuateServerRequest request, CancellationToken cancellationToken = default(CancellationToken))
145-
{
146-
return _computeApi.EvacuateServerAsync(serverId, request, cancellationToken);
147-
}
148-
149143
/// <inheritdoc cref="ComputeApi.GetVncConsoleAsync{T}" />
150144
public virtual Task<RemoteConsole> GetVncConsoleAync(Identifier serverId, RemoteConsoleType type, CancellationToken cancellationToken = default(CancellationToken))
151145
{

src/corelib/Compute/v2_1/ComputeServiceExtensions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ public static void RebootServer(this ComputeService service, Identifier serverId
121121
service.RebootServerAsync(serverId, request).ForceSynchronous();
122122
}
123123

124-
/// <inheritdoc cref="ComputeService.EvacuateServerAsync" />
125-
public static void EvacuateServer(this ComputeService service, Identifier serverId, EvacuateServerRequest request)
126-
{
127-
service.EvacuateServerAsync(serverId, request).ForceSynchronous();
128-
}
129-
130124
/// <inheritdoc cref="ComputeService.GetVncConsoleAync" />
131125
public static RemoteConsole GetVncConsole(this ComputeService service, Identifier serverId, RemoteConsoleType type)
132126
{

src/corelib/Compute/v2_1/Operator/ComputeServiceExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ namespace OpenStack.Compute.v2_1.Operator
99
/// </summary>
1010
public static class ComputeServiceExtensions_v2_1
1111
{
12+
#region Servers
13+
14+
/// <inheritdoc cref="ComputeApi.EvacuateServerAsync" />
15+
public static Task EvacuateServerAsync(this ComputeService service, Identifier serverId, EvacuateServerRequest request, CancellationToken cancellationToken = default(CancellationToken))
16+
{
17+
return service._computeApi.EvacuateServerAsync(serverId, request, cancellationToken);
18+
}
19+
20+
#endregion
21+
1222
#region Compute Service
1323
/// <inheritdoc cref="ComputeApi.GetCurrentQuotasAsync{T}" />
1424
public static Task<ServiceQuotas> GetCurrentQuotasAsync(this ComputeService service, CancellationToken cancellationToken = default(CancellationToken))

src/corelib/Compute/v2_1/Actions/EvacuateServerRequest.cs renamed to src/corelib/Compute/v2_1/Operator/EvacuateServerRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Newtonsoft.Json;
22
using OpenStack.Serialization;
33

4-
namespace OpenStack.Compute.v2_1
4+
namespace OpenStack.Compute.v2_1.Operator
55
{
66
/// <summary>
77
/// Evacuates a server from a failed host to a new one.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using OpenStack.Compute.v2_1.Serialization;
5+
using OpenStack.Serialization;
6+
7+
namespace OpenStack.Compute.v2_1.Operator
8+
{
9+
/// <summary>
10+
/// Provides operator extention methods for a <see cref="Server"/> instance.
11+
/// </summary>
12+
public static class ServerExtensions
13+
{
14+
/// <inheritdoc cref="ComputeApi.EvacuateServerAsync" />
15+
/// <summary />
16+
/// <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>
17+
public static async Task EvacuateAsync(this ServerReference server, EvacuateServerRequest request, CancellationToken cancellationToken = default(CancellationToken))
18+
{
19+
var compute = server.GetOwnerOrThrow<ComputeApi>();
20+
await compute.EvacuateServerAsync(server.Id, request, cancellationToken).ConfigureAwait(false);
21+
}
22+
}
23+
}

src/corelib/Compute/v2_1/ServerExtensions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@ public static void Reboot(this ServerReference server, RebootServerRequest reque
101101
server.RebootAsync(request).ForceSynchronous();
102102
}
103103

104-
/// <inheritdoc cref="ServerReference.EvacuateAsync"/>
105-
public static void Evacuate(this ServerReference server, EvacuateServerRequest request)
106-
{
107-
server.EvacuateAsync(request).ForceSynchronous();
108-
}
109-
110104
/// <inheritdoc cref="Server.AttachVolumeAsync"/>
111105
public static ServerVolume AttachVolume(this Server server, ServerVolumeDefinition volume)
112106
{

src/corelib/Compute/v2_1/ServerReference.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,6 @@ public class ServerReference : IHaveExtraData, IServiceResource
111111
await compute.RebootServerAsync(Id, request, cancellationToken).ConfigureAwait(false);
112112
}
113113

114-
/// <inheritdoc cref="ComputeApi.EvacuateServerAsync" />
115-
/// <summary />
116-
/// <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>
117-
public async Task EvacuateAsync(EvacuateServerRequest request, CancellationToken cancellationToken = default(CancellationToken))
118-
{
119-
var compute = this.GetOwnerOrThrow<ComputeApi>();
120-
await compute.EvacuateServerAsync(Id, request, cancellationToken).ConfigureAwait(false);
121-
}
122-
123114
/// <inheritdoc cref="ComputeApi.ListServerVolumesAsync{T}" />
124115
/// <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>
125116
public async Task<IEnumerable<ServerVolume>> ListVolumesAsync(CancellationToken cancellationToken = default(CancellationToken))

src/corelib/OpenStack.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
<Compile Include="Compute\ComputeOperationFailedException.cs" />
9090
<Compile Include="Compute\NamespaceDoc.cs" />
9191
<Compile Include="Compute\v2_1\Actions\RescueServerRequest.cs" />
92-
<Compile Include="Compute\v2_1\Actions\EvacuateServerRequest.cs" />
9392
<Compile Include="Compute\v2_1\Actions\RebootServerRequest.cs" />
9493
<Compile Include="Compute\v2_1\Actions\RebootType.cs" />
9594
<Compile Include="Compute\v2_1\Actions\SnapshotServerRequest.cs" />
@@ -100,7 +99,9 @@
10099
<Compile Include="Compute\v2_1\FlavorReference.cs" />
101100
<Compile Include="Compute\v2_1\NamespaceDoc.cs" />
102101
<Compile Include="Compute\v2_1\Operator\ComputeServiceExtensions.cs" />
102+
<Compile Include="Compute\v2_1\Operator\EvacuateServerRequest.cs" />
103103
<Compile Include="Compute\v2_1\Operator\NamespaceDoc.cs" />
104+
<Compile Include="Compute\v2_1\Operator\ServerExtensions.cs" />
104105
<Compile Include="Compute\v2_1\Operator\ServiceQuotas.cs" />
105106
<Compile Include="Compute\v2_1\ServerMetadata.cs" />
106107
<Compile Include="Compute\v2_1\ServerMetadataExtensions.cs" />
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Flurl.Http;
7+
using Xunit;
8+
using Xunit.Abstractions;
9+
using VolumeState = net.openstack.Core.Domain.VolumeState;
10+
11+
namespace OpenStack.Compute.v2_1.Operator
12+
{
13+
public class ServerTests : IDisposable
14+
{
15+
private readonly ComputeService _compute;
16+
private readonly ComputeTestDataManager _testData;
17+
18+
public ServerTests(ITestOutputHelper testLog)
19+
{
20+
var testOutput = new XunitTraceListener(testLog);
21+
Trace.Listeners.Add(testOutput);
22+
OpenStackNet.Tracing.Http.Listeners.Add(testOutput);
23+
24+
var authenticationProvider = TestIdentityProvider.GetOperatorIdentity();
25+
_compute = new ComputeService(authenticationProvider, "RegionOne");
26+
27+
_testData = new ComputeTestDataManager(_compute);
28+
}
29+
30+
public void Dispose()
31+
{
32+
Trace.Listeners.Clear();
33+
OpenStackNet.Tracing.Http.Listeners.Clear();
34+
35+
_testData.Dispose();
36+
}
37+
38+
[Fact]
39+
public async Task EvacuateServerTest()
40+
{
41+
var server = await _testData.CreateServer();
42+
await server.WaitUntilActiveAsync();
43+
Trace.WriteLine($"Created server named: {server.Name}");
44+
45+
Trace.WriteLine("Evacuating the server to a new host...");
46+
var request = new EvacuateServerRequest(false)
47+
{
48+
AdminPassword = "top-secret-password"
49+
};
50+
51+
// Our service isn't down, so we can't really evacuate.
52+
// Just check that the request would have gone through (i.e. was valid)
53+
// and only was rejected because the compute service is healthy
54+
try
55+
{
56+
await server.EvacuateAsync(request);
57+
}
58+
catch (FlurlHttpException httpError) when (httpError.Call.ErrorResponseBody.Contains("is still in use"))
59+
{
60+
// Hurray! the test passed
61+
}
62+
}
63+
}
64+
}

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

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -323,33 +323,7 @@ public async Task RebootServerTest()
323323
await server.WaitForStatusAsync(ServerStatus.Reboot);
324324
await server.WaitUntilActiveAsync();
325325
}
326-
327-
[Fact]
328-
public async Task EvacuateServerTest()
329-
{
330-
var server = await _testData.CreateServer();
331-
await server.WaitUntilActiveAsync();
332-
Trace.WriteLine($"Created server named: {server.Name}");
333-
334-
Trace.WriteLine("Evacuating the server to a new host...");
335-
var request = new EvacuateServerRequest(false)
336-
{
337-
AdminPassword = "top-secret-password"
338-
};
339-
340-
// Our service isn't down, so we can't really evacuate.
341-
// Just check that the request would have gone through (i.e. was valid)
342-
// and only was rejected because the compute service is healthy
343-
try
344-
{
345-
await server.EvacuateAsync(request);
346-
}
347-
catch (FlurlHttpException httpError) when (httpError.Call.ErrorResponseBody.Contains("is still in use"))
348-
{
349-
// Hurray! the test passed
350-
}
351-
}
352-
326+
353327
[Fact]
354328
public async Task ServerVolumesTest()
355329
{

0 commit comments

Comments
 (0)