}
// not possible, Home initializes
if (worksp == null) {
logger.error(NO_WRKSP);
throw new WorkspaceException(NO_WRKSP);
}
final ArrayList cmd = new ArrayList(16);
cmd.add(worksp);
cmd.add("--create");
if (startpaused) {
cmd.add("--startpaused");
}
cmd.add("--name");
cmd.add(xenName(vm));
if (vm.getDeployment() != null) {
final VirtualMachineDeployment dep = vm.getDeployment();
// the service does not currently support a default memory
// config, but workspace_control does -- in the future,
// decision to allow a default memory config will be policy
// driven at service level
if (dep.getIndividualPhysicalMemory() > 0) {
cmd.add("--memory");
cmd.add(Integer.toString(dep.getIndividualPhysicalMemory()));
}
if (dep.getIndividualCPUCount() > 0) {
cmd.add("--vcpus");
cmd.add(Integer.toString(dep.getIndividualCPUCount()));
}
}
if (vm.getKernel() != null) {
cmd.add("--kernel");
cmd.add(vm.getKernel());
}
if (vm.getKernelParameters() != null) {
cmd.add("--kernelargs");
cmd.add(vm.getKernelParameters());
}
if (vm.getNetwork() != null) {
cmd.add("--networking");
final String net = "'" + hackStatic(vm.getNetwork()) + "'";
cmd.add(net);
}
// sources:
VirtualMachinePartition rootdisk = null;
final ArrayList regularPartitions = new ArrayList();
final ArrayList blankPartitions = new ArrayList();
// results to send:
final ArrayList images = new ArrayList();
final ArrayList imagemounts = new ArrayList();
final VirtualMachinePartition[] partitions = vm.getPartitions();
if (partitions == null || partitions.length == 0) {
final String err = "should be at least one partition, Binding " +
"should have caught at the outset";
logger.error(err);
throw new WorkspaceException(err);
} else {
for (int i = 0; i < partitions.length; i++) {
if (partitions[i].isRootdisk()) {
rootdisk = partitions[i];
} else if (partitions[i].getBlankspace() > 0) {
blankPartitions.add(partitions[i]);
} else {
regularPartitions.add(partitions[i]);
}
}
}
// todo: generalize when propagating more than just rootdisk
if (rootdisk != null) {
String rootImageURI = rootdisk.getImage();
// We know that if Propagate was required and notificationInfo
// is null that this is a create command following a successful
// Propagate-only command, so we let the backend know it can
// find the file in its workspace-specific secureimage directory
// by setting this file URL to a relative path -- relative paths
// hitting the backend always cause the workspace-specific
// secureimage directory to be consulted first
if (vm.isPropagateRequired() && notificationInfo == null) {
final String newURI = convertToAlreadyPropagated(rootImageURI, vm);
logger.debug("turned '" + rootImageURI + "' into '" +
newURI + "' because file was already propagated");
// not handling readonly root partition yet
images.add(newURI);
} else {
// not handling readonly root partition yet
images.add(rootImageURI);
}
imagemounts.add(rootdisk.getImagemount());
}
if (!blankPartitions.isEmpty()) {
int blankNum = 0;
final Iterator iter = blankPartitions.iterator();
while (iter.hasNext()) {
final VirtualMachinePartition blank =
(VirtualMachinePartition) iter.next();
final int megs = blank.getBlankspace();
//When unpropagate support is added for blank partitions,
// this file will likely be unpropagated to the image node
// with the originally supplied filename as target -- and
// perhaps some schema change will allow the user to specify
// whether or not it should be saved at all (when serializing
// it would have to be)
images.add("blankcreate://blankpartition" + blankNum
+ "-size-" + megs);
imagemounts.add(blank.getImagemount());
blankNum += 1;
// (assuming blank partition will always be readwrite)
}
}
if (!regularPartitions.isEmpty()) {
final Iterator iter = regularPartitions.iterator();
while (iter.hasNext()) {
final VirtualMachinePartition regular =
(VirtualMachinePartition) iter.next();
String imgStr = regular.getImage();
if (!regular.isReadwrite()) {
imgStr += WC_FIELD_SEPARATOR + "ro";
}
images.add(imgStr);
imagemounts.add(regular.getImagemount());
}
}
if (images.isEmpty()) {
final String err = "should be at least one image here...";
logger.error(err);
throw new WorkspaceException(err);
}
Iterator iter = images.iterator();
String imageString = "";
imageString += (String) iter.next();
while (iter.hasNext()) {
imageString += WC_GROUP_SEPARATOR;
imageString += (String) iter.next();
}
cmd.add("--images");
cmd.add("'" + imageString + "'");
if (imagemounts.isEmpty()) {
final String err = "should be at least one image and hence at least " +
"one imagemount string here...";
logger.error(err);
throw new WorkspaceException(err);
}
iter = imagemounts.iterator();
String imagemountString = "";
imagemountString += (String) iter.next();