Revision d77490c5
b/lib/cli.py | ||
---|---|---|
116 | 116 |
"YES_DOIT_OPT", |
117 | 117 |
# Generic functions for CLI programs |
118 | 118 |
"GenericMain", |
119 |
"GenericInstanceCreate", |
|
119 | 120 |
"GetClient", |
120 | 121 |
"GetOnlineNodes", |
121 | 122 |
"JobExecutor", |
... | ... | |
1323 | 1324 |
return result |
1324 | 1325 |
|
1325 | 1326 |
|
1327 |
def GenericInstanceCreate(mode, opts, args): |
|
1328 |
"""Add an instance to the cluster via either creation or import. |
|
1329 |
|
|
1330 |
@param mode: constants.INSTANCE_CREATE or constants.INSTANCE_IMPORT |
|
1331 |
@param opts: the command line options selected by the user |
|
1332 |
@type args: list |
|
1333 |
@param args: should contain only one element, the new instance name |
|
1334 |
@rtype: int |
|
1335 |
@return: the desired exit code |
|
1336 |
|
|
1337 |
""" |
|
1338 |
instance = args[0] |
|
1339 |
|
|
1340 |
(pnode, snode) = SplitNodeOption(opts.node) |
|
1341 |
|
|
1342 |
hypervisor = None |
|
1343 |
hvparams = {} |
|
1344 |
if opts.hypervisor: |
|
1345 |
hypervisor, hvparams = opts.hypervisor |
|
1346 |
|
|
1347 |
if opts.nics: |
|
1348 |
try: |
|
1349 |
nic_max = max(int(nidx[0])+1 for nidx in opts.nics) |
|
1350 |
except ValueError, err: |
|
1351 |
raise errors.OpPrereqError("Invalid NIC index passed: %s" % str(err)) |
|
1352 |
nics = [{}] * nic_max |
|
1353 |
for nidx, ndict in opts.nics: |
|
1354 |
nidx = int(nidx) |
|
1355 |
if not isinstance(ndict, dict): |
|
1356 |
msg = "Invalid nic/%d value: expected dict, got %s" % (nidx, ndict) |
|
1357 |
raise errors.OpPrereqError(msg) |
|
1358 |
nics[nidx] = ndict |
|
1359 |
elif opts.no_nics: |
|
1360 |
# no nics |
|
1361 |
nics = [] |
|
1362 |
else: |
|
1363 |
# default of one nic, all auto |
|
1364 |
nics = [{}] |
|
1365 |
|
|
1366 |
if opts.disk_template == constants.DT_DISKLESS: |
|
1367 |
if opts.disks or opts.sd_size is not None: |
|
1368 |
raise errors.OpPrereqError("Diskless instance but disk" |
|
1369 |
" information passed") |
|
1370 |
disks = [] |
|
1371 |
else: |
|
1372 |
if not opts.disks and not opts.sd_size: |
|
1373 |
raise errors.OpPrereqError("No disk information specified") |
|
1374 |
if opts.disks and opts.sd_size is not None: |
|
1375 |
raise errors.OpPrereqError("Please use either the '--disk' or" |
|
1376 |
" '-s' option") |
|
1377 |
if opts.sd_size is not None: |
|
1378 |
opts.disks = [(0, {"size": opts.sd_size})] |
|
1379 |
try: |
|
1380 |
disk_max = max(int(didx[0])+1 for didx in opts.disks) |
|
1381 |
except ValueError, err: |
|
1382 |
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err)) |
|
1383 |
disks = [{}] * disk_max |
|
1384 |
for didx, ddict in opts.disks: |
|
1385 |
didx = int(didx) |
|
1386 |
if not isinstance(ddict, dict): |
|
1387 |
msg = "Invalid disk/%d value: expected dict, got %s" % (didx, ddict) |
|
1388 |
raise errors.OpPrereqError(msg) |
|
1389 |
elif "size" not in ddict: |
|
1390 |
raise errors.OpPrereqError("Missing size for disk %d" % didx) |
|
1391 |
try: |
|
1392 |
ddict["size"] = utils.ParseUnit(ddict["size"]) |
|
1393 |
except ValueError, err: |
|
1394 |
raise errors.OpPrereqError("Invalid disk size for disk %d: %s" % |
|
1395 |
(didx, err)) |
|
1396 |
disks[didx] = ddict |
|
1397 |
|
|
1398 |
utils.ForceDictType(opts.beparams, constants.BES_PARAMETER_TYPES) |
|
1399 |
utils.ForceDictType(hvparams, constants.HVS_PARAMETER_TYPES) |
|
1400 |
|
|
1401 |
if mode == constants.INSTANCE_CREATE: |
|
1402 |
start = opts.start |
|
1403 |
os_type = opts.os |
|
1404 |
src_node = None |
|
1405 |
src_path = None |
|
1406 |
elif mode == constants.INSTANCE_IMPORT: |
|
1407 |
start = False |
|
1408 |
os_type = None |
|
1409 |
src_node = opts.src_node |
|
1410 |
src_path = opts.src_dir |
|
1411 |
else: |
|
1412 |
raise errors.ProgrammerError("Invalid creation mode %s" % mode) |
|
1413 |
|
|
1414 |
op = opcodes.OpCreateInstance(instance_name=instance, |
|
1415 |
disks=disks, |
|
1416 |
disk_template=opts.disk_template, |
|
1417 |
nics=nics, |
|
1418 |
pnode=pnode, snode=snode, |
|
1419 |
ip_check=opts.ip_check, |
|
1420 |
wait_for_sync=opts.wait_for_sync, |
|
1421 |
file_storage_dir=opts.file_storage_dir, |
|
1422 |
file_driver=opts.file_driver, |
|
1423 |
iallocator=opts.iallocator, |
|
1424 |
hypervisor=hypervisor, |
|
1425 |
hvparams=hvparams, |
|
1426 |
beparams=opts.beparams, |
|
1427 |
mode=mode, |
|
1428 |
start=start, |
|
1429 |
os_type=os_type, |
|
1430 |
src_node=src_node, |
|
1431 |
src_path=src_path) |
|
1432 |
|
|
1433 |
SubmitOrSend(op, opts) |
|
1434 |
return 0 |
|
1435 |
|
|
1436 |
|
|
1326 | 1437 |
def GenerateTable(headers, fields, separator, data, |
1327 | 1438 |
numfields=None, unitfields=None, |
1328 | 1439 |
units=None): |
b/scripts/gnt-backup | ||
---|---|---|
99 | 99 |
def ImportInstance(opts, args): |
100 | 100 |
"""Add an instance to the cluster. |
101 | 101 |
|
102 |
@param opts: the command line options selected by the user |
|
103 |
@type args: list |
|
104 |
@param args: should contain only one element, the new instance name |
|
105 |
@rtype: int |
|
106 |
@return: the desired exit code |
|
102 |
This is just a wrapper over GenericInstanceCreate. |
|
107 | 103 |
|
108 | 104 |
""" |
109 |
instance = args[0] |
|
110 |
|
|
111 |
(pnode, snode) = SplitNodeOption(opts.node) |
|
112 |
|
|
113 |
hypervisor = None |
|
114 |
hvparams = {} |
|
115 |
if opts.hypervisor: |
|
116 |
hypervisor, hvparams = opts.hypervisor |
|
117 |
|
|
118 |
if opts.nics: |
|
119 |
try: |
|
120 |
nic_max = max(int(nidx[0])+1 for nidx in opts.nics) |
|
121 |
except ValueError, err: |
|
122 |
raise errors.OpPrereqError("Invalid NIC index passed: %s" % str(err)) |
|
123 |
nics = [{}] * nic_max |
|
124 |
for nidx, ndict in opts.nics: |
|
125 |
nidx = int(nidx) |
|
126 |
if not isinstance(ndict, dict): |
|
127 |
msg = "Invalid nic/%d value: expected dict, got %s" % (nidx, ndict) |
|
128 |
raise errors.OpPrereqError(msg) |
|
129 |
nics[nidx] = ndict |
|
130 |
elif opts.no_nics: |
|
131 |
# no nics |
|
132 |
nics = [] |
|
133 |
else: |
|
134 |
# default of one nic, all auto |
|
135 |
nics = [{}] |
|
136 |
|
|
137 |
if opts.disk_template == constants.DT_DISKLESS: |
|
138 |
if opts.disks or opts.sd_size is not None: |
|
139 |
raise errors.OpPrereqError("Diskless instance but disk" |
|
140 |
" information passed") |
|
141 |
disks = [] |
|
142 |
else: |
|
143 |
if not opts.disks and not opts.sd_size: |
|
144 |
raise errors.OpPrereqError("No disk information specified") |
|
145 |
if opts.disks and opts.sd_size is not None: |
|
146 |
raise errors.OpPrereqError("Please use either the '--disk' or" |
|
147 |
" '-s' option") |
|
148 |
if opts.sd_size is not None: |
|
149 |
opts.disks = [(0, {"size": opts.sd_size})] |
|
150 |
try: |
|
151 |
disk_max = max(int(didx[0])+1 for didx in opts.disks) |
|
152 |
except ValueError, err: |
|
153 |
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err)) |
|
154 |
disks = [{}] * disk_max |
|
155 |
for didx, ddict in opts.disks: |
|
156 |
didx = int(didx) |
|
157 |
if not isinstance(ddict, dict): |
|
158 |
msg = "Invalid disk/%d value: expected dict, got %s" % (didx, ddict) |
|
159 |
raise errors.OpPrereqError(msg) |
|
160 |
elif "size" not in ddict: |
|
161 |
raise errors.OpPrereqError("Missing size for disk %d" % didx) |
|
162 |
try: |
|
163 |
ddict["size"] = utils.ParseUnit(ddict["size"]) |
|
164 |
except ValueError, err: |
|
165 |
raise errors.OpPrereqError("Invalid disk size for disk %d: %s" % |
|
166 |
(didx, err)) |
|
167 |
disks[didx] = ddict |
|
168 |
|
|
169 |
utils.ForceDictType(opts.beparams, constants.BES_PARAMETER_TYPES) |
|
170 |
utils.ForceDictType(hvparams, constants.HVS_PARAMETER_TYPES) |
|
171 |
|
|
172 |
op = opcodes.OpCreateInstance(instance_name=instance, |
|
173 |
disk_template=opts.disk_template, |
|
174 |
disks=disks, |
|
175 |
nics=nics, |
|
176 |
mode=constants.INSTANCE_IMPORT, |
|
177 |
pnode=pnode, snode=snode, |
|
178 |
ip_check=opts.ip_check, |
|
179 |
start=False, |
|
180 |
src_node=opts.src_node, src_path=opts.src_dir, |
|
181 |
wait_for_sync=opts.wait_for_sync, |
|
182 |
file_storage_dir=opts.file_storage_dir, |
|
183 |
file_driver=opts.file_driver, |
|
184 |
iallocator=opts.iallocator, |
|
185 |
hypervisor=hypervisor, |
|
186 |
hvparams=hvparams, |
|
187 |
beparams=opts.beparams) |
|
188 |
|
|
189 |
SubmitOpCode(op) |
|
190 |
return 0 |
|
105 |
return GenericInstanceCreate(constants.INSTANCE_IMPORT, opts, args) |
|
191 | 106 |
|
192 | 107 |
|
193 | 108 |
def RemoveExport(opts, args): |
... | ... | |
225 | 140 |
FILESTORE_DIR_OPT, |
226 | 141 |
FILESTORE_DRIVER_OPT, |
227 | 142 |
HYPERVISOR_OPT, |
143 |
SUBMIT_OPT, |
|
228 | 144 |
] |
229 | 145 |
|
230 | 146 |
commands = { |
b/scripts/gnt-instance | ||
---|---|---|
311 | 311 |
def AddInstance(opts, args): |
312 | 312 |
"""Add an instance to the cluster. |
313 | 313 |
|
314 |
@param opts: the command line options selected by the user |
|
315 |
@type args: list |
|
316 |
@param args: should contain only one element, the new instance name |
|
317 |
@rtype: int |
|
318 |
@return: the desired exit code |
|
314 |
This is just a wrapper over GenericInstanceCreate. |
|
319 | 315 |
|
320 | 316 |
""" |
321 |
instance = args[0] |
|
322 |
|
|
323 |
(pnode, snode) = SplitNodeOption(opts.node) |
|
324 |
|
|
325 |
hypervisor = None |
|
326 |
hvparams = {} |
|
327 |
if opts.hypervisor: |
|
328 |
hypervisor, hvparams = opts.hypervisor |
|
329 |
|
|
330 |
if opts.nics: |
|
331 |
try: |
|
332 |
nic_max = max(int(nidx[0])+1 for nidx in opts.nics) |
|
333 |
except ValueError, err: |
|
334 |
raise errors.OpPrereqError("Invalid NIC index passed: %s" % str(err)) |
|
335 |
nics = [{}] * nic_max |
|
336 |
for nidx, ndict in opts.nics: |
|
337 |
nidx = int(nidx) |
|
338 |
if not isinstance(ndict, dict): |
|
339 |
msg = "Invalid nic/%d value: expected dict, got %s" % (nidx, ndict) |
|
340 |
raise errors.OpPrereqError(msg) |
|
341 |
nics[nidx] = ndict |
|
342 |
elif opts.no_nics: |
|
343 |
# no nics |
|
344 |
nics = [] |
|
345 |
else: |
|
346 |
# default of one nic, all auto |
|
347 |
nics = [{}] |
|
348 |
|
|
349 |
if opts.disk_template == constants.DT_DISKLESS: |
|
350 |
if opts.disks or opts.sd_size is not None: |
|
351 |
raise errors.OpPrereqError("Diskless instance but disk" |
|
352 |
" information passed") |
|
353 |
disks = [] |
|
354 |
else: |
|
355 |
if not opts.disks and not opts.sd_size: |
|
356 |
raise errors.OpPrereqError("No disk information specified") |
|
357 |
if opts.disks and opts.sd_size is not None: |
|
358 |
raise errors.OpPrereqError("Please use either the '--disk' or" |
|
359 |
" '-s' option") |
|
360 |
if opts.sd_size is not None: |
|
361 |
opts.disks = [(0, {"size": opts.sd_size})] |
|
362 |
try: |
|
363 |
disk_max = max(int(didx[0])+1 for didx in opts.disks) |
|
364 |
except ValueError, err: |
|
365 |
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err)) |
|
366 |
disks = [{}] * disk_max |
|
367 |
for didx, ddict in opts.disks: |
|
368 |
didx = int(didx) |
|
369 |
if not isinstance(ddict, dict): |
|
370 |
msg = "Invalid disk/%d value: expected dict, got %s" % (didx, ddict) |
|
371 |
raise errors.OpPrereqError(msg) |
|
372 |
elif "size" not in ddict: |
|
373 |
raise errors.OpPrereqError("Missing size for disk %d" % didx) |
|
374 |
try: |
|
375 |
ddict["size"] = utils.ParseUnit(ddict["size"]) |
|
376 |
except ValueError, err: |
|
377 |
raise errors.OpPrereqError("Invalid disk size for disk %d: %s" % |
|
378 |
(didx, err)) |
|
379 |
disks[didx] = ddict |
|
380 |
|
|
381 |
utils.ForceDictType(opts.beparams, constants.BES_PARAMETER_TYPES) |
|
382 |
utils.ForceDictType(hvparams, constants.HVS_PARAMETER_TYPES) |
|
383 |
|
|
384 |
op = opcodes.OpCreateInstance(instance_name=instance, |
|
385 |
disks=disks, |
|
386 |
disk_template=opts.disk_template, |
|
387 |
nics=nics, |
|
388 |
mode=constants.INSTANCE_CREATE, |
|
389 |
os_type=opts.os, pnode=pnode, |
|
390 |
snode=snode, |
|
391 |
start=opts.start, ip_check=opts.ip_check, |
|
392 |
wait_for_sync=opts.wait_for_sync, |
|
393 |
hypervisor=hypervisor, |
|
394 |
hvparams=hvparams, |
|
395 |
beparams=opts.beparams, |
|
396 |
iallocator=opts.iallocator, |
|
397 |
file_storage_dir=opts.file_storage_dir, |
|
398 |
file_driver=opts.file_driver, |
|
399 |
) |
|
400 |
|
|
401 |
SubmitOrSend(op, opts) |
|
317 |
return GenericInstanceCreate(constants.INSTANCE_CREATE, opts, args) |
|
402 | 318 |
return 0 |
403 | 319 |
|
404 | 320 |
|
Also available in: Unified diff