diff --git a/lib/cli.js b/lib/cli.js index 9a92316..6104b68 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -61,6 +61,7 @@ function CLI() { 'help', { group: 'Operator Commands' }, 'account', + 'services', 'info', 'keys', { group: 'Instances (aka VMs/Machines/Containers)' }, @@ -136,6 +137,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_info = require('./do_info'); CLI.prototype.do_keys = require('./do_keys'); diff --git a/lib/cloudapi2.js b/lib/cloudapi2.js index b8f4bf2..e744e97 100644 --- a/lib/cloudapi2.js +++ b/lib/cloudapi2.js @@ -283,6 +283,18 @@ CloudAPI.prototype.getNetwork = function getNetwork(id, cb) { }); }; +// ---- datacenters + +/** + * Get services information + * + * @param {Function} callback of the form `function (err, services, response)` + */ +CloudAPI.prototype.listServices = function listServices(opts, cb) { + var endpoint = sprintf('/%s/services', this.user); + this._passThrough(endpoint, opts, cb); +}; + // ---- accounts /** diff --git a/lib/do_services.js b/lib/do_services.js new file mode 100644 index 0000000..cf220bd --- /dev/null +++ b/lib/do_services.js @@ -0,0 +1,58 @@ +/* + * Copyright 2015 Joyent Inc. + * + * `triton services ...` + */ + +var common = require('./common'); + +function do_services(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.listServices(function (err, services) { + if (err) { + callback(err); + return; + } + + if (opts.json) { + console.log(JSON.stringify(services)); + } else { + // pretty print + Object.keys(services).forEach(function (key) { + var val = services[key]; + console.log('%s: %s', key, val); + }); + } + callback(); + }); +} + +do_services.options = [ + { + names: ['help', 'h'], + type: 'bool', + help: 'Show this help.' + }, + { + names: ['json', 'j'], + type: 'bool', + help: 'JSON output.' + } +]; +do_services.help = ( + 'Show services information\n' + + '\n' + + 'Usage:\n' + + ' {{name}} services\n' + + '\n' + + '{{options}}' +); + +module.exports = do_services;