Ejemplo n.º 1
0
class Shares(Referenceable, SignalBroadcaster):
    """A ipc interface to interact with shares."""

    __metaclass__ = RemoteMeta

    # calls that will be accessible remotely
    remote_calls = [
       'get_shares',
       'accept_share',
       'reject_share',
       'delete_share',
       'subscribe',
       'unsubscribe',
       'create_share',
       'create_shares',
       'refresh_shares',
       'get_shared',
    ]

    def __init__(self, fs_manager, volume_manager):
        """Create the instance."""
        super(Shares, self).__init__()
        self.syncdaemon_shares = SyncdaemonShares(fs_manager, volume_manager)

    def get_shares(self):
        """Return a list of dicts, each dict represents a share."""
        logger.debug('called get_shares')
        return self.syncdaemon_shares.get_shares()

    def accept_share(self, share_id, reply_handler=None, error_handler=None):
        """Accept a share.

        A ShareAnswerOk|Error signal will be fired in the future as a
        success/failure indicator.

        """
        logger.debug('accept_share: %r', share_id)
        self.syncdaemon_shares.accept_share(share_id,
            remote_handler(reply_handler), remote_handler(error_handler))

    def reject_share(self, share_id, reply_handler=None, error_handler=None):
        """Reject a share."""
        logger.debug('reject_share: %r', share_id)
        self.syncdaemon_shares.reject_share(share_id,
            remote_handler(reply_handler),
            remote_handler(error_handler))

    def delete_share(self, share_id):
        """Delete a Share, both kinds: "to me" and "from me"."""
        logger.debug('delete_share: %r', share_id)
        try:
            self.syncdaemon_shares.delete_share(share_id)
        except Exception, e:
            logger.exception('Error while deleting share: %r', share_id)
            self.emit_share_delete_error({'volume_id':share_id}, str(e))
            # propagate the error
            raise
Ejemplo n.º 2
0
 def __init__(self, fs_manager, volume_manager):
     """Create the instance."""
     super(Shares, self).__init__()
     self.syncdaemon_shares = SyncdaemonShares(fs_manager, volume_manager)