+ | Static (interface, address, netmask, gateway, nameserver) ->
+ printf "Trying static network configuration.\n\n%!";
+ if not (static_network
+ (interface, address, netmask, gateway, nameserver)) then (
+ printf "\nAuto-configuration failed. Starting a shell.\n\n";
+ printf "Please configure the network from this shell.\n\n";
+ printf "When you have finished, exit the shell with ^D or exit.\n\n";
+ shell ()
+ )
+
+ | Auto rootfs ->
+ printf
+ "Trying network auto-configuration from root filesystem ...\n\n%!";
+
+ (* Mount the root filesystem read-only under /mnt/root. *)
+ sh ("mount -o ro " ^ quote (dev_of_partition rootfs) ^ " /mnt/root");
+
+ if not (auto_network ()) then (
+ printf "\nAuto-configuration failed. Starting a shell.\n\n";
+ printf "Please configure the network from this shell.\n\n";
+ printf "When you have finished, exit the shell with ^D or exit.\n\n";
+ shell ()
+ );
+
+ (* NB. Lazy unmount is required because dhclient keeps its current
+ * directory open on /etc/sysconfig/network-scripts/
+ *)
+ sh ("umount -l /mnt/root");
+
+ | QEMUUserNet ->
+ printf "Trying QEMU network configuration.\n\n%!";
+ qemu_network ()
+
+ | NoNetwork -> (* this is easy ... *) ()
+ );
+
+ (* SSH configuration phase. *)
+ let config_ssh =
+ with_newt (
+ fun () ->
+ match !config_ssh with
+ | Some c -> c
+ | None ->
+ (* Query the user for SSH configuration. *)
+ open_centered_window ~stage:"SSH configuration"
+ 60 20 "SSH configuration";
+
+ let label1 = Newt.label 1 1 "Remote host" in
+ let host = Newt.entry 20 1 None 36 [] in
+ let label2 = Newt.label 1 2 "Remote port" in
+ let port = Newt.entry 20 2 (Some "22") 6 [] in
+ let label3 = Newt.label 1 3 "Remote directory" in
+ let dir = Newt.entry 20 3 (Some "/var/lib/xen/images") 36 [] in
+ 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 [Newt.PASSWORD] in
+
+ let compr =
+ Newt.checkbox 16 7 "Use SSH compression (not good for LANs)"
+ ' ' None in
+
+ let check = Newt.checkbox 16 9 "Test SSH connection" '*' None in
+ let libvirtd =
+ Newt.checkbox 16 10 "libvirtd is running on host" '*' None in
+
+ Newt.component_add_callback check
+ (fun () ->
+ if Newt.checkbox_get_value check = '*' then
+ Newt.component_takes_focus libvirtd true
+ else (
+ Newt.component_takes_focus libvirtd false;
+ Newt.checkbox_set_value libvirtd ' '
+ )
+ );
+
+ 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 [compr;check;libvirtd];
+ Newt.form_add_component form ok;
+
+ let c =
+ let rec loop () =
+ ignore (Newt.run_form form);
+ try
+ let host = Newt.entry_get_value host in
+ let port = int_of_string (Newt.entry_get_value port) in
+ 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 ()
+ with
+ Failure "int_of_string" -> loop ()
+ in
+ loop () in
+
+ Newt.pop_window ();
+ 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
+
+(*