Highlighted
Enthusiast
Enthusiast

[vRA 7.5] - Launch data collection for a specific VC:VirtualMachine

Jump to solution

Hello Team,

I try to find a solution to launch "Data Collection" for a specific VC:VirtualMachine.

We have created a custom day2 action to create a snapshot and after, e launch a data collection "Inventory" on the specific compute resource where VC:VirtualMachine is located.

This permit our customers to get their snapshot available for deletion after few minutes on vRA UI.

It's not very optimum for vRA infrastructure performance, so that we want to update information just for one specific VC:VirtualMachine.

Do you think it's possible ?

Thx for your feedback.

1 Solution

Accepted Solutions
Highlighted
Enthusiast
Enthusiast

We have deleted Data Collection process during Day2 action : Create a snapshot.

We have created a custom DAY2 action to Delete SnapShot.... This custom DAY2 interrogates directly vSphere, so that it's most user friendly for our customers... Not needed to attent Data Collection to get the list of Snapshot.....

Action to retrieve Snapshot list :

// INPUT vcVirtualMachine : type : vc:virtualmachine

if (vcVirtualMachine == "" || vcVirtualMachine == null) {

    return [];

}

vcVirtualMachineSnapshotInfo = vcVirtualMachine.snapshot;

System.log("vcVirtualMachineSnapshotInfo : " + vcVirtualMachineSnapshotInfo);

if (vcVirtualMachineSnapshotInfo != null && vcVirtualMachineSnapshotInfo != "" && vcVirtualMachineSnapshotInfo != undefined) {

    vcVirtualMachineSnapshotTreeList = vcVirtualMachineSnapshotInfo.rootSnapshotList;

    System.log("vcVirtualMachineSnapshotTreeList : " + vcVirtualMachineSnapshotTreeList);

   

    snapshotNameList = getChildSnapshotNameList(vcVirtualMachineSnapshotTreeList);

    System.log("snapshotNameList : " + snapshotNameList);

    return snapshotNameList.sort();

}

function getChildSnapshotNameList(vcVirtualMachineSnapshotTreeList) {

    var snapshotNameList = [];

    // we have an array of tree

    for (keyVVMSTL in vcVirtualMachineSnapshotTreeList) {

        vcVirtualMachineSnapshotTree = vcVirtualMachineSnapshotTreeList[keyVVMSTL];

        // adding the date of creation and the name

        creationDate = vcVirtualMachineSnapshotTree.createTime;

        dateAsString = creationDate.getFullYear() + "/" + ((creationDate.getMonth())+1) + "/" + creationDate.getDate() + "@" + creationDate.getHours() + ":" + creationDate.getMinutes();

        vcVirtualMachineSnapshotTreeName = dateAsString + " - " + vcVirtualMachineSnapshotTree.name;

        System.debug("vcVirtualMachineSnapshotTreeName : " + vcVirtualMachineSnapshotTreeName);

        snapshotNameList.push(vcVirtualMachineSnapshotTreeName);

       

        // now adding the list of name of all its children

        vcVirtualMachineSnapshotTreeChildList = vcVirtualMachineSnapshotTree.childSnapshotList;

        vcVirtualMachineSnapshotTreeChildNameList = getChildSnapshotNameList(vcVirtualMachineSnapshotTreeChildList);

        System.debug("vcVirtualMachineSnapshotTreeChildNameList : " + vcVirtualMachineSnapshotTreeChildNameList);

        snapshotNameList = snapshotNameList.concat(vcVirtualMachineSnapshotTreeChildNameList);

    }

    System.log("snapshotNameList : " + snapshotNameList);

    return snapshotNameList;

}

Workflow to delete Snapshot :

// INPUT vcVirtualMachine / type : vc:virtualmachine

// INPUT snapshotToDeleteName / type : String

vcVirtualMachineSnapshotInfo = vcVirtualMachine.snapshot;

System.log("vcVirtualMachineSnapshotInfo : " + vcVirtualMachineSnapshotInfo);

vcVirtualMachineSnapshotTreeList = vcVirtualMachineSnapshotInfo.rootSnapshotList;

System.log("vcVirtualMachineSnapshotTreeList : " + vcVirtualMachineSnapshotTreeList);

snapshotNameList = getChildSnapshotNameList(vcVirtualMachineSnapshotTreeList);

System.log("snapshotNameList : " + snapshotNameList);

function getChildSnapshotNameList(vcVirtualMachineSnapshotTreeList) {

    var snapshotNameList = [];

    // we have an array of tree

    for (keyVVMSTL in vcVirtualMachineSnapshotTreeList) {

        vcVirtualMachineSnapshotTree = vcVirtualMachineSnapshotTreeList[keyVVMSTL];

        // adding the date of creation and the name

        vcVirtualMachineSnapshotTreeName = vcVirtualMachineSnapshotTree.name;

        System.debug("vcVirtualMachineSnapshotTreeName : " + vcVirtualMachineSnapshotTreeName);

       

        var snapshotNameRegex = new RegExp(".*- ", "g");

        vcVirtualMachineSnapshotTreeNameClean = vcVirtualMachineSnapshotTreeName.replace(snapshotNameRegex,"");

        if (snapshotToDeleteName.match(vcVirtualMachineSnapshotTreeNameClean)){

        vcVirtualMachineSnapshot = vcVirtualMachineSnapshotTree.snapshot;

        System.debug("Found snapshot to delete : " + vcVirtualMachineSnapshotTreeName + " on Virtual Machine : " + vcVirtualMachine.name);

        vcVirtualMachineSnapshot.removeSnapshot_Task(false,true)

        }

        // now adding the list of name of all its children

        vcVirtualMachineSnapshotTreeChildList = vcVirtualMachineSnapshotTree.childSnapshotList;

        vcVirtualMachineSnapshotTreeChildNameList = getChildSnapshotNameList(vcVirtualMachineSnapshotTreeChildList);

        System.debug("vcVirtualMachineSnapshotTreeChildNameList : " + vcVirtualMachineSnapshotTreeChildNameList);

        snapshotNameList = snapshotNameList.concat(vcVirtualMachineSnapshotTreeChildNameList);

    }

}

View solution in original post

0 Kudos
4 Replies
Highlighted

Hey there

Saddly it's only possible for the entire compute Resource. (what is an issue if you want to have good refresh times for your consumers)

What you can do, is create a vRO workflow to replace the out of the box action and present it as a resource action. So this will talk directly to vcenter API and retrieve and present the information to the user.

Cheers

N

Triple VCIX (CMA-NV-DCV) | vExpert | MCSE | CCNA
Highlighted
Enthusiast
Enthusiast

Thx NicolasAlauzet....

We have already created a custom Day2 action......

pastedImage_0.png

But we want to reduce time, before the snapshot appear on vRA UI.

Best regards.

Highlighted

Hey, hope you are doing fine:

I don't think what you are trying to accomplish is possible since the most "atomic" place you can launch a data collection is a compute resource (vSphere Cluster).

If you found this helpful, please consider marking this as correct and giving some kudos.

Warm regards
0 Kudos
Highlighted
Enthusiast
Enthusiast

We have deleted Data Collection process during Day2 action : Create a snapshot.

We have created a custom DAY2 action to Delete SnapShot.... This custom DAY2 interrogates directly vSphere, so that it's most user friendly for our customers... Not needed to attent Data Collection to get the list of Snapshot.....

Action to retrieve Snapshot list :

// INPUT vcVirtualMachine : type : vc:virtualmachine

if (vcVirtualMachine == "" || vcVirtualMachine == null) {

    return [];

}

vcVirtualMachineSnapshotInfo = vcVirtualMachine.snapshot;

System.log("vcVirtualMachineSnapshotInfo : " + vcVirtualMachineSnapshotInfo);

if (vcVirtualMachineSnapshotInfo != null && vcVirtualMachineSnapshotInfo != "" && vcVirtualMachineSnapshotInfo != undefined) {

    vcVirtualMachineSnapshotTreeList = vcVirtualMachineSnapshotInfo.rootSnapshotList;

    System.log("vcVirtualMachineSnapshotTreeList : " + vcVirtualMachineSnapshotTreeList);

   

    snapshotNameList = getChildSnapshotNameList(vcVirtualMachineSnapshotTreeList);

    System.log("snapshotNameList : " + snapshotNameList);

    return snapshotNameList.sort();

}

function getChildSnapshotNameList(vcVirtualMachineSnapshotTreeList) {

    var snapshotNameList = [];

    // we have an array of tree

    for (keyVVMSTL in vcVirtualMachineSnapshotTreeList) {

        vcVirtualMachineSnapshotTree = vcVirtualMachineSnapshotTreeList[keyVVMSTL];

        // adding the date of creation and the name

        creationDate = vcVirtualMachineSnapshotTree.createTime;

        dateAsString = creationDate.getFullYear() + "/" + ((creationDate.getMonth())+1) + "/" + creationDate.getDate() + "@" + creationDate.getHours() + ":" + creationDate.getMinutes();

        vcVirtualMachineSnapshotTreeName = dateAsString + " - " + vcVirtualMachineSnapshotTree.name;

        System.debug("vcVirtualMachineSnapshotTreeName : " + vcVirtualMachineSnapshotTreeName);

        snapshotNameList.push(vcVirtualMachineSnapshotTreeName);

       

        // now adding the list of name of all its children

        vcVirtualMachineSnapshotTreeChildList = vcVirtualMachineSnapshotTree.childSnapshotList;

        vcVirtualMachineSnapshotTreeChildNameList = getChildSnapshotNameList(vcVirtualMachineSnapshotTreeChildList);

        System.debug("vcVirtualMachineSnapshotTreeChildNameList : " + vcVirtualMachineSnapshotTreeChildNameList);

        snapshotNameList = snapshotNameList.concat(vcVirtualMachineSnapshotTreeChildNameList);

    }

    System.log("snapshotNameList : " + snapshotNameList);

    return snapshotNameList;

}

Workflow to delete Snapshot :

// INPUT vcVirtualMachine / type : vc:virtualmachine

// INPUT snapshotToDeleteName / type : String

vcVirtualMachineSnapshotInfo = vcVirtualMachine.snapshot;

System.log("vcVirtualMachineSnapshotInfo : " + vcVirtualMachineSnapshotInfo);

vcVirtualMachineSnapshotTreeList = vcVirtualMachineSnapshotInfo.rootSnapshotList;

System.log("vcVirtualMachineSnapshotTreeList : " + vcVirtualMachineSnapshotTreeList);

snapshotNameList = getChildSnapshotNameList(vcVirtualMachineSnapshotTreeList);

System.log("snapshotNameList : " + snapshotNameList);

function getChildSnapshotNameList(vcVirtualMachineSnapshotTreeList) {

    var snapshotNameList = [];

    // we have an array of tree

    for (keyVVMSTL in vcVirtualMachineSnapshotTreeList) {

        vcVirtualMachineSnapshotTree = vcVirtualMachineSnapshotTreeList[keyVVMSTL];

        // adding the date of creation and the name

        vcVirtualMachineSnapshotTreeName = vcVirtualMachineSnapshotTree.name;

        System.debug("vcVirtualMachineSnapshotTreeName : " + vcVirtualMachineSnapshotTreeName);

       

        var snapshotNameRegex = new RegExp(".*- ", "g");

        vcVirtualMachineSnapshotTreeNameClean = vcVirtualMachineSnapshotTreeName.replace(snapshotNameRegex,"");

        if (snapshotToDeleteName.match(vcVirtualMachineSnapshotTreeNameClean)){

        vcVirtualMachineSnapshot = vcVirtualMachineSnapshotTree.snapshot;

        System.debug("Found snapshot to delete : " + vcVirtualMachineSnapshotTreeName + " on Virtual Machine : " + vcVirtualMachine.name);

        vcVirtualMachineSnapshot.removeSnapshot_Task(false,true)

        }

        // now adding the list of name of all its children

        vcVirtualMachineSnapshotTreeChildList = vcVirtualMachineSnapshotTree.childSnapshotList;

        vcVirtualMachineSnapshotTreeChildNameList = getChildSnapshotNameList(vcVirtualMachineSnapshotTreeChildList);

        System.debug("vcVirtualMachineSnapshotTreeChildNameList : " + vcVirtualMachineSnapshotTreeChildNameList);

        snapshotNameList = snapshotNameList.concat(vcVirtualMachineSnapshotTreeChildNameList);

    }

}

View solution in original post

0 Kudos