"""Run the watcher hooks.
"""
- hooks_dir = os.path.join(constants.HOOKS_BASE_DIR,
- constants.HOOKS_NAME_WATCHER)
+ hooks_dir = utils.PathJoin(constants.HOOKS_BASE_DIR,
+ constants.HOOKS_NAME_WATCHER)
try:
results = utils.RunParts(hooks_dir)
exclude = [os.path.normpath(i) for i in exclude]
for rel_name in utils.ListVisibleFiles(path):
- full_name = os.path.normpath(os.path.join(path, rel_name))
+ full_name = utils.PathJoin(path, rel_name)
if full_name in exclude:
continue
if os.path.isfile(full_name) and not os.path.islink(full_name):
def _GetBlockDevSymlinkPath(instance_name, idx):
- return os.path.join(constants.DISK_LINKS_DIR,
- "%s:%d" % (instance_name, idx))
+ return utils.PathJoin(constants.DISK_LINKS_DIR,
+ "%s:%d" % (instance_name, idx))
def _SymlinkBlockDev(instance_name, device_path, idx):
export_env['EXPORT_DEVICE'] = real_disk.dev_path
export_env['EXPORT_INDEX'] = str(idx)
- destdir = os.path.join(constants.EXPORT_DIR, instance.name + ".new")
+ destdir = utils.PathJoin(constants.EXPORT_DIR, instance.name + ".new")
destfile = disk.physical_id[1]
# the target command is built out of three individual commands,
@rtype: None
"""
- destdir = os.path.join(constants.EXPORT_DIR, instance.name + ".new")
- finaldestdir = os.path.join(constants.EXPORT_DIR, instance.name)
+ destdir = utils.PathJoin(constants.EXPORT_DIR, instance.name + ".new")
+ finaldestdir = utils.PathJoin(constants.EXPORT_DIR, instance.name)
config = objects.SerializableConfigParser()
config.set(constants.INISECT_INS, 'disk_count' , '%d' % disk_total)
- utils.WriteFile(os.path.join(destdir, constants.EXPORT_CONF_FILE),
+ utils.WriteFile(utils.PathJoin(destdir, constants.EXPORT_CONF_FILE),
data=config.Dumps())
shutil.rmtree(finaldestdir, True)
shutil.move(destdir, finaldestdir)
export info
"""
- cff = os.path.join(dest, constants.EXPORT_CONF_FILE)
+ cff = utils.PathJoin(dest, constants.EXPORT_CONF_FILE)
config = objects.SerializableConfigParser()
config.read(cff)
@rtype: None
"""
- target = os.path.join(constants.EXPORT_DIR, export)
+ target = utils.PathJoin(constants.EXPORT_DIR, export)
try:
shutil.rmtree(target)
self.needed_locks[locking.LEVEL_NODE].append(src_node)
if not os.path.isabs(src_path):
self.op.src_path = src_path = \
- os.path.join(constants.EXPORT_DIR, src_path)
+ utils.PathJoin(constants.EXPORT_DIR, src_path)
# On import force_variant must be True, because if we forced it at
# initial install, our only chance when importing it back is that it
if src_path in exp_list[node].payload:
found = True
self.op.src_node = src_node = node
- self.op.src_path = src_path = os.path.join(constants.EXPORT_DIR,
- src_path)
+ self.op.src_path = src_path = utils.PathJoin(constants.EXPORT_DIR,
+ src_path)
break
if not found:
raise errors.OpPrereqError("No export found for relative path %s" %
if export_info.has_option(constants.INISECT_INS, option):
# FIXME: are the old os-es, disk sizes, etc. useful?
export_name = export_info.get(constants.INISECT_INS, option)
- image = os.path.join(src_path, export_name)
+ image = utils.PathJoin(src_path, export_name)
disk_images.append(image)
else:
disk_images.append(False)
string_file_storage_dir = self.op.file_storage_dir
# build the full file storage dir path
- file_storage_dir = os.path.normpath(os.path.join(
- self.cfg.GetFileStorageDir(),
- string_file_storage_dir, instance))
+ file_storage_dir = utils.PathJoin(self.cfg.GetFileStorageDir(),
+ string_file_storage_dir, instance)
disks = _GenerateDiskTemplate(self,
# rename the file paths in logical and physical id
file_storage_dir = os.path.dirname(os.path.dirname(disk.logical_id[1]))
disk.physical_id = disk.logical_id = (disk.logical_id[0],
- os.path.join(file_storage_dir,
- inst.name,
- disk.iv_name))
+ utils.PathJoin(file_storage_dir,
+ inst.name,
+ disk.iv_name))
self._config_data.instances[inst.name] = inst
self._WriteConfig()
"""
return [name for name in os.listdir(self._ROOT_DIR)
- if self._IsDirLive(os.path.join(self._ROOT_DIR, name))]
+ if self._IsDirLive(utils.PathJoin(self._ROOT_DIR, name))]
def GetInstanceInfo(self, instance_name):
"""Get instance properties.
"""
data = []
for file_name in os.listdir(self._ROOT_DIR):
- path = os.path.join(self._ROOT_DIR, file_name)
+ path = utils.PathJoin(self._ROOT_DIR, file_name)
if self._IsDirLive(path):
data.append((file_name, 0, 0, 0, 0, 0))
return data
@return: the path to the job file
"""
- return os.path.join(constants.QUEUE_DIR, "job-%s" % job_id)
+ return utils.PathJoin(constants.QUEUE_DIR, "job-%s" % job_id)
@classmethod
def _GetArchivedJobPath(cls, job_id):
"""
path = "%s/job-%s" % (cls._GetArchiveDirectory(job_id), job_id)
- return os.path.join(constants.JOB_QUEUE_ARCHIVE_DIR, path)
+ return utils.PathJoin(constants.JOB_QUEUE_ARCHIVE_DIR, path)
@classmethod
def _ExtractJobID(cls, name):
if not user_dir:
raise errors.OpExecError("Cannot resolve home of user %s" % user)
- ssh_dir = os.path.join(user_dir, ".ssh")
+ ssh_dir = utils.PathJoin(user_dir, ".ssh")
if not os.path.lexists(ssh_dir):
if mkdir:
try:
elif not os.path.isdir(ssh_dir):
raise errors.OpExecError("path ~%s/.ssh is not a directory" % user)
- return [os.path.join(ssh_dir, base)
+ return [utils.PathJoin(ssh_dir, base)
for base in ["id_dsa", "id_dsa.pub", "authorized_keys"]]
return rr
for relname in sorted(dir_contents):
- fname = os.path.join(dir_name, relname)
+ fname = PathJoin(dir_name, relname)
if not (os.path.isfile(fname) and os.access(fname, os.X_OK) and
constants.EXT_PLUGIN_MASK.match(relname) is not None):
rr.append((relname, constants.RUNPARTS_SKIP, None))
daemon name
"""
- return os.path.join(constants.RUN_GANETI_DIR, "%s.pid" % name)
+ return PathJoin(constants.RUN_GANETI_DIR, "%s.pid" % name)
def EnsureDaemon(name):
for (curpath, _, files) in os.walk(path):
for filename in files:
- st = os.lstat(os.path.join(curpath, filename))
+ st = os.lstat(PathJoin(curpath, filename))
size += st.st_size
return BytesToMebibyte(size)
"""
-import os
import sys
import optparse
import time
shutdown=True)
rem_op = opcodes.OpRemoveInstance(instance_name=instance,
ignore_failures=True)
- imp_dir = os.path.join(constants.EXPORT_DIR, full_name)
+ imp_dir = utils.PathJoin(constants.EXPORT_DIR, full_name)
imp_op = opcodes.OpCreateInstance(instance_name=instance,
disks = [ {"size": size}
for size in self.disk_size],
" key from %s. Fail reason: %s; output: %s" %
(cluster, result.fail_reason, result.output))
- key_path = os.path.join(self.work_dir, cluster)
+ key_path = utils.PathJoin(self.work_dir, cluster)
utils.WriteFile(key_path, mode=0600, data=result.stdout)
result = self._RunCmd(cluster, "gnt-node list -o name --no-header",
(data.cluster, result.fail_reason,
result.output))
- data.config_path = os.path.join(self.work_dir, "%s_config.data" %
- data.cluster)
+ data.config_path = utils.PathJoin(self.work_dir, "%s_config.data" %
+ data.cluster)
utils.WriteFile(data.config_path, data=result.stdout)
# R0201: Method could be a function