• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python bus.fire函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scalarizr.bus.bus.fire函数的典型用法代码示例。如果您正苦于以下问题:Python fire函数的具体用法?Python fire怎么用?Python fire使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了fire函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: on_DbMsr_NewMasterUp

    def on_DbMsr_NewMasterUp(self, message):
        """
        Switch replication to a new master server
        @type message: scalarizr.messaging.Message
        @param message:  DbMsr_NewMasterUp
        """
        try:
            assert message.body.has_key("db_type")
            assert message.body.has_key("local_ip")
            assert message.body.has_key("remote_ip")
            assert message.body.has_key(BEHAVIOUR)

            postgresql_data = message.body[BEHAVIOUR]

            if int(__postgresql__['replication_master']):
                LOG.debug('Skip NewMasterUp. My replication role is master')
                return

            host = message.local_ip or message.remote_ip
            LOG.info("Switching replication to a new PostgreSQL master %s", host)
            bus.fire('before_postgresql_change_master', host=host)

            LOG.debug("__postgresql__['volume']: %s", __postgresql__['volume'])

            if __postgresql__['volume'].type in ('eph', 'lvm'):
                if 'restore' in postgresql_data:
                    restore = backup.restore(**postgresql_data['restore'])
                else:
                    restore = backup.restore(
                        type='snap_postgresql',
                        volume=__postgresql__['volume'],
                        snapshot=postgresql_data[OPT_SNAPSHOT_CNF])

                if __postgresql__['volume'].type == 'eph':
                    self.postgresql.service.stop('Swapping storages to reinitialize slave')

                    LOG.info('Reinitializing Slave from the new snapshot %s',
                        restore.snapshot['id'])
                    new_vol = restore.run()

                #self.postgresql.service.start()

            self.postgresql.init_slave(STORAGE_PATH, host, __postgresql__['port'], self.root_password)
            LOG.debug("Replication switched")
            bus.fire('postgresql_change_master', host=host)

            msg_data = dict(
                db_type = BEHAVIOUR,
                status = 'ok'
            )
            self.send_message(DbMsrMessages.DBMSR_NEW_MASTER_UP_RESULT, msg_data)

        except (Exception, BaseException), e:
            LOG.exception(e)

            msg_data = dict(
                db_type = BEHAVIOUR,
                status="error",
                last_error=str(e))
            self.send_message(DbMsrMessages.DBMSR_NEW_MASTER_UP_RESULT, msg_data)
开发者ID:yoyama,项目名称:scalarizr,代码行数:60,代码来源:postgresql.py


示例2: do_databundle

        def do_databundle(op):
            try:
                bus.fire('before_postgresql_data_bundle')
                LOG.info("Creating PostgreSQL data bundle")
                backup_obj = backup.backup(type='snap_postgresql',
                                           volume=__postgresql__['volume'],
                                           tags=__postgresql__['volume'].tags)
                restore = backup_obj.run()
                snap = restore.snapshot


                used_size = int(system2(('df', '-P', '--block-size=M', STORAGE_PATH))[0].split('\n')[1].split()[2][:-1])
                bus.fire('postgresql_data_bundle', snapshot_id=snap.id)

                # Notify scalr
                msg_data = {
                    'db_type': BEHAVIOUR,
                    'status': 'ok',
                    'used_size' : '%.3f' % (float(used_size) / 1000,),
                    BEHAVIOUR: {OPT_SNAPSHOT_CNF: dict(snap)}
                }

                __node__.messaging.send(DbMsrMessages.DBMSR_CREATE_DATA_BUNDLE_RESULT,
                                        msg_data)

                return restore

            except (Exception, BaseException), e:
                LOG.exception(e)
                
                # Notify Scalr about error
                __node__.messaging.send(DbMsrMessages.DBMSR_CREATE_DATA_BUNDLE_RESULT, 
                                        dict(db_type=BEHAVIOUR,
                                             status='error',
                                             last_error=str(e)))
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:35,代码来源:postgresql.py


示例3: test_create_hook

 def test_create_hook(self):
     bus.base_path = os.path.realpath(os.path.dirname(__file__) + "/../../..")
     config = ConfigParser()
     config.read(bus.base_path + "/etc/config.ini")
     bus.config = config
     init_tests()
     resources_path = os.path.realpath(os.path.dirname(__file__) + "/../../" + "resources")
     bus.base_path = resources_path
     server_id = config.get(configtool.SECT_GENERAL, configtool.OPT_SERVER_ID)
     bus.define_events("init", "test")
     handler = hooks.HooksHandler()
     bus.fire('init')
     bus.fire("test", "test_2_done", aenv="test_3_done")
     #absolutely valid script created an empty file
     self.assertTrue(os.path.exists(resources_path + "/hooks/test_1_done"))
     #next script created a file named as 1st execution parameter
     self.assertTrue(os.path.exists(resources_path + "/hooks/test_2_done"))
     #3rd script touched file named $aenv
     self.assertTrue(os.path.exists(resources_path + "/hooks/test_3_done"))
     #test 4 touched file named server_id
     self.assertTrue(os.path.exists(resources_path + "/hooks/" + server_id))
     #test 5 doesn`t have an execution bit
     self.assertFalse(os.path.exists(resources_path + "/hooks/test_5_done"))
     #test 6 tried to execute script file with Exec format error
     self.assertFalse(os.path.exists(resources_path + "/hooks/test_6_done"))
     #test 7 consists an execution error
     self.assertTrue(os.path.exists(resources_path + "/hooks/test_7_done"))
     #test8 script has not a valid name , so supposed not to be executed
     self.assertFalse(os.path.exists(resources_path + "/hooks/test_8_done"))
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:29,代码来源:test_hooks.py


示例4: on_before_host_up

    def on_before_host_up(self, message):
        self._logger.debug('Handling on_before_host_up message')
        log = bus.init_op.logger
        self._init_script.stop()

        log.info('Copy default html error pages')
        self._copy_error_pages()

        log.info('Setup proxying')
        self._logger.debug('Updating main config')
        v2_mode = bool(self._proxies) or self._get_nginx_v2_mode_flag()
        self._update_main_config(remove_server_section=v2_mode,
                                 reload_service=False)

        if v2_mode:
            self._logger.debug('Recreating proxying with proxies:\n%s' % self._proxies)
            self.api.recreate_proxying(self._proxies)
        else:
            # default behaviour
            roles_for_proxy = []
            if __nginx__['upstream_app_role']:
                roles_for_proxy = [__nginx__['upstream_app_role']]
            else:
                roles_for_proxy = self.get_all_app_roles()
            self.make_default_proxy(roles_for_proxy)

        bus.fire('service_configured',
                 service_name=SERVICE_NAME,
                 preset=self.initial_preset)
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:29,代码来源:nginx.py


示例5: on_IntBlockDeviceUpdated

	def on_IntBlockDeviceUpdated(self, message):
		if not message.devname:
			return
		
		if message.action == "add":
			LOG.debug("udev notified me that block device %s was attached", message.devname)
			
			self.send_message(
				Messages.BLOCK_DEVICE_ATTACHED, 
				{"device_name" : self.get_devname(message.devname)}, 
				broadcast=True
			)
			
			bus.fire("block_device_attached", device=message.devname)
			
		elif message.action == "remove":
			LOG.debug("udev notified me that block device %s was detached", message.devname)
			fstab = mount.fstab()
			fstab.remove(message.devname)
			
			self.send_message(
				Messages.BLOCK_DEVICE_DETACHED, 
				{"device_name" : self.get_devname(message.devname)}, 
				broadcast=True
			)
			
			bus.fire("block_device_detached", device=message.devname)
开发者ID:notbrain,项目名称:scalarizr,代码行数:27,代码来源:block_device.py


示例6: do_databundle

        def do_databundle(op):
            try:
                bus.fire('before_%s_data_bundle' % BEHAVIOUR)
                # Creating snapshot
                LOG.info("Creating Redis data bundle")
                backup_obj = backup.backup(type='snap_redis',
                                           volume=__redis__['volume'],
                                           tags=__redis__['volume'].tags)  # TODO: generate the same way as in
                                                                           # mysql api or use __node__
                restore = backup_obj.run()
                snap = restore.snapshot

                used_size = int(system2(('df', '-P', '--block-size=M', STORAGE_PATH))[0].split('\n')[1].split()[2][:-1])
                bus.fire('%s_data_bundle' % BEHAVIOUR, snapshot_id=snap.id)

                # Notify scalr
                msg_data = dict(
                    db_type=BEHAVIOUR,
                    used_size='%.3f' % (float(used_size) / 1000,),
                    status='ok'
                )
                msg_data[BEHAVIOUR] = {'snapshot_config': dict(snap)}

                node.__node__.messaging.send(DbMsrMessages.DBMSR_CREATE_DATA_BUNDLE_RESULT, msg_data)

                return restore

            except (Exception, BaseException), e:
                LOG.exception(e)

                # Notify Scalr about error
                node.__node__.messaging.send(DbMsrMessages.DBMSR_CREATE_DATA_BUNDLE_RESULT, dict(
                    db_type=BEHAVIOUR,
                    status='error',
                    last_error=str(e)))
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:35,代码来源:redis.py


示例7: on_before_host_up

    def on_before_host_up(self, message):
        op_log = bus.init_op.logger
        self.api.stop_service("Configuring Apache Web Server")
        self.api.init_service()
        self.configure_ip_forwarding()

        if self._initial_v_hosts:
            op_log.info("Configuring VirtualHosts.")
            LOG.debug("VirtualHosts to configure: %s" % self._initial_v_hosts)

            applied_vhosts = self.api.reconfigure(self._initial_v_hosts,
                                                  reload=False,
                                                  rollback_on_error=False,
                                                  async=False)

            if len(applied_vhosts) != len(self._initial_v_hosts):
                raise apache_api.ApacheError("%s Apache VirtualHosts were assigned to server but only %s were applied." % (
                    len(applied_vhosts),
                    len(self._initial_v_hosts),
                ))

            op_log.info("%s Virtual Hosts configured." % len(applied_vhosts))

        self.api.start_service()

        bus.fire("service_configured", service_name=SERVICE_NAME, preset=self._initial_preset)
开发者ID:chenleji,项目名称:scalarizr,代码行数:26,代码来源:apache.py


示例8: _plug_volume

    def _plug_volume(self, qe_mpoint):
        try:
            assert len(qe_mpoint.volumes), 'Invalid mpoint info %s. Volumes list is empty' % qe_mpoint
            qe_volume = qe_mpoint.volumes[0]
            mpoint = qe_mpoint.dir or None
            assert qe_volume.volume_id, 'Invalid volume info %s. volume_id should be non-empty' % qe_volume
            
            vol = storage2.volume(
                type=self._vol_type, 
                id=qe_volume.volume_id, 
                name=qe_volume.device,
                mpoint=mpoint
            )

            if mpoint:
                logger = bus.init_op.logger if bus.init_op else LOG
                logger.info('Ensure %s: take %s, mount to %s', self._vol_type, vol.id, vol.mpoint)

                vol.ensure(mount=True, mkfs=True, fstab=True)
                bus.fire("block_device_mounted", 
                        volume_id=vol.id, device=vol.device)
                self.send_message(Messages.BLOCK_DEVICE_MOUNTED, 
                    {"device_name": vol.device, 
                    "volume_id": vol.id, 
                    "mountpoint": vol.mpoint}
                )                
        except:
            LOG.exception("Can't attach volume")
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:28,代码来源:block_device.py


示例9: on_before_host_up

    def on_before_host_up(self, message):
        LOG.debug("on_before_host_up")
        """
        Configure MySQL __mysql__['behavior']
        @type message: scalarizr.messaging.Message
        @param message: HostUp message
        """

        self.generate_datadir()
        self.mysql.service.stop('Configuring MySQL')

        # On Debian/GCE we've got 'Another MySQL daemon already running with the same unix socket.'
        socket_file = mysql2_svc.my_print_defaults('mysqld').get('socket')
        if socket_file:
            coreutils.remove(socket_file)

        if 'Amazon' == linux.os['name']:
            self.mysql.my_cnf.pid_file = os.path.join(__mysql__['data_dir'], 'mysqld.pid')

        repl = 'master' if int(__mysql__['replication_master']) else 'slave'
        bus.fire('before_mysql_configure', replication=repl)
        if repl == 'master':
            self._init_master(message)
        else:
            self._init_slave(message)
        # Force to resave volume settings
        __mysql__['volume'] = storage2.volume(__mysql__['volume'])
        bus.fire('service_configured', service_name=__mysql__['behavior'],
                        replication=repl, preset=self.initial_preset)
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:29,代码来源:mysql2.py


示例10: on_IntServerHalt

 def on_IntServerHalt(self, message):
     Flag.set(Flag.HALT)
     msg = self.new_message(Messages.HOST_DOWN, broadcast=True)
     try:
         bus.fire("before_host_down", msg)
     finally:
         self.send_message(msg)
     bus.fire("host_down")
开发者ID:chenleji,项目名称:scalarizr,代码行数:8,代码来源:lifecycle.py


示例11: on_IntServerReboot

 def on_IntServerReboot(self, message):
     # Scalarizr must detect that it was resumed after reboot
     Flag.set(Flag.REBOOT)
     # Send message
     msg = self.new_message(Messages.REBOOT_START, broadcast=True)
     try:
         bus.fire("before_reboot_start", msg)
     finally:
         self.send_message(msg)
     bus.fire("reboot_start")
开发者ID:chenleji,项目名称:scalarizr,代码行数:10,代码来源:lifecycle.py


示例12: mount

 def mount(self):
     self._check(mpoint=True)
     mounted_to = self.mounted_to()
     if mounted_to == self.mpoint:
         return
     elif mounted_to:
         LOG.debug('Umounting %s from %s', self.id, mounted_to)
         self.umount()
     if not os.path.exists(self.mpoint):
         os.makedirs(self.mpoint)
     LOG.debug('Mounting %s to %s', self.id, self.mpoint)
     mod_mount.mount(self.device, self.mpoint)
     bus.fire("block_device_mounted", volume=self)
开发者ID:chenleji,项目名称:scalarizr,代码行数:13,代码来源:base.py


示例13: _start_import

	def _start_import(self):
		data = software.system_info()
		data['architecture'] = self._platform.get_architecture()
		data['server_id'] = self._cnf.rawini.get(config.SECT_GENERAL, config.OPT_SERVER_ID)

		# Send Hello
		msg = self.new_message(Messages.HELLO, data,
			broadcast=True # It's not really broadcast but need to contain broadcast message data 
		)
		msg.body['behaviour'] = self.get_ready_behaviours()
		bus.fire("before_hello", msg)
		self.send_message(msg)
		bus.fire("hello")
开发者ID:golovast,项目名称:scalarizr,代码行数:13,代码来源:lifecycle.py


示例14: on_before_host_up

	def on_before_host_up(self, message):
		"""
		Configure PostgreSQL behaviour
		@type message: scalarizr.messaging.Message		
		@param message: HostUp message
		"""

		repl = 'master' if self.is_replication_master else 'slave'
		#bus.fire('before_postgresql_configure', replication=repl)
		
		if self.is_replication_master:
			self._init_master(message)									  
		else:
			self._init_slave(message)	
		bus.fire('service_configured', service_name=SERVICE_NAME, replication=repl)
开发者ID:golovast,项目名称:scalarizr,代码行数:15,代码来源:postgresql.py


示例15: on_before_host_up

	def on_before_host_up(self, message):
		"""
		Configure redis behaviour
		@type message: scalarizr.messaging.Message		
		@param message: HostUp message
		"""

		repl = 'master' if self.is_replication_master else 'slave'

		if self.is_replication_master:
			self._init_master(message)
		else:
			self._init_slave(message)
		self._init_script = self.redis_instances.get_default_process()
		bus.fire('service_configured', service_name=SERVICE_NAME, replication=repl)
开发者ID:golovast,项目名称:scalarizr,代码行数:15,代码来源:redis.py


示例16: _start_init

	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")
开发者ID:golovast,项目名称:scalarizr,代码行数:16,代码来源:lifecycle.py


示例17: _shutdown

    def _shutdown(self):
        self._running = False
        try:
            bus.fire("shutdown")
        except:
            self._logger.debug('Shutdown hooks exception', exc_info=sys.exc_info())

        try:
            self._logger.info("[pid: %d] Stopping scalarizr %s", os.getpid(), __version__)
            self._shutdown_services()
        except:
            self._logger.debug('Shutdown services exception', exc_info=sys.exc_info())
        finally:
            if os.path.exists(PID_FILE):
                os.remove(PID_FILE)

        self._logger.info('[pid: %d] Scalarizr terminated', os.getpid())
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:17,代码来源:app.py


示例18: onSIGHUP

    def onSIGHUP(self, *args):
        pid = os.getpid()
        self._logger.debug('Received SIGHUP (pid: %d)', pid)
        if pid != _pid:
            return

        self._logger.info('Reloading scalarizr')
        self._running = False
        bus.fire('shutdown')
        self._shutdown_services()

        self._running = True
        cnf = bus.cnf
        cnf.bootstrap(force_reload=True)
        self._init_services()
        self._start_services()
        bus.fire('reload')
开发者ID:chenleji,项目名称:scalarizr,代码行数:17,代码来源:app.py


示例19: on_before_host_up

    def on_before_host_up(self, message):
        """
        Configure PostgreSQL behaviour
        @type message: scalarizr.messaging.Message      
        @param message: HostUp message
        """

        repl = 'master' if self.is_replication_master else 'slave'
        #bus.fire('before_postgresql_configure', replication=repl)
        
        if self.is_replication_master:
            self._init_master(message)                                    
        else:
            self._init_slave(message)
        # Force to resave volume settings
        __postgresql__['volume'] = storage2.volume(__postgresql__['volume'])
        bus.fire('service_configured', service_name=SERVICE_NAME, replication=repl, preset=self.initial_preset)
开发者ID:yoyama,项目名称:scalarizr,代码行数:17,代码来源:postgresql.py


示例20: on_before_host_up

	def on_before_host_up(self, message):
		LOG.debug("on_before_host_up")
		"""
		Configure MySQL __mysql__['behavior']
		@type message: scalarizr.messaging.Message		
		@param message: HostUp message
		"""
		
		self.generate_datadir()
		self.mysql.service.stop('Configuring MySQL')
		repl = 'master' if int(__mysql__['replication_master']) else 'slave'
		bus.fire('before_mysql_configure', replication=repl)
		if repl == 'master':
			self._init_master(message)	
		else:
			self._init_slave(message)
		# Force to resave volume settings
		__mysql__['volume'] = storage2.volume(__mysql__['volume'])
		bus.fire('service_configured', service_name=__mysql__['behavior'], replication=repl)
开发者ID:golovast,项目名称:scalarizr,代码行数:19,代码来源:mysql2.py



注:本文中的scalarizr.bus.bus.fire函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python bus.on函数代码示例发布时间:2022-05-27
下一篇:
Python scalaris.ScalarisVM类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap