Пример #1
0
def get_all_users(**kwargs):
    rd = kwargs.pop('rados')
    reuse = kwargs.get('reuse', False)
    try:
        cmd = {'prefix': 'auth ls', 'format': 'json'}
        ret, buf, out = rd.mon_command(json.dumps(cmd), '')
        if ret != 0:
            log.error('ls user error: %s', out)
            raise ListUserError(out)
        users = json.loads(buf.decode('utf8'))['auth_dump']
        fs = cephfs.LibCephFS(rados_inst=rd)
        fs.mount()
        names = []
        for u in users:
            name = u['entity']
            if (name.startswith('client')
                    and not name.startswith('client.bootstrap')
                    and name != 'client.admin'):
                names.append(name[7:])

        def to_dict(name, used):
            return {'user': name, 'used': used[0], 'quota': used[1]}

        return [to_dict(n, _get_used_one_user(fs, n)) for n in names]
    finally:
        if not reuse:
            rd.shutdown()
Пример #2
0
    def connect(self, premount_evict=None):
        """

        :param premount_evict: Optional auth_id to evict before mounting the filesystem: callers
                               may want to use this to specify their own auth ID if they expect
                               to be a unique instance and don't want to wait for caps to time
                               out after failure of another instance of themselves.
        """
        log.debug("Connecting to RADOS with config {0}...".format(
            self.conf_path))
        self.rados = rados.Rados(name="client.{0}".format(self.auth_id),
                                 clustername=self.cluster_name,
                                 conffile=self.conf_path,
                                 conf={})
        self.rados.connect()

        log.debug("Connection to RADOS complete")

        log.debug("Connecting to cephfs...")
        self.fs = cephfs.LibCephFS(rados_inst=self.rados)
        log.debug("CephFS initializing...")
        self.fs.init()
        if premount_evict is not None:
            log.debug(
                "Premount eviction of {0} starting".format(premount_evict))
            self.evict(premount_evict)
            log.debug(
                "Premount eviction of {0} completes".format(premount_evict))
        log.debug("CephFS mounting...")
        self.fs.mount()
        log.debug("Connection to cephfs complete")
Пример #3
0
    def __init__(self, conf_file='/etc/ceph/ceph.conf', auth_id='admin',
                 keyring_file='/etc/ceph/ceph.client.admin.keyring', cluster=None):
        """Creates a CephFS util wrapper instance

        :param conf_file str opt: ceph conf file path
        :param auth_id str opt: the id used to authenticate the client entity (e.g.,
                                client.admin, openattic)
        :param keyring_file str opt: the keyring file path
        :param cluster ceph.models.CephCluster opt: ceph cluster model instance
        """
        if cluster:
            conf_file = cluster.config_file_path
            auth_id = cluster.keyring_user

            # if the auth_id starts with the prefix "client." we need to remove it 
            if auth_id.startswith('client.'):
                auth_id = auth_id[auth_id.find('.')+1:]
            keyring_file = cluster.keyring_file_path

        logger.debug("Initializing CephFS connection: conf_file=%s, auth_id=%s, keyring_file=%s",
                     conf_file, auth_id, keyring_file)

        self.cfs = libcephfs.LibCephFS(conffile=conf_file, auth_id=auth_id,
                                       conf={'keyring': keyring_file})
        self.cfs.mount()
Пример #4
0
 def connect(self):
     log.debug("Connecting to cephfs...")
     self.fs = cephfs.LibCephFS(rados_inst=self.rados)
     log.debug("CephFS initializing...")
     self.fs.init()
     log.debug("CephFS mounting...")
     self.fs.mount(filesystem_name=self.fs_name.encode('utf-8'))
     log.debug("Connection to cephfs complete")
Пример #5
0
 def __init__(self, fs_name=None):
     logger.debug("initializing cephfs connection")
     self.cfs = cephfs.LibCephFS(rados_inst=mgr.rados)
     logger.debug("mounting cephfs filesystem: %s", fs_name)
     if fs_name:
         self.cfs.mount(filesystem_name=fs_name)
     else:
         self.cfs.mount()
     logger.debug("mounted cephfs filesystem")
Пример #6
0
 def connect(self):
     assert self.ops_in_progress == 0
     log.debug("Connecting to cephfs '{0}'".format(self.fs_name))
     self.fs = cephfs.LibCephFS(rados_inst=self.mgr.rados)
     log.debug("CephFS initializing...")
     self.fs.init()
     log.debug("CephFS mounting...")
     self.fs.mount(filesystem_name=self.fs_name.encode('utf-8'))
     log.debug("Connection to cephfs '{0}' complete".format(
         self.fs_name))
Пример #7
0
 def connect(self):
     assert self.ops_in_progress == 0
     log.debug("Connecting to cephfs '{0}'".format(self.fs_name))
     self.fs = cephfs.LibCephFS(rados_inst=self.mgr.rados)
     log.debug("Setting user ID and group ID of CephFS mount as root...")
     self.fs.conf_set("client_mount_uid", "0")
     self.fs.conf_set("client_mount_gid", "0")
     log.debug("CephFS initializing...")
     self.fs.init()
     log.debug("CephFS mounting...")
     self.fs.mount(filesystem_name=self.fs_name.encode('utf-8'))
     log.debug("Connection to cephfs '{0}' complete".format(self.fs_name))
Пример #8
0
    def __init__(self, confFilePath=None, clientPermission='0'):
        self._fileSys = cephfs.LibCephFS()
        self._fileSys.conf_read_file()
        self._fileSys.conf_set('client_permissions', clientPermission)
        self._mounted = False

        if self._fileSys.state != 'mounted':
            try:
                self._fileSys.mount()
                self._mounted = True
            except Exception as ex:
                print(repr(ex))
Пример #9
0
def _get_user_used(rados_instanse, user):
    '''
    get one user used
    login cephfs to get used
    required rados
    '''
    try:
        fs = cephfs.LibCephFS(rados_inst=rados_instanse)
        fs.mount()
        path = os.path.join(root_prefix, user)
        return _get_path_used(fs, path)
    except Exception as e:
        log.error('connect cephfs error: {0}'.format(e))
        raise AttrError(e)
Пример #10
0
 def connect(self) -> None:
     assert self.ops_in_progress == 0
     logger.debug("Connecting to cephfs '{0}'".format(self.fs_name))
     self.fs = cephfs.LibCephFS(rados_inst=self.mgr.rados)
     logger.debug("Setting user ID and group ID of CephFS mount as root...")
     self.fs.conf_set("client_mount_uid", "0")
     self.fs.conf_set("client_mount_gid", "0")
     self.fs.conf_set("client_check_pool_perm", "false")
     logger.debug("CephFS initializing...")
     self.fs.init()
     logger.debug("CephFS mounting...")
     self.fs.mount(filesystem_name=self.fs_name.encode('utf-8'))
     logger.debug("Connection to cephfs '{0}' complete".format(self.fs_name))
     self.mgr._ceph_register_client(self.fs.get_addrs())
Пример #11
0
def _get_users_used(rados_instanse, mds):
    '''
    get all users used from mds
    login cephfs to get used
    required rados
    '''
    try:
        fs = cephfs.LibCephFS(rados_inst=rados_instanse)
        fs.mount()
        paths = _get_paths_from_mds(mds)
        if paths:
            set_root_prefix(os.path.dirname(paths[-1]))
        return [_get_path_used(fs, p) for p in paths]
    except Exception as e:
        log.error('connect cephfs error: {0}'.format(e))
        raise AttrError(e)
Пример #12
0
def connect_to_filesystem(client_name, cluster_name, fs_name, desc):
    try:
        cluster = connect_to_cluster(client_name, cluster_name, desc)
        log.debug(f'connecting to {desc} filesystem: {fs_name}')
        fs = cephfs.LibCephFS(rados_inst=cluster)
        log.debug('CephFS initializing...')
        fs.init()
        log.debug('CephFS mounting...')
        fs.mount(filesystem_name=fs_name.encode('utf-8'))
        log.debug(f'Connection to cephfs {fs_name} complete')
        return (cluster, fs)
    except cephfs.Error as e:
        if e.errno == errno.ENOENT:
            raise MirrorException(-e.errno, f'filesystem {fs_name} does not exist')
        else:
            log.error(f'error connecting to filesystem {fs_name}: {e}')
            raise Exception(-e.errno)
Пример #13
0
def _set_quota_path(rados_instanse, path, quota, unit, verbose):
    try:
        fs = cephfs.LibCephFS(rados_inst=rados_instanse)
        fs.mount()
        fs.conf_set('client_permissions', '0')
        try:
            fs.mkdirs(path, 0o777)
        except cephfs.ObjectExists:
            pass
        quota = quota * units.get(unit)
        fs.setxattr(path, "ceph.quota.max_bytes",
                    str(quota).encode('ascii'), 0)
        if verbose:
            log.info('set path {0} quota max bytes {1}'.format(path, quota))
    except Exception as e:
        log.error('set path {0} quota error: {1}'.format(path, e))
        raise AttrError(e)
Пример #14
0
def flush(ceph, testnum):
    print >>sys.stderr, 'flushing {t}'.format(t=testnum)
    set_mds_config_param(ceph, '--mds_log_max_segments 1')

    for i in range(1, 500):
        f = '{p}.{pid}.{t}.{i}'.format(p=prefix, pid=os.getpid(), t=testnum, i=i)
        print >>sys.stderr, 'flushing with create {f}'.format(f=f)
        fd = ceph.open(f, os.O_CREAT | os.O_RDWR, 0644)
        ceph.close(fd)
        ceph.unlink(f)

    print >> sys.stderr, 'flush doing shutdown'
    ceph.shutdown()
    print >> sys.stderr, 'flush reinitializing ceph'
    ceph = cephfs.LibCephFS(conffile=conf)
    print >> sys.stderr, 'flush doing mount'
    ceph.mount()
    return ceph
Пример #15
0
def setup_cephfs():
    global cephfs
    cephfs = libcephfs.LibCephFS(conffile='ceph/build/ceph.conf')
    cephfs.mount()
Пример #16
0
#!/usr/bin/env python2

import cephfs
import sys
import os
import hashlib

config_file = "ceph.conf"

cephfs_handle = cephfs.LibCephFS()

cephfs_handle.create()  # create
cephfs_handle.conf_read_file(config_file)
cephfs_handle.conf_parse_argv(sys.argv)
cephfs_handle.mount()
cephfs_handle.chdir("/")

# Note: there's no chmod function

file_descriptor = -1
text_to_write = "123pescao"

file_descriptor = cephfs_handle.open(
    "dummy_file", os.O_RDONLY)  # this os.FLAG is VERY IMPORTANT!
print "File descriptor is: ", file_descriptor
#cephfs_handle.write(file_descriptor,cephfs.cstr(len(text_to_write) * 8, str("hola")),0);
return_buffer = cephfs_handle.read(file_descriptor, 0, 4028)

print "size read: ", len(return_buffer)
print "contents of file: ", return_buffer
Пример #17
0
def setup_module():
    global cephfs
    cephfs = libcephfs.LibCephFS(conffile='')
    cephfs.mount()
Пример #18
0
 def __init__(self, cluster):
     self.fs = cephfs.LibCephFS()
     self.fs.create_with_rados(cluster)
     self.fs.init()
     self.fs.mount()
Пример #19
0
#!/usr/bin/env python

import cephfs
import rados
import sys

conf_path = "/etc/ceph/ceph.conf"
cluster_name = "ceph"
auth_id = "admin"
rados = rados.Rados(name="client.{0}".format(auth_id),
                    clustername=cluster_name,
                    conffile=conf_path,
                    conf={})
rados.connect()

fs = cephfs.LibCephFS(rados_inst=rados)
fs.init()
fs.mount()

keys = [
    "ceph.dir.layout.pool", "ceph.dir.layout.pool_namespace",
    "ceph.quota.max_bytes", "ceph.quota.max_files"
]

for arg in sys.argv[1:]:
    for key in keys:
        print("print {}@{}".format(key, arg))
        try:
            value = fs.getxattr(arg, key)
            print(type(value), ",", value)
        except cephfs.NoData:
Пример #20
0
    return fi, expected_bt


test = -1
if len(sys.argv) > 1:
    test = int(sys.argv[1])

conf = ''
if len(sys.argv) > 2:
    conf = sys.argv[2]

radosobj = rados.Rados(conffile=conf)
radosobj.connect()
ioctx = radosobj.open_ioctx('data')

ceph = cephfs.LibCephFS(conffile=conf)
ceph.mount()

rooti = ceph.stat('/')['st_ino']

test = -1
if len(sys.argv) > 1:
    test = int(sys.argv[1])

conf = '/etc/ceph/ceph.conf'
if len(sys.argv) > 2:
    conf = sys.argv[2]

# create /a/b/c
# flush
# verify
Пример #21
0
import cephfs

fileSys = cephfs.LibCephFS()

# Load the ceph.conf from the default location. Pass in the path of ceph.conf if it's in a different location.
fileSys.conf_read_file()
fileSys.conf_set("client_permissions", "0")
# Mount the filesystem to the default location "/"
fileSys.mount()

# Make a dir, change the dir, and get the current working dir.
fileSys.mkdir('testDir', 777)
fileSys.chdir('testDir')
fileSys.getcwd()

# Create and write a file
fd = fileSys.open('/testDir/my.txt','w')
fileSys.write(fd,b'Hello World!',-1)
fileSys.close(fd)

# Read and print the content of the file
fileSys.open('/testDir/my.txt', 'r')
content = fileSys.read(fd,-1,10)
print(content)

# Check the metadata of the file
stat = fileSys.fstat(fd)
print(stat)

# Close the file
fileSys.close(fd)