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):
"""
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")
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
@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)
return True
-def WriteSsconfFiles():
- ssconf.WriteSsconfFiles(constants.CLUSTER_CONF_FILE)
+def WriteSsconfFiles(values):
+ """Update all ssconf files.
+
+ Wrapper around the SimpleStore.WriteFiles.
+
+ """
+ ssconf.SimpleStore().WriteFiles(values)
def _ErrnoOrStr(err):
# 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)
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)