summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Alcantara <paulo@paulo.ac>2018-05-24 16:45:27 -0300
committerPaulo Alcantara <paulo@paulo.ac>2018-05-24 16:45:27 -0300
commitd99fc5abe5475add91e5457910b2aa2f7ee7879c (patch)
treecd4997ec3a0770e2f19ff707a69bc38d93546a2d
parent7b9fe4b24a3ac98edda6fe98b0251596c7b76fce (diff)
downloadvmhtool-d99fc5abe5475add91e5457910b2aa2f7ee7879c.tar.gz
vmhtool-d99fc5abe5475add91e5457910b2aa2f7ee7879c.tar.xz
vmhtool-d99fc5abe5475add91e5457910b2aa2f7ee7879c.zip
Introduce do_run_vm()
Get rid of duplicate code when printing out info about a running guest. Signed-off-by: Paulo Alcantara <paulo@paulo.ac>
-rwxr-xr-xvmhelper39
1 files changed, 21 insertions, 18 deletions
diff --git a/vmhelper b/vmhelper
index 2d1fab8..32041fb 100755
--- a/vmhelper
+++ b/vmhelper
@@ -392,6 +392,23 @@ sub get_vm_macaddr {
return $ret;
}
+sub do_run_vm {
+ my $cmd = shift;
+
+ my $ipaddr = !$vm_conf_opts{'TAP_IP_ADDR'} ? "0.0.0.0" : "$vm_conf_opts{'TAP_IP_ADDR'}";
+
+ print "[*] run $vm_name guest\n";
+ print "[*] ipaddr: " . resolve_name($vm_name) . "\n";
+ print "[*] macaddr: " . get_vm_macaddr() . "\n";
+ print "[*] host iface: " . ($bridge_enabled ? $bridge_iface : $tap_bridge_iface) . " ($ipaddr)\n";
+ print "[*] vm iface: " . "$tap_iface\n";
+ print "[*] cmd: " . "$cmd\n";
+
+ my $ret = system($cmd);
+ print "\n[*] done\n" if !$ret;
+ return $ret;
+}
+
if ($cmd_opts{install_iso_path}) {
create_guest_img($vm_img_path);
@@ -428,14 +445,10 @@ if ($cmd_opts{install_iso_path}) {
$qemu_cmd .= " $qemu_linux_opts{'mon'}";
}
- print "[*] install $vm_name vm\n";
- print "[*] macaddr: $macaddr\n";
- print "[*] cmd: $qemu_cmd\n";
- if (system($qemu_cmd)) {
+ if (do_run_vm($qemu_cmd)) {
destroy_vm_net();
die "failed to exec cmd: $qemu_cmd";
}
- print "[*] done\n";
save_vm_info($vm_name, $macaddr);
destroy_vm_net();
@@ -474,17 +487,12 @@ if ($cmd_opts{windows_guest}) {
" $qemu_win_opts{'gfx'}";
$qemu_cmd .= " $qemu_win_opts{'mon'}";
- print "[*] $vm_name is up and running\n";
- print "[*] ipaddr: " . resolve_name($vm_name) . "\n";
- print "[*] macaddr: " . get_vm_macaddr() . "\n";
- print "[*] cmd: $qemu_cmd\n";
- if (system($qemu_cmd)) {
+ if (do_run_vm($qemu_cmd)) {
destroy_vm_net();
die "failed to exec cmd: $qemu_cmd";
}
- print "\n[*] done\n";
- destroy_vm_net();
+ destroy_vm_net();
exit 0;
}
@@ -661,15 +669,10 @@ if ($cmd_opts{kernel_path}) {
$qemu_cmd .= " -display none" if $cmd_opts{nographic};
}
-print "[*] $vm_name vm is up and running\n";
-print "[*] ipaddr: " . resolve_name($vm_name) . "\n";
-print "[*] macaddr: " . get_vm_macaddr() . "\n";
-print "[*] cmd: $qemu_cmd\n";
-if (system($qemu_cmd)) {
+if (do_run_vm($qemu_cmd)) {
$err = "failed to exec cmd: $qemu_cmd";
goto OUT;
}
-print "\n[*] done\n";
OUT:
rem_shared_dirs();