Example #1
0
    def mount(self, account):
        mount_path = os.path.join(self.mount_path, account)
        export = self.get_export_from_account_id(account)

        pid_dir  = "/var/lib/glusterd/vols/%s/run/" %export
        pid_file = os.path.join(pid_dir, 'swift.pid');

        if not os.path.exists(pid_dir):
            mkdirs(pid_dir)

        fd = os.open(pid_file, os.O_CREAT|os.O_RDWR)
        with os.fdopen(fd, 'r+b') as f:
            try:
                fcntl.lockf(f, fcntl.LOCK_EX|fcntl.LOCK_NB)
            except:
                ex = sys.exc_info()[1]
                if isinstance(ex, IOError) and ex.errno in (EACCES, EAGAIN):
                # This means that some other process is mounting the
                # filesystem, so wait for the mount process to complete
                    return self.busy_wait(mount_path)

            mnt_cmd = 'mount -t glusterfs %s:%s %s' % (self.mount_ip, export, \
                                                       mount_path)
            if os.system(mnt_cmd) or not self.busy_wait(mount_path):
                raise Exception('Mount failed %s: %s' % (self.name, mnt_cmd))
                return False
        return True
Example #2
0
    def mount(self, account):
        mount_path = os.path.join(self.mount_path, account)
        export = self.get_export_from_account_id(account)

        pid_dir = "/var/lib/glusterd/vols/%s/run/" % export
        pid_file = os.path.join(pid_dir, 'swift.pid')

        if not os.path.exists(pid_dir):
            mkdirs(pid_dir)

        fd = os.open(pid_file, os.O_CREAT | os.O_RDWR)
        with os.fdopen(fd, 'r+b') as f:
            try:
                fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
            except:
                ex = sys.exc_info()[1]
                if isinstance(ex, IOError) and ex.errno in (EACCES, EAGAIN):
                    # This means that some other process is mounting the
                    # filesystem, so wait for the mount process to complete
                    return self.busy_wait(mount_path)

            mnt_cmd = 'mount -t glusterfs %s:%s %s' % (self.mount_ip, export, \
                                                       mount_path)
            if os.system(mnt_cmd) or not self.busy_wait(mount_path):
                raise Exception('Mount failed %s: %s' % (self.name, mnt_cmd))
                return False
        return True
Example #3
0
 def create_dir_object(self, dir_path):
     # TODO: if object already exists???
     if os.path.exists(dir_path) and not os.path.isdir(dir_path):
         self.logger.error("Deleting file %s", dir_path)
         do_unlink(dir_path)
     # If dir aleady exist just override metadata.
     mkdirs(dir_path)
     do_chown(dir_path, self.uid, self.gid)
     create_object_metadata(dir_path)
     return True
Example #4
0
 def create_dir_object(self, dir_path):
     #TODO: if object already exists???
     if os.path.exists(dir_path) and not os.path.isdir(dir_path):
         self.logger.error("Deleting file %s", dir_path)
         do_unlink(dir_path)
     #If dir aleady exist just override metadata.
     mkdirs(dir_path)
     do_chown(dir_path, self.uid, self.gid)
     create_object_metadata(dir_path)
     return True
Example #5
0
    def put(self, metadata):
        """
        Create and write metatdata to directory/container.
        :param metadata: Metadata to write.
        """
        if not self.dir_exists:
            mkdirs(self.datadir)

        os.chown(self.datadir, self.uid, self.gid)
        write_metadata(self.datadir, metadata)
        self.metadata = metadata
        self.dir_exists = True
Example #6
0
    def put(self, metadata):
        """
        Create and write metatdata to directory/container.
        :param metadata: Metadata to write.
        """
        if not self.dir_exists:
            mkdirs(self.datadir)

        os.chown(self.datadir, self.uid, self.gid)
        write_metadata(self.datadir, metadata)
        self.metadata = metadata
        self.dir_exists = True
Example #7
0
    def mkstemp(self):
        """Contextmanager to make a temporary file."""

        if not os.path.exists(self.tmpdir):
            mkdirs(self.tmpdir)
        fd, tmppath = mkstemp(dir=self.tmpdir)
        try:
            yield fd, tmppath
        finally:
            try:
                os.close(fd)
            except OSError:
                pass
            try:
                os.unlink(tmppath)
            except OSError:
                pass
Example #8
0
    def mkstemp(self):
        """Contextmanager to make a temporary file."""

        if not os.path.exists(self.tmpdir):
            mkdirs(self.tmpdir)
        fd, tmppath = mkstemp(dir=self.tmpdir)
        try:
            yield fd, tmppath
        finally:
            try:
                os.close(fd)
            except OSError:
                pass
            try:
                os.unlink(tmppath)
            except OSError:
                pass