mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Added a method for getting qemu-img binaries, and moved the qemu folder into a separate method.
This commit is contained in:
1 parent
117630c887
commit
9ef4628cbc
3 files changed
+95
-6
No files matched your search
@@ -292,6 +292,21 @@ class QEMUHandler:
|
||||
binaries = yield from Qemu.binary_list()
|
||||
response.json(binaries)
|
||||
|
||||
@classmethod
|
||||
@Route.get(
|
||||
r"/qemu/img-binaries",
|
||||
status_codes={
|
||||
200: "Success",
|
||||
400: "Invalid request",
|
||||
404: "Instance doesn't exist"
|
||||
},
|
||||
description="Get a list of available Qemu-img binaries",
|
||||
output=QEMU_BINARY_LIST_SCHEMA)
|
||||
def list_img_binaries(request, response):
|
||||
|
||||
binaries = yield from Qemu.img_binary_list()
|
||||
response.json(binaries)
|
||||
|
||||
@Route.get(
|
||||
r"/qemu/vms",
|
||||
status_codes={
|
||||
|
||||
@@ -39,14 +39,13 @@ class Qemu(BaseManager):
|
||||
_VM_CLASS = QemuVM
|
||||
|
||||
@staticmethod
|
||||
def binary_list():
|
||||
def paths_list():
|
||||
"""
|
||||
Gets QEMU binaries list available on the host.
|
||||
Gets a folder list of possibly available QEMU binaries on the host.
|
||||
|
||||
:returns: Array of dictionary {"path": Qemu binary path, "version": version of Qemu}
|
||||
:returns: List of folders where Qemu binaries MAY reside.
|
||||
"""
|
||||
|
||||
qemus = []
|
||||
paths = []
|
||||
try:
|
||||
paths.append(os.getcwd())
|
||||
@@ -72,14 +71,25 @@ class Qemu(BaseManager):
|
||||
paths.append(os.path.join(os.environ["PROGRAMFILES"], "qemu"))
|
||||
elif sys.platform.startswith("darwin"):
|
||||
# add specific locations on Mac OS X regardless of what's in $PATH
|
||||
paths.extend(["/usr/local/bin", "/opt/local/bin"])
|
||||
paths.extend(["/usr/bin", "/usr/local/bin", "/opt/local/bin"])
|
||||
if hasattr(sys, "frozen"):
|
||||
try:
|
||||
paths.append(os.path.abspath(os.path.join(os.getcwd(), "../../../qemu/bin/")))
|
||||
# If the user run the server by hand from outside
|
||||
except FileNotFoundError:
|
||||
paths.append(["/Applications/GNS3.app/Contents/Resources/qemu/bin"])
|
||||
for path in paths:
|
||||
return paths
|
||||
|
||||
@staticmethod
|
||||
def binary_list():
|
||||
"""
|
||||
Gets QEMU binaries list available on the host.
|
||||
|
||||
:returns: Array of dictionary {"path": Qemu binary path, "version": version of Qemu}
|
||||
"""
|
||||
|
||||
qemus = []
|
||||
for path in Qemu.paths_list():
|
||||
try:
|
||||
for f in os.listdir(path):
|
||||
if (f.startswith("qemu-system") or f.startswith("qemu-kvm") or f == "qemu" or f == "qemu.exe") and \
|
||||
@@ -93,6 +103,28 @@ class Qemu(BaseManager):
|
||||
|
||||
return qemus
|
||||
|
||||
@staticmethod
|
||||
def img_binary_list():
|
||||
"""
|
||||
Gets QEMU-img binaries list available on the host.
|
||||
|
||||
:returns: Array of dictionary {"path": Qemu-img binary path, "version": version of Qemu-img}
|
||||
"""
|
||||
qemu_imgs = []
|
||||
for path in Qemu.paths_list():
|
||||
try:
|
||||
for f in os.listdir(path):
|
||||
if (f == "qemu-img" or f == "qemu-img.exe") and \
|
||||
os.access(os.path.join(path, f), os.X_OK) and \
|
||||
os.path.isfile(os.path.join(path, f)):
|
||||
qemu_path = os.path.join(path, f)
|
||||
version = yield from Qemu._get_qemu_img_version(qemu_path)
|
||||
qemu_imgs.append({"path": qemu_path, "version": version})
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
return qemu_imgs
|
||||
|
||||
@staticmethod
|
||||
@asyncio.coroutine
|
||||
def _get_qemu_version(qemu_path):
|
||||
@@ -115,6 +147,26 @@ class Qemu(BaseManager):
|
||||
except subprocess.SubprocessError as e:
|
||||
raise QemuError("Error while looking for the Qemu version: {}".format(e))
|
||||
|
||||
@staticmethod
|
||||
@asyncio.coroutine
|
||||
def _get_qemu_img_version(qemu_img_path):
|
||||
"""
|
||||
Gets the Qemu-img version.
|
||||
|
||||
:param qemu_img_path: path to Qemu-img executable.
|
||||
"""
|
||||
|
||||
try:
|
||||
output = yield from subprocess_check_output(qemu_img_path, "--version")
|
||||
match = re.search("version\s+([0-9a-z\-\.]+)", output)
|
||||
if match:
|
||||
version = match.group(1)
|
||||
return version
|
||||
else:
|
||||
raise QemuError("Could not determine the Qemu-img version for {}".format(qemu_img_path))
|
||||
except subprocess.SubprocessError as e:
|
||||
raise QemuError("Error while looking for the Qemu-img version: {}".format(e))
|
||||
|
||||
@staticmethod
|
||||
def get_legacy_vm_workdir(legacy_vm_id, name):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user