UNPKG

modi-cli

Version:

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

72 lines (59 loc) 2.88 kB
module.exports = function (username, password, domain, machineName, saveCredentials) { console.log('Start destroying machine ' + machineName + '...'); var httpntlm = require('httpntlm'); var endProcess = require('./Lib/EndProcess.js'); var definitions = require('./Lib/Define.js'); var login = require('./Login.js'); //compose the url var destroyUrl = definitions.destroyUrl + machineName; //web api call httpntlm.get({ url: destroyUrl, 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 DestroyRequest = require('./DestroyRequest.js'); login.login(DestroyRequest, 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 + ' returned the status [' + data.Status + '] when requested to destroy'); else { process.stdout.write('');//a control command.seems to cut some remaining text in the console console.log(definitions.DefaultBlueprintsErrorMessage); console.log(res.body); } } catch (e) { process.stdout.write('');//a control command.seems to cut some remaining text in the console console.log(definitions.DefaultBlueprintsErrorMessage); console.log(res.body); } endProcess(); } } else { process.stdout.write('');//a control command.seems to cut some remaining text in the console console.log(definitions.DefaultBlueprintsErrorMessage); endProcess(); } }); }