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
| 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 =
(* 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
| 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