Commit fc5a1655 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[scripts][worker] Add option to set port range

Currently only used by docker executor.
parent ab9146be
Pipeline #23888 failed with stages
in 3 minutes and 19 seconds
......@@ -30,21 +30,23 @@
Usage:
%(prog)s [-v ... | --verbose ...] [ --name=<name>] [--prefix=<path>]
[--cache=<path>] [--docker] [--docker-network=<name>] <scheduler_address>
[--cache=<path>] [--docker] [--docker-network=<name>]
[--port-range=<range>] <scheduler_address>
%(prog)s (--help | -h)
%(prog)s (--version | -V)
Options:
-h, --help Show this screen
-V, --version Show version
-v, --verbose Increases the output verbosity level
-n <name>, --name=<name> The unique name of this worker on the database.
This is typically the assigned hostname of the node,
but not necessarily [default: %(hostname)s]
-p, --prefix=<path> Comma-separated list of the prefix(es) of your local data [default: .]
-c, --cache=<path> Cache prefix, otherwise defaults to '<prefix>/cache'
--docker-network=<name> Name of the docker network to use
-h, --help Show this screen
-V, --version Show version
-v, --verbose Increases the output verbosity level
-n <name>, --name=<name> The unique name of this worker on the database.
This is typically the assigned hostname of the node,
but not necessarily [default: %(hostname)s]
-p, --prefix=<path> Comma-separated list of the prefix(es) of your local data [default: .]
-c, --cache=<path> Cache prefix, otherwise defaults to '<prefix>/cache'
--docker-network=<name> Name of the docker network to use
--port-range=<range> Range of port usable for communication with containers
"""
......@@ -192,7 +194,6 @@ def connect_to_scheduler(address, name):
def main(user_input=None):
# Parse the command-line arguments
if user_input is not None:
arguments = user_input
......@@ -275,6 +276,7 @@ def main(user_input=None):
# (If necessary) Docker-related initialisations
docker_images_cache = None
docker_network_name = None
docker_port_range = None
if args['--docker']:
docker_images_cache = os.path.join(tempfile.gettempdir(), 'beat-docker-images.json')
logger.info("Using docker images cache: '%s'", docker_images_cache)
......@@ -284,6 +286,13 @@ def main(user_input=None):
if docker_network_name:
logger.info("Using docker network: '%s'", docker_network_name)
docker_port_range = args.get('--port-range', None)
if docker_port_range:
if len(docker_port_range.split(':')) != 2:
logger.error("Invalid port range %s" % docker_port_range)
return 1
# Establish a connection with the scheduler
(context, socket, poller) = connect_to_scheduler(args['<scheduler_address>'], args['--name'])
if context is None:
......@@ -374,8 +383,11 @@ def main(user_input=None):
if command == WorkerController.EXECUTE:
job_id = parts[1]
data = simplejson.loads(parts[2])
if docker_network_name:
data['network_name'] = docker_network_name
if args['--docker']:
if docker_network_name:
data['network_name'] = docker_network_name
if docker_port_range:
data['port_range'] = docker_port_range
# Start the execution
logger.info("Running '%s' with job id #%s", data['algorithm'], job_id)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment