Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.