diff --git a/Orchestrator/Workflows/VM Post-Provision/README.md b/Orchestrator/Workflows/VM Post-Provision/README.md new file mode 100644 index 0000000..d584a73 --- /dev/null +++ b/Orchestrator/Workflows/VM Post-Provision/README.md @@ -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 | diff --git a/Orchestrator/Workflows/VM Post-Provision/Tasks/01_get_vm_object.js b/Orchestrator/Workflows/VM Post-Provision/Tasks/01_get_vm_object.js new file mode 100644 index 0000000..e524d7a --- /dev/null +++ b/Orchestrator/Workflows/VM Post-Provision/Tasks/01_get_vm_object.js @@ -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]; \ No newline at end of file diff --git a/Orchestrator/Workflows/VM Post-Provision/Tasks/02_set_notes.js b/Orchestrator/Workflows/VM Post-Provision/Tasks/02_set_notes.js new file mode 100644 index 0000000..e3535c9 --- /dev/null +++ b/Orchestrator/Workflows/VM Post-Provision/Tasks/02_set_notes.js @@ -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); \ No newline at end of file diff --git a/Orchestrator/Workflows/VM Post-Provision/Tasks/03_create_dns_record.js b/Orchestrator/Workflows/VM Post-Provision/Tasks/03_create_dns_record.js new file mode 100644 index 0000000..da9a218 --- /dev/null +++ b/Orchestrator/Workflows/VM Post-Provision/Tasks/03_create_dns_record.js @@ -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."); +} \ No newline at end of file diff --git a/Orchestrator/Workflows/VM Post-Provision/schema.png b/Orchestrator/Workflows/VM Post-Provision/schema.png new file mode 100644 index 0000000..a3e8368 Binary files /dev/null and b/Orchestrator/Workflows/VM Post-Provision/schema.png differ