MXS-1300: Combine REST API and MaxCtrl tests

The REST API tests are now located under the maxctrl directory. This
allows both tests to use the same framework for testing.
This commit is contained in:
Markus Mäkelä
2017-07-11 11:30:36 +03:00
parent f83d793704
commit d59d3ab638
40 changed files with 3 additions and 3 deletions

40
maxctrl/lib/alter.js Normal file
View File

@ -0,0 +1,40 @@
/*
* 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) {
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)
})
.command('service <service> <key> <value>', 'Alter service parameters', {}, function(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)
})
.command('maxscale <key> <value>', 'Alter MaxScale parameters', {}, function(argv) {
updateValue('maxscale', 'attributes.parameters.' + argv.key, argv.value)
})
.usage('Usage: alter <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help alter` for a list of commands.')
})
}

45
maxctrl/lib/call.js Normal file
View File

@ -0,0 +1,45 @@
/*
* 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
doRequest('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;
}
})
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()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help call` for a list of commands.')
})
}

29
maxctrl/lib/clear.js Normal file
View File

@ -0,0 +1,29 @@
/*
* 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
doRequest(target, null, {method: 'PUT'})
})
.usage('Usage: clear <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help clear` for a list of commands.')
})
}

182
maxctrl/lib/create.js Normal file
View File

@ -0,0 +1,182 @@
/*
* 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'})
}
}
doRequest('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'})
}
}
doRequest('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'})
}
}
doRequest('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
}
}
}
doRequest('users/inet', null, {method: 'POST', body: user})
})
.usage('Usage: create <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help create` for a list of commands.')
})
}

37
maxctrl/lib/destroy.js Normal file
View File

@ -0,0 +1,37 @@
/*
* 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) {
doRequest('servers/' + argv.name, null, {method: 'DELETE'})
})
.command('monitor <name>', 'Destroy an unused monitor', {}, function(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'})
})
.command('user <name>', 'Remove a network user', {}, function(argv) {
doRequest('users/inet/' + argv.name, null, {method: 'DELETE'})
})
.usage('Usage: destroy <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help destroy` for a list of commands.')
})
}

48
maxctrl/lib/disable.js Normal file
View File

@ -0,0 +1,48 @@
/*
* 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) {
updateValue('maxscale/logs', 'data.attributes.parameters.log_' + argv.log, false)
} else {
logError('Invalid log priority: ' + argv.log);
}
})
.command('maxlog', 'Disable MaxScale logging', {}, function(argv) {
updateValue('maxscale/logs', 'data.attributes.parameters.maxlog', false)
})
.command('syslog', 'Disable syslog logging', {}, function(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'})
})
.usage('Usage: disable <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help disable` for a list of commands.')
})
}

54
maxctrl/lib/enable.js Normal file
View File

@ -0,0 +1,54 @@
/*
* 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) {
updateValue('maxscale/logs', 'data.attributes.parameters.log_' + argv.log, true)
} else {
logError('Invalid log priority: ' + argv.log);
}
})
.command('maxlog', 'Enable MaxScale logging', {}, function(argv) {
updateValue('maxscale/logs', 'data.attributes.parameters.maxlog', true)
})
.command('syslog', 'Enable syslog logging', {}, function(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 = {
data: {
id: argv.name,
type: 'unix'
}
}
doRequest('users/unix', null, { method: 'POST', body: req_body})
})
.usage('Usage: enable <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help enable` for a list of commands.')
})
}

47
maxctrl/lib/link.js Normal file
View File

@ -0,0 +1,47 @@
/*
* 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(path, targets) {
doRequest(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
doRequest(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('services/' + argv.name, argv.server)
})
.command('monitor <name> <server...>', 'Link servers to a monitor', {}, function(argv) {
addServer('monitors/' + argv.name, argv.server)
})
.usage('Usage: link <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help link` for a list of commands.')
})
}

84
maxctrl/lib/list.js Normal file
View File

@ -0,0 +1,84 @@
/*
* 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() {
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('monitors', 'List monitors', {}, function() {
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('filters', 'List filters', {}, function() {
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('users', 'List created network users', {}, function() {
getCollection('users/inet',[
{'Name':'id'}
])
})
.command('commands', 'List module commands', {}, function() {
getCollection('maxscale/modules',[
{'Module':'id'},
{'Commands': 'attributes.commands[].id'}
])
})
.usage('Usage: list <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help list` for a list of commands.')
})
}

28
maxctrl/lib/rotate.js Normal file
View File

@ -0,0 +1,28 @@
/*
* 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) {
doRequest('maxscale/logs/flush/', null, {method: 'POST'})
})
.usage('Usage: rotate <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help rotate` for a list of commands.')
})
}

29
maxctrl/lib/set.js Normal file
View File

@ -0,0 +1,29 @@
/*
* 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
doRequest(target, null, {method: 'PUT'})
})
.usage('Usage: set <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help set` for a list of commands.')
})
}

108
maxctrl/lib/show.js Normal file
View File

@ -0,0 +1,108 @@
/*
* 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) {
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'}
])
})
.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'}
])
})
.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'}
])
})
.command('filter <filter>', 'Show filter', {}, function(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'}
])
})
.command('maxscale', 'Show MaxScale information', {}, function(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'}
])
})
.usage('Usage: show <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help show` for a list of commands.')
})
}

31
maxctrl/lib/start.js Normal file
View File

@ -0,0 +1,31 @@
/*
* 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) {
doRequest('services/' + argv.name + '/start', null, {method: 'PUT'})
})
.command('monitor <name>', 'Start a monitor', {}, function(argv) {
doRequest('monitors/' + argv.name + '/start', null, {method: 'PUT'})
})
.usage('Usage: start <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help start` for a list of commands.')
})
}

31
maxctrl/lib/stop.js Normal file
View File

@ -0,0 +1,31 @@
/*
* 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) {
doRequest('services/' + argv.name + '/stop', null, {method: 'PUT'})
})
.command('monitor <name>', 'Stop a monitor', {}, function(argv) {
doRequest('monitors/' + argv.name + '/stop', null, {method: 'PUT'})
})
.usage('Usage: stop <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help stop` for a list of commands.')
})
}

47
maxctrl/lib/unlink.js Normal file
View File

@ -0,0 +1,47 @@
/*
* 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(path, targets) {
doRequest(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
doRequest(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('services/' + argv.name, argv.server)
})
.command('monitor <name> <server...>', 'Unlink servers from a monitor', {}, function(argv) {
removeServer('monitors/' + argv.name, argv.server)
})
.usage('Usage: unlink <command>')
.help()
.command('*', 'the default command', {}, () => {
console.log('Unknown command. See output of `help unlink` for a list of commands.')
})
}