listServices

This commit is contained in:
Dave Eddy 2015-08-26 19:56:18 -04:00
parent f1e46a7b21
commit 769e9bbe2b
3 changed files with 72 additions and 0 deletions

View File

@ -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');

View File

@ -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
/**

58
lib/do_services.js Normal file
View File

@ -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;