4 # Copyright (C) 2006, 2007 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 from optparse import make_option
26 from cStringIO import StringIO
28 from ganeti.cli import *
29 from ganeti import opcodes
30 from ganeti import logger
31 from ganeti import constants
32 from ganeti import utils
33 from ganeti import errors
36 def Delay(opts, args):
40 delay = float(args[0])
41 op = opcodes.OpTestDelay(duration=delay,
42 on_master=opts.on_master,
43 on_nodes=opts.on_nodes)
49 def TestAllocator(opts, args):
50 """Runs the test allocator opcode"""
53 disks = [{"size": utils.ParseUnit(val), "mode": 'w'}
54 for val in opts.disks.split(",")]
55 except errors.UnitParseError, err:
56 print >> sys.stderr, "Invalid disks parameter '%s': %s" % (opts.disks, err)
59 nics = [val.split("/") for val in opts.nics.split(",")]
66 nic_dict = [{"mac": v[0], "ip": v[1], "bridge": v[2]} for v in nics]
71 opts.tags = opts.tags.split(",")
73 op = opcodes.OpTestAllocator(mode=opts.mode,
77 disk_template=opts.disk_template,
82 direction=opts.direction,
83 allocator=opts.allocator,
85 result = SubmitOpCode(op)
91 'delay': (Delay, ARGS_ONE,
93 make_option("--no-master", dest="on_master", default=True,
95 help="Do not sleep in the master code"),
96 make_option("-n", dest="on_nodes", default=[],
98 help="Select nodes to sleep on"),
100 "[opts...] <duration>", "Executes a TestDelay OpCode"),
101 'allocator': (TestAllocator, ARGS_ONE,
103 make_option("--dir", dest="direction",
104 default="in", choices=["in", "out"],
105 help="Show allocator input (in) or allocator"
107 make_option("--algorithm", dest="allocator",
109 help="Allocator algorithm name"),
110 make_option("-m", "--mode", default="relocate",
111 choices=["relocate", "allocate"],
112 help="Request mode, either allocate or"
114 cli_option("--mem", default=128, type="unit",
115 help="Memory size for the instance (MiB)"),
116 make_option("--disks", default="4096,4096",
117 help="Comma separated list of disk sizes (MiB)"),
118 make_option("-t", "--disk-template", default="drbd",
119 help="Select the disk template"),
120 make_option("--nics", default="00:11:22:33:44:55",
121 help="Comma separated list of nics, each nic"
122 " definition is of form mac/ip/bridge, if"
123 " missing values are replace by None"),
124 make_option("-o", "--os-type", default=None,
125 help="Select os for the instance"),
126 make_option("-p", "--vcpus", default=1, type="int",
127 help="Select number of VCPUs for the instance"),
128 make_option("--tags", default=None,
129 help="Comma separated list of tags"),
131 "{opts...} <instance>", "Executes a TestAllocator OpCode"),
135 if __name__ == '__main__':
136 sys.exit(GenericMain(commands))