moved all files to subproject

This commit is contained in:
alex
2023-09-06 15:49:19 +02:00
parent 83dfdf7841
commit 1069348d71
7 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
# copyright: Canonical
"""Tools for setting up a rsync bench environment."""
import json
import subprocess
def run_osc(cmdlist: list[str]):
"""Launch a nicely formatted command on openstack and retrieve result in json.
Args:
cmdlist (list[str]): Cmd line args
Returns:
_type_: _description_
"""
cmdlist.extend(["--format", "json"])
res = subprocess.run(cmdlist, capture_output=True, text=True)
return json.loads(res.stdout or "[]")
def provision():
"""Provision servers on openstack."""
run_osc(
[
"openstack",
"flavor",
"create",
"--public",
"8c-64r-150s",
"--ram",
"65536",
"--disk",
"150",
"--vcpus 8",
]
)
for x in range(2):
serv_resp = run_osc(
[
"openstack",
"server",
"create",
"--image",
"ubuntu2204",
"--key-name",
"alexmicouleau",
"--network",
"bench-net",
"--flavor",
"8c-64r-150s",
f"alex_rsync_{x}",
]
)
serv_id = serv_resp["id"]
fip_res = run_osc(
[
"openstack",
"floating",
"ip",
"create",
"--description",
f"alex_rsync_{x}",
"ext-net",
]
)
fip_ad = fip_res["floating_ip_address"]
run_osc(
[
"openstack",
"server",
"add",
"floating",
"ip",
f"{serv_id}",
f"{fip_ad}",
]
)
vol_res = run_osc(
[
"openstack",
"volume",
"create",
"--size",
"150",
f"alex_rsync{x}",
]
)
vol_id = vol_res["id"]
add_vol_res = run_osc(["openstack", "server", "add", "volume", serv_id, vol_id])