1 (* virt-manager-like graphical management tool.
2 (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
4 $Id: mlvirtmanager_domain_ops.ml,v 1.1 2007/08/06 10:16:53 rjones Exp $
6 Domain operations buttons.
11 module C = Libvirt.Connect
12 module D = Libvirt.Domain
13 module N = Libvirt.Network
15 (* Get the selected domain (if there is one) or return None. *)
16 let get_domain (tree : GTree.view) (model : GTree.tree_store)
17 (columns : Mlvirtmanager_connections.columns) =
18 let path, _ = tree#get_cursor () in
20 | None -> None (* No row at all selected. *)
22 let row = model#get_iter path in
23 (* Visit parent to get the conn_id.
24 * If this returns None, then it's a top-level row which is
25 * selected (ie. a connection), so just ignore.
27 match model#iter_parent row with
31 let (_, col_domname, _, _, _, col_id) = columns in
32 let conn_id = model#get ~row:parent ~column:col_id in
34 List.assoc conn_id (Mlvirtmanager_connections.get_conns ()) in
35 let domid = model#get ~row ~column:col_id in
36 if domid = -1 then ( (* Inactive domain. *)
37 let domname = model#get ~row ~column:col_domname in
38 let dom = D.lookup_by_name conn domname in
39 let info = D.get_info dom in
41 ) else if domid > 0 then ( (* Active domU. *)
42 let dom = D.lookup_by_id conn domid in
43 let info = D.get_info dom in
44 Some (dom, info, domid)
45 ) else (* Dom0 - ignore. *)
48 (* Domain or connection disappeared under us. *)
53 | Libvirt.Virterror err ->
54 prerr_endline (Libvirt.Virterror.to_string err);
57 let start_domain tree model columns () =
58 match get_domain tree model columns with
60 | Some (dom, _, domid) ->
64 let pause_domain tree model columns () =
65 match get_domain tree model columns with
67 | Some (dom, info, domid) ->
68 if domid >= 0 && info.D.state <> D.InfoPaused then
71 let resume_domain tree model columns () =
72 match get_domain tree model columns with
74 | Some (dom, info, domid) ->
75 if domid >= 0 && info.D.state = D.InfoPaused then
78 let shutdown_domain tree model columns () =
79 match get_domain tree model columns with
81 | Some (dom, info, domid) ->
82 if domid >= 0 && info.D.state <> D.InfoShutdown then