Skip to content

Commit e059409

Browse files
committed
utils: Add script to add a new version to GNS3 marketplace
You need first to clone gns3-registry from https://github.com/GNS3/gns3-registry Follow this steps: 1. ./utils/gns3-marketplace-updater.py 25.08.0 ../../gns3/gns3-registry/appliances/infix.gns3a 2. TEST in gns3, just add the new version, start it. 3. run python3 check.py inside gns3-registry, verify infix is ok. 4. Create a pull request to gns3-registry This fix #1107
1 parent 52faadf commit e059409

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

utils/gns3-marketplace.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import hashlib
4+
import json
5+
import re
6+
import shutil
7+
import sys
8+
import urllib.request
9+
from datetime import datetime
10+
11+
BIOS_IMAGE = "OVMF-edk2-stable202305.fd"
12+
REPO = "https://github.com/kernelkit/infix"
13+
14+
def check_version_format(ver):
15+
if not re.fullmatch(r"\d{2}\.\d{2}\.\d+", ver):
16+
sys.exit("Error: version must be full form like 25.08.0")
17+
return ver
18+
19+
def compute_md5_and_size(url):
20+
md5 = hashlib.md5()
21+
size = 0
22+
with urllib.request.urlopen(url) as resp:
23+
while True:
24+
chunk = resp.read(1024 * 1024)
25+
if not chunk:
26+
break
27+
md5.update(chunk)
28+
size += len(chunk)
29+
return md5.hexdigest(), size
30+
31+
def main():
32+
parser = argparse.ArgumentParser(description="Add a new Infix version to a GNS3 appliance file")
33+
parser.add_argument("version", help="Infix version (e.g. 25.08.0)")
34+
parser.add_argument("appliance", help="Path to appliance JSON (.gns3a)")
35+
args = parser.parse_args()
36+
37+
version = check_version_format(args.version)
38+
appliance_path = args.appliance
39+
40+
# Load JSON
41+
with open(appliance_path, "r", encoding="utf-8") as f:
42+
data = json.load(f)
43+
44+
# Skip if version already exists
45+
for v in data.get("versions", []):
46+
if v.get("name") == version:
47+
print(f"Version {version} already exists.")
48+
return
49+
50+
# Build qcow2 URL
51+
filename = f"infix-x86_64-disk-{version}.qcow2"
52+
url = f"{REPO}/releases/download/v{version}/{filename}"
53+
54+
print(f"Downloading {url} to compute MD5 and size...")
55+
md5sum, size = compute_md5_and_size(url)
56+
57+
# Add image entry
58+
image_entry = {
59+
"filename": filename,
60+
"filesize": size,
61+
"md5sum": md5sum,
62+
"version": version,
63+
"direct_download_url": url
64+
}
65+
data.setdefault("images", []).append(image_entry)
66+
67+
# Add version entry (newest first)
68+
version_entry = {
69+
"name": version,
70+
"images": {
71+
"bios_image": BIOS_IMAGE,
72+
"hda_disk_image": filename
73+
}
74+
}
75+
data.setdefault("versions", []).insert(0, version_entry)
76+
77+
# Backup
78+
backup = appliance_path + ".bak-" + datetime.now().strftime("%Y%m%d-%H%M%S")
79+
shutil.copy2(appliance_path, backup)
80+
81+
# Save updated JSON
82+
with open(appliance_path, "w", encoding="utf-8") as f:
83+
json.dump(data, f, indent=4)
84+
85+
print(f"✅ Added version {version}")
86+
print(f" File: {appliance_path}")
87+
print(f" Backup: {backup}")
88+
print(f" Disk: {filename} (size={size} bytes, md5={md5sum})")
89+
90+
if __name__ == "__main__":
91+
main()

0 commit comments

Comments
 (0)