from ceph_deploy import conf
from ceph_deploy.lib import remoto
from StringIO import StringIO
+from ceph_deploy.util import constants
def ceph_version(conn):
logger = distro.conn.logger
logger.debug('remote hostname: %s' % hostname)
path = paths.mon.path(args.cluster, hostname)
+ uid = distro.conn.remote_module.path_getuid(constants.base_path)
+ gid = distro.conn.remote_module.path_getgid(constants.base_path)
done_path = paths.mon.done(args.cluster, hostname)
init_path = paths.mon.init(args.cluster, hostname, distro.init)
)
# if the mon path does not exist, create it
- distro.conn.remote_module.create_mon_path(path)
+ distro.conn.remote_module.create_mon_path(path, uid, gid)
logger.debug('checking for done path: %s' % done_path)
if not distro.conn.remote_module.path_exists(done_path):
distro.conn.remote_module.write_monitor_keyring(
keyring,
monitor_keyring,
+ uid, gid,
)
+ user_args = []
+ if uid != 0:
+ user_args = user_args + [ '--setuser', str(uid) ]
+ if gid != 0:
+ user_args = user_args + [ '--setgroup', str(gid) ]
remoto.process.run(
distro.conn,
[
'--mkfs',
'-i', hostname,
'--keyring', keyring,
- ],
+ ] + user_args
)
logger.info('unlinking keyring file %s' % keyring)
distro.conn.remote_module.unlink(keyring)
# create the done file
- distro.conn.remote_module.create_done_path(done_path)
+ distro.conn.remote_module.create_done_path(done_path, uid, gid)
# create init path
- distro.conn.remote_module.create_init_path(init_path)
+ distro.conn.remote_module.create_init_path(init_path, uid, gid)
def mon_add(distro, args, monitor_keyring):
hostname = distro.conn.remote_module.shortname()
logger = distro.conn.logger
path = paths.mon.path(args.cluster, hostname)
+ uid = distro.conn.remote_module.path_getuid(constants.base_path)
+ gid = distro.conn.remote_module.path_getgid(constants.base_path)
monmap_path = paths.mon.monmap(args.cluster, hostname)
done_path = paths.mon.done(args.cluster, hostname)
init_path = paths.mon.init(args.cluster, hostname, distro.init)
)
# if the mon path does not exist, create it
- distro.conn.remote_module.create_mon_path(path)
+ distro.conn.remote_module.create_mon_path(path, uid, gid)
logger.debug('checking for done path: %s' % done_path)
if not distro.conn.remote_module.path_exists(done_path):
distro.conn.remote_module.write_monitor_keyring(
keyring,
monitor_keyring,
+ uid, gid,
)
# get the monmap
)
# now use it to prepare the monitor's data dir
+ user_args = []
+ if uid != 0:
+ user_args = user_args + [ '--setuser', str(uid) ]
+ if gid != 0:
+ user_args = user_args + [ '--setgroup', str(gid) ]
remoto.process.run(
distro.conn,
[
'--monmap',
monmap_path,
'--keyring', keyring,
- ],
+ ] + user_args
)
# add it
distro.conn.remote_module.unlink(keyring)
# create the done file
- distro.conn.remote_module.create_done_path(done_path)
+ distro.conn.remote_module.create_done_path(done_path, uid, gid)
# create init path
- distro.conn.remote_module.create_init_path(init_path)
+ distro.conn.remote_module.create_init_path(init_path, uid, gid)
# start the mon using the address
remoto.process.run(
raise RuntimeError(err_msg)
-def write_keyring(path, key):
+def write_keyring(path, key, uid=-1, gid=-1):
""" create a keyring file """
# Note that we *require* to avoid deletion of the temp file
# otherwise we risk not being able to copy the contents from
tmp_file.close()
keyring_dir = os.path.dirname(path)
if not path_exists(keyring_dir):
- makedir(keyring_dir)
+ makedir(keyring_dir, uid, gid)
shutil.move(tmp_file.name, path)
-def create_mon_path(path):
+def create_mon_path(path, uid=-1, gid=-1):
"""create the mon path if it does not exist"""
if not os.path.exists(path):
os.makedirs(path)
+ os.chown(path, uid, gid);
-def create_done_path(done_path):
+def create_done_path(done_path, uid=-1, gid=-1):
"""create a done file to avoid re-doing the mon deployment"""
with file(done_path, 'w'):
pass
+ os.chown(done_path, uid, gid);
-def create_init_path(init_path):
+def create_init_path(init_path, uid=-1, gid=-1):
"""create the init path if it does not exist"""
if not os.path.exists(init_path):
with file(init_path, 'w'):
pass
+ os.chown(init_path, uid, gid);
def append_to_file(file_path, contents):
with open(file_path, 'a') as f:
f.write(contents)
+def path_getuid(path):
+ return os.stat(path).st_uid
+
+def path_getgid(path):
+ return os.stat(path).st_gid
def readline(path):
with open(path) as _file:
return os.listdir(path)
-def makedir(path, ignored=None):
+def makedir(path, ignored=None, uid=-1, gid=-1):
ignored = ignored or []
try:
os.makedirs(path)
else:
# re-raise the original exception
raise
+ else:
+ os.chown(path, uid, gid);
def unlink(_file):
os.unlink(_file)
-def write_monitor_keyring(keyring, monitor_keyring):
+def write_monitor_keyring(keyring, monitor_keyring, uid=-1, gid=-1):
"""create the monitor keyring file"""
- write_file(keyring, monitor_keyring)
+ write_file(keyring, monitor_keyring, 0600, None, uid, gid)
-def write_file(path, content, mode=0644, directory=None):
+def write_file(path, content, mode=0644, directory=None, uid=-1, gid=-1):
if directory:
if path.startswith("/"):
path = path[1:]
path = os.path.join(directory, path)
with os.fdopen(os.open(path, os.O_WRONLY | os.O_CREAT, mode), 'w') as f:
f.write(content)
+ os.chown(path, uid, gid)
def touch_file(path):
shutil.move(path, os.path.join('/var/lib/ceph/mon-removed/', file_name))
-def safe_mkdir(path):
+def safe_mkdir(path, uid=-1, gid=-1):
""" create path if it doesn't exist """
try:
os.mkdir(path)
pass
else:
raise
+ else:
+ os.chown(path, uid, gid)
-
-def safe_makedirs(path):
+def safe_makedirs(path, uid=-1, gid=-1):
""" create path recursively if it doesn't exist """
try:
os.makedirs(path)
pass
else:
raise
+ else:
+ os.chown(path, uid, gid)
def zeroing(dev):