+ ".ebs-template; this property should be in the format defined in TemplateBuilderSpec");
}
InstanceClient instanceClient = EC2Client.class.cast(view.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
.getInstanceServices();
ElasticBlockStoreClient ebsClient = EC2Client.class.cast(view.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
.getElasticBlockStoreServices();
String group = this.group + "e";
int volumeSize = 8;
final Template template = view.getComputeService().templateBuilder().from(ebsTemplate).build();
Location zone = Iterables.find(view.getComputeService().listAssignableLocations(), new Predicate<Location>() {
@Override
public boolean apply(Location arg0) {
return arg0.getScope() == LocationScope.ZONE
&& arg0.getParent().getId().equals(template.getLocation().getId());
}
});
// create volume only to make a snapshot
Volume volume = ebsClient.createVolumeInAvailabilityZone(zone.getId(), 4);
Snapshot snapshot = ebsClient.createSnapshotInRegion(volume.getRegion(), volume.getId());
ebsClient.deleteVolumeInRegion(volume.getRegion(), volume.getId());
template.getOptions().as(EC2TemplateOptions.class)//
// .unmapDeviceNamed("/dev/foo)
.mapEphemeralDeviceToDeviceName("/dev/sdm", "ephemeral0")//
.mapNewVolumeToDeviceName("/dev/sdn", volumeSize, true)//
.mapEBSSnapshotToDeviceName("/dev/sdo", snapshot.getId(), volumeSize, true);
try {
NodeMetadata node = Iterables.getOnlyElement(client.createNodesInGroup(group, 1, template));
// TODO figure out how to validate the ephemeral drive. perhaps with df -k?
Map<String, BlockDevice> devices = instanceClient.getBlockDeviceMappingForInstanceInRegion(node.getLocation()
.getParent().getId(), node.getProviderId());
BlockDevice device = devices.get("/dev/sdn");
// check delete on termination
assertTrue(device.isDeleteOnTermination());
volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
device.getVolumeId()));
// check volume size
assertEquals(volumeSize, volume.getSize());
device = devices.get("/dev/sdo");
// check delete on termination
assertTrue(device.isDeleteOnTermination());
volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
device.getVolumeId()));
// check volume size
assertEquals(volumeSize, volume.getSize());
// check volume's snapshot id
assertEquals(snapshot.getId(), volume.getSnapshotId());
} finally {
client.destroyNodesMatching(NodePredicates.inGroup(group));
ebsClient.deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId());
}
}