VMware Cloud Community
evil242
Enthusiast
Enthusiast

Importing VMs from vCenter to vRA 6.2

So I was working with the problem of importing VMs currently deployed in vCenter into vRA 6.2 for management.  One of the issues was enabling workflows such as VM deletion and provisioned which involves cleanup of AD and DNS information.

The following vRO Workflow script I created to fetch IP addresses from a powered on VM running vmware tools and import them into VRA with the bulk import process.  I'd like to open up to the community for input, corrections, wild accusations, and just general points for improvement.  Thanks in advance for your input. 

-------------------------------  UpdatevCACentIPaddr ------------------------------------------------------------------------------------------------------

System.log("Workflow started from workflow stub " + externalWFStub + " on vCAC host " + vCACHost.displayName);

System.log("In UpdatevCACentIPaddr");

System.log("Got vCAC virtual machine " + vCACVm.virtualMachineName);

System.log("Matching virtual machine entity keyString " + virtualMachineEntity.keyString);

System.log("Matching virtual machine entity hostId " +        virtualMachineEntity.hostId);

System.log("Matching virtual machine entity modelName " +        virtualMachineEntity.modelName);

System.log("Matching virtual machine entity SetName " +        virtualMachineEntity.entitySetName);

if (vCenterVm != null) {

    System.log("Got vCenter VM " + vCenterVm.name);

} else {

    throw("vCenter VM was null");

}

       

var intfc = 0;

var currNet = '';

var updatedPropertyobj = new Properties();

var ipAddr = '';

var    propertyName = '';

var    propertyValue = '';

                                                               

//Displaying vCAC VM properties

if (vCACVmProperties == null) {

    System.log("vCACVmProperties was null");

    var virtualMachinePropertyEntities = virtualMachineEntity.getLink(vCACHost, "VirtualMachineProperties");

    if (virtualMachinePropertyEntities == null) {

        System.log("virtualMachinePropertyEntities was null");

    } else {

        var vCACVmProperties = new Properties();

        System.log("Putting in properties from entities");

        for each (var virtualMachinePropertyEntity in virtualMachinePropertyEntities)

        {

            var propertyName = virtualMachinePropertyEntity.getProperty("PropertyName");

            var propertyValue = virtualMachinePropertyEntity.getProperty("PropertyValue");

            vCACVmProperties.put(propertyName, propertyValue);

        }

   

    }

}

currNet = "Network" + intfc;

propertyName = 'VirtualMachine.' + currNet + '.Address';

ipAddr = vCACVmProperties.get(propertyName);

if (ipAddr == null) {

    System.log("updateVCACEntity ");

    updateProperties("Infoblox.IPAM.vNicNumber",vCenterVm.guest.net.length);

        while (intfc < vCenterVm.guest.net.length ) {

           

            System.log("Working on vNIC " + currNet);

           

            //Start with VirtualMachine.Network#.Address

            ipAddr = vCenterVm.guest.net[intfc].ipConfig.ipAddress[0].ipAddress;

            System.log("Found vCenterVm.guest.ipAddress: " + ipAddr);

            propertyValue = ipAddr;

            updateProperties(propertyName,propertyValue);

               

            //Infoblox IPAM Network# SearchEa1Value

            propertyName = "VirtualMachine." + currNet + "Name";

            propertyValue = vCACVmProperties.get(propertyName);

            if (propertyValue == null) {

                propertyValue = vCenterVm.guest.net[intfc].network;

                updateProperties(propertyName,propertyValue);

            }

            updateProperties("Infoblox.IPAM." + currNet + ".searchEa1Value", propertyValue);

            //Increase interface count

            intfc++;

            currNet = "Network" + intfc;

            propertyName = 'VirtualMachine.' + currNet + '.Address';

            }

}

if (vCACVmProperties != null) {

    var log = "";

    log += "vCAC VM properties :\n";

    var array = new Array();

    for each (var key in vCACVmProperties.keys) {

        array.push(key + " : " + vCACVmProperties.get(key));   

    }

    array.sort();

   

    for each (var line in array) {

        log += "\t" + line + "\n";

    }   

    System.log(log);   

}

outvCACVmProperties = vCACVmProperties;

function updateProperties(propName, propValue) {

    vCACVmProperties.put(propName,propValue);

    updatedPropertyobj.put(propName,propValue);

    System.getModule("com.vmware.library.vcac").addUpdatePropertyFromVirtualMachineEntity(vCACHost,

                    virtualMachineEntity,propName,propValue,propertyIsHidden,propertyIsRuntime,propertyIsEncrypted,

                    doNotUpdate);

    return;

}   

        /*var hostId = virtualMachineEntity.hostId;

        var modelName = virtualMachineEntity.modelName;

        var entitySetName = virtualMachineEntity.entitySetName;

        var entityIdString = virtualMachineEntity.keyString;

        var links = null;

        var headers = null;

        System.log("updateVCACEntity ");

        System.getModule("com.vmware.library.vcac").updateVCACEntity(hostId, modelName, entitySetName, entityIdString,

        updateProperties, links, headers); */

Damion Terrell  .   +  (He/Him)  +  . *  .  +   @   + .    *  .    +      .                    
Core IT Service Specialist * . + * . + . + . + * +
UNM – IT Platforms – VIS + . . . . . . . . .
. + . + * . + * .
* . . + . . . . + . + * + .
“You learn the job of the person above you, * + . + * @
and you teach your job to the person below you..” . * +
Tags (2)
0 Kudos
0 Replies