Created
May 19, 2020 12:08
-
-
Save virtualhobbit/e08b26bfd0de15d2362976b5ab82eb7b to your computer and use it in GitHub Desktop.
This file contains 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
// Retrieve the virtual machine properties | |
var machine = payload.get("machine"); | |
// Check the machine's properties exist | |
if (machine !== null) { | |
// Retrieve the values | |
var attVirtualMachineId = machine.get("id"); | |
} | |
// Get the hostname generated by vRA | |
var currentHostname = machine.get("name"); | |
System.log("Assigned hostname is: " + currentHostname); | |
// Retrieve the variables | |
var machineProperties = machine.get("properties"); | |
var datacenterLocation = machineProperties.get("Vrm.DataCenter.Location"); | |
var location; | |
switch(datacenterLocation) { | |
case "Utrecht": | |
location = "NL-UTC"; | |
break; | |
case "Southport": | |
location = "GB-SRT"; | |
break; | |
} | |
// Set the environment type | |
var environment = System.getModule("com.hobbitcloud.misc").getConfigurationElement("_HobbitCloud/vRA","Environment","attName"); | |
switch(environment) { | |
case "Development": | |
environment = "D"; | |
break; | |
case "Test": | |
environment = "T"; | |
break; | |
case "Staging": | |
environment = "S"; | |
break; | |
case "Production": | |
environment = "P"; | |
break; | |
} | |
// Get the workload type | |
var workloadType = machineProperties.get("hc.workloadType"); | |
// Create the lock to prevent concurrent execution | |
LockingSystem.lockAndWait(attLockId, attLockOwner); | |
// Get the current highest VM number | |
var currentNum = System.getModule("com.hobbitcloud.misc").getConfigurationElement("_HobbitCloud/vRA/Naming",workloadType,"attNumber"); | |
// Generate the next VM number | |
var newNum = System.getModule("com.hobbitcloud.vra.naming").newNum(currentNum); | |
// Write the new number back | |
System.getModule("com.hobbitcloud.misc").setConfigurationElement("_HobbitCloud/vRA/Naming",workloadType,"attNumber",newNum); | |
// Release the lock | |
LockingSystem.unlock(attLockId, attLockOwner); | |
// Construct new hostname | |
var attNewHostname = location + "-" + environment + "-" + workloadType + "-" + newNum; | |
// Return the new hostname | |
System.log("The new hostname is: " + attNewHostname); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment