Open candlerb opened 6 years ago
This specific issue is covered by the more generic request https://github.com/GNS3/gns3-gui/issues/1095 which should allow export of configs from all Qemu appliances.
@cioby23: I think that IOSv / IOU need to be handled specially, because they need the binary blob NVRAM file converting to text on export, and back from text to blob on import.
Fortunately, GNS3 already has the libraries for converting the nvram file. Here is a manual process I've tested for exporting IOSv / IOSvL2 configs to /tmp/config
(the node must be stopped first!)
cd <node directory>
virt-cat -a hda_disk.qcow2 -m /dev/sda1:/ /nvram >/tmp/nvram
PYTHONPATH=$(echo /usr/share/gns3/gns3-server/lib/*/site-packages) python3 \
-m gns3server.compute.iou.utils.iou_export /tmp/nvram /tmp/config
And to import back again:
PYTHONPATH=$(echo /usr/share/gns3/gns3-server/lib/*/site-packages) python3 \
-m gns3server.compute.iou.utils.iou_import -c 512 /tmp/nvram /tmp/config
guestfish -a hda_disk.qcow2 -m /dev/sda1:/ -- upload /tmp/nvram /nvram
I imagine something similar is already being done for dynamips.
The tricky part is accessing the disk image file safely (without loopback mounting as root) - I used guestfish in the examples above.
Since it's MSDOS vfat format, other options may be possible, such as mtools - but it doesn't work directly with qcow2 files.
$ qemu-img convert -O raw hda_disk.qcow2 tmp.img # ugh, creates (sparse) 2GB file
$ echo 'drive z: file="tmp.img" partition=1' >~/.mtoolsrc
$ mdir z:
Start position mismatch for partition 1
End position mismatch for partition 1
Warning: inconsistent partition table
Possibly unpartitioned device
*** Maybe try without partition=1 in device definition ***
If this is a PCMCIA card, or a disk partitioned on another computer, this message may be in error: add mtools_skip_check=1 to your .mtoolsrc file to suppress this warning
Volume in drive Z has no label
Volume Serial Number is FE29-1AF7
Directory for Z:/
BOOT <DIR> 2013-01-30 0:00 boot
CONFIG <DIR> 2013-10-14 0:00 config
CONFIG~1 GRU 419 2019-10-16 18:58 config.grub
VIOS-A~1 148955508 2018-08-01 0:00 vios-adventerprisek9-m
NVRAM 524288 2019-10-16 19:11 nvram
IOS_CO~1 TXT 1803 2019-10-10 16:53 ios_config.txt
E1000_~1 TXT 79 2019-10-16 18:58 e1000_bia.txt
7 files 149 482 097 bytes
1 988 620 288 bytes free
There might be userland libraries for qcow2 and vfat which could be combined, but I've not looked into this. It would also need to understand partitions.
Icing on the cake would be if the GUI allowed the config to be exported into a window, edited there, and re-imported when you click Save. This is useful especially for password recovery, when someone has forgotten the password to their config :-)
As an interim measure I've written a CGI tool [^1] for manipulating IOSv/IOSvL2 stored configs directly within the (stopped!) qemu disk image, using python3-guestfs to automate the steps shown manually before.
It supports the following use cases:
The number one use case I have for export/import of configs is to be able to reset passwords where students have forgotten them! Hence being able to edit and re-import individual configs within the browser is very convenient - as opposed to downloading a config or bundle of configs and unzipping/editing on the client.
Having similar functionality integrated into GNS3 would be awesome. You're free to use anything which is useful from this code - the short section which uses guestfs is probably the most interesting.
[^1] https://gist.github.com/candlerb/30ba057b9d91a738a893dafc0c282723
To use this tool, the CGI needs to run as the same user ID as gns3-server, so as to have appropriate permissions. I do this using suexec:
sudo apt-get install python3-guestfs apache2 apache2-suexec-pristine unzip
sudo a2enmod cgi suexec userdir
sudo chmod +r /boot/vmlinuz-* # required for libguestfs to work
Create /etc/apache2/conf-enabled/usercgi.conf
containing:
<Directory "/home/*/public_html/cgi-bin/">
Options ExecCGI
SetHandler cgi-script
</Directory>
and restart apache.
Then install the script as ~/public_html/cgi-bin/gns3man
for whatever user gns3-server runs as. Target URL is http://x.x.x.x/~username/cgi-bin/gns3man
Platform: server 2.1.3 running on Ubuntu 16.04, GUI 2.1.3 running on macOS.
To replicate:
Tools > Import/Export Node Configs > Export configs to a directory
What happens is:
host1-campus1_etc_network_interfaces
, where host1-campus1 is one of the devices in the topology.Given that export via the GUI didn't work, I didn't try import.
BTW, I used the IOSv/IOSvL2 appliances from the marketplace, adjusting only the filenames and md5 checksums to match the specific images I have available.
I notice that GNS3 includes scripts for exporting/importing IOU configs, and these work with IOSv.
Using these, I got manual import to work - using the python script to import the text config as an nvram file, and uploading it to
/nvram
using guestfish. Actually, I found it works like that for IOSvL2, but with IOSv the NVRAM config is ignored, and I get the following error during bootup:However if I copy both
/nvram
and/ios_config.txt
(the latter just being the source text config), then the config loads but I get this message:I'm not sure why IOSv and IOSvL2 would behave differently; maybe it's because of the specific versions I'm working with?