Commit 6568dc76 authored by Brennen Bearnes's avatar Brennen Bearnes Committed by Jeena Huneidi
Browse files

runners: list / pause / unpause runners

parent 578e435c
......@@ -45,3 +45,11 @@ for any projects that have turned it on):
```sh
./configure-projects
```
List active runners, pause them, and unpause them after maintenance:
```sh
./runners active | tee active.txt
./runners pause < active.txt
./runners unpause < active.txt
```
#!/usr/bin/env python3
"""
runners - deal with runners on a GitLab instance
"""
import click
import gitlab
import pprint
import sys
import time
from gitlab_settings.util import get_token
pp = pprint.PrettyPrinter(indent=4)
def get_gitlab(instance):
"""Get a GitLab instance."""
token = get_token()
server = gitlab.Gitlab(instance, private_token=token)
return server
@click.group()
@click.option(
'--instance',
default='https://gitlab.wikimedia.org',
help='URL of instance to configure.'
)
@click.pass_context
def cli(ctx, instance):
ctx.obj['instance'] = instance
@click.command()
@click.pass_context
def active(ctx):
"""List all active runners on the server"""
server = get_gitlab(ctx.obj['instance'])
for runner in server.runners.list(scope='active'):
print("#", runner.description)
print(runner.id)
@click.command()
@click.pass_context
def pause(ctx):
"""Pause runners listed in stdin - one per line"""
server = get_gitlab(ctx.obj['instance'])
for runner_id in sys.stdin:
if runner_id.startswith('#'):
continue
runner = server.runners.get(runner_id)
print(runner.id)
runner.paused = True
runner.save()
@click.command()
@click.pass_context
def unpause(ctx):
"""Unpause runners listed in stdin - one per line"""
server = get_gitlab(ctx.obj['instance'])
for runner_id in sys.stdin:
if runner_id.startswith('#'):
continue
runner = server.runners.get(runner_id)
print("unpause:", runner.id)
runner.paused = False
runner.save()
cli.add_command(active)
cli.add_command(pause)
cli.add_command(unpause)
if __name__ == '__main__':
cli(obj={}, auto_envvar_prefix='GITLAB')
Supports Markdown
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