3 # Copyright (C) 2014 Red Hat Inc.
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.
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.
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.
28 parser = argparse.ArgumentParser (
30 description='Mini virtualization cluster management tool',
35 help='specify location of the configuration file',
40 subparsers = parser.add_subparsers ()
42 mclu_build.cmdline (subparsers)
44 mclu_console.cmdline (subparsers)
46 mclu_info.cmdline (subparsers)
48 mclu_list.cmdline (subparsers)
50 mclu_migrate.cmdline (subparsers)
52 mclu_reboot.cmdline (subparsers)
54 mclu_shutdown.cmdline (subparsers)
56 mclu_start.cmdline (subparsers)
58 mclu_status.cmdline (subparsers)
60 mclu_stop.cmdline (subparsers)
62 mclu_viewer.cmdline (subparsers)
64 mclu_wake.cmdline (subparsers)
66 args = parser.parse_args()
68 # Default location of the config file if not defined on the command line:
70 config_dir = config.sysconfdir + "/" + config.PACKAGE_NAME
71 args.f = open (config_dir + "/" + "mclu.conf")
73 # config_dir is the directory containing mclu.conf
74 config_dir = os.path.dirname (args.f.name)
76 # Configuration file default settings. You cannot set defaults per
77 # section, so we have to rely on setting names not overlapping.
79 "home" : os.getenv ("HOME"),
80 "host" : "SET.THIS.IN.MCLU.CONF",
81 "config_dir" : config_dir,
82 "uri" : "qemu+ssh://root@%(host)s/system",
85 # Read the configuration file.
86 conf = ConfigParser.SafeConfigParser (conf_defaults)
89 # Global configuration.
90 images_dir = conf.get ("global", "images_dir")
91 if not os.path.isdir (images_dir):
92 sys.exit ("configuration error: [globals] 'images_dir' (%s) directory does not exist" % images_dir)
93 xmls_dir = conf.get ("global", "xmls_dir")
94 if not os.path.isdir (xmls_dir):
95 sys.exit ("configuration error: [globals] 'xmls_dir' (%s) directory does not exist", xmls_dir)
97 # Get the list of node names.
98 node_names = conf.items ("nodes")
99 node_names = filter (lambda (x, _) : re.search (r'^node', x), node_names)
100 node_names = [ value for _, value in node_names ]
102 sys.exit ("configuration error: [nodes] section in configuration file is empty")
104 # Get information about each node.
106 for node_name in node_names:
107 host = conf.get (node_name, "host")
110 mac = conf.get (node_name, "mac")
111 uri = conf.get (node_name, "uri")
112 node = Node (node_name, host, mac, uri)
113 nodes[node_name] = node
115 # A config dict with less-used configuration settings.
117 "config_file" : args.f.name,
118 "config_dir" : config_dir,
119 "images_dir" : images_dir,
120 "node_names" : node_names,
121 "xmls_dir" : xmls_dir,
126 # Run the subcommand.
127 args.run (c, args, nodes)