protected List<CustomizationAdapterMapping> createCustomizationAdapterMappings( VmwareProcessClient vmwareProcessClient, VirtualMachine machine) { List<CustomizationAdapterMapping> nicSettingMap = new ArrayList<CustomizationAdapterMapping>(); // VirtualEthernetCardを取得 VirtualMachineConfigInfo configInfo = machine.getConfig(); for (VirtualDevice device : configInfo.getHardware().getDevice()) { if (device instanceof VirtualEthernetCard) { VirtualEthernetCard virtualEthernetCard = VirtualEthernetCard.class.cast(device); CustomizationAdapterMapping mapping = new CustomizationAdapterMapping(); CustomizationIPSettings settings = new CustomizationIPSettings(); // すべてのNICをDHCPにする CustomizationDhcpIpGenerator dhcpIp = new CustomizationDhcpIpGenerator(); settings.setIp(dhcpIp); mapping.setMacAddress(virtualEthernetCard.getMacAddress()); mapping.setAdapter(settings); nicSettingMap.add(mapping); } } return nicSettingMap; }
private CustomizationIPSettings getFixedIpSettings(GuestInputs guestInputs) { CustomizationIPSettings ipSettings = new CustomizationIPSettings(); CustomizationFixedIp fixedIp = new CustomizationFixedIp(); fixedIp.setIpAddress(guestInputs.getIpAddress()); ipSettings.setIp(fixedIp); ipSettings.setSubnetMask(guestInputs.getSubnetMask()); if (StringUtils.isNotBlank(guestInputs.getDefaultGateway())) { List<String> gatewaysList = ipSettings.getGateway(); gatewaysList.add(guestInputs.getDefaultGateway()); } if (StringUtils.isNotBlank(guestInputs.getDnsServer())) { List<String> dnsServersList = ipSettings.getDnsServerList(); dnsServersList.add(guestInputs.getDnsServer()); } return ipSettings; }
public void customizeNic(String macAddress, String hostName, String address, SubnetState subnetState, CustomizationSpec template) { // remove existing mapping template.getNicSettingMap().removeIf(x -> Objects.equals(x.getMacAddress(), macAddress)); CustomizationAdapterMapping mapping = new CustomizationAdapterMapping(); mapping.setMacAddress(macAddress); CustomizationIPSettings adapter = new CustomizationIPSettings(); mapping.setAdapter(adapter); adapter.setSubnetMask(cidr2mask(subnetState.subnetCIDR)); adapter.getGateway().add(subnetState.gatewayAddress); adapter.setDnsDomain(subnetState.domain); CustomizationFixedIp ipGen = new CustomizationFixedIp(); ipGen.setIpAddress(address); adapter.setIp(ipGen); template.getNicSettingMap().add(mapping); if (isLinux()) { CustomizationLinuxPrep identity = new CustomizationLinuxPrep(); template.setIdentity(identity); identity.setDomain(subnetState.domain); CustomizationFixedName name = new CustomizationFixedName(); if (hostName == null || hostName.isEmpty()) { hostName = makeHostName(UriUtils.getLastPathSegment(this.state.documentSelfLink)); } name.setName(hostName); identity.setHostName(name); template.setOptions(new CustomizationLinuxOptions()); } }
private VirtualMachineCloneSpec configureVirtualMachineCloneSpec(VirtualMachineRelocateSpec rSpec, String linuxName, boolean postConfiguration) throws Exception { VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec(); cloneSpec.setPowerOn(true); cloneSpec.setTemplate(false); //cloneSpec.setSnapshot(currentSnapshot.getMOR()); cloneSpec.setLocation(rSpec); if (postConfiguration) { CustomizationSpec customizationSpec = new CustomizationSpec(); CustomizationLinuxPrep linuxPrep = new CustomizationLinuxPrep(); CustomizationFixedName fixedName = new CustomizationFixedName(); fixedName.setName(linuxName); linuxPrep.setHostName(fixedName); linuxPrep.setDomain(""); linuxPrep.setHwClockUTC(true); //linuxPrep.setTimeZone("Etc/UTC"); customizationSpec.setIdentity(linuxPrep); customizationSpec.setGlobalIPSettings(new CustomizationGlobalIPSettings()); CustomizationAdapterMapping[] nicSettingMap = new CustomizationAdapterMapping[1]; nicSettingMap[0] = new CustomizationAdapterMapping(); nicSettingMap[0].adapter = new CustomizationIPSettings(); nicSettingMap[0].adapter.setIp(new CustomizationDhcpIpGenerator()); customizationSpec.setNicSettingMap(nicSettingMap); cloneSpec.setCustomization(customizationSpec); } return cloneSpec; }