Commit 0607699d authored by Guido Trotter's avatar Guido Trotter
Browse files

Convert ExportSnapshot to OS API 10

We pass the data via the environment rather than on the command line, as
API 10 says. All the rest remains the same, and we export just one disk,
as the master calls this function for every snapshotted disk.

Reviewed-by: iustinp
parent 19d7f90a
...@@ -1343,9 +1343,7 @@ def ExportSnapshot(disk, dest_node, instance, cluster_name): ...@@ -1343,9 +1343,7 @@ def ExportSnapshot(disk, dest_node, instance, cluster_name):
True if successful, False otherwise. True if successful, False otherwise.
""" """
# TODO(ultrotter): Import/Export still to be converted to OS API 10 export_env = OSEnvironment(instance)
logging.error("Import/Export still to be converted to OS API 10")
return False
inst_os = OSFromDisk(instance.os) inst_os = OSFromDisk(instance.os)
export_script = inst_os.export_script export_script = inst_os.export_script
...@@ -1354,12 +1352,13 @@ def ExportSnapshot(disk, dest_node, instance, cluster_name): ...@@ -1354,12 +1352,13 @@ def ExportSnapshot(disk, dest_node, instance, cluster_name):
instance.name, int(time.time())) instance.name, int(time.time()))
if not os.path.exists(constants.LOG_OS_DIR): if not os.path.exists(constants.LOG_OS_DIR):
os.mkdir(constants.LOG_OS_DIR, 0750) os.mkdir(constants.LOG_OS_DIR, 0750)
real_disk = _RecursiveFindBD(disk)
real_os_dev = _RecursiveFindBD(disk) if real_disk is None:
if real_os_dev is None:
raise errors.BlockDeviceError("Block device '%s' is not set up" % raise errors.BlockDeviceError("Block device '%s' is not set up" %
str(disk)) str(disk))
real_os_dev.Open() real_disk.Open()
export_env['EXPORT_DEVICE'] = real_disk.dev_path
destdir = os.path.join(constants.EXPORT_DIR, instance.name + ".new") destdir = os.path.join(constants.EXPORT_DIR, instance.name + ".new")
destfile = disk.physical_id[1] destfile = disk.physical_id[1]
...@@ -1367,10 +1366,8 @@ def ExportSnapshot(disk, dest_node, instance, cluster_name): ...@@ -1367,10 +1366,8 @@ def ExportSnapshot(disk, dest_node, instance, cluster_name):
# the target command is built out of three individual commands, # the target command is built out of three individual commands,
# which are joined by pipes; we check each individual command for # which are joined by pipes; we check each individual command for
# valid parameters # valid parameters
expcmd = utils.BuildShellCmd("cd %s; %s 2>%s", inst_os.path,
expcmd = utils.BuildShellCmd("cd %s; %s -i %s -b %s 2>%s", inst_os.path, export_script, logfile)
export_script, instance.name,
real_os_dev.dev_path, logfile)
comprcmd = "gzip" comprcmd = "gzip"
...@@ -1383,7 +1380,7 @@ def ExportSnapshot(disk, dest_node, instance, cluster_name): ...@@ -1383,7 +1380,7 @@ def ExportSnapshot(disk, dest_node, instance, cluster_name):
# all commands have been checked, so we're safe to combine them # all commands have been checked, so we're safe to combine them
command = '|'.join([expcmd, comprcmd, utils.ShellQuoteArgs(remotecmd)]) command = '|'.join([expcmd, comprcmd, utils.ShellQuoteArgs(remotecmd)])
result = utils.RunCmd(command) result = utils.RunCmd(command, env=export_env)
if result.failed: if result.failed:
logging.error("os snapshot export command '%s' returned error: %s" logging.error("os snapshot export command '%s' returned error: %s"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment