UNPKG

modi-cli

Version:

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

88 lines (70 loc) 3.69 kB
module.exports = function (username, password, domain, saveCredentials) { console.log('Display user blueprints...'); var httpntlm = require('httpntlm'); var endProcess = require('./Lib/EndProcess.js'); var definitions = require('./Lib/Define.js'); var login = require('./Login.js'); //web api call httpntlm.get({ url: definitions.blueprintsUrl, username: username, password: password, workstation: '', domain: domain }, function (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 BluePrintsRequest = require('./BluePrintsRequest.js'); login.login(BluePrintsRequest, true); } else { if (saveCredentials) login.storeExistingLogin(domain, username, password); try { var dataBluePrints = JSON.parse(res.body); if (dataBluePrints.Blueprints != undefined) { for (var iCount = 0; iCount < dataBluePrints.Blueprints.length; iCount++) { var bluePrint = dataBluePrints.Blueprints[iCount]; if (bluePrint != null) { if (bluePrint.Name != undefined) { console.log('[' + bluePrint.Name + ']'); } else { console.log('\nUnknown blueprint name \n\n'); } } } } 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(); } } //res !=undefined else { process.stdout.write('');//a control command.seems to cut some remaining text in the console console.log(definitions.DefaultBlueprintsErrorMessage); endProcess(); } } ); }