mirror of
https://github.com/jbowdre/vRealize.git
synced 2024-11-22 01:42:19 +00:00
new workflow: VM Post-Provision
This commit is contained in:
parent
f0e65c2bc3
commit
0473812207
5 changed files with 73 additions and 0 deletions
15
Orchestrator/Workflows/VM Post-Provision/README.md
Normal file
15
Orchestrator/Workflows/VM Post-Provision/README.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# VM Post-Provision workflow
|
||||||
|
Performs post-deploy tasks like adding notes to the VM object and creating static DNS records (if needed).
|
||||||
|
|
||||||
|
![Schema](schema.png)
|
||||||
|
|
||||||
|
## Inputs/Outputs
|
||||||
|
| Name | Type | Direction | Description |
|
||||||
|
|:--- |:--- |:---|:---|
|
||||||
|
| `inputProperties` | Properties | Input | full request payload from vRA |
|
||||||
|
|
||||||
|
## Variables
|
||||||
|
| Name | Type | Value | Description |
|
||||||
|
|:--- |:--- |:--- |:--- |
|
||||||
|
| `vm` | VC:VirtualMachine| | virtual machine object |
|
||||||
|
| `dnsHost` | CompositeType(sshHost:string,sshUser:string,sshPass:SecureString,dnsServers:Array/string,supportedDomains:Array/string):dnsConfig | `Endpoints: dnsHost` | object which stores endpoint and credential details for DNS operations |
|
|
@ -0,0 +1,9 @@
|
||||||
|
/* JavaScript: get VM object
|
||||||
|
Retrieves a VC:VirtualMachine object matching the resourceName from the VcPlugin
|
||||||
|
Inputs: inputProperties (Properties)
|
||||||
|
Outputs: vm (VC:VirtualMachine)
|
||||||
|
*/
|
||||||
|
var name = inputProperties.resourceNames[0];
|
||||||
|
var vms = VcPlugin.getAllVirtualMachines(null, name);
|
||||||
|
System.debug("Found VM object: " + vms[0]);
|
||||||
|
vm = vms[0];
|
|
@ -0,0 +1,15 @@
|
||||||
|
/* JavaScript: set notes
|
||||||
|
Adds notes and custom attributes to the VC:VirtualMachine
|
||||||
|
Inputs: inputProperties (Properties), vm (VC:VirtualMachine)
|
||||||
|
Outputs: none
|
||||||
|
*/
|
||||||
|
var notes = inputProperties.customProperties.description;
|
||||||
|
var poc = inputProperties.customProperties.poc;
|
||||||
|
var ticket = inputProperties.customProperties.ticket;
|
||||||
|
var spec = new VcVirtualMachineConfigSpec();
|
||||||
|
spec.annotation = notes;
|
||||||
|
vm.reconfigVM_Task(spec);
|
||||||
|
System.log("Set VM description: " + notes);
|
||||||
|
System.getModule("com.vmware.library.vc.customattribute").setOrCreateCustomField(vm, "Point of Contact", poc);
|
||||||
|
System.getModule("com.vmware.library.vc.customattribute").setOrCreateCustomField(vm, "Ticket", ticket);
|
||||||
|
System.log("Set VM attributes: Point of Contact " + poc + ", Ticket " + ticket);
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* JavaScript: create dns record
|
||||||
|
Optionally creates a static record in Microsoft DNS by way of an SSH bastion host.
|
||||||
|
Inputs: inputProperties (Properties), dnsHost (CompositeType(sshHost:string,sshUser:string,sshPass:SecureString,dnsServers:Array/string,supportedDomains:Array/string):dnsConfig)
|
||||||
|
Outputs: none
|
||||||
|
*/
|
||||||
|
var staticDns = inputProperties.customProperties.staticDns;
|
||||||
|
var hostname = inputProperties.resourceNames[0];
|
||||||
|
var dnsDomain = inputProperties.customProperties.domain;
|
||||||
|
var ipAddress = inputProperties.addresses[0];
|
||||||
|
var created = false;
|
||||||
|
if (staticDns == "true" && dnsHost.supportedDomains.indexOf(dnsDomain) >= 0) {
|
||||||
|
System.log("Attempting to create DNS record for " + hostname + "." + ipAddress + "...");
|
||||||
|
var sshSession = new SSHSession(dnsHost.sshHost, dnsHost_sshUser);
|
||||||
|
System.debug("Connecting to " + dnsHost.sshHost + "...");
|
||||||
|
sshSession.connectWithPassword(dnsHost.sshPass);
|
||||||
|
for each (dnsServer in dnsHost.dnsServers) {
|
||||||
|
if (created == false) {
|
||||||
|
System.debug("Using DNS Server " + dnsServer + "...");
|
||||||
|
var sshCommand = 'Add-DnsServerResourceRecordA -ComputerName ' + dnsServer + ' -Name ' + hostname + ' -ZoneName ' + dnsDomain + ' -AllowUpdateAny -IPv4Address ' + ipAddress;
|
||||||
|
System.debug("sshCommand: " + sshCommand);
|
||||||
|
sshSession.executeCommand(sshCommand, true);
|
||||||
|
if (sshSession.exitCode == 0) {
|
||||||
|
System.log("Successfully created DNS record.");
|
||||||
|
created = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sshSession.disconnect();
|
||||||
|
if (created == false) {
|
||||||
|
System.warn("Error! Unable to create DNS record.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.log("Not trying to do DNS.");
|
||||||
|
}
|
BIN
Orchestrator/Workflows/VM Post-Provision/schema.png
Normal file
BIN
Orchestrator/Workflows/VM Post-Provision/schema.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
Loading…
Reference in a new issue