function parseInfoArgs(args) { var arg; var type; var types = []; for (arg in args) { types = types.concat(args[arg].split(',')); } for (type in types) { if (VM.INFO_TYPES.indexOf(types[type]) === -1) { usage('Invalid info type: ' + types[type]); } } if (types.length === 0) { types.push('all'); } return types; }
VM.load(uuid, function (err, obj) { var socket; //var q = new Qmp(console.log); var q = new Qmp(function () {return;}); if (err) { return callback('Unable to load vm: ' + JSON.stringify(err)); } if (obj.brand !== 'kvm') { return callback(new Error('vmadmd only handles "info" for kvm (' + 'your brand is: ' + obj.brand + ')')); } if (obj.state !== 'running' && obj.state !== 'stopping') { return callback(new Error('Unable to get info for vm from ' + 'state "' + obj.state + '", must be "running" or "stopping".')); } if (!types) { types = ['all']; } for (type in types) { type = types[type]; if (VM.INFO_TYPES.indexOf(type) === -1) { return callback(new Error('unknown info type: ' + type)); } } socket = obj.zonepath + '/root/tmp/vm.qmp'; q.connect(socket, function(err) { if (err) { return callback(err); } // run each command in commands async.map(commands, function (command, cb) { var base = command.replace(/^query-/, ''); if ((types.indexOf('all') !== -1) || (types.indexOf(base) !== -1)) { q.command(command, null, function (err, result) { cb(null, [base, result]); }); } else { cb(null, null); } }, function (err, results) { var i; q.disconnect(); if (err) { VM.log('ERROR', 'getVMInfo(): Unknown Error', err); callback(err); } else { // key is in results[i][0], value in results[i][1] for (i = 0; i < results.length; i++) { if (results[i]) { res[results[i][0]] = results[i][1]; } } if ((types.indexOf('all') !== -1) || (types.indexOf('vnc') !== -1)) { res.vnc = {}; if (VNC.hasOwnProperty(obj.uuid)) { res.vnc.host = VNC[obj.uuid].host; res.vnc.port = VNC[obj.uuid].port; res.vnc.display = VNC[obj.uuid].display; } callback(null, res); } else { callback(null, res); } } } ); }); });