Highlighted
Enthusiast
Enthusiast

Solution Found for Updating Deployment Name/Description from vRO

At the time of this writing I had not found anyone that was able to provide a solution for updating a Deployment Name or Description from vRO during a Subscription Event.  The only method was to update __deploymentName prior to submitting the form.  Any changes to __deploymentName from the subscriptions events such as Requested, MachineBuild, or later have no effect.

I explored all the Request and Resource APIs but could only view the name and description.  There is no API listed for updating a resource.  Or at least no documented API Smiley Happy

While running Fiddler and using the UI to update the Deployment Name i found that there is an obscure, and as far as I know undocumented, API with a uri of /consumer/deployments.

I was successfully able to use this uri to update the Deployment Name (and description if desired) from the MachineBuild subscription event.  It will likely work just about anytime because I initially got it working in a test workflow completely outside of any Subscription Lifecycle event altogether. I should also mention we are on vRA 7.6, but I suspect it will work from earlier versions of 7.x.

Here is the code I'm using during the MachineBuild state to append the machine name to the deployment name:

System.log("*");

System.log("Updating Deployment Name");

System.log("********************************************************************************");

try{

    var correlationId = System.getContext().getParameter("__asd_correlationId");

    var deployment = getDeploymentResourceByRequestId(correlationId)

   

    if (deployment){

        var resourceId = deployment.id;

    //    System.log(res.id);

    //    System.log(res.name);

    //    System.log(res.dateCreated);

           

        var deploymentName = deployment.name;

        var newDeploymentName = deploymentName;

       

        System.log("-- Current Deployment Name is " + deploymentName);

       

        var pos = deploymentName.lastIndexOf("-");

       

        if (pos > 0){

            newDeploymentName = deploymentName.substring(0, pos).trim();

        }

       

        newDeploymentName = newDeploymentName + " - " + assignedServerName;

       

        System.log("-- New Deployment Name is " + newDeploymentName);   

       

        try{

            setDeploymentName(resourceId, newDeploymentName);

        }catch(e){

            System.log("-- Failed to update deployment name: " + e);

        }

    }

}catch(e){

    //don't raise error just because we couldn't update the deployment name....

    System.log("-- An unexpected error occurred while updating the Deployment Name: " + e);

}

   

//////////////////////

// Helper Functions //

//////////////////////

function setDeploymentName(resourceId, name){

    var cafeHost = vCACCAFEHostManager.getDefaultHostForTenant()

   

    //Create the rest client for the targeted tenant

    restClient = cafeHost.createRestClient("com.vmware.csp.core.cafe.catalog.api");

    //Uncomment to view the API URL used by the client

    //System.log(restClient.getUrl());

    var props = new Properties();

    props.put("name", name);

   

    //We can also update the description by adding it here

    //props.put("description", "This blueprint offers the most flexibility in defining a Windows Server build at the cost of completing the most complex request form.");

   

    var response = restClient.put("/consumer/deployments/" + resourceId, props);

//    System.log(response);

}

function getDeploymentResourceByRequestId(requestId){

    var cafeHost = vCACCAFEHostManager.getDefaultHostForTenant()

    var requestService = cafeHost.createCatalogClient().getCatalogConsumerRequestService();

    var deploymentResource = null;

         

    try{

        var results = requestService.getResourcesProvisionedByRequest(requestId);

        //retrieve the results 

        var resources = results.getContent();

   

        //Loop through the resources until we find the Deployment resource

        for (var i in resources){

    //       System.log(resources[i].id);

    //       System.log(resources[i].name);

    //       System.log(resources[i].requestId);

    //       System.log(resources[i].resourceTypeRef.getLabel());

    //       System.log("==============================");

            if (resources[i].resourceTypeRef.getLabel() == "Deployment"){

                deploymentResource = resources[i];

                break;

            }

        }

    }catch(e){

        System.log("-- Failed to get deployment resource");

    }

    return deploymentResource;

}

2 Replies
Highlighted
Hot Shot
Hot Shot

Nice work. I wonder how you injected Fiddler between the UI and API...

0 Kudos
Highlighted
Enthusiast
Enthusiast

Hm... interesting...

I don't see method "put" in vCACCAFERestClient class (vRA 7.6), however it works (plain simple pure REST API call)... AFAIK, "put" was removed starting from 7.4 - vRO API Explorer by Dr Ruurd and Flores of ITQ 

0 Kudos