root / scripts / gnt-debug @ b8f31860
History | View | Annotate | Download (6.3 kB)
1 | fd3ee040 | Iustin Pop | #!/usr/bin/python |
---|---|---|---|
2 | fd3ee040 | Iustin Pop | # |
3 | fd3ee040 | Iustin Pop | |
4 | fd3ee040 | Iustin Pop | # Copyright (C) 2006, 2007 Google Inc. |
5 | fd3ee040 | Iustin Pop | # |
6 | fd3ee040 | Iustin Pop | # This program is free software; you can redistribute it and/or modify |
7 | fd3ee040 | Iustin Pop | # it under the terms of the GNU General Public License as published by |
8 | fd3ee040 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or |
9 | fd3ee040 | Iustin Pop | # (at your option) any later version. |
10 | fd3ee040 | Iustin Pop | # |
11 | fd3ee040 | Iustin Pop | # This program is distributed in the hope that it will be useful, but |
12 | fd3ee040 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | fd3ee040 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | fd3ee040 | Iustin Pop | # General Public License for more details. |
15 | fd3ee040 | Iustin Pop | # |
16 | fd3ee040 | Iustin Pop | # You should have received a copy of the GNU General Public License |
17 | fd3ee040 | Iustin Pop | # along with this program; if not, write to the Free Software |
18 | fd3ee040 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | fd3ee040 | Iustin Pop | # 02110-1301, USA. |
20 | fd3ee040 | Iustin Pop | |
21 | fd3ee040 | Iustin Pop | |
22 | 2f79bd34 | Iustin Pop | # pylint: disable-msg=W0401,W0614 |
23 | 2f79bd34 | Iustin Pop | # W0401: Wildcard import ganeti.cli |
24 | 2f79bd34 | Iustin Pop | # W0614: Unused import %s from wildcard import (since we need cli) |
25 | 2f79bd34 | Iustin Pop | |
26 | fd3ee040 | Iustin Pop | import sys |
27 | f1c66d13 | Iustin Pop | import simplejson |
28 | f1c66d13 | Iustin Pop | import time |
29 | f1c66d13 | Iustin Pop | |
30 | fd3ee040 | Iustin Pop | from optparse import make_option |
31 | fd3ee040 | Iustin Pop | |
32 | fd3ee040 | Iustin Pop | from ganeti.cli import * |
33 | 9d5ba39a | Iustin Pop | from ganeti import cli |
34 | fd3ee040 | Iustin Pop | from ganeti import opcodes |
35 | fd3ee040 | Iustin Pop | from ganeti import constants |
36 | fd3ee040 | Iustin Pop | from ganeti import utils |
37 | fd3ee040 | Iustin Pop | from ganeti import errors |
38 | fd3ee040 | Iustin Pop | |
39 | fd3ee040 | Iustin Pop | |
40 | fd3ee040 | Iustin Pop | def Delay(opts, args): |
41 | fd3ee040 | Iustin Pop | """Sleeps for a while |
42 | fd3ee040 | Iustin Pop | |
43 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user |
44 | 6099bfcf | Iustin Pop | @type args: list |
45 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the duration |
46 | 6099bfcf | Iustin Pop | the sleep |
47 | 6099bfcf | Iustin Pop | @rtype: int |
48 | 6099bfcf | Iustin Pop | @return: the desired exit code |
49 | 6099bfcf | Iustin Pop | |
50 | fd3ee040 | Iustin Pop | """ |
51 | fd3ee040 | Iustin Pop | delay = float(args[0]) |
52 | fd3ee040 | Iustin Pop | op = opcodes.OpTestDelay(duration=delay, |
53 | fd3ee040 | Iustin Pop | on_master=opts.on_master, |
54 | fd3ee040 | Iustin Pop | on_nodes=opts.on_nodes) |
55 | 17621a25 | Michael Hanselmann | SubmitOpCode(op) |
56 | fd3ee040 | Iustin Pop | |
57 | fd3ee040 | Iustin Pop | return 0 |
58 | fd3ee040 | Iustin Pop | |
59 | fd3ee040 | Iustin Pop | |
60 | f1c66d13 | Iustin Pop | def GenericOpCodes(opts, args): |
61 | 6099bfcf | Iustin Pop | """Send any opcode to the master. |
62 | 6099bfcf | Iustin Pop | |
63 | 6099bfcf | Iustin Pop | @todo: The function is broken and needs to be converted to the |
64 | 6099bfcf | Iustin Pop | current job queue API |
65 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user |
66 | 6099bfcf | Iustin Pop | @type args: list |
67 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the path of |
68 | 6099bfcf | Iustin Pop | the file with the opcode definition |
69 | 6099bfcf | Iustin Pop | @rtype: int |
70 | 6099bfcf | Iustin Pop | @return: the desired exit code |
71 | f1c66d13 | Iustin Pop | |
72 | f1c66d13 | Iustin Pop | """ |
73 | 9d5ba39a | Iustin Pop | cl = cli.GetClient() |
74 | b59252fe | Iustin Pop | jex = cli.JobExecutor(cl=cl) |
75 | b59252fe | Iustin Pop | |
76 | 99036060 | Iustin Pop | for fname in args: |
77 | 99036060 | Iustin Pop | op_data = simplejson.loads(open(fname).read()) |
78 | 99036060 | Iustin Pop | op_list = [opcodes.OpCode.LoadOpCode(val) for val in op_data] |
79 | b59252fe | Iustin Pop | jex.QueueJob("file %s" % fname, *op_list) |
80 | b59252fe | Iustin Pop | |
81 | b59252fe | Iustin Pop | jex.GetResults() |
82 | f1c66d13 | Iustin Pop | return 0 |
83 | f1c66d13 | Iustin Pop | |
84 | f1c66d13 | Iustin Pop | |
85 | d61df03e | Iustin Pop | def TestAllocator(opts, args): |
86 | 6099bfcf | Iustin Pop | """Runs the test allocator opcode. |
87 | d61df03e | Iustin Pop | |
88 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user |
89 | 6099bfcf | Iustin Pop | @type args: list |
90 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the iallocator name |
91 | 6099bfcf | Iustin Pop | @rtype: int |
92 | 6099bfcf | Iustin Pop | @return: the desired exit code |
93 | 6099bfcf | Iustin Pop | |
94 | 6099bfcf | Iustin Pop | """ |
95 | d61df03e | Iustin Pop | try: |
96 | d61df03e | Iustin Pop | disks = [{"size": utils.ParseUnit(val), "mode": 'w'} |
97 | d61df03e | Iustin Pop | for val in opts.disks.split(",")] |
98 | d61df03e | Iustin Pop | except errors.UnitParseError, err: |
99 | 3a24c527 | Iustin Pop | ToStderr("Invalid disks parameter '%s': %s", opts.disks, err) |
100 | d61df03e | Iustin Pop | return 1 |
101 | d61df03e | Iustin Pop | |
102 | d61df03e | Iustin Pop | nics = [val.split("/") for val in opts.nics.split(",")] |
103 | d61df03e | Iustin Pop | for row in nics: |
104 | d61df03e | Iustin Pop | while len(row) < 3: |
105 | d61df03e | Iustin Pop | row.append(None) |
106 | d61df03e | Iustin Pop | for i in range(3): |
107 | d61df03e | Iustin Pop | if row[i] == '': |
108 | d61df03e | Iustin Pop | row[i] = None |
109 | d61df03e | Iustin Pop | nic_dict = [{"mac": v[0], "ip": v[1], "bridge": v[2]} for v in nics] |
110 | d61df03e | Iustin Pop | |
111 | d61df03e | Iustin Pop | if opts.tags is None: |
112 | d61df03e | Iustin Pop | opts.tags = [] |
113 | d61df03e | Iustin Pop | else: |
114 | d61df03e | Iustin Pop | opts.tags = opts.tags.split(",") |
115 | d61df03e | Iustin Pop | |
116 | d61df03e | Iustin Pop | op = opcodes.OpTestAllocator(mode=opts.mode, |
117 | d61df03e | Iustin Pop | name=args[0], |
118 | d61df03e | Iustin Pop | mem_size=opts.mem, |
119 | d61df03e | Iustin Pop | disks=disks, |
120 | d61df03e | Iustin Pop | disk_template=opts.disk_template, |
121 | d61df03e | Iustin Pop | nics=nic_dict, |
122 | d61df03e | Iustin Pop | os=opts.os_type, |
123 | d61df03e | Iustin Pop | vcpus=opts.vcpus, |
124 | d61df03e | Iustin Pop | tags=opts.tags, |
125 | d61df03e | Iustin Pop | direction=opts.direction, |
126 | d61df03e | Iustin Pop | allocator=opts.allocator, |
127 | d61df03e | Iustin Pop | ) |
128 | d61df03e | Iustin Pop | result = SubmitOpCode(op) |
129 | 3a24c527 | Iustin Pop | ToStdout("%s" % result) |
130 | d61df03e | Iustin Pop | return 0 |
131 | d61df03e | Iustin Pop | |
132 | d61df03e | Iustin Pop | |
133 | fd3ee040 | Iustin Pop | commands = { |
134 | fd3ee040 | Iustin Pop | 'delay': (Delay, ARGS_ONE, |
135 | fd3ee040 | Iustin Pop | [DEBUG_OPT, |
136 | fd3ee040 | Iustin Pop | make_option("--no-master", dest="on_master", default=True, |
137 | fd3ee040 | Iustin Pop | action="store_false", |
138 | fd3ee040 | Iustin Pop | help="Do not sleep in the master code"), |
139 | fd3ee040 | Iustin Pop | make_option("-n", dest="on_nodes", default=[], |
140 | fd3ee040 | Iustin Pop | action="append", |
141 | fd3ee040 | Iustin Pop | help="Select nodes to sleep on"), |
142 | fd3ee040 | Iustin Pop | ], |
143 | 9a033156 | Iustin Pop | "[opts...] <duration>", "Executes a TestDelay OpCode"), |
144 | 99036060 | Iustin Pop | 'submit-job': (GenericOpCodes, ARGS_ATLEAST(1), |
145 | f1c66d13 | Iustin Pop | [DEBUG_OPT, |
146 | f1c66d13 | Iustin Pop | ], |
147 | 99036060 | Iustin Pop | "<op_list_file...>", "Submits jobs built from json files" |
148 | 99036060 | Iustin Pop | " containing a list of serialized opcodes"), |
149 | d61df03e | Iustin Pop | 'allocator': (TestAllocator, ARGS_ONE, |
150 | d61df03e | Iustin Pop | [DEBUG_OPT, |
151 | d61df03e | Iustin Pop | make_option("--dir", dest="direction", |
152 | d61df03e | Iustin Pop | default="in", choices=["in", "out"], |
153 | d61df03e | Iustin Pop | help="Show allocator input (in) or allocator" |
154 | d61df03e | Iustin Pop | " results (out)"), |
155 | d61df03e | Iustin Pop | make_option("--algorithm", dest="allocator", |
156 | d61df03e | Iustin Pop | default=None, |
157 | d61df03e | Iustin Pop | help="Allocator algorithm name"), |
158 | d61df03e | Iustin Pop | make_option("-m", "--mode", default="relocate", |
159 | d61df03e | Iustin Pop | choices=["relocate", "allocate"], |
160 | d61df03e | Iustin Pop | help="Request mode, either allocate or" |
161 | 8901997e | Iustin Pop | " relocate"), |
162 | d61df03e | Iustin Pop | cli_option("--mem", default=128, type="unit", |
163 | d61df03e | Iustin Pop | help="Memory size for the instance (MiB)"), |
164 | d61df03e | Iustin Pop | make_option("--disks", default="4096,4096", |
165 | d61df03e | Iustin Pop | help="Comma separated list of disk sizes (MiB)"), |
166 | d61df03e | Iustin Pop | make_option("-t", "--disk-template", default="drbd", |
167 | d61df03e | Iustin Pop | help="Select the disk template"), |
168 | d61df03e | Iustin Pop | make_option("--nics", default="00:11:22:33:44:55", |
169 | d61df03e | Iustin Pop | help="Comma separated list of nics, each nic" |
170 | d61df03e | Iustin Pop | " definition is of form mac/ip/bridge, if" |
171 | d61df03e | Iustin Pop | " missing values are replace by None"), |
172 | d61df03e | Iustin Pop | make_option("-o", "--os-type", default=None, |
173 | d61df03e | Iustin Pop | help="Select os for the instance"), |
174 | d61df03e | Iustin Pop | make_option("-p", "--vcpus", default=1, type="int", |
175 | d61df03e | Iustin Pop | help="Select number of VCPUs for the instance"), |
176 | d61df03e | Iustin Pop | make_option("--tags", default=None, |
177 | d61df03e | Iustin Pop | help="Comma separated list of tags"), |
178 | d61df03e | Iustin Pop | ], |
179 | 9a033156 | Iustin Pop | "{opts...} <instance>", "Executes a TestAllocator OpCode"), |
180 | fd3ee040 | Iustin Pop | } |
181 | fd3ee040 | Iustin Pop | |
182 | fd3ee040 | Iustin Pop | |
183 | fd3ee040 | Iustin Pop | if __name__ == '__main__': |
184 | fd3ee040 | Iustin Pop | sys.exit(GenericMain(commands)) |