Sany_1973
Enthusiast
Enthusiast

Destroy action on catalog resource

Jump to solution

If I want to use resource action (destroy ) with following , what should be the inputs and its format

System.getModule("com.vmware.library.vcaccafe.request").requestResourceAction(operation,inputs) ;

Thanks

0 Kudos
1 Solution

Accepted Solutions
Sany_1973
Enthusiast
Enthusiast

var client = vCACCAFEHost.createCatalogClient();

var response = client.get("/consumer/requests/" + asd_catalog_request_id + "/resources").getBodyAsJson();

var resources;

for(var x in response.content)

{

    var resource = response.content[x];

   //System.log(resource.resourceTypeRef.id);

var myop;

    if(resource.resourceTypeRef.id == "Infrastructure.Virtual") {

        resources=(vCACCAFEEntitiesFinder.getCatalogResource(vCACCAFEHost, resource.id));

var operations = resources.getOperations();

for (var op in operations){

if (operations[op].name =='Destroy'){

myop=operations[op];

break;

}

}

System.log(myop.name);

System.log("Getting resource action " + myop.getName() + " request form for... "+resources.name); 

    var form = vCACCAFERequestsHelper.getRequestFormForResourceAction(myop); 

System.log("Expected inputs: "); 

    var fields = vCACCAFERequestsHelper.getFormKeys(form); 

    for (var i = 0; i < fields.length; i++) { 

    System.log(" - " + fields[i]); 

    }; 

System.log("Sending resource action request..."); 

    var request = vCACCAFERequestsHelper.requestResourceAction(myop, form); 

System.log("Resource Action Request #: "+ request.requestNumber)

    }

}

View solution in original post

0 Kudos
1 Reply
Sany_1973
Enthusiast
Enthusiast

var client = vCACCAFEHost.createCatalogClient();

var response = client.get("/consumer/requests/" + asd_catalog_request_id + "/resources").getBodyAsJson();

var resources;

for(var x in response.content)

{

    var resource = response.content[x];

   //System.log(resource.resourceTypeRef.id);

var myop;

    if(resource.resourceTypeRef.id == "Infrastructure.Virtual") {

        resources=(vCACCAFEEntitiesFinder.getCatalogResource(vCACCAFEHost, resource.id));

var operations = resources.getOperations();

for (var op in operations){

if (operations[op].name =='Destroy'){

myop=operations[op];

break;

}

}

System.log(myop.name);

System.log("Getting resource action " + myop.getName() + " request form for... "+resources.name); 

    var form = vCACCAFERequestsHelper.getRequestFormForResourceAction(myop); 

System.log("Expected inputs: "); 

    var fields = vCACCAFERequestsHelper.getFormKeys(form); 

    for (var i = 0; i < fields.length; i++) { 

    System.log(" - " + fields[i]); 

    }; 

System.log("Sending resource action request..."); 

    var request = vCACCAFERequestsHelper.requestResourceAction(myop, form); 

System.log("Resource Action Request #: "+ request.requestNumber)

    }

}

0 Kudos