2 Replies Latest reply on Jul 23, 2019 11:03 AM by GeiAll

    Running System.getModule("com.vmware.library.vc.vm") in one vCenter context.

    klabiak Novice

      I have vRO with several vCenter connected to.

      vCenter connection defined in variable vcDdv (vcDdv = VcPlugin.allSdkConnections[0]).

      How can I run System.getModule("myAction").XXXX for this one particular connection?



        • 1. Re: Running System.getModule("com.vmware.library.vc.vm") in one vCenter context.
          iiliev Champion
          Community WarriorsVMware Employees



          I'm not sure that I correctly understand the question, but still...


          Most of the actions in module "com.vmware.library.vc.vm" accepts as inputs some vCenter entity (virtual machine, host, etc.) and thus one can say they work only in the 'context' of this object.


          There is a couple of actions - getAllVMs() and getAllVMsMatchingRegexp() - which work globally across all registered vCenter servers. If you look at the code of these 2 actions, you'll see they use calls like VcPlugin.getAllVirtualMachines(), and such call will enumerate all virtual machines on all connections.


          To limit these actions to a single connection, you can duplicate them, add the connection you want they to operate on as an input parameter to the action, and then replace calls like VcPlugin.getAllVirtualMachines() with something like vcDdv.getAllVirtualMachines()  (assuming vcDdv is the name of the action parameter specifying the connection, of type VcSdkConnection).

          1 person found this helpful
          • 2. Re:Running System.getModule("com.vmware.library.vc.vm") in one vCenter context.
            GeiAll Enthusiast

            Hi klabiak.

            I might misunderstood you here, but you cannot specify a vCenter to run "myAction" on. This is run on the vRO server.
            But I presume you have some code inside "myAction" who you want to run on a spesific vCenter.

            vcDdv = VcPlugin.allSdkConnections[0]  - will only run on the first vCenter found.

            There is an action from vmware called com.vmware.library.vcac.findVcConnectionById, who will return the spesific vCenter connection.

            However, I would suggest you stay away from all the builtin "VcPlugin" features. They crashes if a vCenter is down (even if you search for another vCenter). So if you have multiple vCenters, and one is down. Your workflows will not run.

            Here is a piece of code I use as my replacement action: 

            [INPUT]uuid as string
            [OUTPUT] VC:SdkConnection (or null if not found)

            var sdkConnections = VcPlugin.allSdkConnections;

            for each (var sdkConnection in sdkConnections) 
                    var uuid = sdkConnection.aboutInfo.instanceUuid;
                    if (uuid == instanceUUID)
                        return sdkConnection;
                catch (exception)
                    System.warn ("vCenter ("+sdkConnection.name+") might be down? (skipped) : "+exception);
            System.warn("vCenter was not found with ID: "+instanceUUID);

            return null;