Skip to content

Commit b187ae7

Browse files
committed
Boot from Volume
1 parent f4a43d7 commit b187ae7

4 files changed

Lines changed: 104 additions & 3 deletions

File tree

src/corelib/Compute/v2_1/ServerBlockDeviceMapping.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace OpenStack.Compute.v2_1
1111
public class ServerBlockDeviceMapping
1212
{
1313
/// <summary />
14-
[JsonProperty("boot_index")]
14+
[JsonProperty("boot_index", DefaultValueHandling = DefaultValueHandling.Include)]
1515
public int BootIndex { get; set; }
1616

1717
/// <summary />
@@ -20,7 +20,7 @@ public class ServerBlockDeviceMapping
2020

2121
/// <summary />
2222
[JsonProperty("uuid")]
23-
public Identifier VolumeId { get; set; }
23+
public Identifier SourceId { get; set; }
2424

2525
/// <summary />
2626
[JsonProperty("source_type")]
@@ -30,6 +30,10 @@ public class ServerBlockDeviceMapping
3030
[JsonProperty("destination_type")]
3131
public VolumeType DestinationType { get; set; }
3232

33+
/// <summary /> // in GB
34+
[JsonProperty("volume_size")]
35+
public int? DestinationVolumeSize { get; set; }
36+
3337
/// <summary />
3438
[JsonProperty("delete_on_termination")]
3539
public bool DeleteWithServer { get; set; }

src/corelib/Compute/v2_1/ServerCreateDefinition.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,58 @@ public void LoadUserDataFromFile(string path)
8383
byte[] contents = System.IO.File.ReadAllBytes(path);
8484
UserData = System.Convert.ToBase64String(contents);
8585
}
86+
87+
/// <summary>
88+
/// Configures the server to boot from an existing volume.
89+
/// </summary>
90+
/// <param name="volumeId">The volume identifier.</param>
91+
/// <param name="deleteVolumeWithServer">if set to <c>true</c> [delete volume with server].</param>
92+
public void ConfigureBootFromVolume(Identifier volumeId, bool deleteVolumeWithServer = false)
93+
{
94+
BlockDeviceMapping.Add(new ServerBlockDeviceMapping
95+
{
96+
SourceType = VolumeType.Volume,
97+
SourceId = volumeId,
98+
BootIndex = 0,
99+
DeleteWithServer = deleteVolumeWithServer
100+
});
101+
}
102+
103+
/// <summary>
104+
/// Configures the server to boot from a copy of an existing volume.
105+
/// </summary>
106+
/// <param name="volumeId">The volume identifier.</param>
107+
/// <param name="volumeSize">Size of the volume.</param>
108+
/// <param name="deleteVolumeWithServer">if set to <c>true</c> [delete volume with server].</param>
109+
public void ConfigureBootFromNewVolume(Identifier volumeId, int volumeSize, bool deleteVolumeWithServer = false)
110+
{
111+
BlockDeviceMapping.Add(new ServerBlockDeviceMapping
112+
{
113+
SourceType = VolumeType.Volume,
114+
SourceId = volumeId,
115+
BootIndex = 0,
116+
DestinationType = VolumeType.Volume,
117+
DestinationVolumeSize = volumeSize,
118+
DeleteWithServer = deleteVolumeWithServer
119+
});
120+
}
121+
122+
/// <summary>
123+
/// Configures the server to boot from a new volume, copied from the base server image.
124+
/// </summary>
125+
/// <param name="volumeSize">Size of the volume.</param>
126+
/// <param name="deleteVolumeWithServer">if set to <c>true</c> [delete volume with server].</param>
127+
public void ConfigureBootFromNewVolume(int volumeSize, bool deleteVolumeWithServer = false)
128+
{
129+
BlockDeviceMapping.Add(new ServerBlockDeviceMapping
130+
{
131+
SourceType = VolumeType.Image,
132+
SourceId = ImageId,
133+
BootIndex = 0,
134+
DestinationType = VolumeType.Volume,
135+
DestinationVolumeSize = volumeSize,
136+
DeleteWithServer = deleteVolumeWithServer
137+
});
138+
}
86139
}
87140
}

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,50 @@ public async Task CreateServerTest()
8686
Assert.Equal(ServerEventStatus.Success, createEvent.Result);
8787
}
8888

89+
[Fact]
90+
[Trait("ci", "false")] // TODO: Run with CI tests once we've implemented cinder
91+
public async Task BootFromVolume()
92+
{
93+
var definition = _testData.BuildServer();
94+
definition.ConfigureBootFromVolume("30ca5d77-c519-48ea-a56c-7c4e0ca0894d");
95+
96+
Trace.WriteLine("Booting new server from volume...");
97+
var server = await _testData.CreateServer(definition);
98+
await server.WaitUntilActiveAsync();
99+
100+
Assert.NotEmpty(server.AttachedVolumes);
101+
Assert.Contains(server.AttachedVolumes, x => x.Id == definition.BlockDeviceMapping[0].SourceId);
102+
}
103+
104+
[Fact]
105+
[Trait("ci", "false")] // TODO: Run with CI tests once we've implemented cinder
106+
public async Task BootFromVolumeCopy()
107+
{
108+
var definition = _testData.BuildServer();
109+
definition.ConfigureBootFromNewVolume("30ca5d77-c519-48ea-a56c-7c4e0ca0894d", volumeSize: 1, deleteVolumeWithServer: true);
110+
111+
Trace.WriteLine("Booting new server from a new volume created from an existing volume...");
112+
var server = await _testData.CreateServer(definition);
113+
await server.WaitUntilActiveAsync();
114+
115+
Assert.NotEmpty(server.AttachedVolumes);
116+
Assert.Contains(server.AttachedVolumes, x => x.Id == definition.BlockDeviceMapping[0].SourceId);
117+
}
118+
119+
[Fact]
120+
[Trait("ci", "false")] // TODO: Run with CI tests once we've implemented cinder
121+
public async Task BootFromImageCopy()
122+
{
123+
var definition = _testData.BuildServer();
124+
definition.ConfigureBootFromNewVolume(volumeSize: 1, deleteVolumeWithServer: true);
125+
Trace.WriteLine("Booting new server from a new volume created from an existing image...");
126+
var server = await _testData.CreateServer(definition);
127+
await server.WaitUntilActiveAsync();
128+
129+
Assert.NotEmpty(server.AttachedVolumes);
130+
Assert.Contains(server.AttachedVolumes, x => x.Id != definition.BlockDeviceMapping[0].SourceId);
131+
}
132+
89133
[Fact]
90134
public async Task ListServerReferencesTest()
91135
{

src/testing/integration/ContentDeliveryNetworks/v1/ContentDeliveryNetworkServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace OpenStack.ContentDeliveryNetworks.v1
77
{
8-
[Trait("ci","false")]
8+
[Trait("ci","false")] // TODO: Run these with the CI tests once Poppy is installed on our environment
99
public class ContentDeliveryNetworkServiceTests : IDisposable
1010
{
1111
private readonly ContentDeliveryNetworkService _cdnService;

0 commit comments

Comments
 (0)