MXS-1300: Take the refactored core into use

The refactored maxctrl function is now in use.
This commit is contained in:
Markus Mäkelä
2017-07-15 06:59:49 +03:00
parent b98b326bba
commit 3255d58e70
18 changed files with 178 additions and 122 deletions

View File

@ -52,7 +52,7 @@ module.exports = function() {
// Request a resource collection and format it as a table // Request a resource collection and format it as a table
this.getCollection = function (host, resource, fields) { this.getCollection = function (host, resource, fields) {
doRequest(host, resource, function(res) { return doRequest(host, resource, function(res) {
var header = [] var header = []
@ -84,8 +84,7 @@ module.exports = function() {
// Request a part of a resource as a collection // Request a part of a resource as a collection
this.getSubCollection = function (host, resource, subres, fields) { this.getSubCollection = function (host, resource, subres, fields) {
doRequest(host, resource, function(res) { return doRequest(host, resource, function(res) {
var header = [] var header = []
fields.forEach(function(i) { fields.forEach(function(i) {
@ -118,7 +117,7 @@ module.exports = function() {
// Request a single resource and format it as a key-value list // Request a single resource and format it as a key-value list
this.getResource = function (host, resource, fields) { this.getResource = function (host, resource, fields) {
doRequest(resource, function(res) { return doRequest(host, resource, function(res) {
var table = getList() var table = getList()
fields.forEach(function(i) { fields.forEach(function(i) {
@ -141,6 +140,12 @@ module.exports = function() {
}) })
} }
this.updateValue = function(host, resource, key, value) {
var body = {}
_.set(body, key, value)
return doRequest(host, resource, null, { method: 'PATCH', body: body })
}
// Helper for converting endpoints to acutal URLs // Helper for converting endpoints to acutal URLs
this.getUri = function(host, secure, endpoint) { this.getUri = function(host, secure, endpoint) {
var base = 'http://' var base = 'http://'
@ -172,10 +177,12 @@ module.exports = function() {
return Promise.resolve() return Promise.resolve()
} }
}, function(err) { }, function(err) {
if (err.response.body) { if (err.response && err.response.body) {
logError(JSON.stringify(err.response.body, null, 4)) logError(JSON.stringify(err.response.body, null, 4))
} else { } else if (err.statusCode) {
logError('Server responded with ' + err.statusCode) logError('Server responded with ' + err.statusCode)
} else {
logError('Undefined error: ' + JSON.stringify(err, null, 4))
} }
return Promise.reject() return Promise.reject()
}) })
@ -186,12 +193,6 @@ module.exports = function() {
.then(this.argv.resolve, this.argv.reject) .then(this.argv.resolve, this.argv.reject)
} }
this.updateValue = function(host, resource, key, value) {
var body = {}
_.set(body, key, value)
doRequest(host, resource, null, { method: 'PATCH', body: body })
}
this.logError = function(err) { this.logError = function(err) {
this.logger.error(colors.red('Error:'), err) this.logger.error(colors.red('Error:'), err)
} }

View File

@ -37,7 +37,7 @@ program
.option('h', { .option('h', {
alias: 'hosts', alias: 'hosts',
describe: 'List of MaxScale hosts. The hosts must be in ' + describe: 'List of MaxScale hosts. The hosts must be in ' +
'<hostname>:<port> format and each host must be separated by spaces.', 'HOST:PORT format and each value must be separated by spaces.',
default: 'localhost:8989', default: 'localhost:8989',
type: 'array' type: 'array'
}) })

View File

@ -18,24 +18,29 @@ exports.handler = function() {}
exports.builder = function(yargs) { exports.builder = function(yargs) {
yargs yargs
.command('server <server> <key> <value>', 'Alter server parameters', {}, function(argv) { .command('server <server> <key> <value>', 'Alter server parameters', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.updateValue('servers/' + argv.server, 'data.attributes.parameters.' + argv.key, argv.value) return updateValue(host, 'servers/' + argv.server, 'data.attributes.parameters.' + argv.key, argv.value)
})
}) })
.command('monitor <monitor> <key> <value>', 'Alter monitor parameters', {}, function(argv) { .command('monitor <monitor> <key> <value>', 'Alter monitor parameters', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.updateValue('monitors/' + argv.monitor, 'data.attributes.parameters.' + argv.key, argv.value) return updateValue(host, 'monitors/' + argv.monitor, 'data.attributes.parameters.' + argv.key, argv.value)
})
}) })
.command('service <service> <key> <value>', 'Alter service parameters', {}, function(argv) { .command('service <service> <key> <value>', 'Alter service parameters', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.updateValue('services/' + argv.service, 'data.attributes.parameters.' + argv.key, argv.value) return updateValue(host, 'services/' + argv.service, 'data.attributes.parameters.' + argv.key, argv.value)
})
}) })
.command('logging <key> <value>', 'Alter logging parameters', {}, function(argv) { .command('logging <key> <value>', 'Alter logging parameters', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.updateValue('maxscale/logs', 'attributes.parameters.' + argv.key, argv.value) return updateValue(host, 'maxscale/logs', 'attributes.parameters.' + argv.key, argv.value)
})
}) })
.command('maxscale <key> <value>', 'Alter MaxScale parameters', {}, function(argv) { .command('maxscale <key> <value>', 'Alter MaxScale parameters', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.updateValue('maxscale', 'attributes.parameters.' + argv.key, argv.value) return updateValue(host, 'maxscale', 'attributes.parameters.' + argv.key, argv.value)
})
}) })
.usage('Usage: alter <command>') .usage('Usage: alter <command>')
.help() .help()

View File

@ -18,10 +18,9 @@ exports.handler = function() {}
exports.builder = function(yargs) { exports.builder = function(yargs) {
yargs yargs
.command('command <module> <command> [parameters...]', 'Call a module command', {}, function(argv) { .command('command <module> <command> [parameters...]', 'Call a module command', {}, function(argv) {
// First we have to find the correct method to use // First we have to find the correct method to use
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('maxscale/modules/' + argv.module + '/', function(resp) { return doRequest(host, 'maxscale/modules/' + argv.module + '/', function(resp) {
// A GET request will return the correct error if the command is not found // A GET request will return the correct error if the command is not found
var verb = 'GET' var verb = 'GET'
@ -32,12 +31,12 @@ exports.builder = function(yargs) {
} }
}) })
return maxctrl return doAsyncRequest(host, 'maxscale/modules/' + argv.module + '/' + argv.command + '?' + argv.parameters.join('&'),
.doAsyncRequest('maxscale/modules/' + argv.module + '/' + argv.command + '?' + argv.parameters.join('&'), function(resp) {
function(resp) { logger.log(JSON.stringify(resp, null, 4))
logger.log(JSON.stringify(resp, null, 4)) }, { method: verb })
}, { method: verb })
}) })
})
}) })
.usage('Usage: call <command>') .usage('Usage: call <command>')
.help() .help()

View File

@ -19,8 +19,9 @@ exports.builder = function(yargs) {
yargs yargs
.command('server <server> <state>', 'Clear server state', {}, function(argv) { .command('server <server> <state>', 'Clear server state', {}, function(argv) {
var target = 'servers/' + argv.server + '/clear?state=' + argv.state var target = 'servers/' + argv.server + '/clear?state=' + argv.state
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest(target, null, {method: 'PUT'}) return doRequest(host, target, null, {method: 'PUT'})
})
}) })
.usage('Usage: clear <command>') .usage('Usage: clear <command>')
.help() .help()

View File

@ -71,8 +71,9 @@ exports.builder = function(yargs) {
} }
} }
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('servers', null, {method: 'POST', body: server}) return doRequest(host, 'servers', null, {method: 'POST', body: server})
})
}) })
// Create monitor // Create monitor
@ -98,8 +99,9 @@ exports.builder = function(yargs) {
} }
} }
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('monitors', null, {method: 'POST', body: monitor}) return doRequest(host, 'monitors', null, {method: 'POST', body: monitor})
})
}) })
// Create listener // Create listener
@ -159,8 +161,9 @@ exports.builder = function(yargs) {
} }
} }
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('services/' + argv.service + '/listeners', null, {method: 'POST', body: listener}) return doRequest(host, 'services/' + argv.service + '/listeners', null, {method: 'POST', body: listener})
})
}) })
.command('user <name> <password>', 'Create a new network user', {}, function(argv) { .command('user <name> <password>', 'Create a new network user', {}, function(argv) {
@ -174,8 +177,9 @@ exports.builder = function(yargs) {
} }
} }
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('users/inet', null, {method: 'POST', body: user}) return doRequest(host, 'users/inet', null, {method: 'POST', body: user})
})
}) })
.usage('Usage: create <command>') .usage('Usage: create <command>')

View File

@ -18,20 +18,24 @@ exports.handler = function() {}
exports.builder = function(yargs) { exports.builder = function(yargs) {
yargs yargs
.command('server <name>', 'Destroy an unused server', {}, function(argv) { .command('server <name>', 'Destroy an unused server', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('servers/' + argv.name, null, {method: 'DELETE'}) return doRequest(host, 'servers/' + argv.name, null, {method: 'DELETE'})
})
}) })
.command('monitor <name>', 'Destroy an unused monitor', {}, function(argv) { .command('monitor <name>', 'Destroy an unused monitor', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('monitors/' + argv.name, null, {method: 'DELETE'}) return doRequest(host, 'monitors/' + argv.name, null, {method: 'DELETE'})
})
}) })
.command('listener <service> <name>', 'Destroy an unused listener', {}, function(argv) { .command('listener <service> <name>', 'Destroy an unused listener', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('services/' + argv.service + '/listeners/' + argv.name, null, {method: 'DELETE'}) return doRequest(host, 'services/' + argv.service + '/listeners/' + argv.name, null, {method: 'DELETE'})
})
}) })
.command('user <name>', 'Remove a network user', {}, function(argv) { .command('user <name>', 'Remove a network user', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('users/inet/' + argv.name, null, {method: 'DELETE'}) return doRequest(host, 'users/inet/' + argv.name, null, {method: 'DELETE'})
})
}) })
.usage('Usage: destroy <command>') .usage('Usage: destroy <command>')
.help() .help()

View File

@ -26,24 +26,30 @@ exports.builder = function(yargs) {
yargs yargs
.command('log-priority <log>', 'Disable log priority [warning|notice|info|debug]', {}, function(argv) { .command('log-priority <log>', 'Disable log priority [warning|notice|info|debug]', {}, function(argv) {
if (log_levels.indexOf(argv.log) != -1) { if (log_levels.indexOf(argv.log) != -1) {
maxctrl(argv) maxctrl(argv, function(host) {
.updateValue('maxscale/logs', 'data.attributes.parameters.log_' + argv.log, false) return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.log_' + argv.log, false)
})
} else { } else {
maxctrl(argv) maxctrl(argv, function() {
.error('Invalid log priority: ' + argv.log); error('Invalid log priority: ' + argv.log)
return Promise.reject()
})
} }
}) })
.command('maxlog', 'Disable MaxScale logging', {}, function(argv) { .command('maxlog', 'Disable MaxScale logging', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.updateValue('maxscale/logs', 'data.attributes.parameters.maxlog', false) return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.maxlog', false)
})
}) })
.command('syslog', 'Disable syslog logging', {}, function(argv) { .command('syslog', 'Disable syslog logging', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.updateValue('maxscale/logs', 'data.attributes.parameters.syslog', false) return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.syslog', false)
})
}) })
.command('account <name>', 'Disable a Linux user account from administrative use', {}, function(argv) { .command('account <name>', 'Disable a Linux user account from administrative use', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('users/unix/' + argv.name, null, { method: 'DELETE'}) return doRequest(host, 'users/unix/' + argv.name, null, { method: 'DELETE'})
})
}) })
.usage('Usage: disable <command>') .usage('Usage: disable <command>')
.help() .help()

View File

@ -26,20 +26,25 @@ exports.builder = function(yargs) {
yargs yargs
.command('log-priority <log>', 'Enable log priority [warning|notice|info|debug]', {}, function(argv) { .command('log-priority <log>', 'Enable log priority [warning|notice|info|debug]', {}, function(argv) {
if (log_levels.indexOf(argv.log) != -1) { if (log_levels.indexOf(argv.log) != -1) {
maxctrl(argv) maxctrl(argv, function(host) {
.updateValue('maxscale/logs', 'data.attributes.parameters.log_' + argv.log, true) return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.log_' + argv.log, true)
})
} else { } else {
maxctrl(argv) maxctrl(argv, function() {
.error('Invalid log priority: ' + argv.log); error('Invalid log priority: ' + argv.log)
return Promise.reject()
})
} }
}) })
.command('maxlog', 'Enable MaxScale logging', {}, function(argv) { .command('maxlog', 'Enable MaxScale logging', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.updateValue('maxscale/logs', 'data.attributes.parameters.maxlog', true) return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.maxlog', true)
})
}) })
.command('syslog', 'Enable syslog logging', {}, function(argv) { .command('syslog', 'Enable syslog logging', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.updateValue('maxscale/logs', 'data.attributes.parameters.syslog', true) return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.syslog', true)
})
}) })
.command('account <name>', 'Activate a Linux user account for administrative use', {}, function(argv) { .command('account <name>', 'Activate a Linux user account for administrative use', {}, function(argv) {
var req_body = { var req_body = {
@ -48,8 +53,9 @@ exports.builder = function(yargs) {
type: 'unix' type: 'unix'
} }
} }
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('users/unix', null, { method: 'POST', body: req_body}) return doRequest(host, 'users/unix', null, { method: 'POST', body: req_body})
})
}) })
.usage('Usage: enable <command>') .usage('Usage: enable <command>')
.help() .help()

View File

@ -13,8 +13,8 @@
require('../common.js')() require('../common.js')()
function addServer(argv, path, targets) { function addServer(argv, path, targets) {
maxctrl(argv) maxctrl(argv, function(host){
.doRequest(path, function(res) { return doRequest(host, path, function(res) {
var servers =_.get(res, 'data.relationships.servers.data', []) var servers =_.get(res, 'data.relationships.servers.data', [])
targets.forEach(function(i){ targets.forEach(function(i){
@ -25,9 +25,9 @@ function addServer(argv, path, targets) {
_.set(res, 'data.relationships.servers.data', servers) _.set(res, 'data.relationships.servers.data', servers)
delete res.data.attributes delete res.data.attributes
return maxctrl(argv) return doAsyncRequest(host, path, null, {method: 'PATCH', body: res})
.doAsyncRequest(path, null, {method: 'PATCH', body: res})
}) })
})
} }
exports.command = 'link <command>' exports.command = 'link <command>'

View File

@ -19,70 +19,78 @@ exports.handler = function() {}
exports.builder = function(yargs) { exports.builder = function(yargs) {
yargs yargs
.command('servers', 'List servers', {}, function(argv) { .command('servers', 'List servers', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getCollection('servers', [ return getCollection(host, 'servers', [
{'Server': 'id'}, {'Server': 'id'},
{'Address': 'attributes.parameters.address'}, {'Address': 'attributes.parameters.address'},
{'Port': 'attributes.parameters.port'}, {'Port': 'attributes.parameters.port'},
{'Connections': 'attributes.statistics.connections'}, {'Connections': 'attributes.statistics.connections'},
{'State': 'attributes.state'} {'State': 'attributes.state'}
]) ])
})
}) })
.command('services', 'List services', {}, function(argv) { .command('services', 'List services', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getCollection('services',[ return getCollection(host, 'services',[
{'Service': 'id'}, {'Service': 'id'},
{'Router': 'attributes.router'}, {'Router': 'attributes.router'},
{'Connections': 'attributes.connections'}, {'Connections': 'attributes.connections'},
{'Total Connections': 'attributes.total_connections'}, {'Total Connections': 'attributes.total_connections'},
{'Servers': 'relationships.servers.data[].id'} {'Servers': 'relationships.servers.data[].id'}
]) ])
})
}) })
.command('monitors', 'List monitors', {}, function(argv) { .command('monitors', 'List monitors', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getCollection('monitors', [ return getCollection(host, 'monitors', [
{'Monitor': 'id'}, {'Monitor': 'id'},
{'State': 'attributes.state'}, {'State': 'attributes.state'},
{'Servers': 'relationships.servers.data[].id'} {'Servers': 'relationships.servers.data[].id'}
]) ])
})
}) })
.command('sessions', 'List sessions', {}, function(argv) { .command('sessions', 'List sessions', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getCollection('sessions',[ return getCollection(host, 'sessions',[
{'Id': 'id'}, {'Id': 'id'},
{'Service': 'relationships.services.data[].id'}, {'Service': 'relationships.services.data[].id'},
{'User': 'attributes.user'}, {'User': 'attributes.user'},
{'Host': 'attributes.remote'} {'Host': 'attributes.remote'}
]) ])
})
}) })
.command('filters', 'List filters', {}, function(argv) { .command('filters', 'List filters', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getCollection('filters', [ return getCollection(host, 'filters', [
{'Filter': 'id'}, {'Filter': 'id'},
{'Service': 'relationships.services.data[].id'}, {'Service': 'relationships.services.data[].id'},
{'Module': 'attributes.module'} {'Module': 'attributes.module'}
]) ])
})
}) })
.command('modules', 'List loaded modules', {}, function(argv) { .command('modules', 'List loaded modules', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getCollection('maxscale/modules',[ return getCollection(host, 'maxscale/modules',[
{'Module':'id'}, {'Module':'id'},
{'Type':'attributes.module_type'}, {'Type':'attributes.module_type'},
{'Version': 'attributes.version'} {'Version': 'attributes.version'}
]) ])
})
}) })
.command('users', 'List created network users', {}, function(argv) { .command('users', 'List created network users', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getCollection('users/inet',[ return getCollection(host, 'users/inet',[
{'Name':'id'} {'Name':'id'}
]) ])
})
}) })
.command('commands', 'List module commands', {}, function(argv) { .command('commands', 'List module commands', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getCollection('maxscale/modules',[ return getCollection(host, 'maxscale/modules',[
{'Module':'id'}, {'Module':'id'},
{'Commands': 'attributes.commands[].id'} {'Commands': 'attributes.commands[].id'}
]) ])
})
}) })
.usage('Usage: list <command>') .usage('Usage: list <command>')
.help() .help()

View File

@ -18,8 +18,9 @@ exports.handler = function() {}
exports.builder = function(yargs) { exports.builder = function(yargs) {
yargs yargs
.command('logs', 'Rotate log files by closing and reopening the files', {}, function(argv) { .command('logs', 'Rotate log files by closing and reopening the files', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host){
.doRequest('maxscale/logs/flush/', null, {method: 'POST'}) return doRequest(host, 'maxscale/logs/flush/', null, {method: 'POST'})
})
}) })
.usage('Usage: rotate <command>') .usage('Usage: rotate <command>')
.help() .help()

View File

@ -19,8 +19,9 @@ exports.builder = function(yargs) {
yargs yargs
.command('server <server> <state>', 'Set server state', {}, function(argv) { .command('server <server> <state>', 'Set server state', {}, function(argv) {
var target = 'servers/' + argv.server + '/set?state=' + argv.state var target = 'servers/' + argv.server + '/set?state=' + argv.state
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest(target, null, {method: 'PUT'}) return doRequest(host, target, null, {method: 'PUT'})
})
}) })
.usage('Usage: set <command>') .usage('Usage: set <command>')
.help() .help()

View File

@ -19,8 +19,8 @@ exports.handler = function() {}
exports.builder = function(yargs) { exports.builder = function(yargs) {
yargs yargs
.command('server <server>', 'Show server', {}, function(argv) { .command('server <server>', 'Show server', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getResource('servers/' + argv.server, [ return getResource(host, 'servers/' + argv.server, [
{'Server': 'id'}, {'Server': 'id'},
{'Address': 'attributes.parameters.address'}, {'Address': 'attributes.parameters.address'},
{'Port': 'attributes.parameters.port'}, {'Port': 'attributes.parameters.port'},
@ -33,10 +33,11 @@ exports.builder = function(yargs) {
{'Statistics': 'attributes.statistics'}, {'Statistics': 'attributes.statistics'},
{'Parameters': 'attributes.parameters'} {'Parameters': 'attributes.parameters'}
]) ])
})
}) })
.command('service <service>', 'Show service', {}, function(argv) { .command('service <service>', 'Show service', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getResource('services/' + argv.service, [ return getResource(host, 'services/' + argv.service, [
{'Service': 'id'}, {'Service': 'id'},
{'Router': 'attributes.router'}, {'Router': 'attributes.router'},
{'State': 'attributes.state'}, {'State': 'attributes.state'},
@ -47,20 +48,22 @@ exports.builder = function(yargs) {
{'Parameters': 'attributes.parameters'}, {'Parameters': 'attributes.parameters'},
{'Router Diagnostics': 'attributes.router_diagnostics'} {'Router Diagnostics': 'attributes.router_diagnostics'}
]) ])
})
}) })
.command('monitor <monitor>', 'Show monitor', {}, function(argv) { .command('monitor <monitor>', 'Show monitor', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getResource('monitors/' + argv.monitor, [ return getResource(host, 'monitors/' + argv.monitor, [
{'Monitor': 'id'}, {'Monitor': 'id'},
{'State': 'attributes.state'}, {'State': 'attributes.state'},
{'Servers': 'relationships.servers.data[].id'}, {'Servers': 'relationships.servers.data[].id'},
{'Parameters': 'attributes.parameters'}, {'Parameters': 'attributes.parameters'},
{'Monitor Diagnostics': 'attributes.monitor_diagnostics'} {'Monitor Diagnostics': 'attributes.monitor_diagnostics'}
]) ])
})
}) })
.command('session <session>', 'Show session', {}, function(argv) { .command('session <session>', 'Show session', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getResource('sessions/' + argv.session, [ return getResource(host, 'sessions/' + argv.session, [
{'Id': 'id'}, {'Id': 'id'},
{'Service': 'relationships.services.data[].id'}, {'Service': 'relationships.services.data[].id'},
{'State': 'attributes.state'}, {'State': 'attributes.state'},
@ -69,19 +72,21 @@ exports.builder = function(yargs) {
{'Connected': 'attributes.connected'}, {'Connected': 'attributes.connected'},
{'Idle': 'attributes.idle'} {'Idle': 'attributes.idle'}
]) ])
})
}) })
.command('filter <filter>', 'Show filter', {}, function(argv) { .command('filter <filter>', 'Show filter', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getResource('filters/' + argv.filter, [ return getResource(host, 'filters/' + argv.filter, [
{'Filter': 'id'}, {'Filter': 'id'},
{'Module': 'attributes.module'}, {'Module': 'attributes.module'},
{'Services': 'relationships.services.data[].id'}, {'Services': 'relationships.services.data[].id'},
{'Parameters': 'attributes.parameters'} {'Parameters': 'attributes.parameters'}
]) ])
})
}) })
.command('module <module>', 'Show loaded module', {}, function(argv) { .command('module <module>', 'Show loaded module', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getResource('maxscale/modules/' + argv.module, [ return getResource(host, 'maxscale/modules/' + argv.module, [
{'Module': 'id'}, {'Module': 'id'},
{'Type': 'attributes.module_type'}, {'Type': 'attributes.module_type'},
{'Version': 'attributes.version'}, {'Version': 'attributes.version'},
@ -90,23 +95,26 @@ exports.builder = function(yargs) {
{'Parameters': 'attributes.parameters'}, {'Parameters': 'attributes.parameters'},
{'Commands': 'attributes.commands'} {'Commands': 'attributes.commands'}
]) ])
})
}) })
.command('maxscale', 'Show MaxScale information', {}, function(argv) { .command('maxscale', 'Show MaxScale information', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getResource('maxscale', [ return getResource(host, 'maxscale', [
{'Version': 'attributes.version'}, {'Version': 'attributes.version'},
{'Commit': 'attributes.commit'}, {'Commit': 'attributes.commit'},
{'Started At': 'attributes.started_at'}, {'Started At': 'attributes.started_at'},
{'Uptime': 'attributes.uptime'} {'Uptime': 'attributes.uptime'}
]) ])
})
}) })
.command('commands <module>', 'Show module commands of a module', {}, function(argv) { .command('commands <module>', 'Show module commands of a module', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.getSubCollection('maxscale/modules/' + argv.module, 'attributes.commands', [ return getSubCollection(host, 'maxscale/modules/' + argv.module, 'attributes.commands', [
{'Command': 'id'}, {'Command': 'id'},
{'Parameters': 'attributes.parameters[].type'}, {'Parameters': 'attributes.parameters[].type'},
{'Descriptions': 'attributes.parameters[].description'} {'Descriptions': 'attributes.parameters[].description'}
]) ])
})
}) })
.usage('Usage: show <command>') .usage('Usage: show <command>')
.help() .help()

View File

@ -18,12 +18,14 @@ exports.handler = function() {}
exports.builder = function(yargs) { exports.builder = function(yargs) {
yargs yargs
.command('service <name>', 'Start a service', {}, function(argv) { .command('service <name>', 'Start a service', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('services/' + argv.name + '/start', null, {method: 'PUT'}) return doRequest(host, 'services/' + argv.name + '/start', null, {method: 'PUT'})
})
}) })
.command('monitor <name>', 'Start a monitor', {}, function(argv) { .command('monitor <name>', 'Start a monitor', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('monitors/' + argv.name + '/start', null, {method: 'PUT'}) return doRequest(host, 'monitors/' + argv.name + '/start', null, {method: 'PUT'})
})
}) })
.usage('Usage: start <command>') .usage('Usage: start <command>')
.help() .help()

View File

@ -18,12 +18,14 @@ exports.handler = function() {}
exports.builder = function(yargs) { exports.builder = function(yargs) {
yargs yargs
.command('service <name>', 'Stop a service', {}, function(argv) { .command('service <name>', 'Stop a service', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('services/' + argv.name + '/stop', null, {method: 'PUT'}) return doRequest(host, 'services/' + argv.name + '/stop', null, {method: 'PUT'})
})
}) })
.command('monitor <name>', 'Stop a monitor', {}, function(argv) { .command('monitor <name>', 'Stop a monitor', {}, function(argv) {
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest('monitors/' + argv.name + '/stop', null, {method: 'PUT'}) return doRequest(host, 'monitors/' + argv.name + '/stop', null, {method: 'PUT'})
})
}) })
.usage('Usage: stop <command>') .usage('Usage: stop <command>')
.help() .help()

View File

@ -13,8 +13,8 @@
require('../common.js')() require('../common.js')()
function removeServer(argv, path, targets) { function removeServer(argv, path, targets) {
maxctrl(argv) maxctrl(argv, function(host) {
.doRequest(path, function(res) { return doRequest(host, path, function(res) {
var servers =_.get(res, 'data.relationships.servers.data', []) var servers =_.get(res, 'data.relationships.servers.data', [])
_.remove(servers, function(i) { _.remove(servers, function(i) {
@ -25,9 +25,9 @@ function removeServer(argv, path, targets) {
_.set(res, 'data.relationships.servers.data', servers) _.set(res, 'data.relationships.servers.data', servers)
delete res.data.attributes delete res.data.attributes
return maxctrl(argv) return doAsyncRequest(host, path, null, {method: 'PATCH', body: res})
.doAsyncRequest(path, null, {method: 'PATCH', body: res})
}) })
})
} }
exports.command = 'unlink <command>' exports.command = 'unlink <command>'

View File

@ -23,4 +23,12 @@ if (process.argv[0] == process.execPath) {
} }
maxctrl.execute(process.argv) maxctrl.execute(process.argv)
.then(function(out) {}, function(out) {}) .then(function(out) {
if (out) {
console.log(out)
}
}, function(out) {
if (out) {
console.log(out)
}
})