add listDatacenters

This commit is contained in:
Dave Eddy 2015-08-26 19:59:28 -04:00
parent 769e9bbe2b
commit 0ccda0af10
3 changed files with 70 additions and 0 deletions

View File

@ -62,6 +62,7 @@ function CLI() {
{ group: 'Operator Commands' },
'account',
'services',
'datacenters',
'info',
'keys',
{ group: 'Instances (aka VMs/Machines/Containers)' },
@ -138,6 +139,7 @@ CLI.prototype.init = function (opts, args, callback) {
// Operator
CLI.prototype.do_account = require('./do_account');
CLI.prototype.do_services = require('./do_services');
CLI.prototype.do_datacenters = require('./do_datacenters');
CLI.prototype.do_info = require('./do_info');
CLI.prototype.do_keys = require('./do_keys');

View File

@ -295,6 +295,16 @@ CloudAPI.prototype.listServices = function listServices(opts, cb) {
this._passThrough(endpoint, opts, cb);
};
/**
* Get datacenters information
*
* @param {Function} callback of the form `function (err, datacenters, response)`
*/
CloudAPI.prototype.listDatacenters = function listDatacenters(opts, cb) {
var endpoint = sprintf('/%s/datacenters', this.user);
this._passThrough(endpoint, opts, cb);
};
// ---- accounts
/**

58
lib/do_datacenters.js Normal file
View File

@ -0,0 +1,58 @@
/*
* Copyright 2015 Joyent Inc.
*
* `triton datacenters ...`
*/
var common = require('./common');
function do_datacenters(subcmd, opts, args, callback) {
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return;
} else if (args.length !== 0) {
callback(new Error('invalid args: ' + args));
return;
}
this.triton.cloudapi.listDatacenters(function (err, datacenters) {
if (err) {
callback(err);
return;
}
if (opts.json) {
console.log(JSON.stringify(datacenters));
} else {
// pretty print
Object.keys(datacenters).forEach(function (key) {
var val = datacenters[key];
console.log('%s: %s', key, val);
});
}
callback();
});
}
do_datacenters.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
},
{
names: ['json', 'j'],
type: 'bool',
help: 'JSON output.'
}
];
do_datacenters.help = (
'Show datacenters information\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} datacenters\n'
+ '\n'
+ '{{options}}'
);
module.exports = do_datacenters;