little bit tweaking
This commit is contained in:
parent
ba2063ed9c
commit
cd1efa16f2
3 changed files with 14 additions and 9 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
.idea/
|
.idea/
|
||||||
venv/
|
.vscode/
|
||||||
|
venv/
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 59974e2047bbea08b72d32129fd905bbea6e9d70
|
Subproject commit cb2a416a17d6789e613ba3b9957917770f4211e1
|
18
main.py
18
main.py
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import shutil
|
||||||
from etcd3_wrapper import Etcd3Wrapper
|
from etcd3_wrapper import Etcd3Wrapper
|
||||||
|
|
||||||
BASE_PATH = "/var/www"
|
BASE_PATH = "/var/www"
|
||||||
|
@ -10,6 +11,7 @@ images = list(client.get_prefix("/v1/image/", value_in_json=True))
|
||||||
images_to_be_created = list(filter(lambda e: e.value["status"] == "TO_BE_CREATED", images))
|
images_to_be_created = list(filter(lambda e: e.value["status"] == "TO_BE_CREATED", images))
|
||||||
|
|
||||||
for image in images_to_be_created:
|
for image in images_to_be_created:
|
||||||
|
image_uuid = image.key.split("/")[-1]
|
||||||
image_full_path = f"{BASE_PATH}/{image.value['owner']}/{image.value['filename']}"
|
image_full_path = f"{BASE_PATH}/{image.value['owner']}/{image.value['filename']}"
|
||||||
if os.path.isfile(image_full_path):
|
if os.path.isfile(image_full_path):
|
||||||
output = subprocess.check_output(["qemu-img", "info", image_full_path]).decode("utf-8")
|
output = subprocess.check_output(["qemu-img", "info", image_full_path]).decode("utf-8")
|
||||||
|
@ -17,13 +19,15 @@ for image in images_to_be_created:
|
||||||
print("qcow2 format")
|
print("qcow2 format")
|
||||||
print("Converting it to raw")
|
print("Converting it to raw")
|
||||||
subprocess.run(["qemu-img", "convert", "-f", "qcow2",
|
subprocess.run(["qemu-img", "convert", "-f", "qcow2",
|
||||||
"-O", "raw", image_full_path, "image.raw"])
|
"-O", "raw", image_full_path, f"{image_uuid}.raw"])
|
||||||
if os.path.isfile("image.raw"):
|
if os.path.isfile(f"{image_uuid}.raw"):
|
||||||
subprocess.run(["rbd", "import", "image.raw",
|
shutil.move(f"{image_uuid}.raw", f"/var/vm/{image_uuid}.raw")
|
||||||
f"{image.value['store_name']}/{image.key.split('/')[-1]}"])
|
# subprocess.run(["rbd", "import", "image.raw",
|
||||||
os.remove("image.raw")
|
# f"{image.value['store_name']}/{image.key.split('/')[-1]}"])
|
||||||
|
image.value["status"] = "CREATED"
|
||||||
|
client.put(image.key, json.dumps(image.value))
|
||||||
else:
|
else:
|
||||||
print("image.raw not found")
|
print(f"{image_uuid}.raw not found")
|
||||||
else:
|
else:
|
||||||
print("not qcow2 format")
|
print("not qcow2 format")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue