From 4b59a9e67994b88c9ff8e2db7ec81ef49d5124ef Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Daily update --- virt-p2v | 74 ++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/virt-p2v b/virt-p2v index 36b186c..269bbe2 100755 --- a/virt-p2v +++ b/virt-p2v @@ -41,6 +41,7 @@ type ssh_config = { ssh_directory : string; (* Remote directory. *) ssh_username : string; (* Remote username. *) ssh_password : string; (* Remote password/passphrase. *) + ssh_compression : bool; (* If true, use SSH compression. *) ssh_check : bool; (* If true, check SSH is working. *) ssh_libvirtd : bool; (* If true, contact remote libvirtd. *) } @@ -93,7 +94,6 @@ let config_architecture = ref None let config_memory = ref None let config_vcpus = ref None let config_mac_address = ref None -let config_compression = ref None (* The name of the program as displayed in various places. *) let program_name = "virt-p2v" @@ -456,6 +456,25 @@ let remote_of_origin_dev = fun dev -> Pcre.replace ~rex:devsd ~itempl:devsd_subst dev +(* Make an SSH connection to the remote machine. *) +(* +let ssh_connect config = + let cmd = sprintf "ssh%s -l %s -p %s %s" XXXXX + (if config.ssh_compression then " -C" else "") + (quote config.ssh_username) + (quote config.ssh_port) + (quote config.ssh_host) in + eprintf "ssh_connect: %s\n%!" cmd; + let chan = open_process_out cmd in + descr_of_out_channel chan, chan + +let ssh_disconnect (_, chan) = + match close_process_out chan with + | WEXITED 0 -> () (* OK *) + | WEXITED i -> failwith (sprintf "ssh: exited with error code %d" i) + | WSIGNALED i -> failwith (sprintf "ssh: killed by signal %d" i) + | WSTOPPED i -> failwith (sprintf "ssh: stopped by signal %d" i)*) + (* Rewrite /mnt/root/etc/fstab. *) let rewrite_fstab state devices_to_send = let filename = "/mnt/root/etc/fstab" in @@ -588,8 +607,7 @@ let rec main ttyname = "You should only run this script from the live CD or a USB key."; (* Start of the information gathering phase. *) - printf "%s detecting hard drives (this may take some time) ...\n%!" - program_name; + printf "Detecting hard drives (this may take some time) ...\n%!"; (* Search for all non-removable block devices. Do this early and bail * if we can't find anything. This is a list of strings, like "hda". @@ -784,7 +802,7 @@ let rec main ttyname = ) all_partitions in - printf "finished detecting hard drives\n%!"; + printf "Finished detecting hard drives.\n%!"; (* Autodetect system memory. *) let system_memory = @@ -1055,7 +1073,7 @@ let rec main ttyname = | None -> (* Query the user for SSH configuration. *) open_centered_window ~stage:"SSH configuration" - 60 15 "SSH configuration"; + 60 20 "SSH configuration"; let label1 = Newt.label 1 1 "Remote host" in let host = Newt.entry 20 1 None 36 [] in @@ -1066,11 +1084,15 @@ let rec main ttyname = let label4 = Newt.label 1 4 "SSH username" in let user = Newt.entry 20 4 (Some "root") 16 [] in let label5 = Newt.label 1 5 "SSH password" in - let pass = Newt.entry 20 5 None 16 [] in + let pass = Newt.entry 20 5 None 16 [Newt.PASSWORD] in + + let compr = + Newt.checkbox 16 7 "Use SSH compression (not good for LANs)" + ' ' None in - let check = Newt.checkbox 17 7 "Test SSH connection" '*' None in + let check = Newt.checkbox 16 9 "Test SSH connection" '*' None in let libvirtd = - Newt.checkbox 17 8 "libvirtd is running on host" '*' None in + Newt.checkbox 16 10 "libvirtd is running on host" '*' None in Newt.component_add_callback check (fun () -> @@ -1082,12 +1104,12 @@ let rec main ttyname = ) ); - let ok = Newt.button 48 11 " OK " in + let ok = Newt.button 48 16 " OK " in let form = Newt.form None None [] in Newt.form_add_components form [label1;label2;label3;label4;label5]; Newt.form_add_components form [host;port;dir;user;pass]; - Newt.form_add_components form [check;libvirtd]; + Newt.form_add_components form [compr;check;libvirtd]; Newt.form_add_component form ok; let c = @@ -1099,12 +1121,14 @@ let rec main ttyname = let dir = Newt.entry_get_value dir in let user = Newt.entry_get_value user in let pass = Newt.entry_get_value pass in + let compr = Newt.checkbox_get_value compr = '*' in let check = Newt.checkbox_get_value check = '*' in let libvirtd = Newt.checkbox_get_value libvirtd = '*' in if host <> "" && port > 0 && port < 65536 && user <> "" then { ssh_host = host; ssh_port = port; ssh_directory = dir; ssh_username = user; ssh_password = pass; + ssh_compression = compr; ssh_check = check; ssh_libvirtd = libvirtd } else loop () @@ -1117,6 +1141,18 @@ let rec main ttyname = c ) in + (* If asked, check the SSH connection. At the same time + * grab the capabilities from the remote host. + *) + let capabilities = + if config_ssh.ssh_check then ( + printf "Testing SSH connection.\n\n"; + + Some "foo" + + + ) + else None in (* @@ -1454,24 +1490,6 @@ Compression: %b" let remote_directory = Option.get state.remote_directory in let remote_username = Option.get state.remote_username in - (* Functions to connect and disconnect from the remote system. *) - let do_connect remote_name _ = - let cmd = sprintf "ssh%s -l %s -p %s %s \"cat > %s/%s\"" - (if state.compression = Some false then "" else " -C") - (quote remote_username) (quote remote_port) (quote remote_host) - (quote remote_directory) (quote remote_name) in - eprintf "connect: %s\n%!" cmd; - let chan = open_process_out cmd in - descr_of_out_channel chan, chan - in - let do_disconnect (_, chan) = - match close_process_out chan with - | WEXITED 0 -> () (* OK *) - | WEXITED i -> failwith (sprintf "ssh: exited with error code %d" i) - | WSIGNALED i -> failwith (sprintf "ssh: killed by signal %d" i) - | WSTOPPED i -> failwith (sprintf "ssh: stopped by signal %d" i) - in - (* XXX This is using the hostname derived from network configuration * above. We might want to ask the user to choose. *) -- 1.8.3.1