VMware Cloud Community
Bdawk_20
Contributor
Contributor

Creating VC: objects

What syntax is used to manually define objects such as VC:HostSystem and VC:VmFolder?

I am having trouble finding information regarding manually setting these.  I imagine its something along the lines of var host_object = VcHostSystem.id("/host-9") ?


Thank you in advance

0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee

VC:HostSystem and VC:VmFolder are examples of so called 'finders' - objects found through some plugin (in this case VC plug-in). You don't create them directly in scripting code.

In Javascript code, you can use so called 'scripting objects'. In this case, the scripting objects matching the above 2 finders would be VcHostSystem and VcFolder. For these 2 particular scripting objects, you usually don't instantiate them directly but get them as a result from some API call or as workflow/action input/output. For example, VcPlugin.allHostSystems will return an array with all host systems, and VcPlugin.getAllHostSystems(param1,param2) will return host systems matching some filters.

For some scripting objects, it may make sense to instantiate them directly using the syntax

   var obj = new MyScriptingObject(params);

where MyScriptingObject is the name of the scripting object exposed by the plug-in and params are the parameters needed by the object constructor.


In general, check plug-in documentation (in vCO API explorer or somewhere else if additional docs are available) to see what scripting objects are available and how they can be created/retrieved.

mlapeyre
Contributor
Contributor

For unit testing purpose, it would be nice to be able to create manually objects like VcSystemHost and setting custom attributes.

It would allow to pass tests without any environment settings/dependency.

There is really no way to create a kind of mocks of VCSystemHost by hand ?

0 Kudos