Skip to content

Commit

Permalink
GC firewall rules
Browse files Browse the repository at this point in the history
Introduced by weaveworks/weave#2670
  • Loading branch information
bboreham authored and marccarre committed Jan 13, 2017
1 parent ed8e757 commit ed5529f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions scheduler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def avg(test):
schedule = Schedule.get_or_insert(schedule_id, shards=shards)
return flask.json.jsonify(tests=schedule.shards[str(shard)])

FIRE_RE = re.compile(r'^(?P<network>\d+)-allow-(?P<type>\d+)-(?P<build>\d+)-(?P<shard>\d+)$')
NAME_REGEXES = [
re.compile(r'^host(?P<index>\d+)-(?P<build>\d+)-(?P<shard>\d+)$'),
re.compile(r'^test-(?P<build>\d+)-(?P<shard>\d+)-(?P<index>\d+)$'),
Expand Down Expand Up @@ -145,4 +146,14 @@ def gc_project(compute, repo, project, zone):
logging.info("Stopping VM %s", name)
compute.instances().delete(project=project, zone=zone, instance=name).execute()

# Remove firewall rules for builds that aren't running
firewalls = compute.firewalls.list(project=project).execute()
for firewall in firewalls['items']:
matches = FIRE_RE.match(firewall['name'])
if matches is None:
continue
if matches.group('build') in running:
continue
compute.firewalls.delete(project=project, firewall=firewall['name'])

return

0 comments on commit ed5529f

Please sign in to comment.