Created
August 3, 2022 07:11
-
-
Save YagmurOzden/fb56d164897bb558a5c0c5ecab809b39 to your computer and use it in GitHub Desktop.
it creates a Custom Specification for reconfigure the VM. and this custom spec creates 2 nic one of them with static connection and the other nic is eth1 and it uses DHCP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VMware vRealize Orchestrator action sample | |
// vRA 8.8.0 | |
//It creates 2 nic one of them with static connection and the other nic is eth1 and it uses DHCP | |
//so therefore i am connecting the machine after this action has deployed and change its value inside. | |
//action input type: VM vc:virtual machine | |
guestNetInfoDNSServerList Array string | |
guestNetInfoDNSSuffixList Array string | |
guestNetInfoDomain string | |
guestNetInfoNIC0Gateways string | |
guestNetInfoNIC0mask string | |
guestNetInfoNIC0IPAddress string | |
guestNetInfoNIC0MACAddress string | |
guestNetInfoNIC1Gateways string | |
guestNetInfoNIC1mask stirng | |
hostname string | |
//action return type: void | |
var spec = new VcCustomizationSpec(); | |
spec.options = new VcCustomizationLinuxOptions(); | |
//check if the OS is Windows?? | |
if (System.getModule("com.vmware.library.vc.vm.os").isWindowsOsInVm(vm)) { | |
var opts = new VcCustomizationWinOptions(); | |
opts.changeSID = true; | |
spec.options = opts; | |
} | |
spec.encryptionKey = null; | |
spec.globalIPSettings = new VcCustomizationGlobalIPSettings(); | |
spec.globalIPSettings.dnsServerList = guestNetInfoDNSServerList; | |
spec.globalIPSettings.dnsSuffixList = guestNetInfoDNSSuffixList; | |
spec.identity = new VcCustomizationLinuxPrep(); | |
spec.identity.domain = guestNetInfoDomain | |
spec.identity.hostName = new VcCustomizationFixedName(); | |
spec.identity.hostName.name = hostname; | |
spec.identity.hwClockUTC = false; | |
spec.identity.timeZone = null; | |
var nicSettingMap = []; | |
// NIC0 for static connection | |
var nic0AdapterMapping = new VcCustomizationAdapterMapping(); | |
nic0AdapterMapping.adapter = new VcCustomizationIPSettings(); | |
nic0AdapterMapping.adapter.gateway = guestNetInfoNIC0Gateways; | |
nic0AdapterMapping.adapter.subnetMask = guestNetInfoNIC0mask; | |
nic0AdapterMapping.adapter.ip = new VcCustomizationFixedIp(); | |
nic0AdapterMapping.adapter.ip.ipAddress = guestNetInfoNIC0IPAddress; | |
nic0AdapterMapping.macAddress = guestNetInfoNIC0MACAddress; | |
nicSettingMap.push(nic0AdapterMapping); | |
//NIC1 for dhcp connection | |
var nic1AdapterMapping = new VcCustomizationAdapterMapping(); | |
nic1AdapterMapping.adapter = new VcCustomizationIPSettings(); | |
nic1AdapterMapping.adapter.gateway = guestNetInfoNIC0Gateways; | |
nic1AdapterMapping.adapter.subnetMask = "255.255.255.255"; | |
nic1AdapterMapping.adapter.ip = new VcCustomizationFixedIp(); | |
nic1AdapterMapping.adapter.ip.ipAddress = "1.1.1.1"; | |
nic1AdapterMapping.macAddress = null; | |
nicSettingMap.push(nic1AdapterMapping); | |
spec.nicSettingMap = nicSettingMap; | |
System.log("ApplyCustomSpecsTask", "Executing customization task..."); | |
System.log("SPEC " + spec); | |
var task = vm.customizeVM_Task(spec); | |
System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task, true, 5); | |
System.log("ApplyCustomSpecsTask", "Customization task finished successfully."); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment