-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With a flag to check if dashboards are updated (so `make check-dashboard-updates` still works). Also run the script to sync the dashboards.
- Loading branch information
1 parent
fbee674
commit ed8747f
Showing
6 changed files
with
4,279 additions
and
31 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
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
This file was deleted.
Oops, something went wrong.
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,72 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import sys | ||
import argparse | ||
from urllib.request import urlretrieve | ||
|
||
# sync the dashboards from https://opendev.org/openstack/sunbeam-charms/src/branch/main/charms/openstack-exporter-k8s/src/grafana_dashboards | ||
BASE_URL = "https://opendev.org/openstack/sunbeam-charms/raw/branch/main/charms/openstack-exporter-k8s/src/grafana_dashboards/" | ||
BASE_LOCAL_PATH = "./src/grafana_dashboards/" | ||
DASHBOARDS = [ | ||
"hypervisor-openstack-exporter-dashboard.json", | ||
"openstack-exporter.json", | ||
"overview-openstack-exporter-dashboard.json", | ||
] | ||
|
||
|
||
def sync_dashboard(url: str, local_path: str, check_mode: bool) -> bool: | ||
"""Sync dashboard from url. | ||
If check_mode is True, don't actually update the file. | ||
Return True if the dashboard changed (or would be changed). | ||
""" | ||
new_dashboard_path, _ = urlretrieve(url) | ||
|
||
changed = False | ||
if os.path.exists(local_path): | ||
with open(new_dashboard_path) as f1, open(local_path) as f2: | ||
changed = f1.read() != f2.read() | ||
else: | ||
changed = True | ||
|
||
if changed and not check_mode: | ||
os.replace(new_dashboard_path, local_path) | ||
|
||
return changed | ||
|
||
|
||
def main(args: argparse.Namespace) -> bool: | ||
"""Main entry point. | ||
Return False to indicate dashboards not up to date in check mode. | ||
""" | ||
result = True | ||
for dashboard in DASHBOARDS: | ||
changed = sync_dashboard( | ||
BASE_URL + dashboard, BASE_LOCAL_PATH + dashboard, args.check | ||
) | ||
if changed: | ||
if args.check: | ||
result = False | ||
print(f"ERROR: {dashboard} not up to date") | ||
else: | ||
print(f"UPDATED: {dashboard} synced from remote source") | ||
else: | ||
print(f"OK: {dashboard} up to date") | ||
|
||
return result | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-c", | ||
"--check", | ||
action="store_true", | ||
help="If any dashboards are outdated, don't update them, but exit with value 1.", | ||
) | ||
args = parser.parse_args() | ||
|
||
if not main(args): | ||
sys.exit(1) |
Oops, something went wrong.