Revision d0c8c01d
b/lib/backend.py | ||
---|---|---|
421 | 421 |
result.cmd, result.exit_code, result.output) |
422 | 422 |
|
423 | 423 |
# Raise a custom exception (handled in ganeti-noded) |
424 |
raise errors.QuitGanetiException(True, 'Shutdown scheduled')
|
|
424 |
raise errors.QuitGanetiException(True, "Shutdown scheduled")
|
|
425 | 425 |
|
426 | 426 |
|
427 | 427 |
def GetNodeInfo(vgname, hypervisor_type): |
... | ... | |
449 | 449 |
if vginfo: |
450 | 450 |
vg_free = int(round(vginfo[0][0], 0)) |
451 | 451 |
vg_size = int(round(vginfo[0][1], 0)) |
452 |
outputarray['vg_size'] = vg_size
|
|
453 |
outputarray['vg_free'] = vg_free
|
|
452 |
outputarray["vg_size"] = vg_size
|
|
453 |
outputarray["vg_free"] = vg_free
|
|
454 | 454 |
|
455 | 455 |
if hypervisor_type is not None: |
456 | 456 |
hyper = hypervisor.GetHypervisor(hypervisor_type) |
... | ... | |
707 | 707 |
|
708 | 708 |
""" |
709 | 709 |
lvs = {} |
710 |
sep = '|'
|
|
710 |
sep = "|"
|
|
711 | 711 |
if not vg_names: |
712 | 712 |
vg_names = [] |
713 | 713 |
result = utils.RunCmd(["lvs", "--noheadings", "--units=m", "--nosuffix", |
... | ... | |
723 | 723 |
logging.error("Invalid line returned from lvs output: '%s'", line) |
724 | 724 |
continue |
725 | 725 |
vg_name, name, size, attr = match.groups() |
726 |
inactive = attr[4] == '-'
|
|
727 |
online = attr[5] == 'o'
|
|
728 |
virtual = attr[0] == 'v'
|
|
726 |
inactive = attr[4] == "-"
|
|
727 |
online = attr[5] == "o"
|
|
728 |
virtual = attr[0] == "v"
|
|
729 | 729 |
if virtual: |
730 | 730 |
# we don't want to report such volumes as existing, since they |
731 | 731 |
# don't really hold data |
... | ... | |
773 | 773 |
result.output) |
774 | 774 |
|
775 | 775 |
def parse_dev(dev): |
776 |
return dev.split('(')[0]
|
|
776 |
return dev.split("(")[0]
|
|
777 | 777 |
|
778 | 778 |
def handle_dev(dev): |
779 | 779 |
return [parse_dev(x) for x in dev.split(",")] |
780 | 780 |
|
781 | 781 |
def map_line(line): |
782 | 782 |
line = [v.strip() for v in line] |
783 |
return [{'name': line[0], 'size': line[1],
|
|
784 |
'dev': dev, 'vg': line[3]} for dev in handle_dev(line[2])]
|
|
783 |
return [{"name": line[0], "size": line[1],
|
|
784 |
"dev": dev, "vg": line[3]} for dev in handle_dev(line[2])]
|
|
785 | 785 |
|
786 | 786 |
all_devs = [] |
787 | 787 |
for line in result.stdout.splitlines(): |
788 |
if line.count('|') >= 3:
|
|
789 |
all_devs.extend(map_line(line.split('|')))
|
|
788 |
if line.count("|") >= 3:
|
|
789 |
all_devs.extend(map_line(line.split("|")))
|
|
790 | 790 |
else: |
791 | 791 |
logging.warning("Strange line in the output from lvs: '%s'", line) |
792 | 792 |
return all_devs |
... | ... | |
851 | 851 |
|
852 | 852 |
iinfo = hypervisor.GetHypervisor(hname).GetInstanceInfo(instance) |
853 | 853 |
if iinfo is not None: |
854 |
output['memory'] = iinfo[2]
|
|
855 |
output['state'] = iinfo[4]
|
|
856 |
output['time'] = iinfo[5]
|
|
854 |
output["memory"] = iinfo[2]
|
|
855 |
output["state"] = iinfo[4]
|
|
856 |
output["time"] = iinfo[5]
|
|
857 | 857 |
|
858 | 858 |
return output |
859 | 859 |
|
... | ... | |
907 | 907 |
if iinfo: |
908 | 908 |
for name, _, memory, vcpus, state, times in iinfo: |
909 | 909 |
value = { |
910 |
'memory': memory,
|
|
911 |
'vcpus': vcpus,
|
|
912 |
'state': state,
|
|
913 |
'time': times,
|
|
910 |
"memory": memory,
|
|
911 |
"vcpus": vcpus,
|
|
912 |
"state": state,
|
|
913 |
"time": times,
|
|
914 | 914 |
} |
915 | 915 |
if name in output: |
916 | 916 |
# we only check static parameters, like memory and vcpus, |
917 | 917 |
# and not state and time which can change between the |
918 | 918 |
# invocations of the different hypervisors |
919 |
for key in 'memory', 'vcpus':
|
|
919 |
for key in "memory", "vcpus":
|
|
920 | 920 |
if value[key] != output[name][key]: |
921 | 921 |
_Fail("Instance %s is running twice" |
922 | 922 |
" with different parameters", name) |
... | ... | |
961 | 961 |
|
962 | 962 |
create_env = OSEnvironment(instance, inst_os, debug) |
963 | 963 |
if reinstall: |
964 |
create_env['INSTANCE_REINSTALL'] = "1"
|
|
964 |
create_env["INSTANCE_REINSTALL"] = "1"
|
|
965 | 965 |
|
966 | 966 |
logfile = _InstanceLogName("add", instance.os, instance.name) |
967 | 967 |
|
... | ... | |
993 | 993 |
inst_os = OSFromDisk(instance.os) |
994 | 994 |
|
995 | 995 |
rename_env = OSEnvironment(instance, inst_os, debug) |
996 |
rename_env['OLD_INSTANCE_NAME'] = old_name
|
|
996 |
rename_env["OLD_INSTANCE_NAME"] = old_name
|
|
997 | 997 |
|
998 | 998 |
logfile = _InstanceLogName("rename", instance.os, |
999 | 999 |
"%s-%s" % (old_name, instance.name)) |
... | ... | |
1331 | 1331 |
it's not required to return anything. |
1332 | 1332 |
|
1333 | 1333 |
""" |
1334 |
# TODO: remove the obsolete 'size' argument
|
|
1334 |
# TODO: remove the obsolete "size" argument
|
|
1335 | 1335 |
# pylint: disable-msg=W0613 |
1336 | 1336 |
clist = [] |
1337 | 1337 |
if disk.children: |
... | ... | |
1831 | 1831 |
destcmd) |
1832 | 1832 |
|
1833 | 1833 |
# all commands have been checked, so we're safe to combine them |
1834 |
command = '|'.join([expcmd, utils.ShellQuoteArgs(remotecmd)])
|
|
1834 |
command = "|".join([expcmd, utils.ShellQuoteArgs(remotecmd)])
|
|
1835 | 1835 |
|
1836 | 1836 |
result = utils.RunCmd(["bash", "-c", command]) |
1837 | 1837 |
|
... | ... | |
1925 | 1925 |
@param err: the exception to format |
1926 | 1926 |
|
1927 | 1927 |
""" |
1928 |
if hasattr(err, 'errno'):
|
|
1928 |
if hasattr(err, "errno"):
|
|
1929 | 1929 |
detail = errno.errorcode[err.errno] |
1930 | 1930 |
else: |
1931 | 1931 |
detail = str(err) |
... | ... | |
2055 | 2055 |
os_files = dict.fromkeys(constants.OS_SCRIPTS) |
2056 | 2056 |
|
2057 | 2057 |
if max(api_versions) >= constants.OS_API_V15: |
2058 |
os_files[constants.OS_VARIANTS_FILE] = ''
|
|
2058 |
os_files[constants.OS_VARIANTS_FILE] = ""
|
|
2059 | 2059 |
|
2060 | 2060 |
if max(api_versions) >= constants.OS_API_V20: |
2061 |
os_files[constants.OS_PARAMETERS_FILE] = ''
|
|
2061 |
os_files[constants.OS_PARAMETERS_FILE] = ""
|
|
2062 | 2062 |
else: |
2063 | 2063 |
del os_files[constants.OS_SCRIPT_VERIFY] |
2064 | 2064 |
|
... | ... | |
2161 | 2161 |
result = {} |
2162 | 2162 |
api_version = \ |
2163 | 2163 |
max(constants.OS_API_VERSIONS.intersection(inst_os.api_versions)) |
2164 |
result['OS_API_VERSION'] = '%d' % api_version
|
|
2165 |
result['OS_NAME'] = inst_os.name
|
|
2166 |
result['DEBUG_LEVEL'] = '%d' % debug
|
|
2164 |
result["OS_API_VERSION"] = "%d" % api_version
|
|
2165 |
result["OS_NAME"] = inst_os.name
|
|
2166 |
result["DEBUG_LEVEL"] = "%d" % debug
|
|
2167 | 2167 |
|
2168 | 2168 |
# OS variants |
2169 | 2169 |
if api_version >= constants.OS_API_V15: |
2170 | 2170 |
variant = objects.OS.GetVariant(os_name) |
2171 | 2171 |
if not variant: |
2172 | 2172 |
variant = inst_os.supported_variants[0] |
2173 |
result['OS_VARIANT'] = variant
|
|
2173 |
result["OS_VARIANT"] = variant
|
|
2174 | 2174 |
|
2175 | 2175 |
# OS params |
2176 | 2176 |
for pname, pvalue in os_params.items(): |
2177 |
result['OSP_%s' % pname.upper()] = pvalue
|
|
2177 |
result["OSP_%s" % pname.upper()] = pvalue
|
|
2178 | 2178 |
|
2179 | 2179 |
return result |
2180 | 2180 |
|
... | ... | |
2199 | 2199 |
for attr in ["name", "os", "uuid", "ctime", "mtime", "primary_node"]: |
2200 | 2200 |
result["INSTANCE_%s" % attr.upper()] = str(getattr(instance, attr)) |
2201 | 2201 |
|
2202 |
result['HYPERVISOR'] = instance.hypervisor
|
|
2203 |
result['DISK_COUNT'] = '%d' % len(instance.disks)
|
|
2204 |
result['NIC_COUNT'] = '%d' % len(instance.nics)
|
|
2205 |
result['INSTANCE_SECONDARY_NODES'] = \
|
|
2206 |
('%s' % " ".join(instance.secondary_nodes))
|
|
2202 |
result["HYPERVISOR"] = instance.hypervisor
|
|
2203 |
result["DISK_COUNT"] = "%d" % len(instance.disks)
|
|
2204 |
result["NIC_COUNT"] = "%d" % len(instance.nics)
|
|
2205 |
result["INSTANCE_SECONDARY_NODES"] = \
|
|
2206 |
("%s" % " ".join(instance.secondary_nodes))
|
|
2207 | 2207 |
|
2208 | 2208 |
# Disks |
2209 | 2209 |
for idx, disk in enumerate(instance.disks): |
2210 | 2210 |
real_disk = _OpenRealBD(disk) |
2211 |
result['DISK_%d_PATH' % idx] = real_disk.dev_path
|
|
2212 |
result['DISK_%d_ACCESS' % idx] = disk.mode
|
|
2211 |
result["DISK_%d_PATH" % idx] = real_disk.dev_path
|
|
2212 |
result["DISK_%d_ACCESS" % idx] = disk.mode
|
|
2213 | 2213 |
if constants.HV_DISK_TYPE in instance.hvparams: |
2214 |
result['DISK_%d_FRONTEND_TYPE' % idx] = \
|
|
2214 |
result["DISK_%d_FRONTEND_TYPE" % idx] = \
|
|
2215 | 2215 |
instance.hvparams[constants.HV_DISK_TYPE] |
2216 | 2216 |
if disk.dev_type in constants.LDS_BLOCK: |
2217 |
result['DISK_%d_BACKEND_TYPE' % idx] = 'block'
|
|
2217 |
result["DISK_%d_BACKEND_TYPE" % idx] = "block"
|
|
2218 | 2218 |
elif disk.dev_type == constants.LD_FILE: |
2219 |
result['DISK_%d_BACKEND_TYPE' % idx] = \
|
|
2220 |
'file:%s' % disk.physical_id[0]
|
|
2219 |
result["DISK_%d_BACKEND_TYPE" % idx] = \
|
|
2220 |
"file:%s" % disk.physical_id[0]
|
|
2221 | 2221 |
|
2222 | 2222 |
# NICs |
2223 | 2223 |
for idx, nic in enumerate(instance.nics): |
2224 |
result['NIC_%d_MAC' % idx] = nic.mac
|
|
2224 |
result["NIC_%d_MAC" % idx] = nic.mac
|
|
2225 | 2225 |
if nic.ip: |
2226 |
result['NIC_%d_IP' % idx] = nic.ip
|
|
2227 |
result['NIC_%d_MODE' % idx] = nic.nicparams[constants.NIC_MODE]
|
|
2226 |
result["NIC_%d_IP" % idx] = nic.ip
|
|
2227 |
result["NIC_%d_MODE" % idx] = nic.nicparams[constants.NIC_MODE]
|
|
2228 | 2228 |
if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED: |
2229 |
result['NIC_%d_BRIDGE' % idx] = nic.nicparams[constants.NIC_LINK]
|
|
2229 |
result["NIC_%d_BRIDGE" % idx] = nic.nicparams[constants.NIC_LINK]
|
|
2230 | 2230 |
if nic.nicparams[constants.NIC_LINK]: |
2231 |
result['NIC_%d_LINK' % idx] = nic.nicparams[constants.NIC_LINK]
|
|
2231 |
result["NIC_%d_LINK" % idx] = nic.nicparams[constants.NIC_LINK]
|
|
2232 | 2232 |
if constants.HV_NIC_TYPE in instance.hvparams: |
2233 |
result['NIC_%d_FRONTEND_TYPE' % idx] = \
|
|
2233 |
result["NIC_%d_FRONTEND_TYPE" % idx] = \
|
|
2234 | 2234 |
instance.hvparams[constants.HV_NIC_TYPE] |
2235 | 2235 |
|
2236 | 2236 |
# HV/BE params |
... | ... | |
2318 | 2318 |
config = objects.SerializableConfigParser() |
2319 | 2319 |
|
2320 | 2320 |
config.add_section(constants.INISECT_EXP) |
2321 |
config.set(constants.INISECT_EXP, 'version', '0')
|
|
2322 |
config.set(constants.INISECT_EXP, 'timestamp', '%d' % int(time.time()))
|
|
2323 |
config.set(constants.INISECT_EXP, 'source', instance.primary_node)
|
|
2324 |
config.set(constants.INISECT_EXP, 'os', instance.os)
|
|
2321 |
config.set(constants.INISECT_EXP, "version", "0")
|
|
2322 |
config.set(constants.INISECT_EXP, "timestamp", "%d" % int(time.time()))
|
|
2323 |
config.set(constants.INISECT_EXP, "source", instance.primary_node)
|
|
2324 |
config.set(constants.INISECT_EXP, "os", instance.os)
|
|
2325 | 2325 |
config.set(constants.INISECT_EXP, "compression", "none") |
2326 | 2326 |
|
2327 | 2327 |
config.add_section(constants.INISECT_INS) |
2328 |
config.set(constants.INISECT_INS, 'name', instance.name)
|
|
2329 |
config.set(constants.INISECT_INS, 'memory', '%d' %
|
|
2328 |
config.set(constants.INISECT_INS, "name", instance.name)
|
|
2329 |
config.set(constants.INISECT_INS, "memory", "%d" %
|
|
2330 | 2330 |
instance.beparams[constants.BE_MEMORY]) |
2331 |
config.set(constants.INISECT_INS, 'vcpus', '%d' %
|
|
2331 |
config.set(constants.INISECT_INS, "vcpus", "%d" %
|
|
2332 | 2332 |
instance.beparams[constants.BE_VCPUS]) |
2333 |
config.set(constants.INISECT_INS, 'disk_template', instance.disk_template)
|
|
2334 |
config.set(constants.INISECT_INS, 'hypervisor', instance.hypervisor)
|
|
2333 |
config.set(constants.INISECT_INS, "disk_template", instance.disk_template)
|
|
2334 |
config.set(constants.INISECT_INS, "hypervisor", instance.hypervisor)
|
|
2335 | 2335 |
config.set(constants.INISECT_INS, "tags", " ".join(instance.GetTags())) |
2336 | 2336 |
|
2337 | 2337 |
nic_total = 0 |
2338 | 2338 |
for nic_count, nic in enumerate(instance.nics): |
2339 | 2339 |
nic_total += 1 |
2340 |
config.set(constants.INISECT_INS, 'nic%d_mac' %
|
|
2341 |
nic_count, '%s' % nic.mac)
|
|
2342 |
config.set(constants.INISECT_INS, 'nic%d_ip' % nic_count, '%s' % nic.ip)
|
|
2340 |
config.set(constants.INISECT_INS, "nic%d_mac" %
|
|
2341 |
nic_count, "%s" % nic.mac)
|
|
2342 |
config.set(constants.INISECT_INS, "nic%d_ip" % nic_count, "%s" % nic.ip)
|
|
2343 | 2343 |
for param in constants.NICS_PARAMETER_TYPES: |
2344 |
config.set(constants.INISECT_INS, 'nic%d_%s' % (nic_count, param),
|
|
2345 |
'%s' % nic.nicparams.get(param, None))
|
|
2344 |
config.set(constants.INISECT_INS, "nic%d_%s" % (nic_count, param),
|
|
2345 |
"%s" % nic.nicparams.get(param, None))
|
|
2346 | 2346 |
# TODO: redundant: on load can read nics until it doesn't exist |
2347 |
config.set(constants.INISECT_INS, 'nic_count' , '%d' % nic_total)
|
|
2347 |
config.set(constants.INISECT_INS, "nic_count" , "%d" % nic_total)
|
|
2348 | 2348 |
|
2349 | 2349 |
disk_total = 0 |
2350 | 2350 |
for disk_count, disk in enumerate(snap_disks): |
2351 | 2351 |
if disk: |
2352 | 2352 |
disk_total += 1 |
2353 |
config.set(constants.INISECT_INS, 'disk%d_ivname' % disk_count,
|
|
2354 |
('%s' % disk.iv_name))
|
|
2355 |
config.set(constants.INISECT_INS, 'disk%d_dump' % disk_count,
|
|
2356 |
('%s' % disk.physical_id[1]))
|
|
2357 |
config.set(constants.INISECT_INS, 'disk%d_size' % disk_count,
|
|
2358 |
('%d' % disk.size))
|
|
2359 |
|
|
2360 |
config.set(constants.INISECT_INS, 'disk_count' , '%d' % disk_total)
|
|
2353 |
config.set(constants.INISECT_INS, "disk%d_ivname" % disk_count,
|
|
2354 |
("%s" % disk.iv_name))
|
|
2355 |
config.set(constants.INISECT_INS, "disk%d_dump" % disk_count,
|
|
2356 |
("%s" % disk.physical_id[1]))
|
|
2357 |
config.set(constants.INISECT_INS, "disk%d_size" % disk_count,
|
|
2358 |
("%d" % disk.size))
|
|
2359 |
|
|
2360 |
config.set(constants.INISECT_INS, "disk_count" , "%d" % disk_total)
|
|
2361 | 2361 |
|
2362 | 2362 |
# New-style hypervisor/backend parameters |
2363 | 2363 |
|
b/lib/bdev.py | ||
---|---|---|
600 | 600 |
# one line for any non-empty string |
601 | 601 |
logging.error("Can't parse LVS output, no lines? Got '%s'", str(out)) |
602 | 602 |
return False |
603 |
out = out[-1].strip().rstrip(',')
|
|
603 |
out = out[-1].strip().rstrip(",")
|
|
604 | 604 |
out = out.split(",") |
605 | 605 |
if len(out) != 5: |
606 | 606 |
logging.error("Can't parse LVS output, len(%s) != 5", str(out)) |
... | ... | |
633 | 633 |
self.minor = minor |
634 | 634 |
self.pe_size = pe_size |
635 | 635 |
self.stripe_count = stripes |
636 |
self._degraded = status[0] == 'v' # virtual volume, i.e. doesn't backing
|
|
636 |
self._degraded = status[0] == "v" # virtual volume, i.e. doesn't backing
|
|
637 | 637 |
# storage |
638 | 638 |
self.attached = True |
639 | 639 |
return True |
... | ... | |
745 | 745 |
BlockDev.SetInfo(self, text) |
746 | 746 |
|
747 | 747 |
# Replace invalid characters |
748 |
text = re.sub('^[^A-Za-z0-9_+.]', '_', text)
|
|
749 |
text = re.sub('[^-A-Za-z0-9_+.]', '_', text)
|
|
748 |
text = re.sub("^[^A-Za-z0-9_+.]", "_", text)
|
|
749 |
text = re.sub("[^-A-Za-z0-9_+.]", "_", text)
|
|
750 | 750 |
|
751 | 751 |
# Only up to 128 characters are allowed |
752 | 752 |
text = text[:128] |
... | ... | |
971 | 971 |
first_line) |
972 | 972 |
|
973 | 973 |
values = version.groups() |
974 |
retval = {'k_major': int(values[0]),
|
|
975 |
'k_minor': int(values[1]),
|
|
976 |
'k_point': int(values[2]),
|
|
977 |
'api': int(values[3]),
|
|
978 |
'proto': int(values[4]),
|
|
974 |
retval = {"k_major": int(values[0]),
|
|
975 |
"k_minor": int(values[1]),
|
|
976 |
"k_point": int(values[2]),
|
|
977 |
"api": int(values[3]),
|
|
978 |
"proto": int(values[4]),
|
|
979 | 979 |
} |
980 | 980 |
if values[5] is not None: |
981 |
retval['proto2'] = values[5]
|
|
981 |
retval["proto2"] = values[5]
|
|
982 | 982 |
|
983 | 983 |
return retval |
984 | 984 |
|
... | ... | |
1113 | 1113 |
super(DRBD8, self).__init__(unique_id, children, size) |
1114 | 1114 |
self.major = self._DRBD_MAJOR |
1115 | 1115 |
version = self._GetVersion(self._GetProcData()) |
1116 |
if version['k_major'] != 8 :
|
|
1116 |
if version["k_major"] != 8 :
|
|
1117 | 1117 |
_ThrowError("Mismatch in DRBD kernel version and requested ganeti" |
1118 | 1118 |
" usage: kernel is %s.%s, ganeti wants 8.x", |
1119 |
version['k_major'], version['k_minor'])
|
|
1119 |
version["k_major"], version["k_minor"])
|
|
1120 | 1120 |
|
1121 | 1121 |
if (self._lhost is not None and self._lhost == self._rhost and |
1122 | 1122 |
self._lport == self._rport): |
... | ... | |
1210 | 1210 |
pyp.Optional(pyp.restOfLine).suppress()) |
1211 | 1211 |
|
1212 | 1212 |
# an entire section |
1213 |
section_name = pyp.Word(pyp.alphas + '_')
|
|
1213 |
section_name = pyp.Word(pyp.alphas + "_")
|
|
1214 | 1214 |
section = section_name + lbrace + pyp.ZeroOrMore(pyp.Group(stmt)) + rbrace |
1215 | 1215 |
|
1216 | 1216 |
bnf = pyp.ZeroOrMore(pyp.Group(section ^ stmt)) |
... | ... | |
1343 | 1343 |
# what we aim here is to revert back to the 'drain' method of |
1344 | 1344 |
# disk flushes and to disable metadata barriers, in effect going |
1345 | 1345 |
# back to pre-8.0.7 behaviour |
1346 |
vmaj = version['k_major']
|
|
1347 |
vmin = version['k_minor']
|
|
1348 |
vrel = version['k_point']
|
|
1346 |
vmaj = version["k_major"]
|
|
1347 |
vmin = version["k_minor"]
|
|
1348 |
vrel = version["k_point"]
|
|
1349 | 1349 |
assert vmaj == 8 |
1350 | 1350 |
if vmin == 0: # 8.0.x |
1351 | 1351 |
if vrel >= 12: |
1352 |
args.extend(['-i', '-m'])
|
|
1352 |
args.extend(["-i", "-m"])
|
|
1353 | 1353 |
elif vmin == 2: # 8.2.x |
1354 | 1354 |
if vrel >= 7: |
1355 |
args.extend(['-i', '-m'])
|
|
1355 |
args.extend(["-i", "-m"])
|
|
1356 | 1356 |
elif vmaj >= 3: # 8.3.x or newer |
1357 |
args.extend(['-i', '-a', 'm'])
|
|
1357 |
args.extend(["-i", "-a", "m"])
|
|
1358 | 1358 |
result = utils.RunCmd(args) |
1359 | 1359 |
if result.failed: |
1360 | 1360 |
_ThrowError("drbd%d: can't attach local disk: %s", minor, result.output) |
... | ... | |
2102 | 2102 |
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2: |
2103 | 2103 |
raise ValueError("Invalid configuration data %s" % str(unique_id)) |
2104 | 2104 |
self.dev_path = unique_id[1] |
2105 |
if not os.path.realpath(self.dev_path).startswith('/dev/'):
|
|
2105 |
if not os.path.realpath(self.dev_path).startswith("/dev/"):
|
|
2106 | 2106 |
raise ValueError("Full path '%s' lies outside /dev" % |
2107 | 2107 |
os.path.realpath(self.dev_path)) |
2108 | 2108 |
# TODO: this is just a safety guard checking that we only deal with devices |
b/lib/cli.py | ||
---|---|---|
517 | 517 |
|
518 | 518 |
""" |
519 | 519 |
if ":" not in value: |
520 |
ident, rest = value, ''
|
|
520 |
ident, rest = value, ""
|
|
521 | 521 |
else: |
522 | 522 |
ident, rest = value.split(":", 1) |
523 | 523 |
|
... | ... | |
621 | 621 |
" (defaults to one space)")) |
622 | 622 |
|
623 | 623 |
USEUNITS_OPT = cli_option("--units", default=None, |
624 |
dest="units", choices=('h', 'm', 'g', 't'),
|
|
624 |
dest="units", choices=("h", "m", "g", "t"),
|
|
625 | 625 |
help="Specify units for output (one of h/m/g/t)") |
626 | 626 |
|
627 | 627 |
FIELDS_OPT = cli_option("-o", "--output", dest="output", action="store", |
... | ... | |
1417 | 1417 |
"""Splits the value of a --node option. |
1418 | 1418 |
|
1419 | 1419 |
""" |
1420 |
if value and ':' in value:
|
|
1421 |
return value.split(':', 1)
|
|
1420 |
if value and ":" in value:
|
|
1421 |
return value.split(":", 1)
|
|
1422 | 1422 |
else: |
1423 | 1423 |
return (value, None) |
1424 | 1424 |
|
... | ... | |
1435 | 1435 |
|
1436 | 1436 |
""" |
1437 | 1437 |
if os_variants: |
1438 |
return ['%s+%s' % (os_name, v) for v in os_variants]
|
|
1438 |
return ["%s+%s" % (os_name, v) for v in os_variants]
|
|
1439 | 1439 |
else: |
1440 | 1440 |
return [os_name] |
1441 | 1441 |
|
... | ... | |
1477 | 1477 |
|
1478 | 1478 |
""" |
1479 | 1479 |
if choices is None: |
1480 |
choices = [('y', True, 'Perform the operation'),
|
|
1481 |
('n', False, 'Do not perform the operation')]
|
|
1480 |
choices = [("y", True, "Perform the operation"),
|
|
1481 |
("n", False, "Do not perform the operation")]
|
|
1482 | 1482 |
if not choices or not isinstance(choices, list): |
1483 | 1483 |
raise errors.ProgrammerError("Invalid choices argument to AskUser") |
1484 | 1484 |
for entry in choices: |
1485 |
if not isinstance(entry, tuple) or len(entry) < 3 or entry[0] == '?':
|
|
1485 |
if not isinstance(entry, tuple) or len(entry) < 3 or entry[0] == "?":
|
|
1486 | 1486 |
raise errors.ProgrammerError("Invalid choices element to AskUser") |
1487 | 1487 |
|
1488 | 1488 |
answer = choices[-1][1] |
... | ... | |
1497 | 1497 |
try: |
1498 | 1498 |
chars = [entry[0] for entry in choices] |
1499 | 1499 |
chars[-1] = "[%s]" % chars[-1] |
1500 |
chars.append('?')
|
|
1500 |
chars.append("?")
|
|
1501 | 1501 |
maps = dict([(entry[0], entry[1]) for entry in choices]) |
1502 | 1502 |
while True: |
1503 | 1503 |
f.write(text) |
1504 |
f.write('\n')
|
|
1504 |
f.write("\n")
|
|
1505 | 1505 |
f.write("/".join(chars)) |
1506 | 1506 |
f.write(": ") |
1507 | 1507 |
line = f.readline(2).strip().lower() |
1508 | 1508 |
if line in maps: |
1509 | 1509 |
answer = maps[line] |
1510 | 1510 |
break |
1511 |
elif line == '?':
|
|
1511 |
elif line == "?":
|
|
1512 | 1512 |
for entry in choices: |
1513 | 1513 |
f.write(" %s - %s\n" % (entry[0], entry[2])) |
1514 | 1514 |
f.write("\n") |
... | ... | |
1965 | 1965 |
retcode = 0 |
1966 | 1966 |
else: |
1967 | 1967 |
obuf.write("Unhandled exception: %s" % msg) |
1968 |
return retcode, obuf.getvalue().rstrip('\n')
|
|
1968 |
return retcode, obuf.getvalue().rstrip("\n")
|
|
1969 | 1969 |
|
1970 | 1970 |
|
1971 | 1971 |
def GenericMain(commands, override=None, aliases=None): |
... | ... | |
2381 | 2381 |
|
2382 | 2382 |
if separator is None: |
2383 | 2383 |
mlens = [0 for name in fields] |
2384 |
format_str = ' '.join(format_fields)
|
|
2384 |
format_str = " ".join(format_fields)
|
|
2385 | 2385 |
else: |
2386 | 2386 |
format_str = separator.replace("%", "%%").join(format_fields) |
2387 | 2387 |
|
... | ... | |
2420 | 2420 |
for line in data: |
2421 | 2421 |
args = [] |
2422 | 2422 |
if line is None: |
2423 |
line = ['-' for _ in fields]
|
|
2423 |
line = ["-" for _ in fields]
|
|
2424 | 2424 |
for idx in range(len(fields)): |
2425 | 2425 |
if separator is None: |
2426 | 2426 |
args.append(mlens[idx]) |
... | ... | |
2826 | 2826 |
|
2827 | 2827 |
""" |
2828 | 2828 |
if not isinstance (ts, (tuple, list)) or len(ts) != 2: |
2829 |
return '?'
|
|
2829 |
return "?"
|
|
2830 | 2830 |
sec, usec = ts |
2831 | 2831 |
return time.strftime("%F %T", time.localtime(sec)) + ".%06d" % usec |
2832 | 2832 |
|
... | ... | |
2849 | 2849 |
if not value: |
2850 | 2850 |
raise errors.OpPrereqError("Empty time specification passed") |
2851 | 2851 |
suffix_map = { |
2852 |
's': 1,
|
|
2853 |
'm': 60,
|
|
2854 |
'h': 3600,
|
|
2855 |
'd': 86400,
|
|
2856 |
'w': 604800,
|
|
2852 |
"s": 1,
|
|
2853 |
"m": 60,
|
|
2854 |
"h": 3600,
|
|
2855 |
"d": 86400,
|
|
2856 |
"w": 604800,
|
|
2857 | 2857 |
} |
2858 | 2858 |
if value[-1] not in suffix_map: |
2859 | 2859 |
try: |
... | ... | |
2966 | 2966 |
stream.write(txt % args) |
2967 | 2967 |
else: |
2968 | 2968 |
stream.write(txt) |
2969 |
stream.write('\n')
|
|
2969 |
stream.write("\n")
|
|
2970 | 2970 |
stream.flush() |
2971 | 2971 |
except IOError, err: |
2972 | 2972 |
if err.errno == errno.EPIPE: |
b/lib/client/gnt_cluster.py | ||
---|---|---|
1242 | 1242 |
|
1243 | 1243 |
|
1244 | 1244 |
commands = { |
1245 |
'init': (
|
|
1245 |
"init": (
|
|
1246 | 1246 |
InitCluster, [ArgHost(min=1, max=1)], |
1247 | 1247 |
[BACKEND_OPT, CP_SIZE_OPT, ENABLED_HV_OPT, GLOBAL_FILEDIR_OPT, |
1248 | 1248 |
HVLIST_OPT, MAC_PREFIX_OPT, MASTER_NETDEV_OPT, NIC_PARAMS_OPT, |
... | ... | |
1252 | 1252 |
DEFAULT_IALLOCATOR_OPT, PRIMARY_IP_VERSION_OPT, PREALLOC_WIPE_DISKS_OPT, |
1253 | 1253 |
NODE_PARAMS_OPT, GLOBAL_SHARED_FILEDIR_OPT], |
1254 | 1254 |
"[opts...] <cluster_name>", "Initialises a new cluster configuration"), |
1255 |
'destroy': (
|
|
1255 |
"destroy": (
|
|
1256 | 1256 |
DestroyCluster, ARGS_NONE, [YES_DOIT_OPT], |
1257 | 1257 |
"", "Destroy cluster"), |
1258 |
'rename': (
|
|
1258 |
"rename": (
|
|
1259 | 1259 |
RenameCluster, [ArgHost(min=1, max=1)], |
1260 | 1260 |
[FORCE_OPT, DRY_RUN_OPT], |
1261 | 1261 |
"<new_name>", |
1262 | 1262 |
"Renames the cluster"), |
1263 |
'redist-conf': (
|
|
1263 |
"redist-conf": (
|
|
1264 | 1264 |
RedistributeConfig, ARGS_NONE, [SUBMIT_OPT, DRY_RUN_OPT, PRIORITY_OPT], |
1265 | 1265 |
"", "Forces a push of the configuration file and ssconf files" |
1266 | 1266 |
" to the nodes in the cluster"), |
1267 |
'verify': (
|
|
1267 |
"verify": (
|
|
1268 | 1268 |
VerifyCluster, ARGS_NONE, |
1269 | 1269 |
[VERBOSE_OPT, DEBUG_SIMERR_OPT, ERROR_CODES_OPT, NONPLUS1_OPT, |
1270 | 1270 |
DRY_RUN_OPT, PRIORITY_OPT, NODEGROUP_OPT], |
1271 | 1271 |
"", "Does a check on the cluster configuration"), |
1272 |
'verify-disks': (
|
|
1272 |
"verify-disks": (
|
|
1273 | 1273 |
VerifyDisks, ARGS_NONE, [PRIORITY_OPT], |
1274 | 1274 |
"", "Does a check on the cluster disk status"), |
1275 |
'repair-disk-sizes': (
|
|
1275 |
"repair-disk-sizes": (
|
|
1276 | 1276 |
RepairDiskSizes, ARGS_MANY_INSTANCES, [DRY_RUN_OPT, PRIORITY_OPT], |
1277 | 1277 |
"", "Updates mismatches in recorded disk sizes"), |
1278 |
'master-failover': (
|
|
1278 |
"master-failover": (
|
|
1279 | 1279 |
MasterFailover, ARGS_NONE, [NOVOTING_OPT], |
1280 | 1280 |
"", "Makes the current node the master"), |
1281 |
'master-ping': (
|
|
1281 |
"master-ping": (
|
|
1282 | 1282 |
MasterPing, ARGS_NONE, [], |
1283 | 1283 |
"", "Checks if the master is alive"), |
1284 |
'version': (
|
|
1284 |
"version": (
|
|
1285 | 1285 |
ShowClusterVersion, ARGS_NONE, [], |
1286 | 1286 |
"", "Shows the cluster version"), |
1287 |
'getmaster': (
|
|
1287 |
"getmaster": (
|
|
1288 | 1288 |
ShowClusterMaster, ARGS_NONE, [], |
1289 | 1289 |
"", "Shows the cluster master"), |
1290 |
'copyfile': (
|
|
1290 |
"copyfile": (
|
|
1291 | 1291 |
ClusterCopyFile, [ArgFile(min=1, max=1)], |
1292 | 1292 |
[NODE_LIST_OPT, USE_REPL_NET_OPT, NODEGROUP_OPT], |
1293 | 1293 |
"[-n node...] <filename>", "Copies a file to all (or only some) nodes"), |
1294 |
'command': (
|
|
1294 |
"command": (
|
|
1295 | 1295 |
RunClusterCommand, [ArgCommand(min=1)], |
1296 | 1296 |
[NODE_LIST_OPT, NODEGROUP_OPT], |
1297 | 1297 |
"[-n node...] <command>", "Runs a command on all (or only some) nodes"), |
1298 |
'info': (
|
|
1298 |
"info": (
|
|
1299 | 1299 |
ShowClusterConfig, ARGS_NONE, [ROMAN_OPT], |
1300 | 1300 |
"[--roman]", "Show cluster configuration"), |
1301 |
'list-tags': (
|
|
1301 |
"list-tags": (
|
|
1302 | 1302 |
ListTags, ARGS_NONE, [], "", "List the tags of the cluster"), |
1303 |
'add-tags': (
|
|
1303 |
"add-tags": (
|
|
1304 | 1304 |
AddTags, [ArgUnknown()], [TAG_SRC_OPT, PRIORITY_OPT], |
1305 | 1305 |
"tag...", "Add tags to the cluster"), |
1306 |
'remove-tags': (
|
|
1306 |
"remove-tags": (
|
|
1307 | 1307 |
RemoveTags, [ArgUnknown()], [TAG_SRC_OPT, PRIORITY_OPT], |
1308 | 1308 |
"tag...", "Remove tags from the cluster"), |
1309 |
'search-tags': (
|
|
1309 |
"search-tags": (
|
|
1310 | 1310 |
SearchTags, [ArgUnknown(min=1, max=1)], [PRIORITY_OPT], "", |
1311 | 1311 |
"Searches the tags on all objects on" |
1312 | 1312 |
" the cluster for a given pattern (regex)"), |
1313 |
'queue': (
|
|
1313 |
"queue": (
|
|
1314 | 1314 |
QueueOps, |
1315 | 1315 |
[ArgChoice(min=1, max=1, choices=["drain", "undrain", "info"])], |
1316 | 1316 |
[], "drain|undrain|info", "Change queue properties"), |
1317 |
'watcher': (
|
|
1317 |
"watcher": (
|
|
1318 | 1318 |
WatcherOps, |
1319 | 1319 |
[ArgChoice(min=1, max=1, choices=["pause", "continue", "info"]), |
1320 | 1320 |
ArgSuggest(min=0, max=1, choices=["30m", "1h", "4h"])], |
1321 | 1321 |
[], |
1322 | 1322 |
"{pause <timespec>|continue|info}", "Change watcher properties"), |
1323 |
'modify': (
|
|
1323 |
"modify": (
|
|
1324 | 1324 |
SetClusterParams, ARGS_NONE, |
1325 | 1325 |
[BACKEND_OPT, CP_SIZE_OPT, ENABLED_HV_OPT, HVLIST_OPT, MASTER_NETDEV_OPT, |
1326 | 1326 |
NIC_PARAMS_OPT, NOLVM_STORAGE_OPT, VG_NAME_OPT, MAINTAIN_NODE_HEALTH_OPT, |
... | ... | |
1347 | 1347 |
|
1348 | 1348 |
#: dictionary with aliases for commands |
1349 | 1349 |
aliases = { |
1350 |
'masterfailover': 'master-failover',
|
|
1350 |
"masterfailover": "master-failover",
|
|
1351 | 1351 |
} |
1352 | 1352 |
|
1353 | 1353 |
|
b/lib/client/gnt_debug.py | ||
---|---|---|
143 | 143 |
while len(row) < 3: |
144 | 144 |
row.append(None) |
145 | 145 |
for i in range(3): |
146 |
if row[i] == '':
|
|
146 |
if row[i] == "":
|
|
147 | 147 |
row[i] = None |
148 | 148 |
nic_dict = [{ |
149 | 149 |
constants.INIC_MAC: v[0], |
... | ... | |
616 | 616 |
|
617 | 617 |
|
618 | 618 |
commands = { |
619 |
'delay': (
|
|
619 |
"delay": (
|
|
620 | 620 |
Delay, [ArgUnknown(min=1, max=1)], |
621 | 621 |
[cli_option("--no-master", dest="on_master", default=True, |
622 | 622 |
action="store_false", help="Do not sleep in the master code"), |
... | ... | |
627 | 627 |
DRY_RUN_OPT, PRIORITY_OPT, |
628 | 628 |
], |
629 | 629 |
"[opts...] <duration>", "Executes a TestDelay OpCode"), |
630 |
'submit-job': (
|
|
630 |
"submit-job": (
|
|
631 | 631 |
GenericOpCodes, [ArgFile(min=1)], |
632 | 632 |
[VERBOSE_OPT, |
633 | 633 |
cli_option("--op-repeat", type="int", default="1", dest="rep_op", |
... | ... | |
642 | 642 |
], |
643 | 643 |
"<op_list_file...>", "Submits jobs built from json files" |
644 | 644 |
" containing a list of serialized opcodes"), |
645 |
'iallocator': (
|
|
645 |
"iallocator": (
|
|
646 | 646 |
TestAllocator, [ArgUnknown(min=1)], |
647 | 647 |
[cli_option("--dir", dest="direction", default=constants.IALLOCATOR_DIR_IN, |
648 | 648 |
choices=list(constants.VALID_IALLOCATOR_DIRECTIONS), |
b/lib/client/gnt_instance.py | ||
---|---|---|
287 | 287 |
"hvparams": {}, |
288 | 288 |
"file_storage_dir": None, |
289 | 289 |
"force_variant": False, |
290 |
"file_driver": 'loop'}
|
|
290 |
"file_driver": "loop"}
|
|
291 | 291 |
|
292 | 292 |
def _PopulateWithDefaults(spec): |
293 | 293 |
"""Returns a new hash combined with default values.""" |
... | ... | |
298 | 298 |
def _Validate(spec): |
299 | 299 |
"""Validate the instance specs.""" |
300 | 300 |
# Validate fields required under any circumstances |
301 |
for required_field in ('os', 'template'):
|
|
301 |
for required_field in ("os", "template"):
|
|
302 | 302 |
if required_field not in spec: |
303 | 303 |
raise errors.OpPrereqError('Required field "%s" is missing.' % |
304 | 304 |
required_field, errors.ECODE_INVAL) |
305 | 305 |
# Validate special fields |
306 |
if spec['primary_node'] is not None:
|
|
307 |
if (spec['template'] in constants.DTS_INT_MIRROR and
|
|
308 |
spec['secondary_node'] is None):
|
|
309 |
raise errors.OpPrereqError('Template requires secondary node, but'
|
|
310 |
' there was no secondary provided.',
|
|
306 |
if spec["primary_node"] is not None:
|
|
307 |
if (spec["template"] in constants.DTS_INT_MIRROR and
|
|
308 |
spec["secondary_node"] is None):
|
|
309 |
raise errors.OpPrereqError("Template requires secondary node, but"
|
|
310 |
" there was no secondary provided.",
|
|
311 | 311 |
errors.ECODE_INVAL) |
312 |
elif spec['iallocator'] is None:
|
|
313 |
raise errors.OpPrereqError('You have to provide at least a primary_node'
|
|
314 |
' or an iallocator.',
|
|
312 |
elif spec["iallocator"] is None:
|
|
313 |
raise errors.OpPrereqError("You have to provide at least a primary_node"
|
|
314 |
" or an iallocator.",
|
|
315 | 315 |
errors.ECODE_INVAL) |
316 | 316 |
|
317 |
if (spec['hvparams'] and
|
|
318 |
not isinstance(spec['hvparams'], dict)):
|
|
319 |
raise errors.OpPrereqError('Hypervisor parameters must be a dict.',
|
|
317 |
if (spec["hvparams"] and
|
|
318 |
not isinstance(spec["hvparams"], dict)):
|
|
319 |
raise errors.OpPrereqError("Hypervisor parameters must be a dict.",
|
|
320 | 320 |
errors.ECODE_INVAL) |
321 | 321 |
|
322 | 322 |
json_filename = args[0] |
... | ... | |
341 | 341 |
specs = _PopulateWithDefaults(specs) |
342 | 342 |
_Validate(specs) |
343 | 343 |
|
344 |
hypervisor = specs['hypervisor']
|
|
345 |
hvparams = specs['hvparams']
|
|
344 |
hypervisor = specs["hypervisor"]
|
|
345 |
hvparams = specs["hvparams"]
|
|
346 | 346 |
|
347 | 347 |
disks = [] |
348 |
for elem in specs['disk_size']:
|
|
348 |
for elem in specs["disk_size"]:
|
|
349 | 349 |
try: |
350 | 350 |
size = utils.ParseUnit(elem) |
351 | 351 |
except (TypeError, ValueError), err: |
... | ... | |
354 | 354 |
(elem, name, err), errors.ECODE_INVAL) |
355 | 355 |
disks.append({"size": size}) |
356 | 356 |
|
357 |
utils.ForceDictType(specs['backend'], constants.BES_PARAMETER_TYPES)
|
|
357 |
utils.ForceDictType(specs["backend"], constants.BES_PARAMETER_TYPES)
|
|
358 | 358 |
utils.ForceDictType(hvparams, constants.HVS_PARAMETER_TYPES) |
359 | 359 |
|
360 | 360 |
tmp_nics = [] |
... | ... | |
364 | 364 |
tmp_nics.append({}) |
365 | 365 |
tmp_nics[0][field] = specs[field] |
366 | 366 |
|
367 |
if specs['nics'] is not None and tmp_nics:
|
|
367 |
if specs["nics"] is not None and tmp_nics:
|
|
368 | 368 |
raise errors.OpPrereqError("'nics' list incompatible with using" |
369 | 369 |
" individual nic fields as well", |
370 | 370 |
errors.ECODE_INVAL) |
371 |
elif specs['nics'] is not None:
|
|
372 |
tmp_nics = specs['nics']
|
|
371 |
elif specs["nics"] is not None:
|
|
372 |
tmp_nics = specs["nics"]
|
|
373 | 373 |
elif not tmp_nics: |
374 | 374 |
tmp_nics = [{}] |
375 | 375 |
|
376 | 376 |
op = opcodes.OpInstanceCreate(instance_name=name, |
377 | 377 |
disks=disks, |
378 |
disk_template=specs['template'],
|
|
378 |
disk_template=specs["template"],
|
|
379 | 379 |
mode=constants.INSTANCE_CREATE, |
380 |
os_type=specs['os'],
|
|
380 |
os_type=specs["os"],
|
|
381 | 381 |
force_variant=specs["force_variant"], |
382 |
pnode=specs['primary_node'],
|
|
383 |
snode=specs['secondary_node'],
|
|
382 |
pnode=specs["primary_node"],
|
|
383 |
snode=specs["secondary_node"],
|
|
384 | 384 |
nics=tmp_nics, |
385 |
start=specs['start'],
|
|
386 |
ip_check=specs['ip_check'],
|
|
387 |
name_check=specs['name_check'],
|
|
385 |
start=specs["start"],
|
|
386 |
ip_check=specs["ip_check"],
|
|
387 |
name_check=specs["name_check"],
|
|
388 | 388 |
wait_for_sync=True, |
389 |
iallocator=specs['iallocator'],
|
|
389 |
iallocator=specs["iallocator"],
|
|
390 | 390 |
hypervisor=hypervisor, |
391 | 391 |
hvparams=hvparams, |
392 |
beparams=specs['backend'],
|
|
393 |
file_storage_dir=specs['file_storage_dir'],
|
|
394 |
file_driver=specs['file_driver'])
|
|
392 |
beparams=specs["backend"],
|
|
393 |
file_storage_dir=specs["file_storage_dir"],
|
|
394 |
file_driver=specs["file_driver"])
|
|
395 | 395 |
|
396 | 396 |
jex.QueueJob(name, op) |
397 | 397 |
# we never want to wait, just show the submitted job IDs |
... | ... | |
438 | 438 |
choices.append(("%s" % number, entry, entry)) |
439 | 439 |
number += 1 |
440 | 440 |
|
441 |
choices.append(('x', 'exit', 'Exit gnt-instance reinstall'))
|
|
441 |
choices.append(("x", "exit", "Exit gnt-instance reinstall"))
|
|
442 | 442 |
selected = AskUser("Enter OS template number (or x to abort):", |
443 | 443 |
choices) |
444 | 444 |
|
445 |
if selected == 'exit':
|
|
445 |
if selected == "exit":
|
|
446 | 446 |
ToStderr("User aborted reinstall, exiting") |
447 | 447 |
return 1 |
448 | 448 |
|
... | ... | |
1225 | 1225 |
_FormatList(buf, _FormatBlockDevInfo(idx, True, device, |
1226 | 1226 |
opts.roman_integers), 2) |
1227 | 1227 |
|
1228 |
ToStdout(buf.getvalue().rstrip('\n'))
|
|
1228 |
ToStdout(buf.getvalue().rstrip("\n"))
|
|
1229 | 1229 |
return retcode |
1230 | 1230 |
|
1231 | 1231 |
|
... | ... | |
1276 | 1276 |
except (TypeError, ValueError): |
1277 | 1277 |
pass |
1278 | 1278 |
if disk_op == constants.DDM_ADD: |
1279 |
if 'size' not in disk_dict:
|
|
1279 |
if "size" not in disk_dict:
|
|
1280 | 1280 |
raise errors.OpPrereqError("Missing required parameter 'size'", |
1281 | 1281 |
errors.ECODE_INVAL) |
1282 |
disk_dict['size'] = utils.ParseUnit(disk_dict['size'])
|
|
1282 |
disk_dict["size"] = utils.ParseUnit(disk_dict["size"])
|
|
1283 | 1283 |
|
1284 | 1284 |
if (opts.disk_template and |
1285 | 1285 |
opts.disk_template in constants.DTS_INT_MIRROR and |
... | ... | |
1368 | 1368 |
] |
1369 | 1369 |
|
1370 | 1370 |
commands = { |
1371 |
'add': (
|
|
1371 |
"add": (
|
|
1372 | 1372 |
AddInstance, [ArgHost(min=1, max=1)], COMMON_CREATE_OPTS + add_opts, |
1373 | 1373 |
"[...] -t disk-type -n node[:secondary-node] -o os-type <name>", |
1374 | 1374 |
"Creates and adds a new instance to the cluster"), |
1375 |
'batch-create': (
|
|
1375 |
"batch-create": (
|
|
1376 | 1376 |
BatchCreate, [ArgFile(min=1, max=1)], [DRY_RUN_OPT, PRIORITY_OPT], |
1377 | 1377 |
"<instances.json>", |
1378 | 1378 |
"Create a bunch of instances based on specs in the file."), |
1379 |
'console': (
|
|
1379 |
"console": (
|
|
1380 | 1380 |
ConnectToInstanceConsole, ARGS_ONE_INSTANCE, |
1381 | 1381 |
[SHOWCMD_OPT, PRIORITY_OPT], |
1382 | 1382 |
"[--show-cmd] <instance>", "Opens a console on the specified instance"), |
1383 |
'failover': (
|
|
1383 |
"failover": (
|
|
1384 | 1384 |
FailoverInstance, ARGS_ONE_INSTANCE, |
1385 | 1385 |
[FORCE_OPT, IGNORE_CONSIST_OPT, SUBMIT_OPT, SHUTDOWN_TIMEOUT_OPT, |
1386 | 1386 |
DRY_RUN_OPT, PRIORITY_OPT, DST_NODE_OPT, IALLOCATOR_OPT], |
1387 | 1387 |
"[-f] <instance>", "Stops the instance and starts it on the backup node," |
1388 | 1388 |
" using the remote mirror (only for mirrored instances)"), |
1389 |
'migrate': (
|
|
1389 |
"migrate": (
|
|
1390 | 1390 |
MigrateInstance, ARGS_ONE_INSTANCE, |
1391 | 1391 |
[FORCE_OPT, NONLIVE_OPT, MIGRATION_MODE_OPT, CLEANUP_OPT, DRY_RUN_OPT, |
1392 | 1392 |
PRIORITY_OPT, DST_NODE_OPT, IALLOCATOR_OPT, ALLOW_FAILOVER_OPT], |
1393 | 1393 |
"[-f] <instance>", "Migrate instance to its secondary node" |
1394 | 1394 |
" (only for mirrored instances)"), |
1395 |
'move': (
|
|
1395 |
"move": (
|
|
1396 | 1396 |
MoveInstance, ARGS_ONE_INSTANCE, |
1397 | 1397 |
[FORCE_OPT, SUBMIT_OPT, SINGLE_NODE_OPT, SHUTDOWN_TIMEOUT_OPT, |
1398 | 1398 |
DRY_RUN_OPT, PRIORITY_OPT, IGNORE_CONSIST_OPT], |
1399 | 1399 |
"[-f] <instance>", "Move instance to an arbitrary node" |
1400 | 1400 |
" (only for instances of type file and lv)"), |
1401 |
'info': (
|
|
1401 |
"info": (
|
|
1402 | 1402 |
ShowInstanceConfig, ARGS_MANY_INSTANCES, |
1403 | 1403 |
[STATIC_OPT, ALL_OPT, ROMAN_OPT, PRIORITY_OPT], |
1404 | 1404 |
"[-s] {--all | <instance>...}", |
1405 | 1405 |
"Show information on the specified instance(s)"), |
1406 |
'list': (
|
|
1406 |
"list": (
|
|
1407 | 1407 |
ListInstances, ARGS_MANY_INSTANCES, |
1408 | 1408 |
[NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, VERBOSE_OPT, |
1409 | 1409 |
FORCE_FILTER_OPT], |
... | ... | |
1418 | 1418 |
[NOHDR_OPT, SEP_OPT], |
1419 | 1419 |
"[fields...]", |
1420 | 1420 |
"Lists all available fields for instances"), |
1421 |
'reinstall': (
|
|
1421 |
"reinstall": (
|
|
1422 | 1422 |
ReinstallInstance, [ArgInstance()], |
1423 | 1423 |
[FORCE_OPT, OS_OPT, FORCE_VARIANT_OPT, m_force_multi, m_node_opt, |
1424 | 1424 |
m_pri_node_opt, m_sec_node_opt, m_clust_opt, m_inst_opt, m_node_tags_opt, |
1425 | 1425 |
m_pri_node_tags_opt, m_sec_node_tags_opt, m_inst_tags_opt, SELECT_OS_OPT, |
1426 | 1426 |
SUBMIT_OPT, DRY_RUN_OPT, PRIORITY_OPT, OSPARAMS_OPT], |
1427 | 1427 |
"[-f] <instance>", "Reinstall a stopped instance"), |
1428 |
'remove': (
|
|
1428 |
"remove": (
|
|
1429 | 1429 |
RemoveInstance, ARGS_ONE_INSTANCE, |
1430 | 1430 |
[FORCE_OPT, SHUTDOWN_TIMEOUT_OPT, IGNORE_FAILURES_OPT, SUBMIT_OPT, |
1431 | 1431 |
DRY_RUN_OPT, PRIORITY_OPT], |
1432 | 1432 |
"[-f] <instance>", "Shuts down the instance and removes it"), |
1433 |
'rename': (
|
|
1433 |
"rename": (
|
|
1434 | 1434 |
RenameInstance, |
1435 | 1435 |
[ArgInstance(min=1, max=1), ArgHost(min=1, max=1)], |
1436 | 1436 |
[NOIPCHECK_OPT, NONAMECHECK_OPT, SUBMIT_OPT, DRY_RUN_OPT, PRIORITY_OPT], |
1437 | 1437 |
"<instance> <new_name>", "Rename the instance"), |
1438 |
'replace-disks': (
|
|
1438 |
"replace-disks": (
|
|
1439 | 1439 |
ReplaceDisks, ARGS_ONE_INSTANCE, |
1440 | 1440 |
[AUTO_REPLACE_OPT, DISKIDX_OPT, IALLOCATOR_OPT, EARLY_RELEASE_OPT, |
1441 | 1441 |
NEW_SECONDARY_OPT, ON_PRIMARY_OPT, ON_SECONDARY_OPT, SUBMIT_OPT, |
1442 | 1442 |
DRY_RUN_OPT, PRIORITY_OPT], |
1443 | 1443 |
"[-s|-p|-n NODE|-I NAME] <instance>", |
1444 | 1444 |
"Replaces all disks for the instance"), |
1445 |
'modify': (
|
|
1445 |
"modify": (
|
|
1446 | 1446 |
SetInstanceParams, ARGS_ONE_INSTANCE, |
1447 | 1447 |
[BACKEND_OPT, DISK_OPT, FORCE_OPT, HVOPTS_OPT, NET_OPT, SUBMIT_OPT, |
1448 | 1448 |
DISK_TEMPLATE_OPT, SINGLE_NODE_OPT, OS_OPT, FORCE_VARIANT_OPT, |
1449 | 1449 |
OSPARAMS_OPT, DRY_RUN_OPT, PRIORITY_OPT, NWSYNC_OPT], |
1450 | 1450 |
"<instance>", "Alters the parameters of an instance"), |
1451 |
'shutdown': (
|
|
1451 |
"shutdown": (
|
|
1452 | 1452 |
GenericManyOps("shutdown", _ShutdownInstance), [ArgInstance()], |
1453 | 1453 |
[m_node_opt, m_pri_node_opt, m_sec_node_opt, m_clust_opt, |
1454 | 1454 |
m_node_tags_opt, m_pri_node_tags_opt, m_sec_node_tags_opt, |
1455 | 1455 |
m_inst_tags_opt, m_inst_opt, m_force_multi, TIMEOUT_OPT, SUBMIT_OPT, |
1456 | 1456 |
DRY_RUN_OPT, PRIORITY_OPT, IGNORE_OFFLINE_OPT, NO_REMEMBER_OPT], |
1457 | 1457 |
"<instance>", "Stops an instance"), |
1458 |
'startup': (
|
|
1458 |
"startup": (
|
|
1459 | 1459 |
GenericManyOps("startup", _StartupInstance), [ArgInstance()], |
1460 | 1460 |
[FORCE_OPT, m_force_multi, m_node_opt, m_pri_node_opt, m_sec_node_opt, |
1461 | 1461 |
m_node_tags_opt, m_pri_node_tags_opt, m_sec_node_tags_opt, |
... | ... | |
1463 | 1463 |
BACKEND_OPT, DRY_RUN_OPT, PRIORITY_OPT, IGNORE_OFFLINE_OPT, |
1464 | 1464 |
NO_REMEMBER_OPT, STARTUP_PAUSED_OPT], |
1465 | 1465 |
"<instance>", "Starts an instance"), |
1466 |
'reboot': (
|
|
1466 |
"reboot": (
|
|
1467 | 1467 |
GenericManyOps("reboot", _RebootInstance), [ArgInstance()], |
1468 | 1468 |
[m_force_multi, REBOOT_TYPE_OPT, IGNORE_SECONDARIES_OPT, m_node_opt, |
1469 | 1469 |
m_pri_node_opt, m_sec_node_opt, m_clust_opt, m_inst_opt, SUBMIT_OPT, |
1470 | 1470 |
m_node_tags_opt, m_pri_node_tags_opt, m_sec_node_tags_opt, |
1471 | 1471 |
m_inst_tags_opt, SHUTDOWN_TIMEOUT_OPT, DRY_RUN_OPT, PRIORITY_OPT], |
1472 | 1472 |
"<instance>", "Reboots an instance"), |
1473 |
'activate-disks': (
|
|
1473 |
"activate-disks": (
|
|
1474 | 1474 |
ActivateDisks, ARGS_ONE_INSTANCE, |
1475 | 1475 |
[SUBMIT_OPT, IGNORE_SIZE_OPT, PRIORITY_OPT], |
1476 | 1476 |
"<instance>", "Activate an instance's disks"), |
1477 |
'deactivate-disks': (
|
|
1477 |
"deactivate-disks": (
|
|
1478 | 1478 |
DeactivateDisks, ARGS_ONE_INSTANCE, |
1479 | 1479 |
[FORCE_OPT, SUBMIT_OPT, DRY_RUN_OPT, PRIORITY_OPT], |
1480 | 1480 |
"[-f] <instance>", "Deactivate an instance's disks"), |
1481 |
'recreate-disks': (
|
|
1481 |
"recreate-disks": (
|
|
1482 | 1482 |
RecreateDisks, ARGS_ONE_INSTANCE, |
1483 | 1483 |
[SUBMIT_OPT, DISKIDX_OPT, NODE_PLACEMENT_OPT, DRY_RUN_OPT, PRIORITY_OPT], |
1484 | 1484 |
"<instance>", "Recreate an instance's disks"), |
1485 |
'grow-disk': (
|
|
1485 |
"grow-disk": (
|
|
1486 | 1486 |
GrowDisk, |
1487 | 1487 |
[ArgInstance(min=1, max=1), ArgUnknown(min=1, max=1), |
1488 | 1488 |
ArgUnknown(min=1, max=1)], |
1489 | 1489 |
[SUBMIT_OPT, NWSYNC_OPT, DRY_RUN_OPT, PRIORITY_OPT], |
1490 | 1490 |
"<instance> <disk> <size>", "Grow an instance's disk"), |
1491 |
'list-tags': (
|
|
1491 |
"list-tags": (
|
|
1492 | 1492 |
ListTags, ARGS_ONE_INSTANCE, [PRIORITY_OPT], |
1493 | 1493 |
"<instance_name>", "List the tags of the given instance"), |
1494 |
'add-tags': (
|
|
1494 |
"add-tags": (
|
|
1495 | 1495 |
AddTags, [ArgInstance(min=1, max=1), ArgUnknown()], |
1496 | 1496 |
[TAG_SRC_OPT, PRIORITY_OPT], |
1497 | 1497 |
"<instance_name> tag...", "Add tags to the given instance"), |
1498 |
'remove-tags': (
|
|
1498 |
"remove-tags": (
|
|
1499 | 1499 |
RemoveTags, [ArgInstance(min=1, max=1), ArgUnknown()], |
1500 | 1500 |
[TAG_SRC_OPT, PRIORITY_OPT], |
1501 | 1501 |
"<instance_name> tag...", "Remove tags from given instance"), |
... | ... | |
1503 | 1503 |
|
1504 | 1504 |
#: dictionary with aliases for commands |
1505 | 1505 |
aliases = { |
1506 |
'start': 'startup',
|
|
1507 |
'stop': 'shutdown',
|
|
1506 |
"start": "startup",
|
|
1507 |
"stop": "shutdown",
|
|
1508 | 1508 |
} |
1509 | 1509 |
|
1510 | 1510 |
|
b/lib/client/gnt_job.py | ||
---|---|---|
157 | 157 |
|
158 | 158 |
age = args[0] |
159 | 159 |
|
160 |
if age == 'all':
|
|
160 |
if age == "all":
|
|
161 | 161 |
age = -1 |
162 | 162 |
else: |
163 | 163 |
age = ParseTimespec(age) |
... | ... | |
357 | 357 |
|
358 | 358 |
|
359 | 359 |
commands = { |
360 |
'list': (
|
|
360 |
"list": (
|
|
361 | 361 |
ListJobs, [ArgJobId()], |
362 | 362 |
[NOHDR_OPT, SEP_OPT, FIELDS_OPT], |
363 | 363 |
"[job_id ...]", |
... | ... | |
366 | 366 |
" op_status, op_result." |
367 | 367 |
" The default field" |
368 | 368 |
" list is (in order): %s." % utils.CommaJoin(_LIST_DEF_FIELDS)), |
369 |
'archive': (
|
|
369 |
"archive": (
|
|
370 | 370 |
ArchiveJobs, [ArgJobId(min=1)], [], |
371 | 371 |
"<job-id> [<job-id> ...]", "Archive specified jobs"), |
372 |
'autoarchive': (
|
|
372 |
"autoarchive": (
|
|
373 | 373 |
AutoArchiveJobs, |
374 | 374 |
[ArgSuggest(min=1, max=1, choices=["1d", "1w", "4w", "all"])], |
375 | 375 |
[], |
376 | 376 |
"<age>", "Auto archive jobs older than the given age"), |
377 |
'cancel': (
|
|
377 |
"cancel": (
|
|
378 | 378 |
CancelJobs, [ArgJobId(min=1)], [], |
379 | 379 |
"<job-id> [<job-id> ...]", "Cancel specified jobs"), |
380 |
'info': (
|
|
380 |
"info": (
|
|
381 | 381 |
ShowJobs, [ArgJobId(min=1)], [], |
382 | 382 |
"<job-id> [<job-id> ...]", |
383 | 383 |
"Show detailed information about the specified jobs"), |
384 |
'watch': (
|
|
384 |
"watch": (
|
|
385 | 385 |
WatchJob, [ArgJobId(min=1, max=1)], [], |
386 | 386 |
"<job-id>", "Follows a job and prints its output as it arrives"), |
387 | 387 |
} |
b/lib/client/gnt_node.py | ||
---|---|---|
174 | 174 |
readd = opts.readd |
175 | 175 |
|
176 | 176 |
try: |
177 |
output = cl.QueryNodes(names=[node], fields=['name', 'sip', 'master'],
|
|
177 |
output = cl.QueryNodes(names=[node], fields=["name", "sip", "master"],
|
|
178 | 178 |
use_locking=False) |
179 | 179 |
node_exists, sip, is_master = output[0] |
180 | 180 |
except (errors.OpPrereqError, errors.OpExecError): |
... | ... | |
197 | 197 |
sip = opts.secondary_ip |
198 | 198 |
|
199 | 199 |
# read the cluster name from the master |
200 |
output = cl.QueryConfigValues(['cluster_name'])
|
|
200 |
output = cl.QueryConfigValues(["cluster_name"])
|
|
201 | 201 |
cluster_name = output[0] |
202 | 202 |
|
203 | 203 |
if not readd and opts.node_setup: |
... | ... | |
851 | 851 |
|
852 | 852 |
|
853 | 853 |
commands = { |
854 |
'add': (
|
|
854 |
"add": (
|
|
855 | 855 |
AddNode, [ArgHost(min=1, max=1)], |
856 | 856 |
[SECONDARY_IP_OPT, READD_OPT, NOSSH_KEYCHECK_OPT, NODE_FORCE_JOIN_OPT, |
857 | 857 |
NONODE_SETUP_OPT, VERBOSE_OPT, NODEGROUP_OPT, PRIORITY_OPT, |
... | ... | |
867 | 867 |
"[-f] {-I <iallocator> | -n <dst>} <node>", |
868 | 868 |
"Relocate the secondary instances from a node" |
869 | 869 |
" to other nodes"), |
870 |
'failover': (
|
|
870 |
"failover": (
|
|
871 | 871 |
FailoverNode, ARGS_ONE_NODE, [FORCE_OPT, IGNORE_CONSIST_OPT, |
872 | 872 |
IALLOCATOR_OPT, PRIORITY_OPT], |
873 | 873 |
"[-f] <node>", |
874 | 874 |
"Stops the primary instances on a node and start them on their" |
875 | 875 |
" secondary node (only for instances with drbd disk template)"), |
876 |
'migrate': (
|
|
876 |
"migrate": (
|
|
877 | 877 |
MigrateNode, ARGS_ONE_NODE, |
878 | 878 |
[FORCE_OPT, NONLIVE_OPT, MIGRATION_MODE_OPT, DST_NODE_OPT, |
879 | 879 |
IALLOCATOR_OPT, PRIORITY_OPT], |
880 | 880 |
"[-f] <node>", |
881 | 881 |
"Migrate all the primary instance on a node away from it" |
882 | 882 |
" (only for instances of type drbd)"), |
883 |
'info': (
|
|
883 |
"info": (
|
|
884 | 884 |
ShowNodeConfig, ARGS_MANY_NODES, [], |
885 | 885 |
"[<node_name>...]", "Show information about the node(s)"), |
886 |
'list': (
|
|
886 |
"list": (
|
|
887 | 887 |
ListNodes, ARGS_MANY_NODES, |
888 | 888 |
[NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, VERBOSE_OPT, |
889 | 889 |
FORCE_FILTER_OPT], |
... | ... | |
897 | 897 |
[NOHDR_OPT, SEP_OPT], |
898 | 898 |
"[fields...]", |
899 | 899 |
"Lists all available fields for nodes"), |
900 |
'modify': (
|
|
900 |
"modify": (
|
|
901 | 901 |
SetNodeParams, ARGS_ONE_NODE, |
902 | 902 |
[FORCE_OPT, SUBMIT_OPT, MC_OPT, DRAINED_OPT, OFFLINE_OPT, |
903 | 903 |
CAPAB_MASTER_OPT, CAPAB_VM_OPT, SECONDARY_IP_OPT, |
904 | 904 |
AUTO_PROMOTE_OPT, DRY_RUN_OPT, PRIORITY_OPT, NODE_PARAMS_OPT, |
905 | 905 |
NODE_POWERED_OPT], |
906 | 906 |
"<node_name>", "Alters the parameters of a node"), |
907 |
'powercycle': (
|
|
907 |
"powercycle": (
|
|
908 | 908 |
PowercycleNode, ARGS_ONE_NODE, |
909 | 909 |
[FORCE_OPT, CONFIRM_OPT, DRY_RUN_OPT, PRIORITY_OPT], |
910 | 910 |
"<node_name>", "Tries to forcefully powercycle a node"), |
911 |
'power': (
|
|
911 |
"power": (
|
|
912 | 912 |
PowerNode, |
913 | 913 |
[ArgChoice(min=1, max=1, choices=_LIST_POWER_COMMANDS), |
914 | 914 |
ArgNode()], |
... | ... | |
916 | 916 |
FORCE_OPT, NOHDR_OPT, SEP_OPT, OOB_TIMEOUT_OPT, POWER_DELAY_OPT], |
917 | 917 |
"on|off|cycle|status [nodes...]", |
918 | 918 |
"Change power state of node by calling out-of-band helper."), |
919 |
'remove': (
|
|
919 |
"remove": (
|
|
920 | 920 |
RemoveNode, ARGS_ONE_NODE, [DRY_RUN_OPT, PRIORITY_OPT], |
921 | 921 |
"<node_name>", "Removes a node from the cluster"), |
922 |
'volumes': (
|
|
922 |
"volumes": (
|
|
923 | 923 |
ListVolumes, [ArgNode()], |
924 | 924 |
[NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, PRIORITY_OPT], |
925 | 925 |
"[<node_name>...]", "List logical volumes on node(s)"), |
926 |
'list-storage': (
|
|
926 |
"list-storage": (
|
|
927 | 927 |
ListStorage, ARGS_MANY_NODES, |
928 | 928 |
[NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, _STORAGE_TYPE_OPT, |
929 | 929 |
PRIORITY_OPT], |
930 | 930 |
"[<node_name>...]", "List physical volumes on node(s). The available" |
931 | 931 |
" fields are (see the man page for details): %s." % |
932 | 932 |
(utils.CommaJoin(_LIST_STOR_HEADERS))), |
933 |
'modify-storage': (
|
|
933 |
"modify-storage": (
|
|
934 | 934 |
ModifyStorage, |
935 | 935 |
[ArgNode(min=1, max=1), |
936 | 936 |
ArgChoice(min=1, max=1, choices=_MODIFIABLE_STORAGE_TYPES), |
937 | 937 |
ArgFile(min=1, max=1)], |
938 | 938 |
[ALLOCATABLE_OPT, DRY_RUN_OPT, PRIORITY_OPT], |
939 | 939 |
"<node_name> <storage_type> <name>", "Modify storage volume on a node"), |
940 |
'repair-storage': (
|
|
940 |
"repair-storage": (
|
|
941 | 941 |
RepairStorage, |
942 | 942 |
[ArgNode(min=1, max=1), |
943 | 943 |
ArgChoice(min=1, max=1, choices=_REPAIRABLE_STORAGE_TYPES), |
... | ... | |
945 | 945 |
[IGNORE_CONSIST_OPT, DRY_RUN_OPT, PRIORITY_OPT], |
946 | 946 |
"<node_name> <storage_type> <name>", |
947 | 947 |
"Repairs a storage volume on a node"), |
948 |
'list-tags': (
|
|
948 |
"list-tags": (
|
|
949 | 949 |
ListTags, ARGS_ONE_NODE, [], |
950 | 950 |
"<node_name>", "List the tags of the given node"), |
951 |
'add-tags': (
|
|
951 |
"add-tags": (
|
|
952 | 952 |
AddTags, [ArgNode(min=1, max=1), ArgUnknown()], [TAG_SRC_OPT, PRIORITY_OPT], |
953 | 953 |
"<node_name> tag...", "Add tags to the given node"), |
954 |
'remove-tags': (
|
|
954 |
"remove-tags": (
|
|
955 | 955 |
RemoveTags, [ArgNode(min=1, max=1), ArgUnknown()], |
956 | 956 |
[TAG_SRC_OPT, PRIORITY_OPT], |
957 | 957 |
"<node_name> tag...", "Remove tags from the given node"), |
b/lib/client/gnt_os.py | ||
---|---|---|
280 | 280 |
|
281 | 281 |
|
282 | 282 |
commands = { |
283 |
'list': (
|
|
283 |
"list": (
|
|
284 | 284 |
ListOS, ARGS_NONE, [NOHDR_OPT, PRIORITY_OPT], |
285 | 285 |
"", "Lists all valid operating systems on the cluster"), |
286 |
'diagnose': (
|
|
286 |
"diagnose": (
|
|
287 | 287 |
DiagnoseOS, ARGS_NONE, [PRIORITY_OPT], |
288 | 288 |
"", "Diagnose all operating systems"), |
289 |
'info': (
|
|
289 |
"info": (
|
|
290 | 290 |
ShowOSInfo, [ArgOs()], [PRIORITY_OPT], |
291 | 291 |
"", "Show detailed information about " |
292 | 292 |
"operating systems"), |
293 |
'modify': (
|
|
293 |
"modify": (
|
|
294 | 294 |
ModifyOS, ARGS_ONE_OS, |
295 | 295 |
[HVLIST_OPT, OSPARAMS_OPT, DRY_RUN_OPT, PRIORITY_OPT, |
296 | 296 |
HID_OS_OPT, BLK_OS_OPT], |
b/lib/cmdlib.py | ||
---|---|---|
998 | 998 |
bep = cluster.FillBE(instance) |
999 | 999 |
hvp = cluster.FillHV(instance) |
1000 | 1000 |
args = { |
1001 |
'name': instance.name,
|
|
1002 |
'primary_node': instance.primary_node,
|
|
1003 |
'secondary_nodes': instance.secondary_nodes,
|
|
1004 |
'os_type': instance.os,
|
|
1005 |
'status': instance.admin_up,
|
|
1006 |
'memory': bep[constants.BE_MEMORY],
|
|
1007 |
'vcpus': bep[constants.BE_VCPUS],
|
|
1008 |
'nics': _NICListToTuple(lu, instance.nics),
|
|
1009 |
'disk_template': instance.disk_template,
|
|
1010 |
'disks': [(disk.size, disk.mode) for disk in instance.disks],
|
|
1011 |
'bep': bep,
|
|
1012 |
'hvp': hvp,
|
|
1013 |
'hypervisor_name': instance.hypervisor,
|
|
1014 |
'tags': instance.tags,
|
|
1001 |
"name": instance.name,
|
|
1002 |
"primary_node": instance.primary_node,
|
|
1003 |
"secondary_nodes": instance.secondary_nodes,
|
|
1004 |
"os_type": instance.os,
|
|
1005 |
"status": instance.admin_up,
|
|
1006 |
"memory": bep[constants.BE_MEMORY],
|
|
1007 |
"vcpus": bep[constants.BE_VCPUS],
|
|
1008 |
"nics": _NICListToTuple(lu, instance.nics),
|
|
1009 |
"disk_template": instance.disk_template,
|
|
1010 |
"disks": [(disk.size, disk.mode) for disk in instance.disks],
|
|
1011 |
"bep": bep,
|
|
1012 |
"hvp": hvp,
|
|
1013 |
"hypervisor_name": instance.hypervisor,
|
|
1014 |
"tags": instance.tags,
|
|
1015 | 1015 |
} |
1016 | 1016 |
if override: |
1017 | 1017 |
args.update(override) |
... | ... | |
2840 | 2840 |
self._ErrorIf(test, self.ENODEHOOKS, node_name, |
2841 | 2841 |
"Script %s failed, output:", script) |
2842 | 2842 |
if test: |
2843 |
output = self._HOOKS_INDENT_RE.sub(' ', output)
|
|
2843 |
output = self._HOOKS_INDENT_RE.sub(" ", output)
|
|
2844 | 2844 |
feedback_fn("%s" % output) |
2845 | 2845 |
lu_result = 0 |
2846 | 2846 |
|
... | ... | |
4279 | 4279 |
if field == "node": |
4280 | 4280 |
val = node |
4281 | 4281 |
elif field == "phys": |
4282 |
val = vol['dev']
|
|
4282 |
val = vol["dev"]
|
|
4283 | 4283 |
elif field == "vg": |
4284 |
val = vol['vg']
|
|
4284 |
val = vol["vg"]
|
|
4285 | 4285 |
elif field == "name": |
4286 |
val = vol['name']
|
|
4286 |
val = vol["name"]
|
|
4287 | 4287 |
elif field == "size": |
4288 |
val = int(float(vol['size']))
|
|
4288 |
val = int(float(vol["size"]))
|
|
4289 | 4289 |
elif field == "instance": |
4290 | 4290 |
val = vol2inst.get((node, vol["vg"] + "/" + vol["name"]), "-") |
4291 | 4291 |
else: |
... | ... | |
5526 | 5526 |
nodeinfo = lu.rpc.call_node_info([node], None, hypervisor_name) |
5527 | 5527 |
nodeinfo[node].Raise("Can't get data from node %s" % node, |
5528 | 5528 |
prereq=True, ecode=errors.ECODE_ENVIRON) |
5529 |
free_mem = nodeinfo[node].payload.get('memory_free', None)
|
|
5529 |
free_mem = nodeinfo[node].payload.get("memory_free", None)
|
|
5530 | 5530 |
if not isinstance(free_mem, int): |
5531 | 5531 |
raise errors.OpPrereqError("Can't compute free memory on node %s, result" |
5532 | 5532 |
" was '%s'" % (node, free_mem), |
... | ... | |
8432 | 8432 |
|
8433 | 8433 |
disk_images = [] |
8434 | 8434 |
for idx in range(export_disks): |
8435 |
option = 'disk%d_dump' % idx
|
|
8435 |
option = "disk%d_dump" % idx
|
|
8436 | 8436 |
if export_info.has_option(constants.INISECT_INS, option): |
8437 | 8437 |
# FIXME: are the old os-es, disk sizes, etc. useful? |
8438 | 8438 |
export_name = export_info.get(constants.INISECT_INS, option) |
... | ... | |
8443 | 8443 |
|
8444 | 8444 |
self.src_images = disk_images |
8445 | 8445 |
|
8446 |
old_name = export_info.get(constants.INISECT_INS, 'name')
|
|
8446 |
old_name = export_info.get(constants.INISECT_INS, "name")
|
|
8447 | 8447 |
try: |
8448 |
exp_nic_count = export_info.getint(constants.INISECT_INS, 'nic_count')
|
|
8448 |
exp_nic_count = export_info.getint(constants.INISECT_INS, "nic_count")
|
|
8449 | 8449 |
except (TypeError, ValueError), err: |
8450 | 8450 |
raise errors.OpPrereqError("Invalid export file, nic_count is not" |
8451 | 8451 |
" an integer: %s" % str(err), |
... | ... | |
8453 | 8453 |
if self.op.instance_name == old_name: |
8454 | 8454 |
for idx, nic in enumerate(self.nics): |
8455 | 8455 |
if nic.mac == constants.VALUE_AUTO and exp_nic_count >= idx: |
8456 |
nic_mac_ini = 'nic%d_mac' % idx
|
|
8456 |
nic_mac_ini = "nic%d_mac" % idx
|
|
8457 | 8457 |
nic.mac = export_info.get(constants.INISECT_INS, nic_mac_ini) |
8458 | 8458 |
|
8459 | 8459 |
# ENDIF: self.op.mode == constants.INSTANCE_IMPORT |
... | ... | |
10374 | 10374 |
raise errors.OpPrereqError("Invalid IP address '%s'" % nic_ip, |
10375 | 10375 |
errors.ECODE_INVAL) |
10376 | 10376 |
|
10377 |
nic_bridge = nic_dict.get('bridge', None)
|
|
10377 |
nic_bridge = nic_dict.get("bridge", None)
|
|
10378 | 10378 |
nic_link = nic_dict.get(constants.INIC_LINK, None) |
10379 | 10379 |
if nic_bridge and nic_link: |
10380 | 10380 |
raise errors.OpPrereqError("Cannot pass 'bridge' and 'link'" |
10381 | 10381 |
" at the same time", errors.ECODE_INVAL) |
10382 | 10382 |
elif nic_bridge and nic_bridge.lower() == constants.VALUE_NONE: |
10383 |
nic_dict['bridge'] = None
|
|
10383 |
nic_dict["bridge"] = None
|
|
10384 | 10384 |
elif nic_link and nic_link.lower() == constants.VALUE_NONE: |
10385 | 10385 |
nic_dict[constants.INIC_LINK] = None |
10386 | 10386 |
|
... | ... | |
10423 | 10423 |
""" |
10424 | 10424 |
args = dict() |
10425 | 10425 |
if constants.BE_MEMORY in self.be_new: |
10426 |
args['memory'] = self.be_new[constants.BE_MEMORY]
|
|
10426 |
args["memory"] = self.be_new[constants.BE_MEMORY]
|
|
10427 | 10427 |
if constants.BE_VCPUS in self.be_new: |
10428 |
args['vcpus'] = self.be_new[constants.BE_VCPUS]
|
|
10428 |
args["vcpus"] = self.be_new[constants.BE_VCPUS]
|
|
10429 | 10429 |
# TODO: export disk changes. Note: _BuildInstanceHookEnv* don't export disk |
10430 | 10430 |
# information at all. |
10431 | 10431 |
if self.op.nics: |
10432 |
args['nics'] = []
|
|
10432 |
args["nics"] = []
|
|
10433 | 10433 |
nic_override = dict(self.op.nics) |
10434 | 10434 |
for idx, nic in enumerate(self.instance.nics): |
10435 | 10435 |
if idx in nic_override: |
... | ... | |
10450 | 10450 |
nicparams = self.cluster.SimpleFillNIC(nic.nicparams) |
10451 | 10451 |
mode = nicparams[constants.NIC_MODE] |
10452 | 10452 |
link = nicparams[constants.NIC_LINK] |
10453 |
args['nics'].append((ip, mac, mode, link))
|
|
10453 |
args["nics"].append((ip, mac, mode, link))
|
|
10454 | 10454 |
if constants.DDM_ADD in nic_override: |
10455 | 10455 |
ip = nic_override[constants.DDM_ADD].get(constants.INIC_IP, None) |
10456 | 10456 |
mac = nic_override[constants.DDM_ADD][constants.INIC_MAC] |
10457 | 10457 |
nicparams = self.nic_pnew[constants.DDM_ADD] |
10458 | 10458 |
mode = nicparams[constants.NIC_MODE] |
10459 | 10459 |
link = nicparams[constants.NIC_LINK] |
10460 |
args['nics'].append((ip, mac, mode, link))
|
|
10460 |
args["nics"].append((ip, mac, mode, link))
|
|
10461 | 10461 |
elif constants.DDM_REMOVE in nic_override: |
10462 |
del args['nics'][-1]
|
|
10462 |
del args["nics"][-1]
|
|
10463 | 10463 |
|
10464 | 10464 |
env = _BuildInstanceHookEnvByObject(self, self.instance, override=args) |
10465 | 10465 |
if self.op.disk_template: |
... | ... | |
10577 | 10577 |
# Assume the primary node is unreachable and go ahead |
10578 | 10578 |
self.warn.append("Can't get info from primary node %s: %s" % |
10579 | 10579 |
(pnode, msg)) |
10580 |
elif not isinstance(pninfo.payload.get('memory_free', None), int):
|
|
10580 |
elif not isinstance(pninfo.payload.get("memory_free", None), int):
|
|
10581 | 10581 |
self.warn.append("Node data from primary node %s doesn't contain" |
10582 | 10582 |
" free memory information" % pnode) |
10583 | 10583 |
elif instance_info.fail_msg: |
... | ... | |
10585 | 10585 |
instance_info.fail_msg) |
10586 | 10586 |
else: |
10587 | 10587 |
if instance_info.payload: |
10588 |
current_mem = int(instance_info.payload['memory'])
|
|
10588 |
current_mem = int(instance_info.payload["memory"])
|
|
10589 | 10589 |
else: |
10590 | 10590 |
# Assume instance not running |
10591 | 10591 |
# (there is a slight race condition here, but it's not very probable, |
10592 | 10592 |
# and we have no other way to check) |
10593 | 10593 |
current_mem = 0 |
10594 | 10594 |
miss_mem = (be_new[constants.BE_MEMORY] - current_mem - |
10595 |
pninfo.payload['memory_free'])
|
|
10595 |
pninfo.payload["memory_free"])
|
|
10596 | 10596 |
if miss_mem > 0: |
10597 | 10597 |
raise errors.OpPrereqError("This change will prevent the instance" |
10598 | 10598 |
" from starting, due to %d MB of memory" |
... | ... | |
10605 | 10605 |
continue |
10606 | 10606 |
nres.Raise("Can't get info from secondary node %s" % node, |
10607 | 10607 |
prereq=True, ecode=errors.ECODE_STATE) |
10608 |
if not isinstance(nres.payload.get('memory_free', None), int):
|
|
10608 |
if not isinstance(nres.payload.get("memory_free", None), int):
|
|
10609 | 10609 |
raise errors.OpPrereqError("Secondary node %s didn't return free" |
10610 | 10610 |
" memory information" % node, |
10611 | 10611 |
errors.ECODE_STATE) |
10612 |
elif be_new[constants.BE_MEMORY] > nres.payload['memory_free']:
|
|
10612 |
elif be_new[constants.BE_MEMORY] > nres.payload["memory_free"]:
|
|
10613 | 10613 |
raise errors.OpPrereqError("This change will prevent the instance" |
10614 | 10614 |
" from failover to its secondary node" |
10615 | 10615 |
" %s, due to not enough memory" % node, |
... | ... | |
10645 | 10645 |
for key in constants.NICS_PARAMETERS |
10646 | 10646 |
if key in nic_dict]) |
10647 | 10647 |
|
10648 |
if 'bridge' in nic_dict:
|
|
10649 |
update_params_dict[constants.NIC_LINK] = nic_dict['bridge']
|
|
10648 |
if "bridge" in nic_dict:
|
|
10649 |
update_params_dict[constants.NIC_LINK] = nic_dict["bridge"]
|
|
10650 | 10650 |
|
10651 | 10651 |
new_nic_params = _GetUpdatedParams(old_nic_params, |
10652 | 10652 |
update_params_dict) |
... | ... | |
10672 | 10672 |
else: |
10673 | 10673 |
nic_ip = old_nic_ip |
10674 | 10674 |
if nic_ip is None: |
10675 |
raise errors.OpPrereqError('Cannot set the nic ip to None'
|
|
10676 |
' on a routed nic', errors.ECODE_INVAL)
|
|
10675 |
raise errors.OpPrereqError("Cannot set the nic ip to None"
|
|
10676 |
" on a routed nic", errors.ECODE_INVAL)
|
|
10677 | 10677 |
if constants.INIC_MAC in nic_dict: |
10678 | 10678 |
nic_mac = nic_dict[constants.INIC_MAC] |
10679 | 10679 |
if nic_mac is None: |
10680 |
raise errors.OpPrereqError('Cannot set the nic mac to None',
|
|
10680 |
raise errors.OpPrereqError("Cannot set the nic mac to None",
|
|
10681 | 10681 |
errors.ECODE_INVAL) |
10682 | 10682 |
elif nic_mac in (constants.VALUE_AUTO, constants.VALUE_GENERATE): |
10683 | 10683 |
# otherwise generate the mac |
... | ... | |
12565 | 12565 |
nname) |
12566 | 12566 |
remote_info = nresult.payload |
12567 | 12567 |
|
12568 |
for attr in ['memory_total', 'memory_free', 'memory_dom0', |
|
12569 |
'vg_size', 'vg_free', 'cpu_total']: |
|
12568 |
for attr in ["memory_total", "memory_free", "memory_dom0", |
|
12569 |
"vg_size", "vg_free", "cpu_total"]: |
Also available in: Unified diff