Revision e2736e40 scripts/gnt-instance
b/scripts/gnt-instance | ||
---|---|---|
34 | 34 |
from ganeti.cli import * |
35 | 35 |
from ganeti import opcodes |
36 | 36 |
from ganeti import constants |
37 |
from ganeti import compat |
|
37 | 38 |
from ganeti import utils |
38 | 39 |
from ganeti import errors |
39 | 40 |
|
... | ... | |
323 | 324 |
val = ",".join(str(item) for item in val) |
324 | 325 |
elif val is None: |
325 | 326 |
val = "-" |
327 |
if opts.roman_integers and isinstance(val, int): |
|
328 |
val = compat.TryToRoman(val) |
|
326 | 329 |
row[idx] = str(val) |
327 | 330 |
|
328 | 331 |
data = GenerateTable(separator=opts.separator, headers=headers, |
... | ... | |
941 | 944 |
os._exit(1) # pylint: disable-msg=W0212 |
942 | 945 |
|
943 | 946 |
|
944 |
def _FormatLogicalID(dev_type, logical_id): |
|
947 |
def _FormatLogicalID(dev_type, logical_id, roman):
|
|
945 | 948 |
"""Formats the logical_id of a disk. |
946 | 949 |
|
947 | 950 |
""" |
948 | 951 |
if dev_type == constants.LD_DRBD8: |
949 | 952 |
node_a, node_b, port, minor_a, minor_b, key = logical_id |
950 | 953 |
data = [ |
951 |
("nodeA", "%s, minor=%s" % (node_a, minor_a)), |
|
952 |
("nodeB", "%s, minor=%s" % (node_b, minor_b)), |
|
953 |
("port", port), |
|
954 |
("nodeA", "%s, minor=%s" % (node_a, compat.TryToRoman(minor_a, |
|
955 |
convert=roman))), |
|
956 |
("nodeB", "%s, minor=%s" % (node_b, compat.TryToRoman(minor_b, |
|
957 |
convert=roman))), |
|
958 |
("port", compat.TryToRoman(port, convert=roman)), |
|
954 | 959 |
("auth key", key), |
955 | 960 |
] |
956 | 961 |
elif dev_type == constants.LD_LV: |
... | ... | |
962 | 967 |
return data |
963 | 968 |
|
964 | 969 |
|
965 |
def _FormatBlockDevInfo(idx, top_level, dev, static): |
|
970 |
def _FormatBlockDevInfo(idx, top_level, dev, static, roman):
|
|
966 | 971 |
"""Show block device information. |
967 | 972 |
|
968 | 973 |
This is only used by L{ShowInstanceConfig}, but it's too big to be |
... | ... | |
977 | 982 |
@type static: boolean |
978 | 983 |
@param static: wheter the device information doesn't contain |
979 | 984 |
runtime information but only static data |
985 |
@type roman: boolean |
|
986 |
@param roman: whether to try to use roman integers |
|
980 | 987 |
@return: a list of either strings, tuples or lists |
981 | 988 |
(which should be formatted at a higher indent level) |
982 | 989 |
|
... | ... | |
998 | 1005 |
if major is None: |
999 | 1006 |
major_string = "N/A" |
1000 | 1007 |
else: |
1001 |
major_string = str(major)
|
|
1008 |
major_string = str(compat.TryToRoman(major, convert=roman))
|
|
1002 | 1009 |
|
1003 | 1010 |
if minor is None: |
1004 | 1011 |
minor_string = "N/A" |
1005 | 1012 |
else: |
1006 |
minor_string = str(minor)
|
|
1013 |
minor_string = str(compat.TryToRoman(minor, convert=roman))
|
|
1007 | 1014 |
|
1008 | 1015 |
txt += ("%s (%s:%s)" % (path, major_string, minor_string)) |
1009 | 1016 |
if dtype in (constants.LD_DRBD8, ): |
1010 | 1017 |
if syncp is not None: |
1011 | 1018 |
sync_text = "*RECOVERING* %5.2f%%," % syncp |
1012 | 1019 |
if estt: |
1013 |
sync_text += " ETA %ds" % estt
|
|
1020 |
sync_text += " ETA %ss" % compat.TryToRoman(estt, convert=roman)
|
|
1014 | 1021 |
else: |
1015 | 1022 |
sync_text += " ETA unknown" |
1016 | 1023 |
else: |
... | ... | |
1039 | 1046 |
if dev["iv_name"] is not None: |
1040 | 1047 |
txt = dev["iv_name"] |
1041 | 1048 |
else: |
1042 |
txt = "disk %d" % idx
|
|
1049 |
txt = "disk %s" % compat.TryToRoman(idx, convert=roman)
|
|
1043 | 1050 |
else: |
1044 |
txt = "child %d" % idx
|
|
1051 |
txt = "child %s" % compat.TryToRoman(idx, convert=roman)
|
|
1045 | 1052 |
if isinstance(dev["size"], int): |
1046 | 1053 |
nice_size = utils.FormatUnit(dev["size"], "h") |
1047 | 1054 |
else: |
... | ... | |
1052 | 1059 |
data.append(("access mode", dev["mode"])) |
1053 | 1060 |
if dev["logical_id"] is not None: |
1054 | 1061 |
try: |
1055 |
l_id = _FormatLogicalID(dev["dev_type"], dev["logical_id"]) |
|
1062 |
l_id = _FormatLogicalID(dev["dev_type"], dev["logical_id"], roman)
|
|
1056 | 1063 |
except ValueError: |
1057 | 1064 |
l_id = [str(dev["logical_id"])] |
1058 | 1065 |
if len(l_id) == 1: |
... | ... | |
1070 | 1077 |
if dev["children"]: |
1071 | 1078 |
data.append("child devices:") |
1072 | 1079 |
for c_idx, child in enumerate(dev["children"]): |
1073 |
data.append(_FormatBlockDevInfo(c_idx, False, child, static)) |
|
1080 |
data.append(_FormatBlockDevInfo(c_idx, False, child, static, roman))
|
|
1074 | 1081 |
d1.append(data) |
1075 | 1082 |
return d1 |
1076 | 1083 |
|
... | ... | |
1137 | 1144 |
instance = result[instance_name] |
1138 | 1145 |
buf.write("Instance name: %s\n" % instance["name"]) |
1139 | 1146 |
buf.write("UUID: %s\n" % instance["uuid"]) |
1140 |
buf.write("Serial number: %s\n" % instance["serial_no"]) |
|
1147 |
buf.write("Serial number: %s\n" % |
|
1148 |
compat.TryToRoman(instance["serial_no"], |
|
1149 |
convert=opts.roman_integers)) |
|
1141 | 1150 |
buf.write("Creation time: %s\n" % utils.FormatTime(instance["ctime"])) |
1142 | 1151 |
buf.write("Modification time: %s\n" % utils.FormatTime(instance["mtime"])) |
1143 | 1152 |
buf.write("State: configured to be %s" % instance["config_state"]) |
... | ... | |
1151 | 1160 |
buf.write(" - secondaries: %s\n" % utils.CommaJoin(instance["snodes"])) |
1152 | 1161 |
buf.write(" Operating system: %s\n" % instance["os"]) |
1153 | 1162 |
if instance.has_key("network_port"): |
1154 |
buf.write(" Allocated network port: %s\n" % instance["network_port"]) |
|
1163 |
buf.write(" Allocated network port: %s\n" % |
|
1164 |
compat.TryToRoman(instance["network_port"], |
|
1165 |
convert=opts.roman_integers)) |
|
1155 | 1166 |
buf.write(" Hypervisor: %s\n" % instance["hypervisor"]) |
1156 | 1167 |
|
1157 | 1168 |
# custom VNC console information |
... | ... | |
1181 | 1192 |
val = "default (%s)" % instance["hv_actual"][key] |
1182 | 1193 |
buf.write(" - %s: %s\n" % (key, val)) |
1183 | 1194 |
buf.write(" Hardware:\n") |
1184 |
buf.write(" - VCPUs: %d\n" % |
|
1185 |
instance["be_actual"][constants.BE_VCPUS]) |
|
1186 |
buf.write(" - memory: %dMiB\n" % |
|
1187 |
instance["be_actual"][constants.BE_MEMORY]) |
|
1195 |
buf.write(" - VCPUs: %s\n" % |
|
1196 |
compat.TryToRoman(instance["be_actual"][constants.BE_VCPUS], |
|
1197 |
convert=opts.roman_integers)) |
|
1198 |
buf.write(" - memory: %sMiB\n" % |
|
1199 |
compat.TryToRoman(instance["be_actual"][constants.BE_MEMORY], |
|
1200 |
convert=opts.roman_integers)) |
|
1188 | 1201 |
buf.write(" - NICs:\n") |
1189 | 1202 |
for idx, (ip, mac, mode, link) in enumerate(instance["nics"]): |
1190 | 1203 |
buf.write(" - nic/%d: MAC: %s, IP: %s, mode: %s, link: %s\n" % |
... | ... | |
1192 | 1205 |
buf.write(" Disks:\n") |
1193 | 1206 |
|
1194 | 1207 |
for idx, device in enumerate(instance["disks"]): |
1195 |
_FormatList(buf, _FormatBlockDevInfo(idx, True, device, opts.static), 2) |
|
1208 |
_FormatList(buf, _FormatBlockDevInfo(idx, True, device, opts.static, |
|
1209 |
opts.roman_integers), 2) |
|
1196 | 1210 |
|
1197 | 1211 |
ToStdout(buf.getvalue().rstrip('\n')) |
1198 | 1212 |
return retcode |
... | ... | |
1379 | 1393 |
" (only for instances of type file and lv)"), |
1380 | 1394 |
'info': ( |
1381 | 1395 |
ShowInstanceConfig, ARGS_MANY_INSTANCES, |
1382 |
[STATIC_OPT, ALL_OPT], |
|
1396 |
[STATIC_OPT, ALL_OPT, ROMAN_OPT],
|
|
1383 | 1397 |
"[-s] {--all | <instance>...}", |
1384 | 1398 |
"Show information on the specified instance(s)"), |
1385 | 1399 |
'list': ( |
1386 | 1400 |
ListInstances, ARGS_MANY_INSTANCES, |
1387 |
[NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, SYNC_OPT], |
|
1401 |
[NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT],
|
|
1388 | 1402 |
"[<instance>...]", |
1389 | 1403 |
"Lists the instances and their status. The available fields are" |
1390 | 1404 |
" (see the man page for details): status, oper_state, oper_ram," |
Also available in: Unified diff