forked from LNST-project/lnst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lnst-pool-wizard
executable file
·90 lines (76 loc) · 2.54 KB
/
lnst-pool-wizard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#! /usr/bin/env python2
"""
Machine pool wizard
Copyright 2014 Red Hat, Inc.
Licensed under the GNU General Public License, version 2 as
published by the Free Software Foundation; see COPYING for details.
"""
__author__ = """
[email protected] (Jiri Prochazka)
"""
from lnst.Controller.Wizard import Wizard
import sys
import getopt
RETVAL_PASS = 0
RETVAL_ERR = 1
def help(retval=0):
print "Usage:\n"\
" lnst-pool-wizard [mode] [hostname[:port]]\n"\
"\n"\
"Modes:\n"\
" -h, --help display this help text and exit\n"\
" -p, --pool_dir <directory> set the pool dir (works both in) "\
"interactive and noninteractive mode\n"\
" -i, --interactive start wizard in interactive mode (this "\
"is default mode)\n"\
" -n, --noninteractive start wizard in noninteractive mode\n"\
" -v, --virtual start wizard in mode for VMs\n"\
"Examples:\n"\
" lnst-pool-wizard --interactive\n"\
" lnst-pool-wizard --noninteractive 192.168.122.2\n"\
" lnst-pool-wizard -n 192.168.122.2:8888 192.168.122.4\n"\
" lnst-pool-wizard -p \".pool/\" -n 192.168.1.1:8877 192.168.122.4"
sys.exit(retval)
def main():
try:
opts, args = getopt.getopt(
sys.argv[1:],
"hinvp:",
["help", "interactive", "noninteractive", "virtual", "pool_dir="]
)
except getopt.GetoptError as err:
sys.stderr.write(str(err))
help(RETVAL_ERR)
pool_dir = None
mode = "interactive"
for opt, arg in opts:
if opt in ("-h", "--help"):
help()
elif opt in ("-i", "--interactive"):
mode = "interactive"
elif opt in ("-n", "--noninteractive"):
if not args:
sys.stderr.write("No hostnames entered\n")
return RETVAL_ERR
else:
hostlist = args
mode = "noninteractive"
elif opt in ("-v", "--virtual"):
mode = "virtual"
elif opt in ("-p", "--pool_dir"):
if not arg:
sys.stderr.write("No pool directory specified\n")
else:
pool_dir = arg
else:
help(RETVAL_ERR)
wizard = Wizard()
if mode == "noninteractive":
wizard.noninteractive(hostlist, pool_dir)
elif mode == "virtual":
wizard.virtual(pool_dir)
else:
wizard.interactive(pool_dir)
sys.exit(RETVAL_PASS)
if __name__ == "__main__":
main()