Giter Site home page Giter Site logo

node-vsphere's People

Contributors

gitter-badger avatar iostat42 avatar mzehrer avatar reedog117 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

node-vsphere's Issues

how get host info

I'm new to vsphere. When I use vc.getMORefsInContainerByTypePropertyArray(rootFolder, 'HostSystem', ['summary']) API. I got error. I don't why?

Can you help me?

Running a command with a payload property called 'attributes' fails

Found an interesting one:
I was calling vc.runCommand('QueryVmfsDatastoreCreateOptions', queryVmfsDatastoreCreateOptions).
The queryVmfsDatastoreCreateOptions.spec.partition.partition object has a property called 'attributes'. This is a required property. If it is included Vsphere returns an error:

Error returned by expat parser: not well-formed (invalid token)
while parsing property "totalSectors" of static type long
while parsing serialized DataObject of type vim.host.DiskPartitionInfo.Specification at line 1, column 527
while parsing property "partition" of static type HostDiskPartitionSpec
while parsing serialized DataObject of type vim.host.VmfsDatastoreCreateSpec at line 1, column 385
while parsing call information for method CreateVmfsDatastore at line 1, column 243

After several hours and several eyes we discovered that 'attributes' is hardcoded in this module. It is expected in validation of certain objects (types.js) and also used for various things in client.js. This conflicts with the use case where we wish to provide our own attributes property for vsphere rather than xml based attributes to help the parser figure out which object to deserialise. Our attributes property is being over written and vsphere is spitting back an error about the object where the 'attributes' property is located. The node-vsphere-soap module also ignores the attributesKey property of the soap client which is used to differentiate between real property attributes and ones to describe the XML type.

As a work around, we have used the $xml property to specify xml for this property rather than json. e.g.

                vc.runCommand('QueryVmfsDatastoreCreateOptions', queryVmfsDatastoreCreateOptions).once('result', function (result) {

                    result.returnval[0].spec.vmfs.volumeName = datastoreName

                    var partitionObj = result.returnval[0].spec.partition.partition;  
                    var partitionXml = '';
                    for (key in partitionObj) {
                        var element = partitionObj[key];
                        var xmlElement = '<' + key + '>' + element + '</' + key + '>'

                        partitionXml += xmlElement;
                    }

                    result.returnval[0].spec.partition.partition = {};
                    result.returnval[0].spec.partition.partition['$xml'] = partitionXml

                    var createVmfsDatastore = {
                        _this: hostDatastoreSystemMOR,
                        spec: result.returnval[0].spec
                    }

                    vc.runCommand('CreateVmfsDatastore', createVmfsDatastore).once('result', function (result) {
                        resolve(result);
                    })
                        .once('error', function (err) {
                            console.log(err);
                            reject(err);
                        });
                })
                    .once('error', function (err) {
                        console.log(err);
                        reject(err);
                    });

One to fix for the future...

An invalid FQDN or IP results in an uncaught DNS error.

An invalid FQDN or IP results in an uncaught DNS error.. I am unable to catch the error too:

error: uncaughtException: getaddrinfo ENOTFOUND test_vcenter2 test_vcenter2:443 date=Tue Jun 28 2016 12:10:19 GMT-0400 (Eastern Daylight Time), pid=33088, uid=n
ull, gid=null,version=v4.4.4, argv=[C:\Program Files\nodejs\n
ode.exe, ], rss=119599104, heapTotal=92604496, heapUsed=90546456, loadavg=[0, 0, 0], uptime=313621.62446
96, trace=[column=10, file=dns.js, function=errnoException, line=27, method=null, native=false, column=26, file=dns.js, function=GetAddrInfoReqWrap.onlookup [as
 oncomplete], line=78, method=onlookup [as oncomplete], native=false], stack=[Error: getaddrinfo ENOTFOUND test_vcenter2 test_vcenter2:443,     at errnoExceptio
n (dns.js:27:10),     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:78:26)]

My code

try{
    vc = new Vsphere.Client(vCenterIP,username,password, false);
    vc.once('ready', function() {
      successCallback("success");
    });
    vc.once('error', function(err) {
      // handle error here
      console.log("Error Connecting to vSphere Client - "+ err);
      errorCallback("Error Connecting to vSphere Client " + err);
    });
  }catch (err){
    console.log("Error Connecting to vSphere Client - "+ err);
    errorCallback("Error Connecting to vSphere Client " + err);
  }

Error on expired session

I've added this library to a hubot script that controls our Vsphere, so it will be running 24x7. I instantiate the client on start of the bot, but after time with no commands, I get this error

 error contents : <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault><faultcode>ServerFaultCode</faultcode><faultstring>The session is not authenticated.</faultstring><detail><NotAuthenticatedFault xmlns="urn:vim25" xsi:type="NotAuthenticated"><object type="Folder">group-d1</object><privilegeId>System.View</privilegeId></NotAuthenticatedFault></detail></soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
authorization token expired! reconnecting...
error contents : <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault><faultcode>ServerFaultCode</faultcode><faultstring>
Required property obj is missing from data object of type ObjectSpec

while parsing serialized DataObject of type vmodl.query.PropertyCollector.ObjectSpec
at line 1, column 584

while parsing property &quot;objectSet&quot; of static type ArrayOfObjectSpec

while parsing serialized DataObject of type vmodl.query.PropertyCollector.FilterSpec
at line 1, column 382

while parsing call information for method RetrievePropertiesEx
at line 1, column 243

while parsing SOAP body
at line 1, column 232

while parsing SOAP envelope
at line 1, column 0

while parsing HTTP request for method retrievePropertiesEx
on object of type vmodl.query.PropertyCollector
at line 1, column 0</faultstring><detail><InvalidRequestFault xmlns="urn:vim25" xsi:type="InvalidRequest"></InvalidRequestFault></detail></soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

Only 100 items returned?

I have the following app that I want to use to grab a bunch of fields from vSphere and stick into a monog repository (which I am then cross reference to chef data and nmap scans to provide visibiliy inot network configuration and orchestration).

The relevant portions are the connect and getVirtualMachines methods. The first is pretty straight forward and returns a Task type resolving to (on success) the VC library instance. I would love the second method getVirtualMachines to return a Task resolving to (on success) all the virtual machines managed by the vcenter instance I am connected to. I am managing 104 virtual machiens in this instance - yet the request only returns an array of 100.

Is this a bug - OR am I not utiuilizing the library correctly?

const process = require('process')
    , mongoose = require('mongoose')
    , Task = require('data.task')
    , Async = require('control.async')(Task)
    , iprange = require('iprange')

const R = require('ramda')

const vSphere = require('../schemas/virtual-machines').model
    , adapt = require('../data-access/mongoose-data.task-adapters.js')

const tap = function(x){
    return x
}

// vSphereUpsert :: (criteria, {}) => Task {ok :: int, ...}
const vSphereUpsert = adapt.findOneAndUpdate(vSphere.collection)

// persist :: [{address :: string, ...}] => [Task {ok :: int, ...}]
const persist = R.map((data) => {
    return vSphereUpsert({ "name": data.name}, data)
})

const connect = () => {
    return new Task( (reject, resolve) => {
        const Vsphere = require('vsphere');
        const vc = new Vsphere.Client('10.10.10.10', 'domain\\user', 'password', false);

        vc.once('ready', () => resolve(vc));
        vc.once('error', reject);
    })
}

const getVirtualMachines = (vc) => {
    return new Task( (reject, resolve) => {
        const rootFolder = vc.serviceContent.rootFolder;
        const vms =  vc.getMORefsInContainerByType( rootFolder, 'VirtualMachine');
        vms.once('result', resolve)
        vms.once('error', reject)
    })
}

const findByName = (name) => R.filter(R.propEq('name', name))

const pluckVmSummary = R.pipe(
    R.prop('returnval'),
    R.prop('objects'),
    R.pluck('propSet'),
    R.map(findByName('summary')),
    R.flatten(),
    R.map(R.prop('val'))
)

const transform = R.map(vm =>{
    const retval = {}
    retval.address = vm.guest.ipAddress
    retval.name = vm.guest.hostName || vm.config.name
    retval.isPoweredOn = vm.runtime.powerState === 'poweredOn'
    retval.memory = parseInt(vm.config.memorySizeMB)
    retval.numCpu = parseInt(vm.config.numCpu)
    retval.numNics = parseInt(vm.config.numEthernetCards)
    retval.imageType = vm.guest.guestFullName || vm.config.guestFullName
    return retval
})

module.exports.scan = function(e,f){
    process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
    mongoose.connect('mongodb://localhost/network');

    connect().
        chain(getVirtualMachines).
        map(tap).
        map(pluckVmSummary).
        map(transform).
        chain(R.compose(Async.parallel, persist)).     // Task [ {ok :: int}]
        map(R.partition(R.propEq('ok', 1))).                    // Task [ [{ok : 1}], [{}]]
        fork(e,f )
}

module.exports.scan(
    console.error,
    console.log
)

No returned value for command 'shutdown'

Hello,

vShpere version : 5.5
node version : 6.9.5 (LTS)

I've been using the example provided in the Readme to execute some vSphere commands.
However, instead of using 'powerOff' command to powerOff my VM, I tried using 'shutdown' so that guest OS is properly powered off. The command is correctly executed by vSphere, but the code in the function powerOpVMByMORef fails to run properly because the result from the runCommand doesn't return anything else than an empty object. So there is no (vSphere) task to wait for.
I've been able to check that it is most probably the expected behaviour according to vSphere 5.5. I didn't take the time to check for other versions.
I'm not sure about what to do here : I've made some modifications on my forked repo which fit my needs but I'm not sure this is the right way to handle this.

The most surprising thing for me is that you're testing the shutdown command in your tests.
I tried running them and they also failed the same way.

So you should probably have encountered this problem already. Unless tests weren't working ?
Or is it due to me using newer versions of the dependencies ?

In case it could be useful, I'm attaching the error log I encountered when running your tests on a unique Win7 VM.

➜  node-vsphere git:(master) ✗ npm test

> [email protected] test /[ my own path]/node-vsphere
> lab


  
  ........xx

Failed tests:

  9) Client tests - VM power operations: powers on and off a VM (by name):

      Cannot read property 'attributes' of undefined

      at Client.<anonymous> (/[ my own path]/node-vsphere/lib/client.js:396:18)
      at Client.g (events.js:291:16)
      at emitNone (events.js:86:13)
      at Client.emit (events.js:185:7)
      at EventEmitter.<anonymous> (/[ my own path]/node-vsphere/node_modules/node-vsphere-soap/lib/client.js:173:14)
      at EventEmitter.g (events.js:291:16)
      at emitThree (events.js:116:13)
      at EventEmitter.emit (events.js:194:7)
      at /[ my own path]/node-vsphere/node_modules/node-vsphere-soap/lib/client.js:98:15
      at /[ my own path]/node-vsphere/node_modules/soap/lib/client.js:130:7
      at /[ my own path]/node-vsphere/node_modules/soap/lib/client.js:248:7
      at Request._callback (/[ my own path]/node-vsphere/node_modules/soap/lib/http.js:60:7)
      at Request.self.callback (/[ my own path]/node-vsphere/node_modules/request/request.js:186:22)
      at emitTwo (events.js:106:13)
      at Request.emit (events.js:191:7)
      at Request.<anonymous> (/[ my own path]/node-vsphere/node_modules/request/request.js:1081:10)
      at emitOne (events.js:96:13)
      at Request.emit (events.js:188:7)
      at IncomingMessage.<anonymous> (/[ my own path]/node-vsphere/node_modules/request/request.js:1001:12)
      at IncomingMessage.g (events.js:291:16)
      at emitNone (events.js:91:20)
      at IncomingMessage.emit (events.js:185:7)
      at endReadableNT (_stream_readable.js:974:12)
      at _combinedTickCallback (internal/process/next_tick.js:74:11)
      at process._tickDomainCallback (internal/process/next_tick.js:122:9)

  10) Client tests - VM power operations: powers on and off multiple VMs (by array of names):

      Cannot read property 'attributes' of undefined

      at Client.<anonymous> (/[ my own path]/node-vsphere/lib/client.js:396:18)
      at Client.g (events.js:291:16)
      at emitNone (events.js:86:13)
      at Client.emit (events.js:185:7)
      at EventEmitter.<anonymous> (/[ my own path]/node-vsphere/node_modules/node-vsphere-soap/lib/client.js:173:14)
      at EventEmitter.g (events.js:291:16)
      at emitThree (events.js:116:13)
      at EventEmitter.emit (events.js:194:7)
      at /[ my own path]/node-vsphere/node_modules/node-vsphere-soap/lib/client.js:98:15
      at /[ my own path]/node-vsphere/node_modules/soap/lib/client.js:130:7
      at /[ my own path]/node-vsphere/node_modules/soap/lib/client.js:248:7
      at Request._callback (/[ my own path]/node-vsphere/node_modules/soap/lib/http.js:60:7)
      at Request.self.callback (/[ my own path]/node-vsphere/node_modules/request/request.js:186:22)
      at emitTwo (events.js:106:13)
      at Request.emit (events.js:191:7)
      at Request.<anonymous> (/[ my own path]/node-vsphere/node_modules/request/request.js:1081:10)
      at emitOne (events.js:96:13)
      at Request.emit (events.js:188:7)
      at IncomingMessage.<anonymous> (/[ my own path]/node-vsphere/node_modules/request/request.js:1001:12)
      at IncomingMessage.g (events.js:291:16)
      at emitNone (events.js:91:20)
      at IncomingMessage.emit (events.js:185:7)
      at endReadableNT (_stream_readable.js:974:12)
      at _combinedTickCallback (internal/process/next_tick.js:74:11)
      at process._tickDomainCallback (internal/process/next_tick.js:122:9)


2 of 10 tests failed
Test duration: 1835 ms
The following leaks were detected:Reflect

npm ERR! Test failed.  See above for more details.

Unable to catch errors

The error event is not working, considering the following code:

var Vsphere = require('vsphere');
var vc = new Vsphere.Client('myhost', 'myuser', 'mypass', false);
vc.once('ready', function() {
  console.log('vSphere ready');
});
vc.once('error', function(err) {
  console.log('vSphere error: ' + err.message);
});

If I change the host to something where the API is not present:

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:443
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)

If I change the user or password to something invalid:

events.js:165
      throw err;
      ^

Error: Uncaught, unspecified "error" event. (<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault><faultcode>ServerFaultCode</faultcode><faultstring>Cannot complete login due to an incorrect user name or password.</faultstring><detail><InvalidLoginFault xmlns="urn:vim25" xsi:type="InvalidLogin"></InvalidLoginFault></detail></soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>)
    at Client.emit (events.js:163:17)
    at EventEmitter.<anonymous> (/home/vdix98r/Workspace/telcel_kue/node_modules/node-vsphere-soap/lib/client.js:178:14)
    at EventEmitter.g (events.js:291:16)
    at emitOne (events.js:96:13)
    at EventEmitter.emit (events.js:188:7)
    at _soapErrorHandler (/home/vdix98r/Workspace/telcel_kue/node_modules/node-vsphere-soap/lib/client.js:236:13)
    at /home/vdix98r/Workspace/telcel_kue/node_modules/node-vsphere-soap/lib/client.js:92:9
    at /home/vdix98r/Workspace/telcel_kue/node_modules/soap/lib/client.js:130:7
    at /home/vdix98r/Workspace/telcel_kue/node_modules/soap/lib/client.js:230:16
    at Request._callback (/home/vdix98r/Workspace/telcel_kue/node_modules/soap/lib/http.js:60:7)

Versions:

├─┬ [email protected]
│ └─┬ [email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.