示例#1
0
    def _start_init(self):
        # Regenerage key
        new_crypto_key = cryptotool.keygen()

        # Prepare HostInit
        __node__['boot_time'] = time.time() - sysutil.uptime()
        msg = self.new_message(
            Messages.HOST_INIT,
            dict(
                seconds_since_start=float(
                    '%.2f' % (time.time() - __node__['start_time'], )),
                seconds_since_boot=float(
                    '%.2f' % (time.time() - __node__['boot_time'], )),
                #operation_id = bus.init_op.operation_id,
                crypto_key=new_crypto_key),
            broadcast=True)
        bus.fire("before_host_init", msg)

        result_msg = self.send_message(msg,
                                       new_crypto_key=new_crypto_key,
                                       handle_host_init=True)

        bus.cnf.state = ScalarizrState.INITIALIZING
        bus.fire("host_init")

        if result_msg and \
            parse_bool(result_msg.body.get('base', {}).get('reboot_after_hostinit_phase')):
            # apply setting from HostInit
            self._system_api.reboot()
            threading.Event().wait(600)
示例#2
0
    def test_on_mysql_newmaster_up(self):
        bus.queryenv_service = _QueryEnv()
        bus.platform = _Platform()
        config = bus.config
        sect_name = configtool.get_behaviour_section_name(mysql.BEHAVIOUR)
        config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '0')
        handler = _MysqlHandler()
        root_pass, repl_pass, stat_pass = handler._add_mysql_users(mysql.ROOT_USER, mysql.REPL_USER, mysql.STAT_USER)
        handler._update_config( {mysql.OPT_ROOT_PASSWORD : root_pass,
                                                         mysql.OPT_REPL_PASSWORD : repl_pass,
                                                         mysql.OPT_STAT_PASSWORD : stat_pass})
        message = _Message()
        if linux.os.redhat_family:
            daemon = "/usr/libexec/mysqld"
        else:
            daemon = "/usr/sbin/mysqld"
        initd.stop("mysql")
        myd = Popen([daemon, '--defaults-file=/etc/mysql2/my.cnf', '--skip-grant-tables'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
        ping_service(LOCAL_IP, 3306, 5)
        myclient = pexpect.spawn('/usr/bin/mysql -h'+LOCAL_IP)
        myclient.expect('mysql>')
        repl_password = re.sub('[^\w]','', cryptotool.keygen(20))
        sql = "update mysql.user set password = PASSWORD('"+repl_password+"') where user = '******';"
        myclient.sendline(sql)
        myclient.expect('mysql>')
        result = myclient.before
        if re.search('ERROR', result):
            os.kill(myd.pid, signal.SIGTERM)
            raise BaseException("Cannot update user", result)
        myclient.sendline('FLUSH TABLES WITH READ LOCK;')
        myclient.expect('mysql>')
#               system('cp -pr /var/lib/mysql /var/lib/backmysql')
#               system('rm -rf /var/lib/mysql && cp -pr /var/lib/mysql2 /var/lib/mysql')
        myclient.sendline('SHOW MASTER STATUS;')
        myclient.expect('mysql>')
        # retrieve log file and position
        try:
            master_status = myclient.before.split('\r\n')[4].split('|')
        except:
            raise BaseException("Cannot get master status")
        finally:
            myclient.sendline('UNLOCK TABLES;')
            os.kill(myd.pid, signal.SIGTERM)
        myd = Popen([daemon, '--defaults-file=/etc/mysql2/my.cnf'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
        ping_service(LOCAL_IP, 3306, 5)
        message.log_file = master_status[1].strip()
        message.log_pos = master_status[2].strip()
        message.repl_user = mysql.REPL_USER
        message.repl_password = repl_password
        message.root_password = root_pass
        handler.on_Mysql_NewMasterUp(message)
        os.kill(myd.pid, signal.SIGTERM)
        initd.stop("mysql")
        system ('rm -rf /var/lib/mysql && cp -pr /var/lib/backmysql /var/lib/mysql && rm -rf /var/lib/backmysql')
        config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '1')
示例#3
0
    def test_on_mysql_newmaster_up(self):
        bus.queryenv_service = _QueryEnv()
        bus.platform = _Platform()
        config = bus.config
        sect_name = configtool.get_behaviour_section_name(mysql.BEHAVIOUR)
        config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '0')
        handler = _MysqlHandler()
        root_pass, repl_pass, stat_pass = handler._add_mysql_users(mysql.ROOT_USER, mysql.REPL_USER, mysql.STAT_USER)
        handler._update_config( {mysql.OPT_ROOT_PASSWORD : root_pass,
                                                         mysql.OPT_REPL_PASSWORD : repl_pass,
                                                         mysql.OPT_STAT_PASSWORD : stat_pass})
        message = _Message()
        if disttool.is_redhat_based():
            daemon = "/usr/libexec/mysqld"
        else:
            daemon = "/usr/sbin/mysqld"
        initd.stop("mysql")
        myd = Popen([daemon, '--defaults-file=/etc/mysql2/my.cnf', '--skip-grant-tables'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
        ping_service(LOCAL_IP, 3306, 5)
        myclient = pexpect.spawn('/usr/bin/mysql -h'+LOCAL_IP)
        myclient.expect('mysql>')
        repl_password = re.sub('[^\w]','', cryptotool.keygen(20))
        sql = "update mysql.user set password = PASSWORD('"+repl_password+"') where user = '******';"
        myclient.sendline(sql)
        myclient.expect('mysql>')
        result = myclient.before
        if re.search('ERROR', result):
            os.kill(myd.pid, signal.SIGTERM)
            raise BaseException("Cannot update user", result)
        myclient.sendline('FLUSH TABLES WITH READ LOCK;')
        myclient.expect('mysql>')
#               system('cp -pr /var/lib/mysql /var/lib/backmysql')
#               system('rm -rf /var/lib/mysql && cp -pr /var/lib/mysql2 /var/lib/mysql')
        myclient.sendline('SHOW MASTER STATUS;')
        myclient.expect('mysql>')
        # retrieve log file and position
        try:
            master_status = myclient.before.split('\r\n')[4].split('|')
        except:
            raise BaseException("Cannot get master status")
        finally:
            myclient.sendline('UNLOCK TABLES;')
            os.kill(myd.pid, signal.SIGTERM)
        myd = Popen([daemon, '--defaults-file=/etc/mysql2/my.cnf'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
        ping_service(LOCAL_IP, 3306, 5)
        message.log_file = master_status[1].strip()
        message.log_pos = master_status[2].strip()
        message.repl_user = mysql.REPL_USER
        message.repl_password = repl_password
        message.root_password = root_pass
        handler.on_Mysql_NewMasterUp(message)
        os.kill(myd.pid, signal.SIGTERM)
        initd.stop("mysql")
        system ('rm -rf /var/lib/mysql && cp -pr /var/lib/backmysql /var/lib/mysql && rm -rf /var/lib/backmysql')
        config.set(sect_name, mysql.OPT_REPLICATION_MASTER, '1')
    def setup(self):
        self.tmp = tempfile.mkdtemp()

        self.crypto_key_path = os.path.join(self.tmp, 'crypto_key')
        with open(self.crypto_key_path, 'w') as fp:
            fp.write(cryptotool.keygen())

        def app_creator():
            return jsonrpc_http.WsgiApplication(
                rpc.RequestHandler({'myservice': MyService()}),
                self.crypto_key_path)

        self.app = app_creator()
        self.app_creator = app_creator
示例#5
0
    def setup(self):
        self.tmp = tempfile.mkdtemp()

        self.crypto_key_path = os.path.join(self.tmp, 'crypto_key')
        with open(self.crypto_key_path, 'w') as fp:
            fp.write(cryptotool.keygen())


        def app_creator():
            return jsonrpc_http.WsgiApplication(
                                    rpc.RequestHandler({'myservice': MyService()}),
                                    self.crypto_key_path)

        self.app = app_creator()
        self.app_creator = app_creator
示例#6
0
	def _start_init(self):
		# Regenerage key
		new_crypto_key = cryptotool.keygen()
		
		# Prepare HostInit
		msg = self.new_message(Messages.HOST_INIT, dict(
			crypto_key = new_crypto_key,
			snmp_port = self._cnf.rawini.get(config.SECT_SNMP, config.OPT_PORT),
			snmp_community_name = self._cnf.rawini.get(config.SECT_SNMP, config.OPT_COMMUNITY_NAME)
		), broadcast=True)
		bus.fire("before_host_init", msg)

		self.send_message(msg, new_crypto_key=new_crypto_key, wait_ack=True)
		bus.cnf.state = ScalarizrState.INITIALIZING

		bus.fire("host_init")
示例#7
0
    def _start_init(self):
        # Regenerage key
        new_crypto_key = cryptotool.keygen()

        # Prepare HostInit
        msg = self.new_message(Messages.HOST_INIT,
                               dict(crypto_key=new_crypto_key,
                                    snmp_port=self._cnf.rawini.get(
                                        config.SECT_SNMP, config.OPT_PORT),
                                    snmp_community_name=self._cnf.rawini.get(
                                        config.SECT_SNMP,
                                        config.OPT_COMMUNITY_NAME)),
                               broadcast=True)
        bus.fire("before_host_init", msg)

        self.send_message(msg, new_crypto_key=new_crypto_key, wait_ack=True)
        bus.cnf.state = ScalarizrState.INITIALIZING

        bus.fire("host_init")
示例#8
0
    def _init_bollard(self):
        if linux.os.windows:
            return
        # FatMouse integration
        import agent.celeryfile
        import agent.config
        agent.config.TASK_ENGINE = 'bollard'
        agent.config.HOME_DIR = \
            os.path.expandvars('$ProgramData\\scalarizr') \
            if linux.os.windows else \
            '/var/lib/scalarizr'
        agent.config.CACHE_DIR = os.path.join(agent.config.HOME_DIR, 'cache')
        task_modules = [
            'scalarizr.api.mariadb',
            'scalarizr.api.mysql',
            'scalarizr.api.operation',
            'scalarizr.api.postgresql',
            'scalarizr.api.redis',
            'scalarizr.api.storage',
            'scalarizr.api.system'] + \
            list(agent.celeryfile.CELERY_INCLUDE)
        callbacks = {
            'global.push': _bollard_pass_access_data,
            'global.before': _bollard_set_access_data,
            'global.after': _bollard_clear_access_data,
            'global.pull': _bollard_send_operation_result,
            'global.fork': _bollard_fork
        }

        if not os.path.exists(bus.cnf.key_path('bollard')):
            bollard_key = cryptotool.keygen(length=40)
            bus.cnf.write_key('bollard', bollard_key, 'Bollard crypto key')

        bollard.CRYPTO_KEY = bus.cnf.read_key('bollard')
        bollard.AUTH_KEY = bollard.CRYPTO_KEY[0:16]

        __node__['bollard'] = bollard.Executor(
            task_modules=task_modules,
            callbacks=callbacks,
            push_server_address='/var/run/scalarizr.push.sock',
            pull_server_address='/var/run/scalarizr.pull.sock')
示例#9
0
    def _start_init(self):
        # Regenerage key
        new_crypto_key = cryptotool.keygen()
        bus.init_op = self._op_api.create('system.init', lambda op: None)

        # Prepare HostInit
        msg = self.new_message(
            Messages.HOST_INIT,
            dict(seconds_since_start=float(
                '%.2f' % (time.time() - __node__['start_time'], )),
                 seconds_since_boot=float(
                     '%.2f' % (time.time() - metadata.boot_time(), )),
                 operation_id=bus.init_op.operation_id,
                 crypto_key=new_crypto_key),
            broadcast=True)
        bus.fire("before_host_init", msg)

        self.send_message(msg, new_crypto_key=new_crypto_key, wait_ack=True)
        bus.cnf.state = ScalarizrState.INITIALIZING

        bus.fire("host_init")
示例#10
0
    def _start_init(self):
        # Regenerage key
        new_crypto_key = cryptotool.keygen()
        bus.init_op = self._op_api.create("system.init", lambda op: None)

        # Prepare HostInit
        msg = self.new_message(
            Messages.HOST_INIT,
            dict(
                seconds_since_start=float("%.2f" % (time.time() - __node__["start_time"],)),
                seconds_since_boot=float("%.2f" % (time.time() - metadata.boot_time(),)),
                operation_id=bus.init_op.operation_id,
                crypto_key=new_crypto_key,
            ),
            broadcast=True,
        )
        bus.fire("before_host_init", msg)

        self.send_message(msg, new_crypto_key=new_crypto_key, wait_ack=True)
        bus.cnf.state = ScalarizrState.INITIALIZING

        bus.fire("host_init")
示例#11
0
def do_keygen():
    from scalarizr.util import cryptotool
    print cryptotool.keygen()
示例#12
0
def do_keygen():
    print cryptotool.keygen()
示例#13
0
def do_keygen():
	from scalarizr.util import cryptotool
	print cryptotool.keygen()	
示例#14
0
 def test_keygen(self):
     print cryptotool.keygen(40)
示例#15
0
 def test_keygen(self):
     print cryptotool.keygen(40)