mirror of
https://github.com/jbowdre/vRealize.git
synced 2024-12-22 04:52:18 +00:00
update workflow
This commit is contained in:
parent
40095f1eb1
commit
5bf97e5e5c
10 changed files with 124 additions and 0 deletions
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
|
@ -0,0 +1,30 @@
|
|||
/* JavaScript: generate candidateVmName
|
||||
Appends appropriate numbering sequence to nameBase
|
||||
Inputs: digitCount (number), nameBase (string), digits (number), hostnameSequence (number), computerNames (ConfigurationElement)
|
||||
Outputs: computerNames (ConfigurationElement), candidateVmName (string), hostnameSequence (number)
|
||||
Exception binding: errMsg (string)
|
||||
*/
|
||||
if (digits) {
|
||||
hostnameSequence = digits;
|
||||
System.log("Manually setting sequence to user-provided input: " + digits)
|
||||
} else {
|
||||
try {
|
||||
hostnameSequence = computerNames.getAttributeWithKey(nameBase).value;
|
||||
System.debug("Found hostname base " + nameBase + " with sequence " + hostnameSequence);
|
||||
} catch (e) {
|
||||
System.debug("Hostname base " + nameBase + " does not exist, it will be created.");
|
||||
} finally {
|
||||
hostnameSequence++;
|
||||
if (hostnameSequence.toString().length > digitCount) {
|
||||
errMsg = 'All out of potential VM names, aborting...';
|
||||
throw(errMsg);
|
||||
}
|
||||
System.debug("Adding " + nameBase + " with sequence " + hostnameSequence);
|
||||
computerNames.setAttributeWithKey(nameBase,hostnameSequence);
|
||||
}
|
||||
}
|
||||
var hostnameNum = hostnameSequence.toString();
|
||||
var leadingZeroes = new Array(digitCount - hostnameNum.length + 1).join("0");
|
||||
hostnameNum = leadingZeroes + hostnameNum;
|
||||
candidateVmName = (nameBase + hostnameNum).toUpperCase();
|
||||
System.log("Proposed VM name: " + candidateVmName);
|
|
@ -0,0 +1,15 @@
|
|||
/* JavaScript: check for VM name conflict
|
||||
Iterates through an array of VM object to check for naming collisions.
|
||||
Inputs: candidateVmName (string), vms (Array/VC:VirtualMachine)
|
||||
Outputs: conflict (boolean)
|
||||
Exception binding: errMsg (string)
|
||||
*/
|
||||
vms.forEach(function(vm) {
|
||||
if (vm.name.toUpperCase() === candidateVmName) {
|
||||
conflict = true;
|
||||
errMsg = "Found a conflicting VM name!";
|
||||
System.warn(errMsg);
|
||||
throw(errMsg);
|
||||
}
|
||||
});
|
||||
System.log("No VM name conflicts found for " + candidateVmName);
|
|
@ -0,0 +1,18 @@
|
|||
/* JavaScript: check for DNS conflict
|
||||
Checks for conflicting DNS records.
|
||||
Inputs: candidateVmName (string), conflict (boolean), domain (string)
|
||||
Outputs: conflict (boolean)
|
||||
Exception binding: errMsg (string)
|
||||
*/
|
||||
if (conflict) {
|
||||
System.debug("Existing conflict found, skipping DNS check...");
|
||||
} else {
|
||||
if (System.resolveHostName(candidateVmName + "." + domain)) {
|
||||
conflict = true;
|
||||
errMsg = "Conflicting DNS record found!";
|
||||
System.warn(errMsg);
|
||||
throw(errMsg);
|
||||
} else {
|
||||
System.log("No DNS conflict for " + candidateVmName)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/* JavaScript: check for AD conflict
|
||||
Checks for conflicting names in Active Directory
|
||||
Inputs: candidateVmName (string), conflict (boolean), adHost (AD:AdHost)
|
||||
Outputs: conflict (boolean)
|
||||
Exception binding: errMsg (string)
|
||||
*/
|
||||
if (conflict) {
|
||||
System.debug("Existing conflict found, skipping AD check...");
|
||||
} else {
|
||||
var computer = ActiveDirectory.getComputerAD(candidateVmName, adHost);
|
||||
System.log("Searched AD for: " + candidateVmName);
|
||||
if (computer) {
|
||||
conflict = true;
|
||||
errMsg = "Conflicting AD object found!"
|
||||
System.warn(errMsg);
|
||||
throw(errMsg);
|
||||
} else {
|
||||
System.log("No AD conflict found for " + candidateVmName);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
/* JavaScript: return nextVmName
|
||||
Returns the selected nextVmName after passing all collision checks
|
||||
Inputs: candidateVmName (string)
|
||||
Outputs: nextVmName (string)
|
||||
*/
|
||||
nextVmName = candidateVmName;
|
||||
System.log(" ***** Selecting [" + nextVmName + "] as the next VM name ***** ")
|
|
@ -0,0 +1,7 @@
|
|||
/* JavaScript: remove lock
|
||||
Removes the lock to re-allow subsequent workflow runs
|
||||
Inputs: none
|
||||
Outputs: none
|
||||
*/
|
||||
System.debug("Releasing lock...");
|
||||
LockingSystem.unlock("namingLock","eventBroker");
|
|
@ -0,0 +1,13 @@
|
|||
/* JavaScript: conflict encountered
|
||||
Resets the conflict flag and passes control back to the 'generate candidateVmName'
|
||||
Inputs: digits (number)
|
||||
Outputs: conflict (boolean)
|
||||
Exception binding: errMsg (string)
|
||||
*/
|
||||
if (digits) {
|
||||
errMsg = 'User-specified name is not available, aborting...';
|
||||
throw(errMsg);
|
||||
} else {
|
||||
System.log("Conflict encountered, trying a new name...")
|
||||
conflict = false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
/* JavaScript: errors
|
||||
Terminate the workflow in the event of an unrecoverable error
|
||||
Inputs: errMsg (string)
|
||||
Outputs: none
|
||||
*/
|
||||
System.error("FATAL ERROR!");
|
||||
System.error(errMsg);
|
|
@ -0,0 +1,7 @@
|
|||
/* JavaScript: remove lock
|
||||
Removes the lock to re-allow subsequent workflow runs
|
||||
Inputs: none
|
||||
Outputs: none
|
||||
*/
|
||||
System.debug("Releasing lock...");
|
||||
LockingSystem.unlock("namingLock","eventBroker");
|
Loading…
Reference in a new issue