MXS-1300: Make MaxCtrl more like a library
All invocations into the common helper functions are now done through the `maxctrl` function. This allows the program arguments to be passed to the core as a parameter instead of reading them from global variables. This helps with the implicit initialization that was done when the yargs library was required which caused duplicated output. Refactored the core functions so that they only process the argument vector. The parsing of the argument vector is done in maxctrl.js where it is more appropriate.
This commit is contained in:
@ -18,19 +18,24 @@ exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('server <server> <key> <value>', 'Alter server parameters', {}, function(argv) {
|
||||
updateValue('servers/' + argv.server, 'data.attributes.parameters.' + argv.key, argv.value)
|
||||
maxctrl(argv)
|
||||
.updateValue('servers/' + argv.server, 'data.attributes.parameters.' + argv.key, argv.value)
|
||||
})
|
||||
.command('monitor <monitor> <key> <value>', 'Alter monitor parameters', {}, function(argv) {
|
||||
updateValue('monitors/' + argv.monitor, 'data.attributes.parameters.' + argv.key, argv.value)
|
||||
maxctrl(argv)
|
||||
.updateValue('monitors/' + argv.monitor, 'data.attributes.parameters.' + argv.key, argv.value)
|
||||
})
|
||||
.command('service <service> <key> <value>', 'Alter service parameters', {}, function(argv) {
|
||||
updateValue('services/' + argv.service, 'data.attributes.parameters.' + argv.key, argv.value)
|
||||
maxctrl(argv)
|
||||
.updateValue('services/' + argv.service, 'data.attributes.parameters.' + argv.key, argv.value)
|
||||
})
|
||||
.command('logging <key> <value>', 'Alter logging parameters', {}, function(argv) {
|
||||
updateValue('maxscale/logs', 'attributes.parameters.' + argv.key, argv.value)
|
||||
maxctrl(argv)
|
||||
.updateValue('maxscale/logs', 'attributes.parameters.' + argv.key, argv.value)
|
||||
})
|
||||
.command('maxscale <key> <value>', 'Alter MaxScale parameters', {}, function(argv) {
|
||||
updateValue('maxscale', 'attributes.parameters.' + argv.key, argv.value)
|
||||
maxctrl(argv)
|
||||
.updateValue('maxscale', 'attributes.parameters.' + argv.key, argv.value)
|
||||
})
|
||||
.usage('Usage: alter <command>')
|
||||
.help()
|
||||
|
@ -20,22 +20,24 @@ exports.builder = function(yargs) {
|
||||
.command('command <module> <command> [parameters...]', 'Call a module command', {}, function(argv) {
|
||||
|
||||
// First we have to find the correct method to use
|
||||
doRequest('maxscale/modules/' + argv.module + '/', function(resp) {
|
||||
maxctrl(argv)
|
||||
.doRequest('maxscale/modules/' + argv.module + '/', function(resp) {
|
||||
|
||||
// A GET request will return the correct error if the command is not found
|
||||
var verb = 'GET'
|
||||
// A GET request will return the correct error if the command is not found
|
||||
var verb = 'GET'
|
||||
|
||||
resp.data.attributes.commands.forEach(function(i) {
|
||||
if (i.id == argv.command) {
|
||||
verb = i.attributes.method;
|
||||
}
|
||||
resp.data.attributes.commands.forEach(function(i) {
|
||||
if (i.id == argv.command) {
|
||||
verb = i.attributes.method;
|
||||
}
|
||||
})
|
||||
|
||||
maxctrl
|
||||
.doRequest('maxscale/modules/' + argv.module + '/' + argv.command + '?' + argv.parameters.join('&'),
|
||||
function(resp) {
|
||||
console.log(JSON.stringify(resp, null, 4))
|
||||
}, { method: verb })
|
||||
})
|
||||
|
||||
doRequest('maxscale/modules/' + argv.module + '/' + argv.command + '?' + argv.parameters.join('&'),
|
||||
function(resp) {
|
||||
console.log(JSON.stringify(resp, null, 4))
|
||||
}, { method: verb })
|
||||
})
|
||||
})
|
||||
.usage('Usage: call <command>')
|
||||
.help()
|
||||
|
@ -19,7 +19,8 @@ exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('server <server> <state>', 'Clear server state', {}, function(argv) {
|
||||
var target = 'servers/' + argv.server + '/clear?state=' + argv.state
|
||||
doRequest(target, null, {method: 'PUT'})
|
||||
maxctrl(argv)
|
||||
.doRequest(target, null, {method: 'PUT'})
|
||||
})
|
||||
.usage('Usage: clear <command>')
|
||||
.help()
|
||||
|
@ -71,7 +71,8 @@ exports.builder = function(yargs) {
|
||||
}
|
||||
}
|
||||
|
||||
doRequest('servers', null, {method: 'POST', body: server})
|
||||
maxctrl(argv)
|
||||
.doRequest('servers', null, {method: 'POST', body: server})
|
||||
})
|
||||
|
||||
// Create monitor
|
||||
@ -97,7 +98,8 @@ exports.builder = function(yargs) {
|
||||
}
|
||||
}
|
||||
|
||||
doRequest('monitors', null, {method: 'POST', body: monitor})
|
||||
maxctrl(argv)
|
||||
.doRequest('monitors', null, {method: 'POST', body: monitor})
|
||||
})
|
||||
|
||||
// Create listener
|
||||
@ -157,7 +159,8 @@ exports.builder = function(yargs) {
|
||||
}
|
||||
}
|
||||
|
||||
doRequest('services/' + argv.service + '/listeners', null, {method: 'POST', body: listener})
|
||||
maxctrl(argv)
|
||||
.doRequest('services/' + argv.service + '/listeners', null, {method: 'POST', body: listener})
|
||||
})
|
||||
.command('user <name> <password>', 'Create a new network user', {}, function(argv) {
|
||||
|
||||
@ -171,7 +174,8 @@ exports.builder = function(yargs) {
|
||||
}
|
||||
}
|
||||
|
||||
doRequest('users/inet', null, {method: 'POST', body: user})
|
||||
maxctrl(argv)
|
||||
.doRequest('users/inet', null, {method: 'POST', body: user})
|
||||
})
|
||||
|
||||
.usage('Usage: create <command>')
|
||||
|
@ -18,16 +18,20 @@ exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('server <name>', 'Destroy an unused server', {}, function(argv) {
|
||||
doRequest('servers/' + argv.name, null, {method: 'DELETE'})
|
||||
maxctrl(argv)
|
||||
.doRequest('servers/' + argv.name, null, {method: 'DELETE'})
|
||||
})
|
||||
.command('monitor <name>', 'Destroy an unused monitor', {}, function(argv) {
|
||||
doRequest('monitors/' + argv.name, null, {method: 'DELETE'})
|
||||
maxctrl(argv)
|
||||
.doRequest('monitors/' + argv.name, null, {method: 'DELETE'})
|
||||
})
|
||||
.command('listener <service> <name>', 'Destroy an unused listener', {}, function(argv) {
|
||||
doRequest('services/' + argv.service + '/listeners/' + argv.name, null, {method: 'DELETE'})
|
||||
maxctrl(argv)
|
||||
.doRequest('services/' + argv.service + '/listeners/' + argv.name, null, {method: 'DELETE'})
|
||||
})
|
||||
.command('user <name>', 'Remove a network user', {}, function(argv) {
|
||||
doRequest('users/inet/' + argv.name, null, {method: 'DELETE'})
|
||||
maxctrl(argv)
|
||||
.doRequest('users/inet/' + argv.name, null, {method: 'DELETE'})
|
||||
})
|
||||
.usage('Usage: destroy <command>')
|
||||
.help()
|
||||
|
@ -26,19 +26,24 @@ exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('log-priority <log>', 'Disable log priority [warning|notice|info|debug]', {}, function(argv) {
|
||||
if (log_levels.indexOf(argv.log) != -1) {
|
||||
updateValue('maxscale/logs', 'data.attributes.parameters.log_' + argv.log, false)
|
||||
maxctrl(argv)
|
||||
.updateValue('maxscale/logs', 'data.attributes.parameters.log_' + argv.log, false)
|
||||
} else {
|
||||
logError('Invalid log priority: ' + argv.log);
|
||||
maxctrl(argv)
|
||||
.logError('Invalid log priority: ' + argv.log);
|
||||
}
|
||||
})
|
||||
.command('maxlog', 'Disable MaxScale logging', {}, function(argv) {
|
||||
updateValue('maxscale/logs', 'data.attributes.parameters.maxlog', false)
|
||||
maxctrl(argv)
|
||||
.updateValue('maxscale/logs', 'data.attributes.parameters.maxlog', false)
|
||||
})
|
||||
.command('syslog', 'Disable syslog logging', {}, function(argv) {
|
||||
updateValue('maxscale/logs', 'data.attributes.parameters.syslog', false)
|
||||
maxctrl(argv)
|
||||
.updateValue('maxscale/logs', 'data.attributes.parameters.syslog', false)
|
||||
})
|
||||
.command('account <name>', 'Disable a Linux user account from administrative use', {}, function(argv) {
|
||||
doRequest('users/unix/' + argv.name, null, { method: 'DELETE'})
|
||||
maxctrl(argv)
|
||||
.doRequest('users/unix/' + argv.name, null, { method: 'DELETE'})
|
||||
})
|
||||
.usage('Usage: disable <command>')
|
||||
.help()
|
||||
|
@ -26,16 +26,20 @@ exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('log-priority <log>', 'Enable log priority [warning|notice|info|debug]', {}, function(argv) {
|
||||
if (log_levels.indexOf(argv.log) != -1) {
|
||||
updateValue('maxscale/logs', 'data.attributes.parameters.log_' + argv.log, true)
|
||||
maxctrl(argv)
|
||||
.updateValue('maxscale/logs', 'data.attributes.parameters.log_' + argv.log, true)
|
||||
} else {
|
||||
logError('Invalid log priority: ' + argv.log);
|
||||
maxctrl(argv)
|
||||
.logError('Invalid log priority: ' + argv.log);
|
||||
}
|
||||
})
|
||||
.command('maxlog', 'Enable MaxScale logging', {}, function(argv) {
|
||||
updateValue('maxscale/logs', 'data.attributes.parameters.maxlog', true)
|
||||
maxctrl(argv)
|
||||
.updateValue('maxscale/logs', 'data.attributes.parameters.maxlog', true)
|
||||
})
|
||||
.command('syslog', 'Enable syslog logging', {}, function(argv) {
|
||||
updateValue('maxscale/logs', 'data.attributes.parameters.syslog', true)
|
||||
maxctrl(argv)
|
||||
.updateValue('maxscale/logs', 'data.attributes.parameters.syslog', true)
|
||||
})
|
||||
.command('account <name>', 'Activate a Linux user account for administrative use', {}, function(argv) {
|
||||
var req_body = {
|
||||
@ -44,7 +48,8 @@ exports.builder = function(yargs) {
|
||||
type: 'unix'
|
||||
}
|
||||
}
|
||||
doRequest('users/unix', null, { method: 'POST', body: req_body})
|
||||
maxctrl(argv)
|
||||
.doRequest('users/unix', null, { method: 'POST', body: req_body})
|
||||
})
|
||||
.usage('Usage: enable <command>')
|
||||
.help()
|
||||
|
@ -12,20 +12,22 @@
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
function addServer(path, targets) {
|
||||
doRequest(path, function(res) {
|
||||
var servers =_.get(res, 'data.relationships.servers.data', [])
|
||||
function addServer(argv, path, targets) {
|
||||
maxctrl(argv)
|
||||
.doRequest(path, function(res) {
|
||||
var servers =_.get(res, 'data.relationships.servers.data', [])
|
||||
|
||||
targets.forEach(function(i){
|
||||
servers.push({id: i, type: 'servers'})
|
||||
targets.forEach(function(i){
|
||||
servers.push({id: i, type: 'servers'})
|
||||
})
|
||||
|
||||
// Update relationships and remove unnecessary parts
|
||||
_.set(res, 'data.relationships.servers.data', servers)
|
||||
delete res.data.attributes
|
||||
|
||||
maxctrl(argv)
|
||||
.doRequest(path, null, {method: 'PATCH', body: res})
|
||||
})
|
||||
|
||||
// Update relationships and remove unnecessary parts
|
||||
_.set(res, 'data.relationships.servers.data', servers)
|
||||
delete res.data.attributes
|
||||
|
||||
doRequest(path, null, {method: 'PATCH', body: res})
|
||||
})
|
||||
}
|
||||
|
||||
exports.command = 'link <command>'
|
||||
@ -34,10 +36,10 @@ exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('service <name> <server...>', 'Link servers to a service', {}, function(argv) {
|
||||
addServer('services/' + argv.name, argv.server)
|
||||
addServer(argv, 'services/' + argv.name, argv.server)
|
||||
})
|
||||
.command('monitor <name> <server...>', 'Link servers to a monitor', {}, function(argv) {
|
||||
addServer('monitors/' + argv.name, argv.server)
|
||||
addServer(argv, 'monitors/' + argv.name, argv.server)
|
||||
})
|
||||
.usage('Usage: link <command>')
|
||||
.help()
|
||||
|
@ -18,63 +18,71 @@ exports.desc = 'List objects'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('servers', 'List servers', {}, function() {
|
||||
getCollection('servers', [
|
||||
{'Server': 'id'},
|
||||
{'Address': 'attributes.parameters.address'},
|
||||
{'Port': 'attributes.parameters.port'},
|
||||
{'Connections': 'attributes.statistics.connections'},
|
||||
{'State': 'attributes.state'}
|
||||
])
|
||||
.command('servers', 'List servers', {}, function(argv) {
|
||||
maxctrl(argv)
|
||||
.getCollection('servers', [
|
||||
{'Server': 'id'},
|
||||
{'Address': 'attributes.parameters.address'},
|
||||
{'Port': 'attributes.parameters.port'},
|
||||
{'Connections': 'attributes.statistics.connections'},
|
||||
{'State': 'attributes.state'}
|
||||
])
|
||||
})
|
||||
.command('services', 'List services', {}, function() {
|
||||
getCollection('services',[
|
||||
{'Service': 'id'},
|
||||
{'Router': 'attributes.router'},
|
||||
{'Connections': 'attributes.connections'},
|
||||
{'Total Connections': 'attributes.total_connections'},
|
||||
{'Servers': 'relationships.servers.data[].id'}
|
||||
])
|
||||
.command('services', 'List services', {}, function(argv) {
|
||||
maxctrl(argv)
|
||||
.getCollection('services',[
|
||||
{'Service': 'id'},
|
||||
{'Router': 'attributes.router'},
|
||||
{'Connections': 'attributes.connections'},
|
||||
{'Total Connections': 'attributes.total_connections'},
|
||||
{'Servers': 'relationships.servers.data[].id'}
|
||||
])
|
||||
})
|
||||
.command('monitors', 'List monitors', {}, function() {
|
||||
getCollection('monitors', [
|
||||
{'Monitor': 'id'},
|
||||
{'State': 'attributes.state'},
|
||||
{'Servers': 'relationships.servers.data[].id'}
|
||||
])
|
||||
.command('monitors', 'List monitors', {}, function(argv) {
|
||||
maxctrl(argv)
|
||||
.getCollection('monitors', [
|
||||
{'Monitor': 'id'},
|
||||
{'State': 'attributes.state'},
|
||||
{'Servers': 'relationships.servers.data[].id'}
|
||||
])
|
||||
})
|
||||
.command('sessions', 'List sessions', {}, function() {
|
||||
getCollection('sessions',[
|
||||
{'Id': 'id'},
|
||||
{'Service': 'relationships.services.data[].id'},
|
||||
{'User': 'attributes.user'},
|
||||
{'Host': 'attributes.remote'}
|
||||
])
|
||||
.command('sessions', 'List sessions', {}, function(argv) {
|
||||
maxctrl(argv)
|
||||
.getCollection('sessions',[
|
||||
{'Id': 'id'},
|
||||
{'Service': 'relationships.services.data[].id'},
|
||||
{'User': 'attributes.user'},
|
||||
{'Host': 'attributes.remote'}
|
||||
])
|
||||
})
|
||||
.command('filters', 'List filters', {}, function() {
|
||||
getCollection('filters', [
|
||||
{'Filter': 'id'},
|
||||
{'Service': 'relationships.services.data[].id'},
|
||||
{'Module': 'attributes.module'}
|
||||
])
|
||||
.command('filters', 'List filters', {}, function(argv) {
|
||||
maxctrl(argv)
|
||||
.getCollection('filters', [
|
||||
{'Filter': 'id'},
|
||||
{'Service': 'relationships.services.data[].id'},
|
||||
{'Module': 'attributes.module'}
|
||||
])
|
||||
})
|
||||
.command('modules', 'List loaded modules', {}, function() {
|
||||
getCollection('maxscale/modules',[
|
||||
{'Module':'id'},
|
||||
{'Type':'attributes.module_type'},
|
||||
{'Version': 'attributes.version'}
|
||||
])
|
||||
.command('modules', 'List loaded modules', {}, function(argv) {
|
||||
maxctrl(argv)
|
||||
.getCollection('maxscale/modules',[
|
||||
{'Module':'id'},
|
||||
{'Type':'attributes.module_type'},
|
||||
{'Version': 'attributes.version'}
|
||||
])
|
||||
})
|
||||
.command('users', 'List created network users', {}, function() {
|
||||
getCollection('users/inet',[
|
||||
{'Name':'id'}
|
||||
])
|
||||
.command('users', 'List created network users', {}, function(argv) {
|
||||
maxctrl(argv)
|
||||
.getCollection('users/inet',[
|
||||
{'Name':'id'}
|
||||
])
|
||||
})
|
||||
.command('commands', 'List module commands', {}, function() {
|
||||
getCollection('maxscale/modules',[
|
||||
{'Module':'id'},
|
||||
{'Commands': 'attributes.commands[].id'}
|
||||
])
|
||||
.command('commands', 'List module commands', {}, function(argv) {
|
||||
maxctrl(argv)
|
||||
.getCollection('maxscale/modules',[
|
||||
{'Module':'id'},
|
||||
{'Commands': 'attributes.commands[].id'}
|
||||
])
|
||||
})
|
||||
.usage('Usage: list <command>')
|
||||
.help()
|
||||
|
@ -18,7 +18,8 @@ exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('logs', 'Rotate log files by closing and reopening the files', {}, function(argv) {
|
||||
doRequest('maxscale/logs/flush/', null, {method: 'POST'})
|
||||
maxctrl(argv)
|
||||
.doRequest('maxscale/logs/flush/', null, {method: 'POST'})
|
||||
})
|
||||
.usage('Usage: rotate <command>')
|
||||
.help()
|
||||
|
@ -19,7 +19,8 @@ exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('server <server> <state>', 'Set server state', {}, function(argv) {
|
||||
var target = 'servers/' + argv.server + '/set?state=' + argv.state
|
||||
doRequest(target, null, {method: 'PUT'})
|
||||
maxctrl(argv)
|
||||
.doRequest(target, null, {method: 'PUT'})
|
||||
})
|
||||
.usage('Usage: set <command>')
|
||||
.help()
|
||||
|
@ -19,86 +19,94 @@ exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('server <server>', 'Show server', {}, function(argv) {
|
||||
getResource('servers/' + argv.server, [
|
||||
{'Server': 'id'},
|
||||
{'Address': 'attributes.parameters.address'},
|
||||
{'Port': 'attributes.parameters.port'},
|
||||
{'State': 'attributes.state'},
|
||||
{'Services': 'relationships.services.data[].id'},
|
||||
{'Monitors': 'relationships.monitors.data[].id'},
|
||||
{'Master ID': 'attributes.master_id'},
|
||||
{'Node ID': 'attributes.node_id'},
|
||||
{'Slave Server IDs': 'attributes.slaves'},
|
||||
{'Statistics': 'attributes.statistics'},
|
||||
{'Parameters': 'attributes.parameters'}
|
||||
])
|
||||
maxctrl(argv)
|
||||
.getResource('servers/' + argv.server, [
|
||||
{'Server': 'id'},
|
||||
{'Address': 'attributes.parameters.address'},
|
||||
{'Port': 'attributes.parameters.port'},
|
||||
{'State': 'attributes.state'},
|
||||
{'Services': 'relationships.services.data[].id'},
|
||||
{'Monitors': 'relationships.monitors.data[].id'},
|
||||
{'Master ID': 'attributes.master_id'},
|
||||
{'Node ID': 'attributes.node_id'},
|
||||
{'Slave Server IDs': 'attributes.slaves'},
|
||||
{'Statistics': 'attributes.statistics'},
|
||||
{'Parameters': 'attributes.parameters'}
|
||||
])
|
||||
})
|
||||
.command('service <service>', 'Show service', {}, function(argv) {
|
||||
getResource('services/' + argv.service, [
|
||||
{'Service': 'id'},
|
||||
{'Router': 'attributes.router'},
|
||||
{'State': 'attributes.state'},
|
||||
{'Started At': 'attributes.started'},
|
||||
{'Current Connections': 'attributes.connections'},
|
||||
{'Total Connections': 'attributes.total_connections'},
|
||||
{'Servers': 'relationships.servers.data[].id'},
|
||||
{'Parameters': 'attributes.parameters'},
|
||||
{'Router Diagnostics': 'attributes.router_diagnostics'}
|
||||
])
|
||||
maxctrl(argv)
|
||||
.getResource('services/' + argv.service, [
|
||||
{'Service': 'id'},
|
||||
{'Router': 'attributes.router'},
|
||||
{'State': 'attributes.state'},
|
||||
{'Started At': 'attributes.started'},
|
||||
{'Current Connections': 'attributes.connections'},
|
||||
{'Total Connections': 'attributes.total_connections'},
|
||||
{'Servers': 'relationships.servers.data[].id'},
|
||||
{'Parameters': 'attributes.parameters'},
|
||||
{'Router Diagnostics': 'attributes.router_diagnostics'}
|
||||
])
|
||||
})
|
||||
.command('monitor <monitor>', 'Show monitor', {}, function(argv) {
|
||||
getResource('monitors/' + argv.monitor, [
|
||||
{'Monitor': 'id'},
|
||||
{'State': 'attributes.state'},
|
||||
{'Servers': 'relationships.servers.data[].id'},
|
||||
{'Parameters': 'attributes.parameters'},
|
||||
{'Monitor Diagnostics': 'attributes.monitor_diagnostics'}
|
||||
])
|
||||
maxctrl(argv)
|
||||
.getResource('monitors/' + argv.monitor, [
|
||||
{'Monitor': 'id'},
|
||||
{'State': 'attributes.state'},
|
||||
{'Servers': 'relationships.servers.data[].id'},
|
||||
{'Parameters': 'attributes.parameters'},
|
||||
{'Monitor Diagnostics': 'attributes.monitor_diagnostics'}
|
||||
])
|
||||
})
|
||||
.command('session <session>', 'Show session', {}, function(argv) {
|
||||
getResource('sessions/' + argv.session, [
|
||||
{'Id': 'id'},
|
||||
{'Service': 'relationships.services.data[].id'},
|
||||
{'State': 'attributes.state'},
|
||||
{'User': 'attributes.user'},
|
||||
{'Host': 'attributes.remote'},
|
||||
{'Connected': 'attributes.connected'},
|
||||
{'Idle': 'attributes.idle'}
|
||||
])
|
||||
maxctrl(argv)
|
||||
.getResource('sessions/' + argv.session, [
|
||||
{'Id': 'id'},
|
||||
{'Service': 'relationships.services.data[].id'},
|
||||
{'State': 'attributes.state'},
|
||||
{'User': 'attributes.user'},
|
||||
{'Host': 'attributes.remote'},
|
||||
{'Connected': 'attributes.connected'},
|
||||
{'Idle': 'attributes.idle'}
|
||||
])
|
||||
})
|
||||
.command('filter <filter>', 'Show filter', {}, function(argv) {
|
||||
getResource('filters/' + argv.filter, [
|
||||
{'Filter': 'id'},
|
||||
{'Module': 'attributes.module'},
|
||||
{'Services': 'relationships.services.data[].id'},
|
||||
{'Parameters': 'attributes.parameters'}
|
||||
])
|
||||
maxctrl(argv)
|
||||
.getResource('filters/' + argv.filter, [
|
||||
{'Filter': 'id'},
|
||||
{'Module': 'attributes.module'},
|
||||
{'Services': 'relationships.services.data[].id'},
|
||||
{'Parameters': 'attributes.parameters'}
|
||||
])
|
||||
})
|
||||
.command('module <module>', 'Show loaded module', {}, function(argv) {
|
||||
getResource('maxscale/modules/' + argv.module, [
|
||||
{'Module': 'id'},
|
||||
{'Type': 'attributes.module_type'},
|
||||
{'Version': 'attributes.version'},
|
||||
{'Maturity': 'attributes.maturity'},
|
||||
{'Description': 'attributes.description'},
|
||||
{'Parameters': 'attributes.parameters'},
|
||||
{'Commands': 'attributes.commands'}
|
||||
])
|
||||
maxctrl(argv)
|
||||
.getResource('maxscale/modules/' + argv.module, [
|
||||
{'Module': 'id'},
|
||||
{'Type': 'attributes.module_type'},
|
||||
{'Version': 'attributes.version'},
|
||||
{'Maturity': 'attributes.maturity'},
|
||||
{'Description': 'attributes.description'},
|
||||
{'Parameters': 'attributes.parameters'},
|
||||
{'Commands': 'attributes.commands'}
|
||||
])
|
||||
})
|
||||
.command('maxscale', 'Show MaxScale information', {}, function(argv) {
|
||||
getResource('maxscale', [
|
||||
{'Version': 'attributes.version'},
|
||||
{'Commit': 'attributes.commit'},
|
||||
{'Started At': 'attributes.started_at'},
|
||||
{'Uptime': 'attributes.uptime'}
|
||||
])
|
||||
maxctrl(argv)
|
||||
.getResource('maxscale', [
|
||||
{'Version': 'attributes.version'},
|
||||
{'Commit': 'attributes.commit'},
|
||||
{'Started At': 'attributes.started_at'},
|
||||
{'Uptime': 'attributes.uptime'}
|
||||
])
|
||||
})
|
||||
.command('commands <module>', 'Show module commands of a module', {}, function(argv) {
|
||||
getSubCollection('maxscale/modules/' + argv.module, 'attributes.commands', [
|
||||
{'Command': 'id'},
|
||||
{'Parameters': 'attributes.parameters[].type'},
|
||||
{'Descriptions': 'attributes.parameters[].description'}
|
||||
])
|
||||
maxctrl(argv)
|
||||
.getSubCollection('maxscale/modules/' + argv.module, 'attributes.commands', [
|
||||
{'Command': 'id'},
|
||||
{'Parameters': 'attributes.parameters[].type'},
|
||||
{'Descriptions': 'attributes.parameters[].description'}
|
||||
])
|
||||
})
|
||||
.usage('Usage: show <command>')
|
||||
.help()
|
||||
|
@ -18,10 +18,12 @@ exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('service <name>', 'Start a service', {}, function(argv) {
|
||||
doRequest('services/' + argv.name + '/start', null, {method: 'PUT'})
|
||||
maxctrl(argv)
|
||||
.doRequest('services/' + argv.name + '/start', null, {method: 'PUT'})
|
||||
})
|
||||
.command('monitor <name>', 'Start a monitor', {}, function(argv) {
|
||||
doRequest('monitors/' + argv.name + '/start', null, {method: 'PUT'})
|
||||
maxctrl(argv)
|
||||
.doRequest('monitors/' + argv.name + '/start', null, {method: 'PUT'})
|
||||
})
|
||||
.usage('Usage: start <command>')
|
||||
.help()
|
||||
|
@ -18,10 +18,12 @@ exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('service <name>', 'Stop a service', {}, function(argv) {
|
||||
doRequest('services/' + argv.name + '/stop', null, {method: 'PUT'})
|
||||
maxctrl(argv)
|
||||
.doRequest('services/' + argv.name + '/stop', null, {method: 'PUT'})
|
||||
})
|
||||
.command('monitor <name>', 'Stop a monitor', {}, function(argv) {
|
||||
doRequest('monitors/' + argv.name + '/stop', null, {method: 'PUT'})
|
||||
maxctrl(argv)
|
||||
.doRequest('monitors/' + argv.name + '/stop', null, {method: 'PUT'})
|
||||
})
|
||||
.usage('Usage: stop <command>')
|
||||
.help()
|
||||
|
@ -12,20 +12,22 @@
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
function removeServer(path, targets) {
|
||||
doRequest(path, function(res) {
|
||||
var servers =_.get(res, 'data.relationships.servers.data', [])
|
||||
function removeServer(argv, path, targets) {
|
||||
maxctrl(argv)
|
||||
.doRequest(path, function(res) {
|
||||
var servers =_.get(res, 'data.relationships.servers.data', [])
|
||||
|
||||
_.remove(servers, function(i) {
|
||||
return targets.indexOf(i.id) != -1
|
||||
_.remove(servers, function(i) {
|
||||
return targets.indexOf(i.id) != -1
|
||||
})
|
||||
|
||||
// Update relationships and remove unnecessary parts
|
||||
_.set(res, 'data.relationships.servers.data', servers)
|
||||
delete res.data.attributes
|
||||
|
||||
maxctrl(argv)
|
||||
.doRequest(path, null, {method: 'PATCH', body: res})
|
||||
})
|
||||
|
||||
// Update relationships and remove unnecessary parts
|
||||
_.set(res, 'data.relationships.servers.data', servers)
|
||||
delete res.data.attributes
|
||||
|
||||
doRequest(path, null, {method: 'PATCH', body: res})
|
||||
})
|
||||
}
|
||||
|
||||
exports.command = 'unlink <command>'
|
||||
@ -34,10 +36,10 @@ exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('service <name> <server...>', 'Unlink servers from a service', {}, function(argv) {
|
||||
removeServer('services/' + argv.name, argv.server)
|
||||
removeServer(argv, 'services/' + argv.name, argv.server)
|
||||
})
|
||||
.command('monitor <name> <server...>', 'Unlink servers from a monitor', {}, function(argv) {
|
||||
removeServer('monitors/' + argv.name, argv.server)
|
||||
removeServer(argv, 'monitors/' + argv.name, argv.server)
|
||||
})
|
||||
.usage('Usage: unlink <command>')
|
||||
.help()
|
||||
|
Reference in New Issue
Block a user