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.
40 parser = argparse.ArgumentParser (
42 description='Mini virtualization cluster management tool',
47 help='specify location of the configuration file',
52 subparsers = parser.add_subparsers ()
53 mclu_build.cmdline (subparsers)
54 mclu_console.cmdline (subparsers)
55 mclu_import.cmdline (subparsers)
56 mclu_info.cmdline (subparsers)
57 mclu_list.cmdline (subparsers)
58 mclu_migrate.cmdline (subparsers)
59 mclu_off.cmdline (subparsers)
60 mclu_on.cmdline (subparsers)
61 mclu_reboot.cmdline (subparsers)
62 mclu_start.cmdline (subparsers)
63 mclu_status.cmdline (subparsers)
64 mclu_stop.cmdline (subparsers)
65 mclu_viewer.cmdline (subparsers)
67 args = parser.parse_args()
69 # Default location of the config file if not defined on the command line:
71 config_dir = config.sysconfdir + "/" + config.PACKAGE_NAME
72 args.f = open (config_dir + "/" + "mclu.conf")
74 # config_dir is the directory containing mclu.conf
75 config_dir = os.path.dirname (args.f.name)
77 # Configuration file default settings. You cannot set defaults per
78 # section, so we have to rely on setting names not overlapping.
80 "home" : os.getenv ("HOME"),
81 "config_dir" : config_dir,
84 # Read the configuration file.
85 conf = ConfigParser.SafeConfigParser (conf_defaults)
88 # Global configuration.
89 images_dir = conf.get ("global", "images_dir")
90 if not os.path.isdir (images_dir):
91 sys.exit ("configuration error: [globals] 'images_dir' (%s) directory does not exist" % images_dir)
92 xmls_dir = conf.get ("global", "xmls_dir")
93 if not os.path.isdir (xmls_dir):
94 sys.exit ("configuration error: [globals] 'xmls_dir' (%s) directory does not exist", xmls_dir)
95 nodes_group = conf.get ("global", "nodes_group")
97 # A config dict with less-used configuration settings.
99 "config_file" : args.f.name,
100 "config_dir" : config_dir,
101 "images_dir" : images_dir,
102 "nodes_group" : nodes_group,
103 "xmls_dir" : xmls_dir,
108 # Run the subcommand.