@stordata/vsphere-soapify
Version:
A NodeJS abstraction layer for the vSphere SOAP API
40 lines (35 loc) • 1.71 kB
JavaScript
;
const ManagedEntity = require('./ManagedEntity'),
PropertyFilterSpec = require('../data/PropertyFilterSpec'),
PropertySpec = require('../data/PropertySpec'),
ObjectSpec = require('../data/ObjectSpec'),
TraversalSpec = require('../data/TraversalSpec');
module.exports = class Folder extends ManagedEntity {
/**
* Get children of this {@link Folder} object.
* Internally uses the {@link PropertyCollector} to fetch instances and properties.
*
* @param type {Class} The type of objects to fetch
* @param [recursive=false] {Boolean} Whether the call recurses or not. If `false` only direct children are fetched
* @param [properties] {Array<String>} An optional list of properties to fetch. By default, all supported (i.e. mapped) properties
* are taken into account. If you only need a few, you'd better list the properties explicitely.
*
* @returns {Promise<Array<ManagedEntity>>} A Promise resolving to a list of {@link ManagedEntity} (or subclass) instances
*/
async getChildren(type, recursive = false, properties = type.properties()) {
const viewManager = await this.client.getViewManager(),
propertyCollector = await this.client.getPropertyCollector(),
view = await viewManager.createContainerView(this, type.name, recursive);
return propertyCollector.retrievePropertiesEx(new PropertyFilterSpec(
new PropertySpec(type.name, false, properties),
new ObjectSpec(view, true, new TraversalSpec('ContainerView', 'view'))
));
}
static mappings() {
return {
...super.mappings(),
childEntity: 'ArrayOfManagedObjectReference',
childType: 'xsd:string'
};
}
};