NodeGroupCreate nodeGroup, int index) {
String vmName =
PlacementUtil.getVmName(cluster.getName(), nodeGroup.getName(),
index);
BaseNode node = new BaseNode(vmName, nodeGroup, cluster);
// initialize disks
List<DiskSpec> disks = new ArrayList<DiskSpec>();
DiskSpec systemDisk = new DiskSpec(templateNode.getDisks().get(0));
/*
* TRICK: here we count the size of vswp file into the system disk size, as the
* vswp file will be put together with system disk.
*/
Integer memCapa = nodeGroup.getMemCapacityMB();
memCapa = (memCapa == null) ? 0 : memCapa;
systemDisk.setSize(systemDisk.getSize() + (memCapa + 1023) / 1024);
systemDisk.setDiskType(DiskType.SYSTEM_DISK);
systemDisk.setSeparable(false);
disks.add(systemDisk);
AllocationType diskAllocType = null;
if (nodeGroup.getStorage().getAllocType() != null) {
diskAllocType =
AllocationType.valueOf(nodeGroup.getStorage().getAllocType());
} else {
// THICK as by default
diskAllocType = AllocationType.THICK;
}
// swap disk
int swapDisk =
(((int) Math.ceil(nodeGroup.getMemCapacityMB()
* nodeGroup.getSwapRatio()) + 1023) / 1024);
disks.add(new DiskSpec(DiskType.SWAP_DISK.getDiskName(), swapDisk, node
.getVmName(), false, DiskType.SWAP_DISK,
DiskScsiControllerType.LSI_CONTROLLER, null, diskAllocType
.toString(), null, null, null));
// data disks
if (!DatastoreType.TEMPFS.name().equalsIgnoreCase(
nodeGroup.getStorage().getType())) {
// no need to add data disk for storage type tempfs
disks.add(new DiskSpec(DiskType.DATA_DISK.getDiskName(), nodeGroup
.getStorage().getSizeGB(), node.getVmName(), true,
DiskType.DATA_DISK, nodeGroup.getStorage().getControllerType(),
nodeGroup.getStorage().getSplitPolicy(), diskAllocType
.toString(), null, null, null));
}
node.setDisks(disks);
// target vm folder
node.setVmFolder(nodeGroup.getVmFolderPath());
// target network, hard coded as the only one NIC
NetworkSchema netSchema = new NetworkSchema();
ArrayList<Network> networks = new ArrayList<Network>();
netSchema.networks = networks;
// TODO: enhance this logic to support nodegroup level networks
for (NetworkAdd networkAdd : cluster.getNetworkings()) {
Network network = new Network();
network.vcNetwork = networkAdd.getPortGroup();
networks.add(network);
}
node.getVmSchema().networkSchema = netSchema;
// resource schema
ResourceSchema resourceSchema = new ResourceSchema();
resourceSchema.numCPUs = node.getCpu();
// we don't reserve cpu resource
resourceSchema.cpuReservationMHz = 0;
resourceSchema.memSize = node.getMem();
resourceSchema.memReservationSize = 0;
resourceSchema.name = "Resource Schema";
resourceSchema.priority = Priority.Normal;
node.getVmSchema().resourceSchema = resourceSchema;
return node;
}