X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/d868edb49c8dc11204865233e41e6a64c1257018..6192c9b7a2dda64c38415f3cf65fff16b726fae7:/lib/backend.py diff --git a/lib/backend.py b/lib/backend.py index c221107..0c1f237 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -45,13 +45,13 @@ from ganeti import ssconf def _GetConfig(): - """Simple wrapper to return a ConfigReader. + """Simple wrapper to return a SimpleStore. - @rtype: L{ssconf.SimpleConfigReader} - @return: a SimpleConfigReader instance + @rtype: L{ssconf.SimpleStore} + @return: a SimpleStore instance """ - return ssconf.SimpleConfigReader() + return ssconf.SimpleStore() def _GetSshRunner(cluster_name): @@ -350,37 +350,38 @@ def VerifyNode(what, cluster_name): """ result = {} - if 'hypervisor' in what: - result['hypervisor'] = my_dict = {} - for hv_name in what['hypervisor']: - my_dict[hv_name] = hypervisor.GetHypervisor(hv_name).Verify() + if constants.NV_HYPERVISOR in what: + result[constants.NV_HYPERVISOR] = tmp = {} + for hv_name in what[constants.NV_HYPERVISOR]: + tmp[hv_name] = hypervisor.GetHypervisor(hv_name).Verify() - if 'filelist' in what: - result['filelist'] = utils.FingerprintFiles(what['filelist']) + if constants.NV_FILELIST in what: + result[constants.NV_FILELIST] = utils.FingerprintFiles( + what[constants.NV_FILELIST]) - if 'nodelist' in what: - result['nodelist'] = {} - random.shuffle(what['nodelist']) - for node in what['nodelist']: + if constants.NV_NODELIST in what: + result[constants.NV_NODELIST] = tmp = {} + random.shuffle(what[constants.NV_NODELIST]) + for node in what[constants.NV_NODELIST]: success, message = _GetSshRunner(cluster_name).VerifyNodeHostname(node) if not success: - result['nodelist'][node] = message - if 'node-net-test' in what: - result['node-net-test'] = {} + tmp[node] = message + + if constants.NV_NODENETTEST in what: + result[constants.NV_NODENETTEST] = tmp = {} my_name = utils.HostInfo().name my_pip = my_sip = None - for name, pip, sip in what['node-net-test']: + for name, pip, sip in what[constants.NV_NODENETTEST]: if name == my_name: my_pip = pip my_sip = sip break if not my_pip: - result['node-net-test'][my_name] = ("Can't find my own" - " primary/secondary IP" - " in the node list") + tmp[my_name] = ("Can't find my own primary/secondary IP" + " in the node list") else: port = utils.GetNodeDaemonPort() - for name, pip, sip in what['node-net-test']: + for name, pip, sip in what[constants.NV_NODENETTEST]: fail = [] if not utils.TcpPing(pip, port, source=my_pip): fail.append("primary") @@ -388,9 +389,25 @@ def VerifyNode(what, cluster_name): if not utils.TcpPing(sip, port, source=my_sip): fail.append("secondary") if fail: - result['node-net-test'][name] = ("failure using the %s" - " interface(s)" % - " and ".join(fail)) + tmp[name] = ("failure using the %s interface(s)" % + " and ".join(fail)) + + if constants.NV_LVLIST in what: + result[constants.NV_LVLIST] = GetVolumeList(what[constants.NV_LVLIST]) + + if constants.NV_INSTANCELIST in what: + result[constants.NV_INSTANCELIST] = GetInstanceList( + what[constants.NV_INSTANCELIST]) + + if constants.NV_VGLIST in what: + result[constants.NV_VGLIST] = ListVolumeGroups() + + if constants.NV_VERSION in what: + result[constants.NV_VERSION] = constants.PROTOCOL_VERSION + + if constants.NV_HVINFO in what: + hyper = hypervisor.GetHypervisor(what[constants.NV_HVINFO]) + result[constants.NV_HVINFO] = hyper.GetNodeInfo() return result @@ -567,7 +584,7 @@ def GetAllInstancesInfo(hypervisor_list): @type hypervisor_list: list @param hypervisor_list: list of hypervisors to query for instance data - @rtype: dict of dicts + @rtype: dict @return: dictionary of instance: data, with data having the following keys: - memory: memory size of instance (int) - state: xen state of instance (string) @@ -1226,6 +1243,15 @@ def UploadFile(file_name, data, mode, uid, gid, atime, mtime): return True +def WriteSsconfFiles(values): + """Update all ssconf files. + + Wrapper around the SimpleStore.WriteFiles. + + """ + ssconf.SimpleStore().WriteFiles(values) + + def _ErrnoOrStr(err): """Format an EnvironmentError exception. @@ -1602,24 +1628,21 @@ def FinalizeExport(instance, snap_disks): # TODO: redundant: on load can read nics until it doesn't exist config.set(constants.INISECT_INS, 'nic_count' , '%d' % nic_count) - disk_count = 0 + disk_total = 0 for disk_count, disk in enumerate(snap_disks): if disk: + disk_total += 1 config.set(constants.INISECT_INS, 'disk%d_ivname' % disk_count, ('%s' % disk.iv_name)) config.set(constants.INISECT_INS, 'disk%d_dump' % disk_count, ('%s' % disk.physical_id[1])) config.set(constants.INISECT_INS, 'disk%d_size' % disk_count, ('%d' % disk.size)) - config.set(constants.INISECT_INS, 'disk_count' , '%d' % disk_count) - cff = os.path.join(destdir, constants.EXPORT_CONF_FILE) - cfo = open(cff, 'w') - try: - config.write(cfo) - finally: - cfo.close() + config.set(constants.INISECT_INS, 'disk_count' , '%d' % disk_total) + utils.WriteFile(os.path.join(destdir, constants.EXPORT_CONF_FILE), + data=config.Dumps()) shutil.rmtree(finaldestdir, True) shutil.move(destdir, finaldestdir) @@ -1687,8 +1710,9 @@ def ImportOSIntoInstance(instance, src_node, src_images, cluster_name): import_env['IMPORT_INDEX'] = str(idx) result = utils.RunCmd(command, env=import_env) if result.failed: - logging.error("disk import command '%s' returned error: %s" - " output: %s", command, result.fail_reason, result.output) + logging.error("Disk import command '%s' returned error: %s" + " output: %s", command, result.fail_reason, + result.output) final_result.append(False) else: final_result.append(True)