MXS-1300: Make the MaxCtrl core a Node.js module
The core is now a module that is loaded by the command line client. This allows the core library to be reused for testing.
This commit is contained in:
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
exports.command = 'alter <command>'
|
||||
exports.desc = 'Alter objects'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('server <server> <key> <value>', 'Alter server parameters', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return updateValue(host, 'servers/' + argv.server, 'data.attributes.parameters.' + argv.key, argv.value)
|
||||
})
|
||||
})
|
||||
.command('monitor <monitor> <key> <value>', 'Alter monitor parameters', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return updateValue(host, 'monitors/' + argv.monitor, 'data.attributes.parameters.' + argv.key, argv.value)
|
||||
})
|
||||
})
|
||||
.command('service <service> <key> <value>', 'Alter service parameters', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return updateValue(host, 'services/' + argv.service, 'data.attributes.parameters.' + argv.key, argv.value)
|
||||
})
|
||||
})
|
||||
.command('logging <key> <value>', 'Alter logging parameters', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return updateValue(host, 'maxscale/logs', 'attributes.parameters.' + argv.key, argv.value)
|
||||
})
|
||||
})
|
||||
.command('maxscale <key> <value>', 'Alter MaxScale parameters', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return updateValue(host, 'maxscale', 'attributes.parameters.' + argv.key, argv.value)
|
||||
})
|
||||
})
|
||||
.usage('Usage: alter <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help alter` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
exports.command = 'call <command>'
|
||||
exports.desc = 'Call module commands'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('command <module> <command> [parameters...]', 'Call a module command', {}, function(argv) {
|
||||
// First we have to find the correct method to use
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'maxscale/modules/' + argv.module + '/', function(resp) {
|
||||
|
||||
// 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;
|
||||
}
|
||||
})
|
||||
|
||||
return doAsyncRequest(host, 'maxscale/modules/' + argv.module + '/' + argv.command + '?' + argv.parameters.join('&'),
|
||||
function(resp) {
|
||||
logger.log(JSON.stringify(resp, null, 4))
|
||||
}, { method: verb })
|
||||
})
|
||||
})
|
||||
})
|
||||
.usage('Usage: call <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help call` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
exports.command = 'clear <command>'
|
||||
exports.desc = 'Clear object state'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('server <server> <state>', 'Clear server state', {}, function(argv) {
|
||||
var target = 'servers/' + argv.server + '/clear?state=' + argv.state
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, target, null, {method: 'PUT'})
|
||||
})
|
||||
})
|
||||
.usage('Usage: clear <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help clear` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,190 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
exports.command = 'create <command>'
|
||||
exports.desc = 'Create objects'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
// Common options
|
||||
.group(['protocol', 'authenticator', 'authenticator-options'], 'Common create options:')
|
||||
.option('protocol', {
|
||||
describe: 'Protocol module name',
|
||||
type: 'string'
|
||||
})
|
||||
.option('authenticator', {
|
||||
describe: 'Authenticator module name',
|
||||
type: 'string'
|
||||
})
|
||||
.option('authenticator-options', {
|
||||
describe: 'Option string for the authenticator',
|
||||
type: 'string'
|
||||
})
|
||||
|
||||
// Create server
|
||||
.group(['services', 'monitors'], 'Create server options:')
|
||||
.option('services', {
|
||||
describe: 'Link the created server to these services',
|
||||
type: 'array'
|
||||
})
|
||||
.option('monitors', {
|
||||
describe: 'Link the created server to these monitors',
|
||||
type: 'array'
|
||||
})
|
||||
.command('server <name> <host> <port>', 'Create a new server', {}, function(argv) {
|
||||
var server = {
|
||||
'data': {
|
||||
'id': argv.name,
|
||||
'type': 'servers',
|
||||
'attributes': {
|
||||
'parameters': {
|
||||
'address': argv.host,
|
||||
'port': argv.port,
|
||||
'protocol': argv.protocol,
|
||||
'authenticator': argv.authenticator,
|
||||
'authenticator_options': argv.auth_options
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv.services) {
|
||||
for (i = 0; i < argv.services.length; i++) {
|
||||
_.set(server, 'data.relationships.services.data[' + i + ']', {id: argv.services[i], type: 'services'})
|
||||
}
|
||||
}
|
||||
|
||||
if (argv.monitors) {
|
||||
for (i = 0; i < argv.monitors.length; i++) {
|
||||
_.set(server, 'data.relationships.monitors.data[' + i + ']', {id: argv.monitors[i], type: 'monitors'})
|
||||
}
|
||||
}
|
||||
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'servers', null, {method: 'POST', body: server})
|
||||
})
|
||||
})
|
||||
|
||||
// Create monitor
|
||||
.group(['servers'], 'Create monitor options:')
|
||||
.option('servers', {
|
||||
describe: 'Link the created monitor to these servers',
|
||||
type: 'array'
|
||||
})
|
||||
.command('monitor <name> <module>', 'Create a new server', {}, function(argv) {
|
||||
|
||||
var monitor = {
|
||||
'data': {
|
||||
'id': argv.name,
|
||||
'attributes': {
|
||||
'module': argv.module
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv.servers) {
|
||||
for (i = 0; i < argv.servers.length; i++) {
|
||||
_.set(server, 'data.relationships.servers.data[' + i + ']', {id: argv.monitors[i], type: 'servers'})
|
||||
}
|
||||
}
|
||||
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'monitors', null, {method: 'POST', body: monitor})
|
||||
})
|
||||
})
|
||||
|
||||
// Create listener
|
||||
.group(['interface', 'tls-key', 'tls-cert', 'tls-ca-cert', 'tls-version', 'tls-cert-verify-depth'], 'Create listener options:')
|
||||
.option('interface', {
|
||||
describe: 'Interface to listen on',
|
||||
type: 'string',
|
||||
default: '::'
|
||||
})
|
||||
// Should these have ssl as a prefix even though SSL isn't supported?
|
||||
.option('tls-key', {
|
||||
describe: 'Path to TLS key',
|
||||
type: 'string'
|
||||
})
|
||||
.option('tls-cert', {
|
||||
describe: 'Path to TLS certificate',
|
||||
type: 'string'
|
||||
})
|
||||
.option('tls-ca-cert', {
|
||||
describe: 'Path to TLS CA certificate',
|
||||
type: 'string'
|
||||
})
|
||||
.option('tls-version', {
|
||||
describe: 'TLS version to use',
|
||||
type: 'string'
|
||||
})
|
||||
.option('tls-cert-verify-depth', {
|
||||
describe: 'TLS certificate verification depth',
|
||||
type: 'string'
|
||||
})
|
||||
.command('listener <service> <name> <port>', 'Create a new server', {}, function(argv) {
|
||||
|
||||
var listener = {
|
||||
'data': {
|
||||
'id': argv.name,
|
||||
'type': 'listeners',
|
||||
'attributes': {
|
||||
'parameters': {
|
||||
'port': argv.port,
|
||||
'address': argv.interface,
|
||||
'protocol': argv.protocol,
|
||||
'authenticator': argv.authenticator,
|
||||
'authenticator_options': argv.auth_options,
|
||||
'ssl_key': argv['tls-key'],
|
||||
'ssl_cert': argv['tls-cert'],
|
||||
'ssl_ca_cert': argv['tls-ca-cert'],
|
||||
'ssl_version': argv['tls-version'],
|
||||
'ssl_cert_verify_depth': argv['tls-cert-verify-depth'],
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argv.servers) {
|
||||
for (i = 0; i < argv.servers.length; i++) {
|
||||
_.set(server, 'data.relationships.servers.data[' + i + ']', {id: argv.monitors[i], type: 'servers'})
|
||||
}
|
||||
}
|
||||
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'services/' + argv.service + '/listeners', null, {method: 'POST', body: listener})
|
||||
})
|
||||
})
|
||||
.command('user <name> <password>', 'Create a new network user', {}, function(argv) {
|
||||
|
||||
var user = {
|
||||
'data': {
|
||||
'id': argv.name,
|
||||
'type': 'inet',
|
||||
'attributes': {
|
||||
'password': argv.password
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'users/inet', null, {method: 'POST', body: user})
|
||||
})
|
||||
})
|
||||
|
||||
.usage('Usage: create <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help create` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
exports.command = 'destroy <command>'
|
||||
exports.desc = 'Destroy objects'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('server <name>', 'Destroy an unused server', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'servers/' + argv.name, null, {method: 'DELETE'})
|
||||
})
|
||||
})
|
||||
.command('monitor <name>', 'Destroy an unused monitor', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'monitors/' + argv.name, null, {method: 'DELETE'})
|
||||
})
|
||||
})
|
||||
.command('listener <service> <name>', 'Destroy an unused listener', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'services/' + argv.service + '/listeners/' + argv.name, null, {method: 'DELETE'})
|
||||
})
|
||||
})
|
||||
.command('user <name>', 'Remove a network user', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'users/inet/' + argv.name, null, {method: 'DELETE'})
|
||||
})
|
||||
})
|
||||
.usage('Usage: destroy <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help destroy` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
const log_levels = [
|
||||
'debug',
|
||||
'info',
|
||||
'notice',
|
||||
'warning'
|
||||
]
|
||||
|
||||
exports.command = 'disable <command>'
|
||||
exports.desc = 'Disable functionality'
|
||||
exports.handler = function() {}
|
||||
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) {
|
||||
maxctrl(argv, function(host) {
|
||||
return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.log_' + argv.log, false)
|
||||
})
|
||||
} else {
|
||||
maxctrl(argv, function() {
|
||||
error('Invalid log priority: ' + argv.log)
|
||||
return Promise.reject()
|
||||
})
|
||||
}
|
||||
})
|
||||
.command('maxlog', 'Disable MaxScale logging', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.maxlog', false)
|
||||
})
|
||||
})
|
||||
.command('syslog', 'Disable syslog logging', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.syslog', false)
|
||||
})
|
||||
})
|
||||
.command('account <name>', 'Disable a Linux user account from administrative use', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'users/unix/' + argv.name, null, { method: 'DELETE'})
|
||||
})
|
||||
})
|
||||
.usage('Usage: disable <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help disable` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
const log_levels = [
|
||||
'debug',
|
||||
'info',
|
||||
'notice',
|
||||
'warning'
|
||||
]
|
||||
|
||||
exports.command = 'enable <command>'
|
||||
exports.desc = 'Enable functionality'
|
||||
exports.handler = function() {}
|
||||
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) {
|
||||
maxctrl(argv, function(host) {
|
||||
return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.log_' + argv.log, true)
|
||||
})
|
||||
} else {
|
||||
maxctrl(argv, function() {
|
||||
error('Invalid log priority: ' + argv.log)
|
||||
return Promise.reject()
|
||||
})
|
||||
}
|
||||
})
|
||||
.command('maxlog', 'Enable MaxScale logging', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.maxlog', true)
|
||||
})
|
||||
})
|
||||
.command('syslog', 'Enable syslog logging', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return updateValue(host, 'maxscale/logs', 'data.attributes.parameters.syslog', true)
|
||||
})
|
||||
})
|
||||
.command('account <name>', 'Activate a Linux user account for administrative use', {}, function(argv) {
|
||||
var req_body = {
|
||||
data: {
|
||||
id: argv.name,
|
||||
type: 'unix'
|
||||
}
|
||||
}
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'users/unix', null, { method: 'POST', body: req_body})
|
||||
})
|
||||
})
|
||||
.usage('Usage: enable <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help enable` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
function addServer(argv, path, targets) {
|
||||
maxctrl(argv, function(host){
|
||||
return doRequest(host, path, function(res) {
|
||||
var servers =_.get(res, 'data.relationships.servers.data', [])
|
||||
|
||||
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
|
||||
|
||||
return doAsyncRequest(host, path, null, {method: 'PATCH', body: res})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
exports.command = 'link <command>'
|
||||
exports.desc = 'Link objects'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('service <name> <server...>', 'Link servers to a service', {}, function(argv) {
|
||||
addServer(argv, 'services/' + argv.name, argv.server)
|
||||
})
|
||||
.command('monitor <name> <server...>', 'Link servers to a monitor', {}, function(argv) {
|
||||
addServer(argv, 'monitors/' + argv.name, argv.server)
|
||||
})
|
||||
.usage('Usage: link <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help link` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
require('../common.js')()
|
||||
|
||||
exports.command = 'list <command>'
|
||||
exports.desc = 'List objects'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('servers', 'List servers', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getCollection(host, 'servers', [
|
||||
{'Server': 'id'},
|
||||
{'Address': 'attributes.parameters.address'},
|
||||
{'Port': 'attributes.parameters.port'},
|
||||
{'Connections': 'attributes.statistics.connections'},
|
||||
{'State': 'attributes.state'}
|
||||
])
|
||||
})
|
||||
})
|
||||
.command('services', 'List services', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getCollection(host, 'services',[
|
||||
{'Service': 'id'},
|
||||
{'Router': 'attributes.router'},
|
||||
{'Connections': 'attributes.connections'},
|
||||
{'Total Connections': 'attributes.total_connections'},
|
||||
{'Servers': 'relationships.servers.data[].id'}
|
||||
])
|
||||
})
|
||||
})
|
||||
.command('listeners <service>', 'List listeners of a service', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getSubCollection(host, 'services/' + argv.service, 'attributes.listeners', [
|
||||
{'Name': 'id'},
|
||||
{'Port': 'attributes.parameters.port'},
|
||||
{'Host': 'attributes.parameters.host'}
|
||||
])
|
||||
})
|
||||
})
|
||||
.command('monitors', 'List monitors', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getCollection(host, 'monitors', [
|
||||
{'Monitor': 'id'},
|
||||
{'State': 'attributes.state'},
|
||||
{'Servers': 'relationships.servers.data[].id'}
|
||||
])
|
||||
})
|
||||
})
|
||||
.command('sessions', 'List sessions', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getCollection(host, 'sessions',[
|
||||
{'Id': 'id'},
|
||||
{'Service': 'relationships.services.data[].id'},
|
||||
{'User': 'attributes.user'},
|
||||
{'Host': 'attributes.remote'}
|
||||
])
|
||||
})
|
||||
})
|
||||
.command('filters', 'List filters', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getCollection(host, 'filters', [
|
||||
{'Filter': 'id'},
|
||||
{'Service': 'relationships.services.data[].id'},
|
||||
{'Module': 'attributes.module'}
|
||||
])
|
||||
})
|
||||
})
|
||||
.command('modules', 'List loaded modules', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getCollection(host, 'maxscale/modules',[
|
||||
{'Module':'id'},
|
||||
{'Type':'attributes.module_type'},
|
||||
{'Version': 'attributes.version'}
|
||||
])
|
||||
})
|
||||
})
|
||||
.command('users', 'List created network users', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getCollection(host, 'users/inet',[
|
||||
{'Name':'id'}
|
||||
])
|
||||
})
|
||||
})
|
||||
.command('commands', 'List module commands', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getCollection(host, 'maxscale/modules',[
|
||||
{'Module':'id'},
|
||||
{'Commands': 'attributes.commands[].id'}
|
||||
])
|
||||
})
|
||||
})
|
||||
.usage('Usage: list <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help list` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
exports.command = 'rotate <command>'
|
||||
exports.desc = 'Rotate log files'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('logs', 'Rotate log files by closing and reopening the files', {}, function(argv) {
|
||||
maxctrl(argv, function(host){
|
||||
return doRequest(host, 'maxscale/logs/flush/', null, {method: 'POST'})
|
||||
})
|
||||
})
|
||||
.usage('Usage: rotate <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help rotate` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
exports.command = 'set <command>'
|
||||
exports.desc = 'Set object state'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('server <server> <state>', 'Set server state', {}, function(argv) {
|
||||
var target = 'servers/' + argv.server + '/set?state=' + argv.state
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, target, null, {method: 'PUT'})
|
||||
})
|
||||
})
|
||||
.usage('Usage: set <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help set` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
require('../common.js')()
|
||||
|
||||
exports.command = 'show <command>'
|
||||
exports.desc = 'Show objects'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('server <server>', 'Show server', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getResource(host, '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) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getResource(host, '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) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getResource(host, '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) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getResource(host, '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) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getResource(host, 'filters/' + argv.filter, [
|
||||
{'Filter': 'id'},
|
||||
{'Module': 'attributes.module'},
|
||||
{'Services': 'relationships.services.data[].id'},
|
||||
{'Parameters': 'attributes.parameters'}
|
||||
])
|
||||
})
|
||||
})
|
||||
.command('module <module>', 'Show loaded module', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getResource(host, '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) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getResource(host, '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) {
|
||||
maxctrl(argv, function(host) {
|
||||
return getSubCollection(host, 'maxscale/modules/' + argv.module, 'attributes.commands', [
|
||||
{'Command': 'id'},
|
||||
{'Parameters': 'attributes.parameters[].type'},
|
||||
{'Descriptions': 'attributes.parameters[].description'}
|
||||
])
|
||||
})
|
||||
})
|
||||
.usage('Usage: show <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help show` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
exports.command = 'start <command>'
|
||||
exports.desc = 'Start objects'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('service <name>', 'Start a service', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'services/' + argv.name + '/start', null, {method: 'PUT'})
|
||||
})
|
||||
})
|
||||
.command('monitor <name>', 'Start a monitor', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'monitors/' + argv.name + '/start', null, {method: 'PUT'})
|
||||
})
|
||||
})
|
||||
.usage('Usage: start <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help start` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
exports.command = 'stop <command>'
|
||||
exports.desc = 'Stop objects'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('service <name>', 'Stop a service', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'services/' + argv.name + '/stop', null, {method: 'PUT'})
|
||||
})
|
||||
})
|
||||
.command('monitor <name>', 'Stop a monitor', {}, function(argv) {
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, 'monitors/' + argv.name + '/stop', null, {method: 'PUT'})
|
||||
})
|
||||
})
|
||||
.usage('Usage: stop <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help stop` for a list of commands.')
|
||||
})
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2020-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
require('../common.js')()
|
||||
|
||||
function removeServer(argv, path, targets) {
|
||||
maxctrl(argv, function(host) {
|
||||
return doRequest(host, path, function(res) {
|
||||
var servers =_.get(res, 'data.relationships.servers.data', [])
|
||||
|
||||
_.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
|
||||
|
||||
return doAsyncRequest(host, path, null, {method: 'PATCH', body: res})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
exports.command = 'unlink <command>'
|
||||
exports.desc = 'Unlink objects'
|
||||
exports.handler = function() {}
|
||||
exports.builder = function(yargs) {
|
||||
yargs
|
||||
.command('service <name> <server...>', 'Unlink servers from a service', {}, function(argv) {
|
||||
removeServer(argv, 'services/' + argv.name, argv.server)
|
||||
})
|
||||
.command('monitor <name> <server...>', 'Unlink servers from a monitor', {}, function(argv) {
|
||||
removeServer(argv, 'monitors/' + argv.name, argv.server)
|
||||
})
|
||||
.usage('Usage: unlink <command>')
|
||||
.help()
|
||||
.command('*', 'the default command', {}, () => {
|
||||
logger.log('Unknown command. See output of `help unlink` for a list of commands.')
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user