From 1fe5a3afcc1bfd6a15eef5d20215267d144a205c Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Include and (required for Xen hypervisor). --- virt-p2v | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/virt-p2v b/virt-p2v index 20baf62..6133595 100755 --- a/virt-p2v +++ b/virt-p2v @@ -563,6 +563,22 @@ let rewrite_fstab state devices_to_send = close_out chan ) +let () = Random.self_init () + +let random_mac_address () = + let random = + List.map (sprintf "%02x") ( + List.map (fun _ -> Random.int 256) [0;0;0] + ) in + String.concat ":" ("00"::"16"::"3e"::random) + +let random_uuid = + let hex = "0123456789abcdef" in + fun () -> + let str = String.create 32 in + for i = 0 to 31 do str.[i] <- hex.[Random.int 16] done; + str + (* Main entry point. *) let rec main ttyname = (* Running from an init script. We don't have much of a @@ -1319,12 +1335,7 @@ MAC address: %s" | Some n -> n in let mac_address = match state.mac_address with - | Some "" | None -> - let random = - List.map (sprintf "%02x") ( - List.map (fun _ -> Random.int 256) [0;0;0] - ) in - String.concat ":" ("00"::"16"::"3e"::random) + | Some "" | None -> random_mac_address () | Some mac -> mac in let xml = @@ -1335,6 +1346,8 @@ MAC address: %s" (* Standard stuff for every domain. *) let name = leaf "name" hostname in + let uuid = leaf "uuid" (random_uuid ()) in + let maxmem = leaf "maxmem" (string_of_int (memory * 1024)) in let memory = leaf "memory" (string_of_int (memory * 1024)) in let vcpu = leaf "vcpu" (string_of_int vcpus) in @@ -1413,7 +1426,7 @@ MAC address: %s" | Some QEMU -> ["type", "qemu"] | Some KVM -> ["type", "kvm"] | None -> []), - name :: memory :: vcpu :: extras @ [devices] + name :: uuid :: memory :: maxmem :: vcpu :: extras @ [devices] ) in (* Convert XML configuration file to a string, then send it to the -- 1.8.3.1