WARNING.  This script is to be used for informational and learning purposes only.  Should you choose to modify and or include this script in your test or production environments, you do so at your own risk.  Custom scripts are only supported by Embotics, when they are produced by an Embotics Application Architect as part of a paid service engagement.


PhpIpam is a free opensource IP address Management tool. PhpIpam can be integrated into vCommander to get and assign IP address on deployment for VM's in an VMware environment and remove the address on decomissioning. 


Requirements

Prepare the Script Files


Download and extract the script to your vCommander application server. Embotics recommends storing all scripts called by vCommander in a single location (c:\Scripts) for example. These scripts are executed by vCommander. With the scripts extracted, the file system will look like this:


The scripts require minor editing before they will work with your systems. Refer to the comments in the individual script or the table below for guidance on editing the contents.


Setting
Description
$vCommanderURL
The Web URL of the vCommander server.
$vCredFile
The credentials file which handles access to your vCommander. For more details, please refer to the Appendix: PowerShell Script Credential Encryption in the vCommander API Getting Started Guide, available here.
$phpipamurl
The vCenter Server name as it appears in vCommander. This value must be resolvable via DNS and reachable from the vCommander application server.
$phpipamCred
The credentials file which handles access to your phpipam Server. For more details, please refer to the Appendix: PowerShell Script Credential Encryption in the vCommander API Getting Started Guide, available here.
$PhpIpamAppID
The AppID from PhpIpam set to "None" for security to use password authentication
$Description
Description field for IPAM so administrators know which system populated the address


Note: Your Environment may require additional or different logic depending on how phpipam has been configured. This example assumes the virtual Portgroup Name matches the subnet Description in phpIpam and DNS, Gateway are configured. 


The phpipam_NextIP.ps1 has sample logic to ensure that production goes to the production portgroup when deploying through vCommander. You can edit this logic for any combination as long as there is a match in phpipam for the name of the portgroup in the description field for a subnet. 



Update Approval Workflow


Now that the scripts and credentials have been configured it's time to update the approval workflow to call out to phpipam and Assign IP addresses for each VM in the request based on a Service Form attribute. In this example we use a "Service Type" form attribute with Static drop downs for "Production, Development,and QA"


Sample Form:


Adding a step to call the script on a new request with the following command line syntax:


powershell.exe c:\Scripts\phpipam\phpipam_nextIP.ps1 -RequestID "#{request.id}" -ServiceType "#{request.services[1].settings.customAttribute['Service Type']}"



That's all there is to assigining an ip from phpipam. 



Update Decomissioning Workflow


Now to configure vCommander to remove the assigned address when the service is decommissioned through vCommander. 


Edit your completion workflow that's tied to your decommissioning change request form. 


Add an execute script step to remove the IP from phpIpam before your delete vm step with the following commandline syntax: 

    

            powershell.exe c:\Scripts\phpipam\phpipam_releaseIP.ps1 -IPAddress "#{target.ipv4Addresses}"


Now Request a VM as a test if everything was configured properly you will see an entry in phpipam for the newly created VM and the Customized vm will have the correct network information assigned. 


New address assigned in phpipam: 


Verify the Deployed VM has the correct information: