MXS-1929: Add create/destroy service MaxCtrl commands

Added commands for creating and destroying services. The create command
allows server and filter relationships to be defined but they are not yet
processed by MaxScale. This will be done once the use of filters is made
dynamic.
This commit is contained in:
Markus Mäkelä 2018-07-18 12:12:10 +03:00
parent 037cedf70e
commit 146fe76c7a
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
2 changed files with 64 additions and 0 deletions

View File

@ -156,6 +156,60 @@ exports.builder = function(yargs) {
})
})
// Create service
.group(['servers', 'filters'], 'Create service options:')
.option('servers', {
describe: 'Link the created service to these servers',
type: 'array'
})
.option('filters', {
describe: 'Link the created service to these filters',
type: 'array'
})
.command('service <name> <router> <params...>', 'Create a new service', function(yargs) {
return yargs.epilog('The last argument to this command is a list of key=value parameters ' +
'given as the service parameters. If the --servers or --filters options ' +
'are used, they must be defined after the service parameters.')
.usage('Usage: service <name> <router> <params...>')
}, function(argv) {
var to_obj = (obj, value) => {
var kv = value.split('=')
if (kv.length < 2) {
throw 'Error: Not a key-value parameter: ' + value
}
obj[kv[0]] = kv[1]
return obj
}
var service = {
'data': {
'id': argv.name,
'attributes': {
'router': argv.router,
'parameters': argv.params.reduce(to_obj, {})
}
}
}
if (argv.servers) {
for (i = 0; i < argv.servers.length; i++) {
_.set(service, 'data.relationships.servers.data[' + i + ']', {id: argv.servers[i], type: 'servers'})
}
}
if (argv.filters) {
for (i = 0; i < argv.filters.length; i++) {
_.set(service, 'data.relationships.filters.data[' + i + ']', {id: argv.filters[i], type: 'filters'})
}
}
maxctrl(argv, function(host) {
return doRequest(host, 'services', null, {method: 'POST', body: service})
})
})
// Create listener
.group(['interface'], 'Create listener options:')
.option('interface', {

View File

@ -45,6 +45,16 @@ exports.builder = function(yargs) {
return doRequest(host, 'services/' + argv.service + '/listeners/' + argv.name, null, {method: 'DELETE'})
})
})
.command('service <name>', 'Destroy an unused service', function(yargs) {
return yargs.epilog('The service must be unlinked from all servers and filter and ' +
'all listeners for the service must be destroyed before the service ' +
'itself can be destroyed.')
.usage('Usage: destroy service <name>')
}, function(argv) {
maxctrl(argv, function(host) {
return doRequest(host, 'services/' + argv.name, null, {method: 'DELETE'})
})
})
.command('user <name>', 'Remove a network user', function(yargs) {
return yargs.epilog('The last remaining administrative user cannot be removed. ' +
'Create a replacement administrative user before attempting ' +