VcVmUtil { public static VmSchema getVmSchema(ClusterCreate spec, String nodeGroup, List<DiskSpec> diskSet, String templateVmId, String templateVmSnapId) { NodeGroupCreate groupSpec = spec.getNodeGroup(nodeGroup); VmSchema schema = new VmSchema(); ResourceSchema resourceSchema = new ResourceSchema(); resourceSchema.name = "Resource Schema"; resourceSchema.cpuReservationMHz = 0; resourceSchema.memReservationSize = 0; resourceSchema.numCPUs = (groupSpec.getCpuNum() == null) ? 0 : groupSpec.getCpuNum(); resourceSchema.memSize = (groupSpec.getMemCapacityMB() == null) ? 0 : groupSpec .getMemCapacityMB(); resourceSchema.priority = com.vmware.aurora.interfaces.model.IDatabaseConfig.Priority.Normal; LatencyPriority latencyPriority = groupSpec.getLatencySensitivity(); resourceSchema.latencySensitivity = (latencyPriority == null || CommonUtil.isBlank(latencyPriority.name()) ? LatencyPriority.NORMAL : latencyPriority); schema.resourceSchema = resourceSchema; VcVmUtil.sortDiskOrder(diskSet); DiskSchema diskSchema = new DiskSchema(); ArrayList<Disk> disks = new ArrayList<Disk>(diskSet.size()); for (DiskSpec disk : diskSet) { Disk tmDisk = new Disk(); tmDisk.name = disk.getName(); tmDisk.type = disk.getDiskType().getType(); tmDisk.initialSizeMB = disk.getSize() * 1024; if (disk.getAllocType() != null && !disk.getAllocType().isEmpty()) tmDisk.allocationType = AllocationType.valueOf(disk.getAllocType().toUpperCase()); else tmDisk.allocationType = null; tmDisk.datastore = disk.getTargetDs(); tmDisk.externalAddress = disk.getExternalAddress(); tmDisk.vmdkPath = disk.getVmdkPath(); tmDisk.mode = DiskMode.valueOf(disk.getDiskMode()); disks.add(tmDisk); } diskSchema.setParent(templateVmId); diskSchema.setParentSnap(templateVmSnapId); diskSchema.setDisks(disks); schema.diskSchema = diskSchema; ArrayList<Network> networks = new ArrayList<Network>(); List<NetworkAdd> networkAdds = spec.getNetworkings(); int labelIndex = 1; for (NetworkAdd networkAdd : networkAdds) { Network network = new Network(); network.vcNetwork = networkAdd.getPortGroup(); network.nicLabel = NIC_LABEL_PREFIX + labelIndex; labelIndex++; networks.add(network); } NetworkSchema networkSchema = new NetworkSchema(); networkSchema.name = "Network Schema"; networkSchema.networks = networks; schema.networkSchema = networkSchema; return schema; }  static boolean checkIpAddresses(final VcVirtualMachine vcVm); static List<String> getAllIpAddresses(final VcVirtualMachine vcVm); static Set<String> getAllIpAddresses(final VcVirtualMachine vcVm,
         final Set<String> portGroups, boolean inSession); static String getIpAddressOfPortGroup(final VcVirtualMachine vcVm,
         final String portGroup, boolean inSession); static ArrayList<String> getNodePrimaryMgtIPV4sFromEntitys(List<NodeEntity> nodes); static void populateNicInfo(final NicEntity nicEntity,
         final String moid, final String pgName); static String getGuestHostName(final VcVirtualMachine vcVm,
         boolean inSession); static boolean setBaseNodeForVm(BaseNode vNode, String vmId); static boolean verifyFTState(final VcVirtualMachine vm); static VirtualDisk findVirtualDisk(String vmMobId, String externalAddr); static String fetchDiskUUID(final String vmMobId, final String diskExtAddress); static void populateDiskInfo(final DiskEntity diskEntity,
         final String vmMobId); static boolean isDatastoreAccessible(String dsMobId); static void updateVm(String vmId); static boolean configIOShares(final String vmId,
         final Priority ioShares); static boolean runSPOnSingleVM(NodeEntity node, Callable<Void> call); static VcResourcePool getTargetRp(String clusterName,
         String groupName, NodeEntity node); static VmSchema getVmSchema(ClusterCreate spec, String nodeGroup,
         List<DiskSpec> diskSet, String templateVmId, String templateVmSnapId); static long makeVmMemoryDivisibleBy4(long memory); static void addBootupUUID(Map<String, String> bootupConfigs); static String getVolumes(String moid, List<Disk> disks); static List<DiskSpec> toDiskSpecList(Collection<DiskEntity> diskEntityCollection); static void sortDiskOrder(List<DiskSpec> diskSpecs); static String getVolumesFromSpecs(String moid, List<DiskSpec> diskEntities); static void destroyVm(final String vmId); static void destroyVm(final String vmId, Boolean inSession); static VcVirtualMachine findVmInRp(final VcResourcePool rp, final String vmName); static void rename(final String vmId, final String newName); static void enableFt(final VcVirtualMachine vm); static void disableHa(final VcVirtualMachine vm); static void enableDiskUUID(final VcVirtualMachine vm); static boolean enableOvfEnvTransport(final VcVirtualMachine vm); static boolean validateCPU(final String vmId, final int cpuNum); static boolean enableSyncTimeWithHost(final VcVirtualMachine vm); static void checkAndCreateSnapshot(final VmSchema vmSchema); static String getHostNameFromIpV4(VcVirtualMachine vcVm, String ipV4); static String getMgtHostName(VcVirtualMachine vcVm, String primaryMgtIpV4); static final String NIC_LABEL_PREFIX; }
@Test public void testGetVmSchema() { ClusterCreate spec = getClusterSpec(); List<DiskSpec> diskSet = getDiskSpec(); VmSchema schema = VcVmUtil.getVmSchema(spec, "master", diskSet, "vm-101", "snap-102"); Assert.assertTrue(schema.resourceSchema.numCPUs == 2, "Excepted cpu number is 2, but got " + schema.resourceSchema.numCPUs); List<Disk> disks = schema.diskSchema.getDisks(); Assert.assertTrue(disks != null && disks.size() == 1, "Excepted one disk, but got " + schema.diskSchema.getDisks()); Assert.assertTrue(disks.get(0).name.equals("OS"), "Excepted name is OS, but got " + schema.diskSchema.getName()); }