-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "feat: added export current schedules"
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#! /usr/bin/env python | ||
|
||
import argparse | ||
from quads.model import Schedule | ||
import yaml | ||
|
||
|
||
def export_current_schedules(output): | ||
current_schedules = [] | ||
clouds = {} | ||
future_schedules = Schedule.future_schedules() | ||
for schedule in future_schedules: | ||
cloud = schedule.cloud | ||
if cloud.name not in clouds: | ||
clouds[cloud.name] = { | ||
"description": cloud.description, | ||
"owner": cloud.owner, | ||
"ticket": cloud.ticket, | ||
"qinq": cloud.qinq, | ||
"wipe": cloud.wipe, | ||
"ccuser": [cc for cc in cloud.ccuser], | ||
"vlan": cloud.vlan.vlan_id if cloud.vlan else None, | ||
} | ||
current_schedules.append( | ||
{ | ||
"cloud": cloud.name, | ||
"host": schedule.host.name, | ||
"start": schedule.start, | ||
"end": schedule.end, | ||
"build_start": schedule.build_start, | ||
"build_end": schedule.build_end, | ||
} | ||
) | ||
|
||
data = {"clouds": clouds, "current_schedules": current_schedules} | ||
|
||
with open(output, "w") as outfile: | ||
yaml.dump(data, outfile, default_flow_style=False) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Export current schedules to a YAML file.") | ||
parser.add_argument("--output", type=str, help="The name of the output file.") | ||
args = parser.parse_args() | ||
export_current_schedules(args.output) |