Skip to content

Commit e501ccf

Browse files
committed
Compute os-volumes
2 parents b187ae7 + dc620c3 commit e501ccf

23 files changed

Lines changed: 1011 additions & 8 deletions

src/corelib/Compute/v2_1/ComputeApiBuilder.cs

Lines changed: 200 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,15 +1151,15 @@ public virtual async Task<TPage> ListImageDetailsAsync<TPage>(Url url, Cancellat
11511151
public virtual async Task<T> ListSecurityGroupsAsync<T>(string serverId = null, CancellationToken cancellationToken = default(CancellationToken))
11521152
where T : IEnumerable<IServiceResource>
11531153
{
1154-
var result = await BuildListSecurityGropusAsync(serverId, cancellationToken)
1154+
var result = await BuildListSecurityGroupsAsync(serverId, cancellationToken)
11551155
.SendAsync()
11561156
.ReceiveJson<T>();
11571157
result.PropogateOwner(this);
11581158
return result;
11591159
}
11601160

11611161
/// <summary />
1162-
public virtual async Task<PreparedRequest> BuildListSecurityGropusAsync(string serverId = null, CancellationToken cancellationToken = default(CancellationToken))
1162+
public virtual async Task<PreparedRequest> BuildListSecurityGroupsAsync(string serverId = null, CancellationToken cancellationToken = default(CancellationToken))
11631163
{
11641164
Url endpoint = await UrlBuilder.GetEndpoint(cancellationToken).ConfigureAwait(false);
11651165

@@ -1246,6 +1246,204 @@ public virtual async Task<TPage> ListImageDetailsAsync<TPage>(Url url, Cancellat
12461246

12471247
#endregion
12481248

1249+
#region Server Groups
1250+
1251+
/// <summary />
1252+
public virtual async Task<T> GetServerGroupAsync<T>(string serverGroupId, CancellationToken cancellationToken = default(CancellationToken))
1253+
where T : IServiceResource
1254+
{
1255+
var result = await BuildGetServerGroupsAsync(serverGroupId, cancellationToken)
1256+
.SendAsync()
1257+
.ReceiveJson<T>();
1258+
result.PropogateOwner(this);
1259+
return result;
1260+
}
1261+
1262+
/// <summary />
1263+
public virtual async Task<PreparedRequest> BuildGetServerGroupsAsync(string serverGroupId, CancellationToken cancellationToken = default(CancellationToken))
1264+
{
1265+
if (serverGroupId == null)
1266+
throw new ArgumentNullException("serverGroupId");
1267+
1268+
Url endpoint = await UrlBuilder.GetEndpoint(cancellationToken).ConfigureAwait(false);
1269+
1270+
return endpoint
1271+
.AppendPathSegment($"os-server-groups/{serverGroupId}")
1272+
.Authenticate(AuthenticationProvider)
1273+
.SetMicroversion(this)
1274+
.PrepareGet(cancellationToken);
1275+
}
1276+
1277+
/// <summary />
1278+
public virtual async Task<T> CreateServerGroupAsync<T>(object serverGroup, CancellationToken cancellationToken = default(CancellationToken))
1279+
where T : IServiceResource
1280+
{
1281+
var result = await BuildCreateServerGroupAsync(serverGroup, cancellationToken).SendAsync().ReceiveJson<T>();
1282+
result.PropogateOwner(this);
1283+
return result;
1284+
}
1285+
1286+
/// <summary />
1287+
public virtual async Task<PreparedRequest> BuildCreateServerGroupAsync(object serverGroup, CancellationToken cancellationToken = default(CancellationToken))
1288+
{
1289+
if (serverGroup == null)
1290+
throw new ArgumentNullException("serverGroup");
1291+
1292+
Url endpoint = await UrlBuilder.GetEndpoint(cancellationToken).ConfigureAwait(false);
1293+
1294+
return endpoint
1295+
.AppendPathSegments("os-server-groups")
1296+
.Authenticate(AuthenticationProvider)
1297+
.SetMicroversion(this)
1298+
.PreparePostJson(serverGroup, cancellationToken);
1299+
}
1300+
1301+
/// <summary />
1302+
public virtual async Task<T> ListServerGroupsAsync<T>(CancellationToken cancellationToken = default(CancellationToken))
1303+
where T : IEnumerable<IServiceResource>
1304+
{
1305+
var result = await BuildListServerGroupsAsync(cancellationToken)
1306+
.SendAsync()
1307+
.ReceiveJson<T>();
1308+
result.PropogateOwner(this);
1309+
return result;
1310+
}
1311+
1312+
/// <summary />
1313+
public virtual async Task<PreparedRequest> BuildListServerGroupsAsync(CancellationToken cancellationToken = default(CancellationToken))
1314+
{
1315+
Url endpoint = await UrlBuilder.GetEndpoint(cancellationToken).ConfigureAwait(false);
1316+
1317+
return endpoint
1318+
.AppendPathSegment("os-server-groups")
1319+
.Authenticate(AuthenticationProvider)
1320+
.SetMicroversion(this)
1321+
.PrepareGet(cancellationToken);
1322+
}
1323+
1324+
/// <summary />
1325+
public virtual Task DeleteServerGroupAsync(string serverGroupId, CancellationToken cancellationToken = default(CancellationToken))
1326+
{
1327+
return BuildDeleteServerGroupAsync(serverGroupId, cancellationToken).SendAsync();
1328+
}
1329+
1330+
/// <summary />
1331+
public virtual async Task<PreparedRequest> BuildDeleteServerGroupAsync(string serverGroupId, CancellationToken cancellationToken = default(CancellationToken))
1332+
{
1333+
if (serverGroupId == null)
1334+
throw new ArgumentNullException("serverGroupId");
1335+
1336+
Url endpoint = await UrlBuilder.GetEndpoint(cancellationToken).ConfigureAwait(false);
1337+
1338+
return (PreparedRequest)endpoint
1339+
.AppendPathSegment($"os-server-groups/{serverGroupId}")
1340+
.Authenticate(AuthenticationProvider)
1341+
.SetMicroversion(this)
1342+
.PrepareDelete(cancellationToken)
1343+
.AllowHttpStatus(HttpStatusCode.NotFound);
1344+
}
1345+
1346+
#endregion
1347+
1348+
#region Volumes
1349+
1350+
/// <summary />
1351+
public virtual async Task<T> GetVolumeAsync<T>(string volumeId, CancellationToken cancellationToken = default(CancellationToken))
1352+
where T : IServiceResource
1353+
{
1354+
var result = await BuildGetVolumesAsync(volumeId, cancellationToken)
1355+
.SendAsync()
1356+
.ReceiveJson<T>();
1357+
result.PropogateOwner(this);
1358+
return result;
1359+
}
1360+
1361+
/// <summary />
1362+
public virtual async Task<PreparedRequest> BuildGetVolumesAsync(string volumeId, CancellationToken cancellationToken = default(CancellationToken))
1363+
{
1364+
if (volumeId == null)
1365+
throw new ArgumentNullException("volumeId");
1366+
1367+
Url endpoint = await UrlBuilder.GetEndpoint(cancellationToken).ConfigureAwait(false);
1368+
1369+
return endpoint
1370+
.AppendPathSegment($"os-volumes/{volumeId}")
1371+
.Authenticate(AuthenticationProvider)
1372+
.SetMicroversion(this)
1373+
.PrepareGet(cancellationToken);
1374+
}
1375+
1376+
/// <summary />
1377+
public virtual async Task<T> CreateVolumeAsync<T>(object volume, CancellationToken cancellationToken = default(CancellationToken))
1378+
where T : IServiceResource
1379+
{
1380+
var result = await BuildCreateVolumeAsync(volume, cancellationToken).SendAsync().ReceiveJson<T>();
1381+
result.PropogateOwner(this);
1382+
return result;
1383+
}
1384+
1385+
/// <summary />
1386+
public virtual async Task<PreparedRequest> BuildCreateVolumeAsync(object volume, CancellationToken cancellationToken = default(CancellationToken))
1387+
{
1388+
if (volume == null)
1389+
throw new ArgumentNullException("volume");
1390+
1391+
Url endpoint = await UrlBuilder.GetEndpoint(cancellationToken).ConfigureAwait(false);
1392+
1393+
return endpoint
1394+
.AppendPathSegments("os-volumes")
1395+
.Authenticate(AuthenticationProvider)
1396+
.SetMicroversion(this)
1397+
.PreparePostJson(volume, cancellationToken);
1398+
}
1399+
1400+
/// <summary />
1401+
public virtual async Task<T> ListVolumesAsync<T>(CancellationToken cancellationToken = default(CancellationToken))
1402+
where T : IEnumerable<IServiceResource>
1403+
{
1404+
var result = await BuildListVolumesAsync(cancellationToken)
1405+
.SendAsync()
1406+
.ReceiveJson<T>();
1407+
result.PropogateOwner(this);
1408+
return result;
1409+
}
1410+
1411+
/// <summary />
1412+
public virtual async Task<PreparedRequest> BuildListVolumesAsync(CancellationToken cancellationToken = default(CancellationToken))
1413+
{
1414+
Url endpoint = await UrlBuilder.GetEndpoint(cancellationToken).ConfigureAwait(false);
1415+
1416+
return endpoint
1417+
.AppendPathSegment("os-volumes")
1418+
.Authenticate(AuthenticationProvider)
1419+
.SetMicroversion(this)
1420+
.PrepareGet(cancellationToken);
1421+
}
1422+
1423+
/// <summary />
1424+
public virtual Task DeleteVolumeAsync(string volumeId, CancellationToken cancellationToken = default(CancellationToken))
1425+
{
1426+
return BuildDeleteVolumeAsync(volumeId, cancellationToken).SendAsync();
1427+
}
1428+
1429+
/// <summary />
1430+
public virtual async Task<PreparedRequest> BuildDeleteVolumeAsync(string volumeId, CancellationToken cancellationToken = default(CancellationToken))
1431+
{
1432+
if (volumeId == null)
1433+
throw new ArgumentNullException("volumeId");
1434+
1435+
Url endpoint = await UrlBuilder.GetEndpoint(cancellationToken).ConfigureAwait(false);
1436+
1437+
return (PreparedRequest)endpoint
1438+
.AppendPathSegment($"os-volumes/{volumeId}")
1439+
.Authenticate(AuthenticationProvider)
1440+
.SetMicroversion(this)
1441+
.PrepareDelete(cancellationToken)
1442+
.AllowHttpStatus(HttpStatusCode.NotFound);
1443+
}
1444+
1445+
#endregion
1446+
12491447
#region Compute Service
12501448
/// <summary />
12511449
public virtual Task<T> GetLimitsAsync<T>(CancellationToken cancellationToken = default(CancellationToken))

src/corelib/Compute/v2_1/ComputeService.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,62 @@ public ComputeService(IAuthenticationProvider authenticationProvider, string reg
386386

387387
#endregion
388388

389+
#region Sever Groups
390+
391+
/// <inheritdoc cref="ComputeApiBuilder.GetServerGroupAsync{T}" />
392+
public Task<ServerGroup> GetServerGroupAsync(Identifier serverGroupId, CancellationToken cancellationToken = default(CancellationToken))
393+
{
394+
return _computeApi.GetServerGroupAsync<ServerGroup>(serverGroupId, cancellationToken);
395+
}
396+
397+
/// <inheritdoc cref="ComputeApiBuilder.CreateServerGroupAsync{T}" />
398+
public Task<ServerGroup> CreateServerGroupAsync(ServerGroupDefinition serverGroup, CancellationToken cancellationToken = default(CancellationToken))
399+
{
400+
return _computeApi.CreateServerGroupAsync<ServerGroup>(serverGroup, cancellationToken);
401+
}
402+
403+
/// <inheritdoc cref="ComputeApiBuilder.ListServerGroupsAsync{T}" />
404+
public async Task<IEnumerable<ServerGroup>> ListServerGroupsAsync(CancellationToken cancellationToken = default(CancellationToken))
405+
{
406+
return await _computeApi.ListServerGroupsAsync<ServerGroupCollection>(cancellationToken);
407+
}
408+
409+
/// <inheritdoc cref="ComputeApiBuilder.DeleteServerGroupAsync" />
410+
public Task DeleteServerGroupAsync(Identifier serverGroupId, CancellationToken cancellationToken = default(CancellationToken))
411+
{
412+
return _computeApi.DeleteServerGroupAsync(serverGroupId, cancellationToken);
413+
}
414+
415+
#endregion
416+
417+
#region Volumes
418+
419+
/// <inheritdoc cref="ComputeApiBuilder.GetVolumeAsync{T}" />
420+
public Task<Volume> GetVolumeAsync(Identifier volumeId, CancellationToken cancellationToken = default(CancellationToken))
421+
{
422+
return _computeApi.GetVolumeAsync<Volume>(volumeId, cancellationToken);
423+
}
424+
425+
/// <inheritdoc cref="ComputeApiBuilder.CreateVolumeAsync{T}" />
426+
public Task<Volume> CreateVolumeAsync(VolumeDefinition volume, CancellationToken cancellationToken = default(CancellationToken))
427+
{
428+
return _computeApi.CreateVolumeAsync<Volume>(volume, cancellationToken);
429+
}
430+
431+
/// <inheritdoc cref="ComputeApiBuilder.ListVolumesAsync{T}" />
432+
public async Task<IEnumerable<Volume>> ListVolumesAsync(CancellationToken cancellationToken = default(CancellationToken))
433+
{
434+
return await _computeApi.ListVolumesAsync<VolumeCollection>(cancellationToken);
435+
}
436+
437+
/// <inheritdoc cref="ComputeApiBuilder.DeleteVolumeAsync" />
438+
public Task DeleteVolumeAsync(Identifier volumeId, CancellationToken cancellationToken = default(CancellationToken))
439+
{
440+
return _computeApi.DeleteVolumeAsync(volumeId, cancellationToken);
441+
}
442+
443+
#endregion
444+
389445
#region Compute Service
390446
/// <inheritdoc cref="ComputeApiBuilder.GetLimitsAsync{T}" />
391447
public Task<ServiceLimits> GetLimitsAsync(CancellationToken cancellationToken = default(CancellationToken))

src/corelib/Compute/v2_1/ComputeServiceExtensions.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,62 @@ public static void DeleteSecurityGroup(this ComputeService service, Identifier s
366366

367367
#endregion
368368

369+
#region Server Groups
370+
371+
/// <inheritdoc cref="ComputeService.GetServerGroupAsync" />
372+
public static ServerGroup GetServerGroup(this ComputeService service, Identifier severGroupId)
373+
{
374+
return service.GetServerGroupAsync(severGroupId).ForceSynchronous();
375+
}
376+
377+
/// <inheritdoc cref="ComputeService.CreateServerGroupAsync" />
378+
public static ServerGroup CreateServerGroup(this ComputeService service, ServerGroupDefinition serverGroup)
379+
{
380+
return service.CreateServerGroupAsync(serverGroup).ForceSynchronous();
381+
}
382+
383+
/// <inheritdoc cref="ComputeService.ListServerGroupsAsync" />
384+
public static IEnumerable<ServerGroup> ListServerGroups(this ComputeService service)
385+
{
386+
return service.ListServerGroupsAsync().ForceSynchronous();
387+
}
388+
389+
/// <inheritdoc cref="ComputeService.DeleteServerGroupAsync" />
390+
public static void DeleteServerGroup(this ComputeService service, Identifier serverGroupId)
391+
{
392+
service.DeleteServerGroupAsync(serverGroupId).ForceSynchronous();
393+
}
394+
395+
#endregion
396+
397+
#region Volumes
398+
399+
/// <inheritdoc cref="ComputeService.GetVolumeAsync" />
400+
public static Volume GetVolume(this ComputeService service, Identifier volumeId)
401+
{
402+
return service.GetVolumeAsync(volumeId).ForceSynchronous();
403+
}
404+
405+
/// <inheritdoc cref="ComputeService.CreateVolumeAsync" />
406+
public static Volume CreateVolume(this ComputeService service, VolumeDefinition volume)
407+
{
408+
return service.CreateVolumeAsync(volume).ForceSynchronous();
409+
}
410+
411+
/// <inheritdoc cref="ComputeService.ListVolumesAsync" />
412+
public static IEnumerable<Volume> ListVolumes(this ComputeService service)
413+
{
414+
return service.ListVolumesAsync().ForceSynchronous();
415+
}
416+
417+
/// <inheritdoc cref="ComputeService.DeleteVolumeAsync" />
418+
public static void DeleteVolume(this ComputeService service, Identifier volumeId)
419+
{
420+
service.DeleteVolumeAsync(volumeId).ForceSynchronous();
421+
}
422+
423+
#endregion
424+
369425
#region Compute Service
370426
/// <inheritdoc cref="ComputeService.GetLimitsAsync" />
371427
public static ServiceLimits GetLimits(this ComputeService service)

src/corelib/Compute/v2_1/SchedulerHints.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,15 @@ public SchedulerHints()
3838
/// <summary />
3939
[JsonExtensionData]
4040
public IDictionary<string, JToken> Data { get; set; } = new Dictionary<string, JToken>();
41+
42+
/// <summary>
43+
/// Adds a custom scheduling hint.
44+
/// </summary>
45+
/// <param name="hint">The hint key.</param>
46+
/// <param name="value">The hint value.</param>
47+
public void Add(string hint, object value)
48+
{
49+
Data.Add(hint, JToken.FromObject(value));
50+
}
4151
}
4252
}

0 commit comments

Comments
 (0)