bug 12957: sort volume by device id to make sure ROOT disk device is configured at the very first

This commit is contained in:
Kelven Yang 2012-01-25 11:44:36 -08:00
parent c023db10cc
commit b0154aeb5c
1 changed files with 26 additions and 2 deletions

View File

@ -1323,7 +1323,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
i++;
}
for (VolumeTO vol : disks) {
for (VolumeTO vol : sortVolumesByDeviceId(disks)) {
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
if (vol.getType() == Volume.Type.ISO) {
@ -1525,7 +1525,31 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
});
return listForSort.toArray(new NicTO[0]);
}
}
private VolumeTO[] sortVolumesByDeviceId(VolumeTO[] volumes) {
List<VolumeTO> listForSort = new ArrayList<VolumeTO>();
for (VolumeTO vol : volumes) {
listForSort.add(vol);
}
Collections.sort(listForSort, new Comparator<VolumeTO>() {
@Override
public int compare(VolumeTO arg0, VolumeTO arg1) {
if (arg0.getDeviceId() < arg1.getDeviceId()) {
return -1;
} else if (arg0.getDeviceId() == arg1.getDeviceId()) {
return 0;
}
return 1;
}
});
return listForSort.toArray(new VolumeTO[0]);
}
private HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> inferDatastoreDetailsFromDiskInfo(VmwareHypervisorHost hyperHost, VmwareContext context, VolumeTO[] disks) throws Exception {
HashMap<String ,Pair<ManagedObjectReference, DatastoreMO>> poolMors = new HashMap<String, Pair<ManagedObjectReference, DatastoreMO>>();