Exemple #1
0
 def _shutdown(self, ports, remove_data=False, op=None):
     is_replication_master = self.is_replication_master
     freed_ports = []
     for port in ports:
         if op:
             msg = 'Shutdown Redis %s on port %s' % ('Master' if is_replication_master else 'Slave', port)
             op.step(msg)
         try:
             if op:
                 op.__enter__()
             LOG.debug('Shutting down redis instance on port %s' % (port))
             instance = redis_service.Redis(port=port)
             if instance.service.running:
                 password = instance.redis_conf.requirepass
                 instance.password = password
                 LOG.debug('Dumping redis data on disk using password %s from config file %s' % (password, instance.redis_conf.path))
                 instance.redis_cli.save()
                 LOG.debug('Stopping the process')
                 instance.service.stop()
                 freed_ports.append(port)
             if remove_data and os.path.exists(instance.db_path):
                 os.remove(instance.db_path)
         except:
             if op:
                 op.__exit__(sys.exc_info())
             raise
         finally:
             if op:
                 op.__exit__(None)
     return dict(ports=freed_ports)
Exemple #2
0
    def _launch(self, ports=[], passwords=[], op=None):
        LOG.debug('Launching redis processes on ports %s with passwords %s' % (ports, passwords))
        is_replication_master = self.is_replication_master

        primary_ip = self.get_primary_ip()
        assert primary_ip is not None

        new_passwords = []
        new_ports = []



        for port,password in zip(ports, passwords or [None for port in ports]):
            if op:
                op.step('Launch Redis %s on port %s' % ('Master' if is_replication_master else 'Slave', port))
            try:
                if op:
                    op.__enter__()

                if iptables.enabled():
                    iptables.FIREWALL.ensure({
                            "jump": "ACCEPT", "protocol": "tcp", "match": "tcp", "dport": port
                    })


                redis_service.create_redis_conf_copy(port)
                redis_process = redis_service.Redis(is_replication_master, self.persistence_type, port, password)

                if not redis_process.service.running:
                    LOG.debug('Launch Redis %s on port %s' % ('Master' if is_replication_master else 'Slave', port))
                    if is_replication_master:
                        current_password = redis_process.init_master(STORAGE_PATH)
                    else:
                        current_password = redis_process.init_slave(STORAGE_PATH, primary_ip, port)
                    new_passwords.append(current_password)
                    new_ports.append(port)
                    LOG.debug('Redis process has been launched on port %s with password %s' % (port, current_password))

                else:
                    raise BaseException('Cannot launch redis on port %s: the process is already running' % port)

            except:
                if op:
                    op.__exit__(sys.exc_info())
                raise
            finally:
                if op:
                    op.__exit__(None)
        return (new_ports, new_passwords)
Exemple #3
0
    def _launch(self, ports=None, passwords=None, op=None):
        log = op.logger if op else LOG
        ports = ports or []
        passwords = passwords or []
        log.debug('Launching redis processes on ports %s with passwords %s',
                  ports, passwords)

        primary_ip = self.get_primary_ip()
        assert primary_ip is not None

        new_passwords = []
        new_ports = []

        for port, password in zip(ports, passwords
                                  or [None for port in ports]):
            log.info('Launch Redis %s on port %s',
                     'Master' if __redis__["replication_master"] else 'Slave',
                     port)

            if iptables.enabled():
                iptables.FIREWALL.ensure({
                    "jump": "ACCEPT",
                    "protocol": "tcp",
                    "match": "tcp",
                    "dport": port
                })

            redis_service.create_redis_conf_copy(port)
            redis_process = redis_service.Redis(port, password)

            if not redis_process.service.running:
                if __redis__["replication_master"]:
                    current_password = redis_process.init_master(STORAGE_PATH)
                else:
                    current_password = redis_process.init_slave(
                        STORAGE_PATH, primary_ip, port)
                new_passwords.append(current_password)
                new_ports.append(port)
                log.debug(
                    'Redis process has been launched on port %s with password %s'
                    % (port, current_password))

            else:
                raise BaseException(
                    'Cannot launch redis on port %s: the process is already running'
                    % port)

        return new_ports, new_passwords
Exemple #4
0
    def reset_password(self, port=DEFAULT_PORT, new_password=None):
        """ Reset auth for Redis process on port `port`. Return new password """
        if not new_password:
            new_password = pwgen(20)

        redis_conf = redis_service.RedisConf.find(port=port)
        redis_conf.requirepass = new_password

        if redis_conf.slaveof:
            redis_conf.masterauth = new_password

        redis_wrapper = redis_service.Redis(port=port)
        redis_wrapper.service.reload()

        if int(port) == DEFAULT_PORT:
            __redis__['master_password'] = new_password

        return new_password
Exemple #5
0
    def reset_password(self,
                       port=__redis__['defaults']['port'],
                       new_password=None):
        """ Reset auth for Redis process on port `port`. Return new password """
        if not new_password:
            new_password = pwgen(20)

        redis_conf = redis_service.RedisConf.find(port=port)
        redis_conf.requirepass = new_password

        if redis_conf.slaveof:
            redis_conf.masterauth = new_password

        redis_wrapper = redis_service.Redis(port=port, password=new_password)
        redis_wrapper.service.reload()

        if int(port) == __redis__['defaults']['port']:
            __redis__["master_password"] = new_password

        return new_password
Exemple #6
0
    def _shutdown(self, ports, remove_data=False, op=None):
        log = op.logger if op else LOG
        freed_ports = []
        for port in ports:
            log.info('Shutdown Redis %s on port %s' %
                     ('Master' if __redis__["replication_master"] else 'Slave',
                      port))

            instance = redis_service.Redis(port=port)
            if instance.service.running:
                password = instance.redis_conf.requirepass
                instance.password = password
                log.debug(
                    'Dumping redis data on disk using password %s from config file %s'
                    % (password, instance.redis_conf.path))
                instance.redis_cli.save()
                log.debug('Stopping the process')
                instance.service.stop()
                freed_ports.append(port)
            if remove_data and instance.db_path and os.path.exists(
                    instance.db_path):
                os.remove(instance.db_path)

        return dict(ports=freed_ports)