"""
allowed_files = set([
pathutils.CLUSTER_CONF_FILE,
- constants.ETC_HOSTS,
+ pathutils.ETC_HOSTS,
pathutils.SSH_KNOWN_HOSTS_FILE,
pathutils.VNC_PASSWORD_FILE,
pathutils.RAPI_CERT_FILE,
hv_class = hypervisor.GetHypervisorClass(hv_name)
allowed_files.update(hv_class.GetAncillaryFiles()[0])
+ assert pathutils.FILE_STORAGE_PATHS_FILE not in allowed_files, \
+ "Allowed file storage paths should never be uploaded via RPC"
+
return frozenset(allowed_files)
if modify_ssh_setup:
try:
- priv_key, pub_key, auth_keys = ssh.GetUserFiles(constants.GANETI_RUNAS)
+ priv_key, pub_key, auth_keys = ssh.GetUserFiles(constants.SSH_LOGIN_USER)
utils.RemoveAuthorizedKey(auth_keys, utils.ReadFile(pub_key))
tmp.append((source, hv_name, str(err)))
if constants.NV_FILELIST in what:
- result[constants.NV_FILELIST] = utils.FingerprintFiles(
- what[constants.NV_FILELIST])
+ fingerprints = utils.FingerprintFiles(map(vcluster.LocalizeVirtualPath,
+ what[constants.NV_FILELIST]))
+ result[constants.NV_FILELIST] = \
+ dict((vcluster.MakeVirtualPath(key), value)
+ for (key, value) in fingerprints.items())
if constants.NV_NODELIST in what:
(nodes, bynode) = what[constants.NV_NODELIST]
@param size: The size in MiB to write
"""
+ # Internal sizes are always in Mebibytes; if the following "dd" command
+ # should use a different block size the offset and size given to this
+ # function must be adjusted accordingly before being passed to "dd".
+ block_size = 1024 * 1024
+
cmd = [constants.DD_CMD, "if=/dev/zero", "seek=%d" % offset,
- "bs=%d" % constants.WIPE_BLOCK_SIZE, "oflag=direct", "of=%s" % path,
+ "bs=%s" % block_size, "oflag=direct", "of=%s" % path,
"count=%d" % size]
result = utils.RunCmd(cmd)
_Fail("Cannot execute wipe for device %s: device not found", disk.iv_name)
# Do cross verify some of the parameters
+ if offset < 0:
+ _Fail("Negative offset")
+ if size < 0:
+ _Fail("Negative size")
if offset > rdev.size:
_Fail("Offset is bigger than device size")
if (offset + size) > rdev.size:
" oflag=dsync", dest_path)
remotecmd = _GetSshRunner(cluster_name).BuildCmd(dest_node,
- constants.GANETI_RUNAS,
+ constants.SSH_LOGIN_USER,
destcmd)
# all commands have been checked, so we're safe to combine them
return result.stdout
-def WriteSsconfFiles(values):
- """Update all ssconf files.
-
- Wrapper around the SimpleStore.WriteFiles.
-
- """
- ssconf.SimpleStore().WriteFiles(values)
-
-
def _OSOndiskAPIVersion(os_dir):
"""Compute and return the API version of a given OS.
if constants.OS_VARIANTS_FILE in os_files:
variants_file = os_files[constants.OS_VARIANTS_FILE]
try:
- variants = utils.ReadFile(variants_file).splitlines()
+ variants = \
+ utils.FilterEmptyLinesAndComments(utils.ReadFile(variants_file))
except EnvironmentError, err:
# we accept missing files, but not other errors
if err.errno != errno.ENOENT:
disk.unique_id, disk.dev_type)
+def BlockdevSetInfo(disk, info):
+ """Sets 'metadata' information on block devices.
+
+ This function sets 'info' metadata on block devices. Initial
+ information is set at device creation; this function should be used
+ for example after renames.
+
+ @type disk: L{objects.Disk}
+ @param disk: the disk to be grown
+ @type info: string
+ @param info: new 'info' metadata
+ @rtype: (status, result)
+ @return: a tuple with the status of the operation (True/False), and
+ the errors message if status is False
+
+ """
+ r_dev = _RecursiveFindBD(disk)
+ if r_dev is None:
+ _Fail("Cannot find block device %s", disk)
+
+ try:
+ r_dev.SetInfo(info)
+ except errors.BlockDeviceError, err:
+ _Fail("Failed to set information on block device: %s", err, exc=True)
+
+
def FinalizeExport(instance, snap_disks):
"""Write out the export configuration information.
@return: the normalized path if valid, None otherwise
"""
- if not constants.ENABLE_FILE_STORAGE:
+ if not (constants.ENABLE_FILE_STORAGE or
+ constants.ENABLE_SHARED_FILE_STORAGE):
_Fail("File storage disabled at configure time")
cfg = _GetConfig()
fs_dir = os.path.normpath(fs_dir)
@raises RPCFail: if the file is not valid
"""
- queue_dir = os.path.normpath(pathutils.QUEUE_DIR)
- result = (os.path.commonprefix([queue_dir, file_name]) == queue_dir)
-
- if not result:
+ if not utils.IsBelowDir(pathutils.QUEUE_DIR, file_name):
_Fail("Passed job queue file '%s' does not belong to"
- " the queue directory '%s'", file_name, queue_dir)
+ " the queue directory '%s'", file_name, pathutils.QUEUE_DIR)
def JobQueueUpdate(file_name, content):