modi-cli
Version:
Console application for provisioning, displaying or destroying virtual machines in MODI
67 lines (57 loc) • 2.73 kB
JavaScript
module.exports = function (username, password, domain, machineName, saveCredentials)
{
console.log('Start getting status of the machine ' + machineName + '...');
var httpntlm = require('httpntlm');
var definitions = require('./Lib/Define.js');
var endProcess = require('./Lib/EndProcess.js');
var login = require('./Login.js');
//compose the url
var displayStatusUrl = definitions.displayStatusUrl + machineName;
//web api call
httpntlm.get({
url: displayStatusUrl,
username: username,
password: password,
workstation: '',
domain: domain
}, function callbackntlm(err, res) {
if (err) {
process.stdout.write('');//a control command.seems to cut some remaining text in the console
console.log('There was an error. Error is ' + err);
endProcess();
}
if (res != undefined
&& res != null
&& res.body != null
&& res.body != undefined) {
if (res.body.indexOf(definitions.AccessDeniedMessage) > 0) {
process.stdout.write(''); //a control command.seems to cut some remaining text in the console
console.log(definitions.WrongCredentialsMessage);
var StatusRequest = require('./StatusRequest.js');
login.login(StatusRequest, machineName, true);
}
else {
if (saveCredentials)
login.storeExistingLogin(domain, username, password);
try {
var data = JSON.parse(res.body);
if (data.MachineName != undefined && data.Status != undefined)
console.log('The machine ' + data.MachineName + ' has the status ' + data.Status);
else {
console.log(definitions.DefaultStatusErrorMessage);
console.log(res.body);
}
}
catch (e) {
console.log(definitions.DefaultStatusErrorMessage);
console.log(res.body);
}
endProcess();
}
}
else {
console.log(definitions.DefaultStatusErrorMessage);
endProcess();
}
});
}