Install via CDROM

This commit is contained in:
Julien Duponchelle 2015-05-25 23:06:34 +02:00
parent 91ba5b5416
commit 58d5867718
6 changed files with 162 additions and 18 deletions

View File

@ -14,7 +14,7 @@
"qemu": {
"adapter_type": "e1000",
"adapters": 8,
"graphics": false,
"graphic": false,
"kvm_support": true,
"ram": 2048,
"processor": "x64"

View File

@ -0,0 +1,37 @@
{
"name": "HP VSR1001",
"category": "router",
"vendor_name": "HP",
"vendor_url": "http://www.hp.com",
"documentation_url": "http://h20564.www2.hp.com/portal/site/hpsc/public/psi/home/?sp4ts.oid=5443163",
"product_name": "VSR1001",
"product_url": "http://www8.hp.com/us/en/products/networking-routers/product-detail.html?oid=5443163",
"repository_version": 1,
"status": "stable",
"maintainer": "GNS3 Team",
"maintainer_email": "developers@gns3.net",
"qemu": {
"adapter_type": "e1000",
"adapters": 16,
"ram": 1024,
"processor": "x64",
"graphic": false,
"kvm": true,
"hda_disk_image": "vsr1000-hp.img",
"hda_disk_size": "8G",
"install_cdrom_to_hda": true,
"install_instructions": "* Wait for boot.\n* Run fresh install."
},
"images": {
"cdrom": [
{
"filename": "VSR1000_HP-CMW710-R0204P01-X64.iso",
"version": "7.10.R0204P01",
"sha1sum": "9ead89601e84aa7dd341869c1d7933a583ab2794",
"download_url": "https://h10145.www1.hp.com/Downloads/DownloadSoftware.aspx?SoftwareReleaseUId=11832&ProductNumber=JG811AAE&lang=en&cc=us&prodSeriesId=5443163&OrderNumber=&PurchaseDate="
}
]
}
}

View File

@ -16,7 +16,7 @@
"adapters": 1,
"ram": 32,
"processor": "i386",
"graphics": false
"graphic": false
},
"images": {

View File

@ -20,6 +20,8 @@
import json
import sys
import os
import shlex
import subprocess
from gns3registry.image import Image
@ -99,22 +101,20 @@ class Config:
new_config["kernel_command_line"] = ""
new_config["kernel_image"] = ""
if device_config["qemu"].get("graphics", False):
if device_config["qemu"].get("graphic", False):
options = ""
else:
options = "-nographics "
options = "-nographic "
options += device_config["qemu"].get("options", "")
new_config["options"] = options.strip()
new_config["hdb_disk_image"] = ""
new_config["hdc_disk_image"] = ""
new_config["hdd_disk_image"] = ""
#TODO: Manage Windows
if device_config["qemu"]["processor"] == "i386":
new_config["qemu_path"] = "qemu-system-i386"
elif device_config["qemu"]["processor"] == "x64":
new_config["qemu_path"] = "qemu-system-x86_64"
new_config["hda_disk_image"] = device_config["qemu"].get("hda_disk_image", "")
new_config["hdb_disk_image"] = device_config["qemu"].get("hdb_disk_image", "")
new_config["hdc_disk_image"] = device_config["qemu"].get("hdc_disk_image", "")
new_config["hdd_disk_image"] = device_config["qemu"].get("hdd_disk_image", "")
new_config["qemu_path"] = self._get_qemu_binary(device_config)
if device_config["category"] == "guest":
new_config["default_symbol"] = ":/symbols/qemu_guest.normal.svg"
@ -123,7 +123,7 @@ class Config:
new_config["default_symbol"] = ":/symbols/router.normal.svg"
new_config["hover_symbol"] = ":/symbols/router.selected.svg"
disks = ["hda_disk_image", "hdb_disk_image", "hdc_disk_image", "hdd_disk_image"]
disks = ["hda_disk_image", "hdb_disk_image", "hdc_disk_image", "hdd_disk_image", "cdrom"]
for disk in disks:
if disk in device_config["images"]:
if isinstance(device_config["images"][disk], list):
@ -135,11 +135,73 @@ class Config:
new_config["name"] += " {}".format(device_config["images"][disk].version)
new_config[disk] = device_config["images"][disk].path
if device_config["qemu"].get("install_cdrom_to_hda", False):
new_config["hda_disk_image"] = self._create_qemu_img(device_config, new_config)
if "cdrom" in new_config:
self._install_qemu_cdrom(device_config, new_config)
del new_config["cdrom"]
# Remove VM with the same Name
self._config["Qemu"]["vms"] = [item for item in self._config["Qemu"]["vms"] if item["name"] != new_config["name"]]
self._config["Qemu"]["vms"].append(new_config)
def _get_qemu_binary(self, device_config):
"""
Create a blank hda disk image
:param device_config: The require device configuration
"""
#TODO: Manage Windows
if device_config["qemu"]["processor"] == "i386":
return "qemu-system-i386"
elif device_config["qemu"]["processor"] == "x64":
return "qemu-system-x86_64"
def _create_qemu_img(self, device_config, new_config):
"""
Create a blank hda disk image
:param device_config: The require device configuration
:param new_config: The GNS3 device configuration
:returns: Return new disk path
"""
#TODO: Manage error
image_path = os.path.join(self.images_dir, "QEMU", device_config["qemu"]["hda_disk_image"])
#TODO: raise an error if size is missing
cmd = ["qemu-img", "create", "-f", "qcow2", image_path, device_config["qemu"]["hda_disk_size"]]
print(" ".join(cmd))
subprocess.call(cmd)
return image_path
def _install_qemu_cdrom(self, device_config, new_config):
"""
Install the cdrom to disk
:param device_config: The require device configuration
:param new_config: The GNS3 device configuration
"""
print("Starting cdrom installation. Please follow the instructions in the qemu Windows and close qemu when install is finish in order to finish the process.")
print("\nInstall instructions:")
print(device_config["qemu"]["install_instructions"])
cmd = "{options} -cdrom {cdrom} -m {ram} {hda}".format(
options=device_config.get("options", ""),
cdrom=device_config["images"]["cdrom"].path,
ram=device_config["qemu"]["ram"],
hda=new_config["hda_disk_image"])
self._qemu_run(device_config, cmd.strip())
def _qemu_run(self, device_config, cmd):
"""
Run the qemu command
"""
cmd = shlex.split(cmd)
cmd.insert(0, self._get_qemu_binary(device_config))
print(" ".join(cmd))
subprocess.call(cmd)
def save(self):
"""
Save the configuration file

View File

@ -70,5 +70,3 @@ class Image:
m.update(buf)
self._sha1sum = m.hexdigest()
return self._sha1sum

View File

@ -19,7 +19,8 @@
import pytest
import json
from unittest.mock import MagicMock
import os
from unittest.mock import MagicMock, patch
from gns3registry.config import Config, ConfigException
from gns3registry.image import Image
@ -99,7 +100,7 @@ def test_add_images_guest(empty_config, linux_microcore_img):
"kernel_image": "",
"legacy_networking": False,
"name": "Micro Core Linux 3.4.1",
"options": "-nographics",
"options": "-nographic",
"process_priority": "normal",
"qemu_path": "qemu-system-i386",
"ram": 32,
@ -107,6 +108,52 @@ def test_add_images_guest(empty_config, linux_microcore_img):
}
def test_add_images_cdrom(empty_config, linux_microcore_img):
with open("devices/qemu/hp-vsr1001.json") as f:
config = json.load(f)
hda = os.path.join(empty_config.images_dir, "QEMU", "vsr1000-hp.img")
image = Image(linux_microcore_img)
image.version = "7.10.R0204P01"
config["images"]["cdrom"] = image
with patch("subprocess.call") as mock_qemu_img:
with patch("gns3registry.config.Config._qemu_run") as mock_qemu:
mock_qemu.return_value = hda
empty_config.add_images(config)
assert mock_qemu_img.called
args, kwargs = mock_qemu_img.call_args
assert args[0] == ["qemu-img", "create", "-f", "qcow2", hda, "8G"]
assert mock_qemu.called
args, kwargs = mock_qemu.call_args
assert args[1] == "-cdrom {} -m 1024 {}".format(image.path, hda)
assert empty_config._config["Qemu"]["vms"][0] == {
"adapter_type": "e1000",
"adapters": 16,
"category": 0,
"cpu_throttling": 0,
"default_symbol": ":/symbols/router.normal.svg",
"hda_disk_image": hda,
"hdb_disk_image": "",
"hdc_disk_image": "",
"hdd_disk_image": "",
"hover_symbol": ":/symbols/router.selected.svg",
"initrd": "",
"kernel_command_line": "",
"kernel_image": "",
"legacy_networking": False,
"name": "HP VSR1001 7.10.R0204P01",
"options": "-nographic",
"process_priority": "normal",
"qemu_path": "qemu-system-x86_64",
"ram": 1024,
"server": "local"
}
def test_add_images_router_two_disk(empty_config):
with open("devices/qemu/arista-veos.json") as f:
config = json.load(f)
@ -142,7 +189,7 @@ def test_add_images_router_two_disk(empty_config):
"kernel_image": "",
"legacy_networking": False,
"name": "Arista vEOS 2.1.0 4.13.8M",
"options": "-nographics",
"options": "-nographic",
"process_priority": "normal",
"qemu_path": "qemu-system-x86_64",
"ram": 2048,