245 |
245 |
"""
|
246 |
246 |
selected_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
|
247 |
247 |
|
248 |
|
output = GetClient().QueryInstances(args, selected_fields, opts.do_locking)
|
249 |
|
|
250 |
|
if not opts.no_headers:
|
251 |
|
headers = {
|
252 |
|
"name": "Instance", "os": "OS", "pnode": "Primary_node",
|
253 |
|
"snodes": "Secondary_Nodes", "admin_state": "Autostart",
|
254 |
|
"oper_state": "Running",
|
255 |
|
"oper_ram": "Memory", "disk_template": "Disk_template",
|
256 |
|
"oper_vcpus": "VCPUs",
|
257 |
|
"ip": "IP_address", "mac": "MAC_address",
|
258 |
|
"nic_mode": "NIC_Mode", "nic_link": "NIC_Link",
|
259 |
|
"bridge": "Bridge",
|
260 |
|
"sda_size": "Disk/0", "sdb_size": "Disk/1",
|
261 |
|
"disk_usage": "DiskUsage",
|
262 |
|
"status": "Status", "tags": "Tags",
|
263 |
|
"network_port": "Network_port",
|
264 |
|
"hv/kernel_path": "Kernel_path",
|
265 |
|
"hv/initrd_path": "Initrd_path",
|
266 |
|
"hv/boot_order": "Boot_order",
|
267 |
|
"hv/acpi": "ACPI",
|
268 |
|
"hv/pae": "PAE",
|
269 |
|
"hv/cdrom_image_path": "CDROM_image_path",
|
270 |
|
"hv/nic_type": "NIC_type",
|
271 |
|
"hv/disk_type": "Disk_type",
|
272 |
|
"hv/vnc_bind_address": "VNC_bind_address",
|
273 |
|
"serial_no": "SerialNo", "hypervisor": "Hypervisor",
|
274 |
|
"hvparams": "Hypervisor_parameters",
|
275 |
|
"be/memory": "Configured_memory",
|
276 |
|
"be/vcpus": "VCPUs",
|
277 |
|
"vcpus": "VCPUs",
|
278 |
|
"be/auto_balance": "Auto_balance",
|
279 |
|
"disk.count": "Disks", "disk.sizes": "Disk_sizes",
|
280 |
|
"nic.count": "NICs", "nic.ips": "NIC_IPs",
|
281 |
|
"nic.modes": "NIC_modes", "nic.links": "NIC_links",
|
282 |
|
"nic.bridges": "NIC_bridges", "nic.macs": "NIC_MACs",
|
283 |
|
"ctime": "CTime", "mtime": "MTime", "uuid": "UUID",
|
284 |
|
}
|
285 |
|
else:
|
286 |
|
headers = None
|
287 |
|
|
288 |
|
unitfields = ["be/memory", "oper_ram", "sd(a|b)_size", "disk\.size/.*"]
|
289 |
|
numfields = ["be/memory", "oper_ram", "sd(a|b)_size", "be/vcpus",
|
290 |
|
"serial_no", "(disk|nic)\.count", "disk\.size/.*"]
|
291 |
|
|
292 |
|
list_type_fields = ("tags", "disk.sizes", "nic.macs", "nic.ips",
|
293 |
|
"nic.modes", "nic.links", "nic.bridges")
|
294 |
|
# change raw values to nicer strings
|
295 |
|
for row in output:
|
296 |
|
for idx, field in enumerate(selected_fields):
|
297 |
|
val = row[idx]
|
298 |
|
if field == "snodes":
|
299 |
|
val = ",".join(val) or "-"
|
300 |
|
elif field == "admin_state":
|
301 |
|
if val:
|
302 |
|
val = "yes"
|
303 |
|
else:
|
304 |
|
val = "no"
|
305 |
|
elif field == "oper_state":
|
306 |
|
if val is None:
|
307 |
|
val = "(node down)"
|
308 |
|
elif val: # True
|
309 |
|
val = "running"
|
310 |
|
else:
|
311 |
|
val = "stopped"
|
312 |
|
elif field == "oper_ram":
|
313 |
|
if val is None:
|
314 |
|
val = "(node down)"
|
315 |
|
elif field == "oper_vcpus":
|
316 |
|
if val is None:
|
317 |
|
val = "(node down)"
|
318 |
|
elif field == "sda_size" or field == "sdb_size":
|
319 |
|
if val is None:
|
320 |
|
val = "N/A"
|
321 |
|
elif field == "ctime" or field == "mtime":
|
322 |
|
val = utils.FormatTime(val)
|
323 |
|
elif field in list_type_fields:
|
324 |
|
val = ",".join(str(item) for item in val)
|
325 |
|
elif val is None:
|
326 |
|
val = "-"
|
327 |
|
if opts.roman_integers and isinstance(val, int):
|
328 |
|
val = compat.TryToRoman(val)
|
329 |
|
row[idx] = str(val)
|
330 |
|
|
331 |
|
data = GenerateTable(separator=opts.separator, headers=headers,
|
332 |
|
fields=selected_fields, unitfields=unitfields,
|
333 |
|
numfields=numfields, data=output, units=opts.units)
|
334 |
|
|
335 |
|
for line in data:
|
336 |
|
ToStdout(line)
|
|
248 |
fmtoverride = dict.fromkeys(["tags", "disk.sizes", "nic.macs", "nic.ips",
|
|
249 |
"nic.modes", "nic.links", "nic.bridges",
|
|
250 |
"snodes"],
|
|
251 |
(lambda value: ",".join(str(item)
|
|
252 |
for item in value),
|
|
253 |
False))
|
337 |
254 |
|
338 |
|
return 0
|
|
255 |
return GenericList(constants.QR_INSTANCE, selected_fields, args, opts.units,
|
|
256 |
opts.separator, not opts.no_headers,
|
|
257 |
format_override=fmtoverride)
|
|
258 |
|
|
259 |
|
|
260 |
def ListInstanceFields(opts, args):
|
|
261 |
"""List instance fields.
|
|
262 |
|
|
263 |
@param opts: the command line options selected by the user
|
|
264 |
@type args: list
|
|
265 |
@param args: fields to list, or empty for all
|
|
266 |
@rtype: int
|
|
267 |
@return: the desired exit code
|
|
268 |
|
|
269 |
"""
|
|
270 |
return GenericListFields(constants.QR_INSTANCE, args, opts.separator,
|
|
271 |
not opts.no_headers)
|
339 |
272 |
|
340 |
273 |
|
341 |
274 |
def AddInstance(opts, args):
|
... | ... | |
1421 |
1354 |
"Show information on the specified instance(s)"),
|
1422 |
1355 |
'list': (
|
1423 |
1356 |
ListInstances, ARGS_MANY_INSTANCES,
|
1424 |
|
[NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT],
|
|
1357 |
[NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
|
1425 |
1358 |
"[<instance>...]",
|
1426 |
|
"Lists the instances and their status. The available fields are"
|
1427 |
|
" (see the man page for details): status, oper_state, oper_ram,"
|
1428 |
|
" oper_vcpus, name, os, pnode, snodes, admin_state, admin_ram,"
|
1429 |
|
" disk_template, ip, mac, nic_mode, nic_link, sda_size, sdb_size,"
|
1430 |
|
" vcpus, serial_no,"
|
1431 |
|
" nic.count, nic.mac/N, nic.ip/N, nic.mode/N, nic.link/N,"
|
1432 |
|
" nic.macs, nic.ips, nic.modes, nic.links,"
|
1433 |
|
" disk.count, disk.size/N, disk.sizes,"
|
1434 |
|
" hv/NAME, be/memory, be/vcpus, be/auto_balance,"
|
1435 |
|
" hypervisor."
|
1436 |
|
" The default field"
|
1437 |
|
" list is (in order): %s." % utils.CommaJoin(_LIST_DEF_FIELDS),
|
|
1359 |
"Lists the instances and their status. The available fields can be shown"
|
|
1360 |
" using the \"list-fields\" command (see the man page for details)."
|
|
1361 |
" The default field list is (in order): %s." %
|
|
1362 |
utils.CommaJoin(_LIST_DEF_FIELDS),
|
1438 |
1363 |
),
|
|
1364 |
"list-fields": (
|
|
1365 |
ListInstanceFields, [ArgUnknown()],
|
|
1366 |
[NOHDR_OPT, SEP_OPT],
|
|
1367 |
"[fields...]",
|
|
1368 |
"Lists all available fields for instances"),
|
1439 |
1369 |
'reinstall': (
|
1440 |
1370 |
ReinstallInstance, [ArgInstance()],
|
1441 |
1371 |
[FORCE_OPT, OS_OPT, FORCE_VARIANT_OPT, m_force_multi, m_node_opt,
|