UNPKG

modi-cli

Version:

Console application for provisioning, displaying or destroying virtual machines in MODI

97 lines (73 loc) 3.56 kB
module.exports = function (username, password, domain, machineName,saveCredentials) { console.log('Start getting properties 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 displayPropsUrl = definitions.displayPropsUrl + machineName; var getMachineIpUrl = definitions.GetMachineIPUrl + machineName; //web api call httpntlm.get({ url: displayPropsUrl, 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(); } var totalResult = res.body; console.log('Getting the machine IP from VCenter...' ); httpntlm.get({ url: getMachineIpUrl, 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 DisplayPropertiesRequest = require('./DisplayPropertiesRequest.js'); login.login(DisplayPropertiesRequest, machineName, true); } else { if (saveCredentials) login.storeExistingLogin(domain, username, password); totalResult = totalResult.substring(0, totalResult.length - 1); //var ip = res.body.replace(/"/g, ''); var ip = res.body; totalResult += ',{ "Key": "MachineIP", "Value":' + ip + '}]'; console.log('Machine properties are returned from the server:'); var properties = JSON.parse(totalResult); for (var iCount = 0; iCount < properties.length; iCount++) { var prop = properties[iCount]; if (prop != null) { if (prop.Key != undefined && prop.Value != null) { console.log('Property with key [' + prop.Key + '] has the value [' + prop.Value + ']'); } } } endProcess(); } } else { console.log(definitions.DefaultPropsErrorMessage); endProcess(); } }); }); }