New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@stordata/vsphere-soapify

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stordata/vsphere-soapify - npm Package Compare versions

Comparing version

to
0.0.10

lib/sdk/data/Description.js

3

index.js
'use strict';
module.exports = {
Client: require('./lib/client')
Client: require('./lib/client'),
sdk: require('./lib/sdk')
};

@@ -5,4 +5,6 @@ 'use strict';

request = require('request'),
_ = require('lodash'),
Parser = require('./parser'),
{ ServiceInstance, HostSystem, VirtualMachine, Datacenter } = require('./sdk').managed;
{ ServiceInstance, HostSystem, VirtualMachine, Datacenter } = require('./sdk').managed,
{ PerfQuerySpec, PerfMetricId } = require('./sdk').data;

@@ -96,2 +98,6 @@ module.exports = class Client {

getPerformanceManager() {
return this.getServiceContent().then(serviceContent => serviceContent.perfManager);
}
/**

@@ -147,2 +153,48 @@ * Retrieves the list of {@link HostSystem} instances in this vSphere system.

/**
* Retrieves a list of counter and their id from this vSphere system.
*
* @param {Class} type The type of entity to retrieve
* @param {Object<String, String>} counters The map of counter names <> instance type to retrieve.
* Instance type can be an asterisk (*) to specify all instances or empty string ("") to specify aggregated statistics
* @param {Array<String>} [properties=[]] The optional list of entity properties
*
* @returns {Promise<Array<String>>} A Promise resolving to an array of Objects { metric string and key to call }
*/
async getPerfCounters(type, counters, properties = []) {
const perfMng = await this.getPerformanceManager(), /* eslint-disable one-var */
entities = await this.getInventoryItems(type, properties);
if (!entities || entities.length === 0) {
return [];
}
const { counterToId, idToCounter } = await perfMng.preparePerfCounters(counters);
return Promise.all(entities.map(entity => perfMng.queryPerfProviderSummary(entity)
.then((summary) => {
const spec = new PerfQuerySpec();
spec.entity = entity;
spec.maxSample = 1;
spec.metricId = _.map(counterToId, ({ counterId, instance }) => new PerfMetricId(this, { counterId, instance }));
spec.intervalId = summary.refreshRate;
return spec;
})))
.then(specs => perfMng.queryPerf(specs))
.then(result => result.map(perf => ({
entity: _.find(entities, { ref: perf.entity.ref }),
sampleInfo: perf.sampleInfo,
value: perf.value.filter(metric => Array.isArray(metric.value)).map(metric => ({
value: metric.value,
id: {
counterId: metric.id.counterId,
counterName: idToCounter[metric.id.counterId],
instance: metric.id.instance
}
}))
})));
}
login(username, password) {

@@ -149,0 +201,0 @@ return this.getSessionManager().then(sessionManager => sessionManager.login(username, password));

@@ -36,3 +36,5 @@ 'use strict';

DpmBehavior: parseString,
DrsBehavior: parseString
DrsBehavior: parseString,
PerfSummaryType: parseString,
PerfStatsType: parseString
};

@@ -39,0 +41,0 @@

@@ -13,5 +13,6 @@ 'use strict';

propertyCollector: 'ManagedObjectReference',
viewManager: 'ManagedObjectReference'
viewManager: 'ManagedObjectReference',
perfManager: 'ManagedObjectReference'
};
}
};

@@ -47,3 +47,3 @@ /* eslint-disable no-param-reassign */

return this.client.getPropertyCollector()
.then(propertyCollector => propertyCollector.retrievePropertiesEx(new PropertyFilterSpec(
.then(collector => collector.retrievePropertiesEx(new PropertyFilterSpec(
new PropertySpec(type.name, false, properties || type.properties()),

@@ -70,2 +70,14 @@ new ObjectSpec(this, true, new TraversalSpec(this.constructor.name, property))

/**
* Reloads this ManagedEntity instance with properties.
* Internally delegates to the {@link PropertyCollector} to retrieve the properties.
*
* @param [properties] {Array<String>} An optional list of properties to fetch. By default all properties are fetched
*
* @returns {Promise<ManagedEntity>} A Promise resolving with the entity, including fetched properties
*/
async withProperties(properties) {
return this.client.getPropertyCollector().then(collector => collector.retrieveObjectWithProperties(this, properties));
}
// Utility functions

@@ -82,3 +94,13 @@

call(method, args) {
/**
* Calls a method.
* Serialization is handled automatically (hopefully !) so you pass object instances directly
*
* @param method {String} The method to call
* @param [args] {Object} The arguments for the call
* @param [type] {Class} The return type of the call. When defined, the result is parsed to that SDK object
*
* @returns {Promise<Object>} A Promise resolving with the (optinally parsed) result of the call
*/
call(method, args, type) {
return this.client.getClient()

@@ -89,3 +111,10 @@ .then(client => client[method]({

}))
.then(([result]) => result && result.returnval);
.then(([result]) => result && result.returnval)
.then((result) => {
if (!type) {
return result;
}
return this.parse(result, type);
});
}

@@ -92,0 +121,0 @@

'use strict';
const ManagedEntity = require('./ManagedEntity'),
RetrieveResult = require('../data/RetrieveResult');
const _ = require('lodash'),
ManagedEntity = require('./ManagedEntity'),
RetrieveResult = require('../data/RetrieveResult'),
PropertyFilterSpec = require('../data/PropertyFilterSpec'),
PropertySpec = require('../data/PropertySpec'),
ObjectSpec = require('../data/ObjectSpec');
module.exports = class PropertyCollector extends ManagedEntity {
retrievePropertiesEx(specSet, options = {}) {
return this.call('RetrievePropertiesExAsync', { specSet, options })
.then(result => this.parse(result, RetrieveResult.name))
.then(result => result.objects);
async retrievePropertiesEx(specSet, options = {}) {
return this.call('RetrievePropertiesExAsync', { specSet, options }, RetrieveResult).then(result => result.objects);
}
async retrieveObjectWithProperties(object, properties) {
const { constructor } = object;
return this.retrievePropertiesEx(new PropertyFilterSpec(
new PropertySpec(constructor.name, false, properties || constructor.properties()),
new ObjectSpec(object)
))
.then(_.first);
}
};

@@ -12,5 +12,4 @@ 'use strict';

retrieveServiceContent() {
return this.call('RetrieveServiceContentAsync')
.then(result => this.parse(result, ServiceContent.name));
return this.call('RetrieveServiceContentAsync', {}, ServiceContent);
}
};
{
"name": "@stordata/vsphere-soapify",
"version": "0.0.9",
"version": "0.0.10",
"description": "A NodeJS abstraction layer for the vSphere SOAP API",

@@ -29,3 +29,3 @@ "main": "index.js",

"require-all": "3.0.0",
"soap": "0.26.0"
"soap": "stordata/node-soap#af80f0eeb5437f651d5d17568608ab83d36ea417"
},

@@ -32,0 +32,0 @@ "devDependencies": {

Sorry, the diff of this file is too big to display