Skip to content

Commit 14a1299

Browse files
committed
Compute os-snapshots
Place SnapshotStatus and VolumeStatus under the OpenStack.BlockStorage.v2 since these values are coming from cinder.
1 parent e033550 commit 14a1299

23 files changed

Lines changed: 1093 additions & 17 deletions
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using OpenStack.Serialization;
2+
3+
namespace OpenStack.BlockStorage.v2.Serialization
4+
{
5+
/// <summary />
6+
/// <exclude />
7+
public class SnapshotStatus<T> : ResourceStatus
8+
where T : SnapshotStatus<T>, new()
9+
{
10+
/// <summary>
11+
/// The snapshot is being created.
12+
/// </summary>
13+
public static readonly T Creating = new T {DisplayName = "creating"};
14+
15+
/// <summary>
16+
/// The snapshot is ready to use.
17+
/// </summary>
18+
public static readonly T Available = new T {DisplayName = "available"};
19+
20+
/// <summary>
21+
/// The snapshot is being deleted.
22+
/// </summary>
23+
public static readonly T Deleting = new T {DisplayName = "deleting"};
24+
25+
/// <summary>
26+
/// A snapshot creation error occurred.
27+
/// </summary>
28+
public static readonly T Error = new T {DisplayName = "error", IsError = true};
29+
30+
/// <summary>
31+
/// A snapshot deletion error occurred.
32+
/// </summary>
33+
public static readonly T ErrorDeleting = new T {DisplayName = "error_deleting", IsError = true};
34+
}
35+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using OpenStack.Serialization;
2+
3+
namespace OpenStack.BlockStorage.v2.Serialization
4+
{
5+
/// <summary />
6+
/// <exclude />
7+
public class VolumeStatus<T> : ResourceStatus
8+
where T : VolumeStatus<T>, new()
9+
{
10+
/// <summary>
11+
/// The volume is being created.
12+
/// </summary>
13+
public static readonly T Creating = new T {DisplayName = "creating"};
14+
15+
/// <summary>
16+
/// The volume is ready to attach to an instance.
17+
/// </summary>
18+
public static readonly T Available = new T {DisplayName = "available"};
19+
20+
/// <summary>
21+
/// The volume is attaching to an instance.
22+
/// </summary>
23+
public static readonly T Attaching = new T {DisplayName = "attaching"};
24+
25+
/// <summary>
26+
/// The volume is attached to an instance.
27+
/// </summary>
28+
public static readonly T InUse = new T {DisplayName = "in-use"};
29+
30+
/// <summary>
31+
/// The volume is being deleted.
32+
/// </summary>
33+
public static readonly T Deleting = new T {DisplayName = "deleting"};
34+
35+
/// <summary>
36+
/// A volume creation error occurred.
37+
/// </summary>
38+
public static readonly T Error = new T {DisplayName = "error", IsError = true};
39+
40+
/// <summary>
41+
/// A volume deletion error occurred.
42+
/// </summary>
43+
public static readonly T ErrorDeleting = new T {DisplayName = "error_deleting", IsError = true};
44+
45+
/// <summary>
46+
/// A backup restoration error occurred.
47+
/// </summary>
48+
public static readonly T ErrorRestoring = new T {DisplayName = "error_restoring", IsError = true};
49+
50+
/// <summary>
51+
/// An error occurred while attempting to extend a volume.
52+
/// </summary>
53+
public static readonly T ErrorExtending = new T {DisplayName = "error_extending", IsError = true};
54+
55+
/// <summary>
56+
/// The volume is being backed up.
57+
/// </summary>
58+
public static readonly T BackingUp = new T {DisplayName = "backing-up"};
59+
60+
/// <summary>
61+
/// A backup is being restored to the volume.
62+
/// </summary>
63+
public static readonly T RestoringBackup = new T {DisplayName = "restoring-backup"};
64+
}
65+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace OpenStack.BlockStorage.v2
2+
{
3+
/// <summary/>
4+
public class SnapshotStatus : Serialization.SnapshotStatus<SnapshotStatus>
5+
{
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace OpenStack.BlockStorage.v2
2+
{
3+
/// <summary/>
4+
public class VolumeStatus : Serialization.VolumeStatus<VolumeStatus>
5+
{
6+
}
7+
}

src/corelib/Compute/v2_1/ComputeApiBuilder.cs

Lines changed: 217 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ protected ComputeApiBuilder(IServiceType serviceType, IAuthenticationProvider au
259259
}
260260

261261
/// <summary />
262-
public virtual async Task<T> CreateSnapshotAsync<T>(string serverId, object request, CancellationToken cancellationToken = default(CancellationToken))
262+
public virtual async Task<T> SnapshotServerAsync<T>(string serverId, object request, CancellationToken cancellationToken = default(CancellationToken))
263263
where T : IServiceResource
264264
{
265265
var response = await BuildServerActionAsync(serverId, request, cancellationToken).SendAsync();
@@ -1088,6 +1088,25 @@ protected ComputeApiBuilder(IServiceType serviceType, IAuthenticationProvider au
10881088
return Endpoint.PrepareGetResourceRequest($"os-volume-types/{volumeTypeId}", cancellationToken);
10891089
}
10901090

1091+
/// <summary />
1092+
public virtual async Task<T> GetVolumeSnapshotAsync<T>(string snapshotId, CancellationToken cancellationToken = default(CancellationToken))
1093+
where T : IServiceResource
1094+
{
1095+
return await BuildGetVolumeSnapshotRequest(snapshotId, cancellationToken)
1096+
.SendAsync()
1097+
.ReceiveJson<T>()
1098+
.PropogateOwner(this);
1099+
}
1100+
1101+
/// <summary />
1102+
public virtual Task<PreparedRequest> BuildGetVolumeSnapshotRequest(string snapshotId, CancellationToken cancellationToken = default(CancellationToken))
1103+
{
1104+
if (snapshotId == null)
1105+
throw new ArgumentNullException("snapshotId");
1106+
1107+
return Endpoint.PrepareGetResourceRequest($"os-snapshots/{snapshotId}", cancellationToken);
1108+
}
1109+
10911110
/// <summary />
10921111
public virtual async Task<T> CreateVolumeAsync<T>(object volume, CancellationToken cancellationToken = default(CancellationToken))
10931112
where T : IServiceResource
@@ -1107,6 +1126,25 @@ protected ComputeApiBuilder(IServiceType serviceType, IAuthenticationProvider au
11071126
return Endpoint.PrepareCreateResourceRequest("os-volumes", volume, cancellationToken);
11081127
}
11091128

1129+
/// <summary />
1130+
public virtual async Task<T> SnapshotVolumeAsync<T>(object snapshot, CancellationToken cancellationToken = default(CancellationToken))
1131+
where T : IServiceResource
1132+
{
1133+
return await BuildCreateVolumeSnapshotRequest(snapshot, cancellationToken)
1134+
.SendAsync()
1135+
.ReceiveJson<T>()
1136+
.PropogateOwner(this);
1137+
}
1138+
1139+
/// <summary />
1140+
public virtual async Task<PreparedRequest> BuildCreateVolumeSnapshotRequest(object snapshot, CancellationToken cancellationToken = default(CancellationToken))
1141+
{
1142+
if(snapshot == null)
1143+
throw new ArgumentNullException("snapshot");
1144+
1145+
return await Endpoint.PrepareCreateResourceRequest("os-snapshots", snapshot, cancellationToken);
1146+
}
1147+
11101148
/// <summary />
11111149
public virtual async Task<T> ListVolumesAsync<T>(CancellationToken cancellationToken = default(CancellationToken))
11121150
where T : IEnumerable<IServiceResource>
@@ -1137,6 +1175,22 @@ protected ComputeApiBuilder(IServiceType serviceType, IAuthenticationProvider au
11371175
return Endpoint.PrepareGetResourceRequest("os-volume-types", cancellationToken);
11381176
}
11391177

1178+
/// <summary />
1179+
public virtual async Task<T> ListVolumeSnapshotsAsync<T>(CancellationToken cancellationToken = default(CancellationToken))
1180+
where T : IEnumerable<IServiceResource>
1181+
{
1182+
return await BuildListVolumeSnapshotsRequest(cancellationToken)
1183+
.SendAsync()
1184+
.ReceiveJson<T>()
1185+
.PropogateOwnerToChildren(this);
1186+
}
1187+
1188+
/// <summary />
1189+
public virtual Task<PreparedRequest> BuildListVolumeSnapshotsRequest(CancellationToken cancellationToken = default(CancellationToken))
1190+
{
1191+
return Endpoint.PrepareGetResourceRequest("os-snapshots", cancellationToken);
1192+
}
1193+
11401194
/// <summary />
11411195
public virtual Task DeleteVolumeAsync(string volumeId, CancellationToken cancellationToken = default(CancellationToken))
11421196
{
@@ -1152,6 +1206,168 @@ protected ComputeApiBuilder(IServiceType serviceType, IAuthenticationProvider au
11521206
return Endpoint.PrepareDeleteResourceRequest($"os-volumes/{volumeId}", cancellationToken);
11531207
}
11541208

1209+
/// <summary />
1210+
public virtual Task DeleteVolumeSnapshotAsync(string snapshotId, CancellationToken cancellationToken = default(CancellationToken))
1211+
{
1212+
return BuildDeleteVolumeSnapshotRequest(snapshotId, cancellationToken).SendAsync();
1213+
}
1214+
1215+
/// <summary />
1216+
public virtual Task<PreparedRequest> BuildDeleteVolumeSnapshotRequest(string snapshotId, CancellationToken cancellationToken = default(CancellationToken))
1217+
{
1218+
if (snapshotId == null)
1219+
throw new ArgumentNullException("snapshotId");
1220+
1221+
return Endpoint.PrepareDeleteResourceRequest($"os-snapshots/{snapshotId}", cancellationToken);
1222+
}
1223+
1224+
/// <summary>
1225+
/// Waits for the volume to reach the specified status.
1226+
/// </summary>
1227+
/// <param name="volumeId">The volume identifier.</param>
1228+
/// <param name="status">The status to wait for.</param>
1229+
/// <param name="refreshDelay">The amount of time to wait between requests.</param>
1230+
/// <param name="timeout">The amount of time to wait before throwing a <see cref="TimeoutException"/>.</param>
1231+
/// <param name="progress">The progress callback.</param>
1232+
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
1233+
/// <exception cref="TimeoutException">If the <paramref name="timeout"/> value is reached.</exception>
1234+
/// <exception cref="FlurlHttpException">If the API call returns a bad <see cref="HttpStatusCode"/>.</exception>
1235+
public async Task<TVolume> WaitForVolumeStatusAsync<TVolume, TStatus>(string volumeId, TStatus status, TimeSpan? refreshDelay = null, TimeSpan? timeout = null, IProgress<bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
1236+
where TVolume : IServiceResource
1237+
where TStatus : ResourceStatus
1238+
{
1239+
if(volumeId == null)
1240+
throw new ArgumentNullException("volumeId");
1241+
1242+
if(status == null)
1243+
throw new ArgumentNullException("status");
1244+
1245+
Func<Task<TVolume>> getVolume = async () => await GetVolumeAsync<TVolume>(volumeId, cancellationToken);
1246+
return await Endpoint.WaitForStatusAsync(volumeId, status, getVolume, refreshDelay, timeout, progress, cancellationToken)
1247+
.PropogateOwner(this);
1248+
}
1249+
1250+
/// <summary>
1251+
/// Waits for the volume snapshot to reach the specified status.
1252+
/// </summary>
1253+
/// <param name="snapshotId">The snapshot identifier.</param>
1254+
/// <param name="status">The status to wait for.</param>
1255+
/// <param name="refreshDelay">The amount of time to wait between requests.</param>
1256+
/// <param name="timeout">The amount of time to wait before throwing a <see cref="TimeoutException"/>.</param>
1257+
/// <param name="progress">The progress callback.</param>
1258+
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
1259+
/// <exception cref="TimeoutException">If the <paramref name="timeout"/> value is reached.</exception>
1260+
/// <exception cref="FlurlHttpException">If the API call returns a bad <see cref="HttpStatusCode"/>.</exception>
1261+
public async Task<TSnapshot> WaitForVolumeSnapshotStatusAsync<TSnapshot, TStatus>(string snapshotId, TStatus status, TimeSpan? refreshDelay = null, TimeSpan? timeout = null, IProgress<bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
1262+
where TSnapshot : IServiceResource
1263+
where TStatus : ResourceStatus
1264+
{
1265+
if (snapshotId == null)
1266+
throw new ArgumentNullException("snapshotId");
1267+
1268+
if (status == null)
1269+
throw new ArgumentNullException("status");
1270+
1271+
Func<Task<TSnapshot>> getSnapshot = async () => await GetVolumeSnapshotAsync<TSnapshot>(snapshotId, cancellationToken);
1272+
return await Endpoint.WaitForStatusAsync(snapshotId, status, getSnapshot, refreshDelay, timeout, progress, cancellationToken)
1273+
.PropogateOwner(this);
1274+
}
1275+
1276+
/// <summary>
1277+
/// Waits for the volume to reach the specified status.
1278+
/// </summary>
1279+
/// <param name="volumeId">The volume identifier.</param>
1280+
/// <param name="status">The status to wait for.</param>
1281+
/// <param name="refreshDelay">The amount of time to wait between requests.</param>
1282+
/// <param name="timeout">The amount of time to wait before throwing a <see cref="TimeoutException"/>.</param>
1283+
/// <param name="progress">The progress callback.</param>
1284+
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
1285+
/// <exception cref="TimeoutException">If the <paramref name="timeout"/> value is reached.</exception>
1286+
/// <exception cref="FlurlHttpException">If the API call returns a bad <see cref="HttpStatusCode"/>.</exception>
1287+
public async Task<TVolume> WaitForVolumeStatusAsync<TVolume, TStatus>(string volumeId, IEnumerable<TStatus> status, TimeSpan? refreshDelay = null, TimeSpan? timeout = null, IProgress<bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
1288+
where TVolume : IServiceResource
1289+
where TStatus : ResourceStatus
1290+
{
1291+
if (volumeId == null)
1292+
throw new ArgumentNullException("volumeId");
1293+
1294+
if (status == null)
1295+
throw new ArgumentNullException("status");
1296+
1297+
Func<Task<TVolume>> getVolume = async () => await GetVolumeAsync<TVolume>(volumeId, cancellationToken);
1298+
return await Endpoint.WaitForStatusAsync(volumeId, status, getVolume, refreshDelay, timeout, progress, cancellationToken)
1299+
.PropogateOwner(this);
1300+
}
1301+
1302+
/// <summary>
1303+
/// Waits for the volume snapshot to reach the specified status.
1304+
/// </summary>
1305+
/// <param name="snapshotId">The snapshot identifier.</param>
1306+
/// <param name="status">The status to wait for.</param>
1307+
/// <param name="refreshDelay">The amount of time to wait between requests.</param>
1308+
/// <param name="timeout">The amount of time to wait before throwing a <see cref="TimeoutException"/>.</param>
1309+
/// <param name="progress">The progress callback.</param>
1310+
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
1311+
/// <exception cref="TimeoutException">If the <paramref name="timeout"/> value is reached.</exception>
1312+
/// <exception cref="FlurlHttpException">If the API call returns a bad <see cref="HttpStatusCode"/>.</exception>
1313+
public async Task<TSnapshot> WaitForVolumeSnapshotStatusAsync<TSnapshot, TStatus>(string snapshotId, IEnumerable<TStatus> status, TimeSpan? refreshDelay = null, TimeSpan? timeout = null, IProgress<bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
1314+
where TSnapshot : IServiceResource
1315+
where TStatus : ResourceStatus
1316+
{
1317+
if (snapshotId == null)
1318+
throw new ArgumentNullException("snapshotId");
1319+
1320+
if (status == null)
1321+
throw new ArgumentNullException("status");
1322+
1323+
Func<Task<TSnapshot>> getSnapshot = async () => await GetVolumeSnapshotAsync<TSnapshot>(snapshotId, cancellationToken);
1324+
return await Endpoint.WaitForStatusAsync(snapshotId, status, getSnapshot, refreshDelay, timeout, progress, cancellationToken)
1325+
.PropogateOwner(this);
1326+
}
1327+
1328+
/// <summary>
1329+
/// Waits for the volume to be deleted.
1330+
/// <para>Treats a 404 NotFound exception as confirmation that it is deleted.</para>
1331+
/// </summary>
1332+
/// <param name="volumeId">The volume identifier.</param>
1333+
/// <param name="refreshDelay">The amount of time to wait between requests.</param>
1334+
/// <param name="timeout">The amount of time to wait before throwing a <see cref="TimeoutException"/>.</param>
1335+
/// <param name="progress">The progress callback.</param>
1336+
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
1337+
/// <exception cref="TimeoutException">If the <paramref name="timeout"/> value is reached.</exception>
1338+
/// <exception cref="FlurlHttpException">If the API call returns a bad <see cref="HttpStatusCode"/>.</exception>
1339+
public Task WaitUntilVolumeIsDeletedAsync<TVolume, TStatus>(string volumeId, TimeSpan? refreshDelay = null, TimeSpan? timeout = null, IProgress<bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
1340+
where TVolume : IServiceResource
1341+
where TStatus : ResourceStatus
1342+
{
1343+
if (volumeId == null)
1344+
throw new ArgumentNullException("volumeId");
1345+
1346+
Func<Task<dynamic>> getVolume = async () => await GetVolumeAsync<TVolume>(volumeId, cancellationToken);
1347+
return Endpoint.WaitUntilDeletedAsync<TStatus>(volumeId, getVolume, refreshDelay, timeout, progress, cancellationToken);
1348+
}
1349+
1350+
/// <summary>
1351+
/// Waits for the volume snapshot to be deleted.
1352+
/// <para>Treats a 404 NotFound exception as confirmation that it is deleted.</para>
1353+
/// </summary>
1354+
/// <param name="snapshotId">The snapshot identifier.</param>
1355+
/// <param name="refreshDelay">The amount of time to wait between requests.</param>
1356+
/// <param name="timeout">The amount of time to wait before throwing a <see cref="TimeoutException"/>.</param>
1357+
/// <param name="progress">The progress callback.</param>
1358+
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
1359+
/// <exception cref="TimeoutException">If the <paramref name="timeout"/> value is reached.</exception>
1360+
/// <exception cref="FlurlHttpException">If the API call returns a bad <see cref="HttpStatusCode"/>.</exception>
1361+
public Task WaitUntilVolumeSnapshotIsDeletedAsync<TVolume, TStatus>(string snapshotId, TimeSpan? refreshDelay = null, TimeSpan? timeout = null, IProgress<bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
1362+
where TVolume : IServiceResource
1363+
where TStatus : ResourceStatus
1364+
{
1365+
if (snapshotId == null)
1366+
throw new ArgumentNullException("snapshotId");
1367+
1368+
Func<Task<dynamic>> getSnapshot = async () => await GetVolumeSnapshotAsync<TVolume>(snapshotId, cancellationToken);
1369+
return Endpoint.WaitUntilDeletedAsync<TStatus>(snapshotId, getSnapshot, refreshDelay, timeout, progress, cancellationToken);
1370+
}
11551371
#endregion
11561372

11571373
#region Compute Service

0 commit comments

Comments
 (0)