mclu build: Print the node that we started the guest on.
[mclu.git] / mclu_list.py
1 #!/usr/bin/python
2 # mclu (mini cluster)
3 # Copyright (C) 2014 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 import argparse
20 import libvirt
21
22 import lib
23
24 def cmdline (subparsers):
25     p = subparsers.add_parser (
26         'list',
27         help='list virtual machines',
28     )
29     p.add_argument (
30         '--running', action='store_const', const=True,
31         help='list only running VMs'
32     )
33     p.add_argument (
34         '--inactive', action='store_const', const=True,
35         help='list only inactive VMs'
36     )
37     p.set_defaults (run=run)
38
39 def run (c, args, nodes):
40     show_running = True
41     show_inactive = True
42     if not args.running or not args.inactive:
43         if args.running:
44             show_running = True
45             show_inactive = False
46         if args.inactive:
47             show_running = False
48             show_inactive = True
49
50     running, inactive = lib.get_all_guests (c, nodes.values ())
51
52     if show_running:
53         for guest in running.values():
54             node_name = guest['node'].name
55             dom_name = guest['dom'].name()
56             dom_state = lib.pretty_run_status (guest['dom'].state()[0])
57             print "%s:%s\t%s" % (node_name, dom_name, dom_state)
58
59     if show_inactive:
60         for name in inactive.values():
61             print "%s\tinactive" % name