int index = 0;
int remain = separable.getSize();
List<DiskSpec> disks = new ArrayList<DiskSpec>();
for (; i < datastores.size(); i++) {
AbstractDatastore ds = datastores.get(i);
if (ds.getFreeSpace() == 0)
continue;
int size = remain;
if (remain > ds.getFreeSpace()) {
size = ds.getFreeSpace();
}
remain -= size;
DiskSpec subDisk = new DiskSpec(separable);
subDisk.setSize(size);
subDisk.setSeparable(false);
subDisk.setTargetDs(ds.getName());
// new name with index as suffix, e.g., DATA1.vmdk
subDisk.setName(separable.getName().split("\\.")[0] + index + ".vmdk");
disks.add(subDisk);
ds.allocate(size);
index++;
if (remain == 0)
break;
}
// not enough space to place this disk