Revision 9f13fc7a tools/burnin
b/tools/burnin | ||
---|---|---|
10 | 10 |
from ganeti import constants |
11 | 11 |
from ganeti import cli |
12 | 12 |
from ganeti import logger |
13 |
from ganeti import errors |
|
14 |
from ganeti import utils |
|
13 | 15 |
|
14 |
USAGE = ("\tburnin [options] instance_name ...")
|
|
16 |
USAGE = ("\tburnin -o OS_NAME [options...] instance_name ...")
|
|
15 | 17 |
|
16 | 18 |
def Usage(): |
17 | 19 |
"""Shows program usage information and exits the program.""" |
... | ... | |
50 | 52 |
parser.add_option("-v", "--verbose", |
51 | 53 |
action="store_true", dest="verbose", default=False, |
52 | 54 |
help="print command execution messages to stdout") |
55 |
parser.add_option("--do-replace1", dest="do_replace1", |
|
56 |
help="Do disk replacement with the same secondary", |
|
57 |
action="store_false", default=True) |
|
58 |
parser.add_option("--do-replace2", dest="do_replace2", |
|
59 |
help="Do disk replacement with a different secondary", |
|
60 |
action="store_false", default=True) |
|
61 |
parser.add_option("--do-failover", dest="do_failover", |
|
62 |
help="Do instance failovers", action="store_false", |
|
63 |
default=True) |
|
53 | 64 |
|
54 | 65 |
options, args = parser.parse_args() |
55 |
if len(args) < 1: |
|
66 |
if len(args) < 1 or options.os is None:
|
|
56 | 67 |
Usage() |
57 | 68 |
|
58 | 69 |
return options, args |
... | ... | |
93 | 104 |
os_set &= set([os_inst.name for os_inst in oses[node]]) |
94 | 105 |
|
95 | 106 |
if opts.os not in os_set: |
96 |
Feedback("OS not found")
|
|
107 |
Feedback("OS '%s' not found" % opts.os)
|
|
97 | 108 |
return 1 |
98 | 109 |
|
99 | 110 |
to_remove = [] |
... | ... | |
125 | 136 |
idx = next_idx |
126 | 137 |
|
127 | 138 |
|
128 |
if len(nodelist) > 1: |
|
129 |
# failover |
|
130 |
for instance_name in args: |
|
131 |
op = opcodes.OpFailoverInstance(instance_name=instance_name, |
|
132 |
ignore_consistency=True) |
|
139 |
if opts.do_replace1: |
|
140 |
if len(nodelist) > 1: |
|
141 |
# failover |
|
142 |
for instance_name in args: |
|
143 |
op = opcodes.OpReplaceDisks(instance_name=instance_name, |
|
144 |
remote_node=None) |
|
145 |
|
|
146 |
Feedback("- Replace disks for instance %s" % (instance_name)) |
|
147 |
result = proc.ExecOpCode(op, Feedback) |
|
148 |
else: |
|
149 |
Feedback("- Can't run replace1, not enough nodes") |
|
133 | 150 |
|
134 |
Feedback("- Failover instance %s" % (instance_name)) |
|
135 |
result = proc.ExecOpCode(op, Feedback) |
|
151 |
if opts.do_failover: |
|
152 |
if len(nodelist) > 1: |
|
153 |
# failover |
|
154 |
for instance_name in args: |
|
155 |
op = opcodes.OpFailoverInstance(instance_name=instance_name, |
|
156 |
ignore_consistency=True) |
|
157 |
|
|
158 |
Feedback("- Failover instance %s" % (instance_name)) |
|
159 |
result = proc.ExecOpCode(op, Feedback) |
|
160 |
else: |
|
161 |
Feedback("- Can't run failovers, not enough nodes") |
|
136 | 162 |
|
137 | 163 |
# stop / start |
138 | 164 |
for instance_name in args: |
... | ... | |
156 | 182 |
"""Main function""" |
157 | 183 |
|
158 | 184 |
opts, args = ParseOptions() |
159 |
return BurninCluster(opts, args) |
|
185 |
try: |
|
186 |
utils.Lock('cmd', max_retries=15, debug=True) |
|
187 |
except errors.LockError, err: |
|
188 |
logger.ToStderr(str(err)) |
|
189 |
return 1 |
|
190 |
try: |
|
191 |
retval = BurninCluster(opts, args) |
|
192 |
finally: |
|
193 |
utils.Unlock('cmd') |
|
194 |
utils.LockCleanup() |
|
195 |
return retval |
|
160 | 196 |
|
161 | 197 |
if __name__ == "__main__": |
162 | 198 |
main() |
Also available in: Unified diff