mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Linked clone support for VirtualBox (still problems with temporary projects).
This commit is contained in:
parent
2509ee70e8
commit
5a7e482dac
@ -197,7 +197,7 @@ class VirtualBox(IModule):
|
|||||||
self._working_dir = new_working_dir
|
self._working_dir = new_working_dir
|
||||||
for vbox_id in self._vbox_instances:
|
for vbox_id in self._vbox_instances:
|
||||||
vbox_instance = self._vbox_instances[vbox_id]
|
vbox_instance = self._vbox_instances[vbox_id]
|
||||||
vbox_instance.working_dir = os.path.join(self._working_dir, "vbox", "vm-{}".format(vbox_instance.id))
|
vbox_instance.working_dir = os.path.join(self._working_dir, "vbox", "{}".format(vbox_instance.name))
|
||||||
|
|
||||||
if "vboxmanage_path" in request:
|
if "vboxmanage_path" in request:
|
||||||
self._vboxmanage_path = request["vboxmanage_path"]
|
self._vboxmanage_path = request["vboxmanage_path"]
|
||||||
|
@ -303,7 +303,7 @@ class VirtualBoxVM(object):
|
|||||||
for hdd_info in hdd_table:
|
for hdd_info in hdd_table:
|
||||||
hdd_file = os.path.join(self._working_dir, self._vmname, "Snapshots", hdd_info["hdd"])
|
hdd_file = os.path.join(self._working_dir, self._vmname, "Snapshots", hdd_info["hdd"])
|
||||||
if os.path.exists(hdd_file):
|
if os.path.exists(hdd_file):
|
||||||
print("Reattaching: {}".format(hdd_file))
|
log.debug("reattaching hdd {}".format(hdd_file))
|
||||||
self._storage_attach('--storagectl {} --port {} --device {} --type hdd --medium "{}"'.format(hdd_info["controller"],
|
self._storage_attach('--storagectl {} --port {} --device {} --type hdd --medium "{}"'.format(hdd_info["controller"],
|
||||||
hdd_info["port"],
|
hdd_info["port"],
|
||||||
hdd_info["device"],
|
hdd_info["device"],
|
||||||
@ -322,36 +322,37 @@ class VirtualBoxVM(object):
|
|||||||
self._allocated_console_ports.remove(self.console)
|
self._allocated_console_ports.remove(self.console)
|
||||||
|
|
||||||
if self._linked_clone:
|
if self._linked_clone:
|
||||||
hdd_table = []
|
if os.path.exists(self._working_dir):
|
||||||
hdd_files = self._get_all_hdd_files()
|
hdd_table = []
|
||||||
vm_info = self._get_vm_info()
|
hdd_files = self._get_all_hdd_files()
|
||||||
for entry, value in vm_info.items():
|
vm_info = self._get_vm_info()
|
||||||
match = re.search("^(\w+)\-(\d)\-(\d)$", entry)
|
for entry, value in vm_info.items():
|
||||||
if match:
|
match = re.search("^(\w+)\-(\d)\-(\d)$", entry)
|
||||||
controller = match.group(1)
|
if match:
|
||||||
port = match.group(2)
|
controller = match.group(1)
|
||||||
device = match.group(3)
|
port = match.group(2)
|
||||||
if value in hdd_files:
|
device = match.group(3)
|
||||||
self._storage_attach("--storagectl {} --port {} --device {} --type hdd --medium none".format(controller, port, device))
|
if value in hdd_files:
|
||||||
hdd_table.append(
|
self._storage_attach("--storagectl {} --port {} --device {} --type hdd --medium none".format(controller, port, device))
|
||||||
{
|
hdd_table.append(
|
||||||
"hdd": os.path.basename(value),
|
{
|
||||||
"controller": controller,
|
"hdd": os.path.basename(value),
|
||||||
"port": port,
|
"controller": controller,
|
||||||
"device": device,
|
"port": port,
|
||||||
}
|
"device": device,
|
||||||
)
|
}
|
||||||
|
)
|
||||||
|
|
||||||
self._execute("unregistervm", [self._vmname])
|
self._execute("unregistervm", [self._vmname])
|
||||||
print(self._working_dir)
|
|
||||||
try:
|
|
||||||
hdd_info_file = os.path.join(self._working_dir, self._vmname, "hdd_info.json")
|
|
||||||
with open(hdd_info_file, "w") as f:
|
|
||||||
#log.info("saving project: {}".format(path))
|
|
||||||
json.dump(hdd_table, f, indent=4)
|
|
||||||
except OSError as e:
|
|
||||||
raise VirtualBoxError("Could not write HDD info file: {}".format(e))
|
|
||||||
|
|
||||||
|
if hdd_table:
|
||||||
|
try:
|
||||||
|
hdd_info_file = os.path.join(self._working_dir, self._vmname, "hdd_info.json")
|
||||||
|
with open(hdd_info_file, "w") as f:
|
||||||
|
#log.info("saving project: {}".format(path))
|
||||||
|
json.dump(hdd_table, f, indent=4)
|
||||||
|
except OSError as e:
|
||||||
|
raise VirtualBoxError("Could not write HDD info file: {}".format(e))
|
||||||
|
|
||||||
|
|
||||||
log.info("VirtualBox VM {name} [id={id}] has been deleted".format(name=self._name,
|
log.info("VirtualBox VM {name} [id={id}] has been deleted".format(name=self._name,
|
||||||
@ -743,6 +744,9 @@ class VirtualBoxVM(object):
|
|||||||
self._modify_vm("--nic{} none".format(adapter_id + 1))
|
self._modify_vm("--nic{} none".format(adapter_id + 1))
|
||||||
|
|
||||||
def _create_linked_clone(self):
|
def _create_linked_clone(self):
|
||||||
|
"""
|
||||||
|
Creates a new linked clone.
|
||||||
|
"""
|
||||||
|
|
||||||
gns3_snapshot_exists = False
|
gns3_snapshot_exists = False
|
||||||
vm_info = self._get_vm_info()
|
vm_info = self._get_vm_info()
|
||||||
@ -752,8 +756,7 @@ class VirtualBoxVM(object):
|
|||||||
|
|
||||||
if not gns3_snapshot_exists:
|
if not gns3_snapshot_exists:
|
||||||
result = self._execute("snapshot", [self._vmname, "take", "GNS3 Linked Base for clones"])
|
result = self._execute("snapshot", [self._vmname, "take", "GNS3 Linked Base for clones"])
|
||||||
print(result)
|
log.debug("GNS3 snapshot created: {}".format(result))
|
||||||
#log.debug("cloned VirtualBox VM: {}".format(result))
|
|
||||||
|
|
||||||
args = [self._vmname,
|
args = [self._vmname,
|
||||||
"--snapshot",
|
"--snapshot",
|
||||||
|
Loading…
Reference in New Issue
Block a user