X-Git-Url: http://git.annexia.org/?p=virt-top.git;a=blobdiff_plain;f=virt-ctrl%2Fvc_connections.ml;h=8f5fba05dbd63119f88abcd428c177a43f93a76e;hp=c99b2c463cadac5c9119157e95d4c8b76b6c40af;hb=e6cca10e5cf86b9bd280e371fb1195835a96bff0;hpb=430d646f23385cff10f3cfe359f27226f42cf01a diff --git a/virt-ctrl/vc_connections.ml b/virt-ctrl/vc_connections.ml index c99b2c4..8f5fba0 100644 --- a/virt-ctrl/vc_connections.ml +++ b/virt-ctrl/vc_connections.ml @@ -18,6 +18,7 @@ *) open Printf +open Virt_ctrl_gettext.Gettext module C = Libvirt.Connect module D = Libvirt.Domain @@ -43,22 +44,29 @@ let get_conns, add_conn, del_conn = in get_conns, add_conn, del_conn -(* The current state. This is used so that we can see changes that - * have happened and add or remove parts of the model. (Previously - * we used to recreate the whole model each time, but the problem - * with that is we "forget" things like the selection). - *) -type state = connection list -and connection = int (* connection ID *) * (active list * inactive list) -and active = int (* domain's ID *) -and inactive = string (* domain's name *) - (* Store the node_info and hostname for each connection, fetched * once just after we connect since these don't normally change. * Hash of connid -> (C.node_info, hostname option, uri) *) let static_conn_info = Hashtbl.create 13 +let open_connection uri = + (* If this fails, let the exception escape and be printed + * in the global exception handler. + *) + let conn = C.connect ~name:uri () in + + let node_info = C.get_node_info conn in + let hostname = + try Some (C.get_hostname conn) + with + | Libvirt.Not_supported "virConnectGetHostname" + | Libvirt.Virterror _ -> None in + + (* Add it to our list of connections. *) + let conn_id = add_conn conn in + Hashtbl.add static_conn_info conn_id (node_info, hostname, uri) + (* Stores the state and history for each domain. * Hash of (connid, domid) -> mutable domhistory structure. * We never delete entries in this hash table, which may be a problem @@ -92,6 +100,16 @@ let new_domhistory () = { let hist_max = 86400 (* max history stored, seconds *) let hist_rot = 3600 (* rotation of array when we hit max *) +(* The current state. This is used so that we can see changes that + * have happened and add or remove parts of the model. (Previously + * we used to recreate the whole model each time, but the problem + * with that is we "forget" things like the selection). + *) +type state = connection list +and connection = int (* connection ID *) * (active list * inactive list) +and active = int (* domain's ID *) +and inactive = string (* domain's name *) + (* The types of the display columns in the main window. The interesting * one of the final (int) field which stores the ID of the row, either * connid or domid. @@ -384,11 +402,11 @@ let make_treeview ?packing () = view_col#set_sort_order sort_order; view_col#set_sort_column_id sort_column_id in - append_visible_column "ID" col_name_id (Some (false, `ASCENDING, 0)); - append_visible_column "Name" col_domname (Some (true, `ASCENDING, 1)); - append_visible_column "Status" col_status None; - append_visible_column "CPU" col_cpu None; - append_visible_column "Memory" col_mem None; + append_visible_column (s_ "ID") col_name_id (Some (false, `ASCENDING, 0)); + append_visible_column (s_ "Name") col_domname (Some (true, `ASCENDING, 1)); + append_visible_column (s_ "Status") col_status None; + append_visible_column (s_ "CPU") col_cpu None; + append_visible_column (s_ "Memory") col_mem None; let columns = col_name_id, col_domname, col_status, col_cpu, col_mem, col_id in @@ -396,32 +414,6 @@ let make_treeview ?packing () = (tree, model, columns, state) -(* Callback function to open a connection. - * This should be a lot more sophisticated. XXX - *) -let open_connection () = - let title = "Open connection to hypervisor" in - let uri = - GToolbox.input_string ~title ~text:"xen:///" ~ok:"Open" "Connection:" in - match uri with - | None -> () - | Some uri -> - (* If this fails, let the exception escape and be printed - * in the global exception handler. - *) - let conn = C.connect ~name:uri () in - - let node_info = C.get_node_info conn in - let hostname = - try Some (C.get_hostname conn) - with - | Libvirt.Not_supported "virConnectGetHostname" - | Libvirt.Virterror _ -> None in - - (* Add it to our list of connections. *) - let conn_id = add_conn conn in - Hashtbl.add static_conn_info conn_id (node_info, hostname, uri) - (* Get historical data size. *) let get_hist_size connid domid = try