UNPKG

modi-cli

Version:

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

123 lines (99 loc) 4.01 kB
module.exports = function (args) { var isValid = true; var defs = require('./Define.js'); var validator = require('validator'); if (validator.isNull(args.n) && validator.isNull(args.machineName)) { console.log('The machine name should not be empty or missing'); isValid = false; } else { if ( (args.n != null && args.n.length == 0) && (args.machineName != null && args.machineName.length == 0) ) { console.log('The machine name should not be empty'); isValid = false; } } if (validator.isNull(args.b) && validator.isNull(args.blueprint)) { console.log('The blueprint name should not be empty or missing'); isValid = false; } else { if ( (args.b != null && args.b.length == 0) && (args.blueprint!=null && args.blueprintsUrl.length == 0 ) ) { console.log('The blueprint name should not be empty'); isValid = false; } } if (validator.isNull(args.g) && validator.isNull(args.memory)) { args.g = 2; args.memory = 2; } if (validator.isNull(args.l) && validator.isNull(eval(args)['lease-days'])) { args.l = 1; eval(args)['lease-days'] = 1; } if (validator.isNull(args.m) && validator.isNull(args.monitoring)) { args.m = true; args.monitoring = true; } if (validator.isNull(args.c) && validator.isNull(eval(args)['num-cpu'])) { args.c = 1; eval(args)['num-cpu'] = 1; } if (validator.isNull(args.a) && validator.isNull(args.alerting)) { args.a = true; args.alerting = true; } if (validator.isNull(args.p) && validator.isNull(eval(args)['contains-pii'])) { args.p = false; eval(args)['contains-pii'] = false; } if (validator.isNull(eval(args)['ppu-le'])) { console.log('The pay-per-use LE information should not be empty or missing'); isValid = false; } if (validator.isNull(eval(args)['ppu-bu'])) { console.log('The pay-per-use business unit should not be empty or missing'); isValid = false; } if (validator.isNull(eval(args)['ppu-dept'])) { console.log('The pay-per-use department should not be empty or missing'); isValid = false; } if (validator.isNull(eval(args)['ppu-project'])) { console.log('The pay-per-use project should not be empty or missing'); isValid = false; } if (validator.isNull(eval(args)['ppu-contact-name'])) { console.log('The pay-per-use contact name should not be empty or missing'); isValid = false; } if (validator.isNull(eval(args)['ppu-contact'])) { console.log('The email address of the Team Finance contact should not be empty or missing'); isValid = false; } else { if (!validator.isEmail(eval(args)['ppu-contact'])) { console.log('The email address of the Team Finance contact is not correctly formatted'); isValid = false; } } if (!validator.isInt(args.l)) { console.log('Lease days should be an integer number'); isValid = false; } if (!validator.isInt(args.c)) { console.log('Number of processors should be an integer number'); isValid = false; } if (!validator.isFloat(args.g)) { console.log('Memory size should be numeric'); isValid = false; } if (args.loc != defs.USEastCoastLocation && args.loc != defs.USWestCoastLocation) { console.log('Machine location is mandatory and should be [' + defs.USWestCoastLocation + '] or [' + defs.USEastCoastLocation + ']'); isValid = false; } return isValid; }