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

Python util.firstmatched函数代码示例

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

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



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

示例1: __init__

 def __init__(self):
     initd_script = None
     if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
         initd_script = ("/usr/sbin/service", "mongodb")
     else:
         initd_script = firstmatched(os.path.exists, ("/etc/init.d/mongodb", "/etc/init.d/mongod"))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME, initd_script=initd_script)
开发者ID:rpallas,项目名称:scalarizr,代码行数:7,代码来源:mongodb.py


示例2: _cleanup_after_rebundle

def _cleanup_after_rebundle():
    cnf = bus.cnf
    pl = bus.platform
    logger = logging.getLogger(__name__)
    
    if 'volumes' not in pl.features:
        # Destory mysql storages
        if os.path.exists(cnf.private_path('storage/mysql.json')) and pl.name == 'rackspace':
            logger.info('Cleanuping old MySQL storage')
            mysql_bhv = firstmatched(lambda x: x in node.__node__['behavior'], ('mysql', 'mysql2', 'percona'))
            vol = node.__node__[mysql_bhv]['volume']
            vol.destroy(force=True)

    if os.path.exists('/etc/chef/client.pem'):
        os.remove('/etc/chef/client.pem')
    if os.path.exists('/etc/chef/client.rb'):
        os.remove('/etc/chef/client.rb')
    
    # Reset private configuration
    priv_path = cnf.private_path()
    for file in os.listdir(priv_path):
        if file in ('.user-data', '.update'):
            continue
        path = os.path.join(priv_path, file)
        coreutils.chmod_r(path, 0700)
        os.remove(path) if (os.path.isfile(path) or os.path.islink(path)) else shutil.rmtree(path)
    if not linux.os.windows_family:
        system2('sync', shell=True)
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:28,代码来源:app.py


示例3: get_free_devname

            def get_free_devname(device):
                if device:
                    device = ebstool.get_ebs_devname(device)

                used_letters = set(row['device'][-1]
                                        for row in Storage.volume_table()
                                        if row['device'] and ( \
                                                row['state'] == 'attached' or ( \
                                                pl.get_instance_type() == 't1.micro' and row['state'] == 'detached')))

                with self.letters_lock:

                    avail_letters = list(set(self.all_letters) - used_letters - self.acquired_letters)

                    volumes = conn.get_all_volumes(filters={'attachment.instance-id': pl.get_instance_id()})

                    for volume in volumes:
                        volume_device = volume.attach_data.device
                        volume_device = re.sub('\d+', '', volume_device)
                        try:
                            avail_letters.remove(volume_device[-1])
                        except ValueError:
                            pass

                    if not device or not (device[-1] in avail_letters) or os.path.exists(device):
                        letter = firstmatched(
                                lambda l: not os.path.exists(ebstool.real_devname('/dev/sd%s' % l)), avail_letters
                        )
                        if letter:
                            device = '/dev/sd%s' % letter
                            self.acquired_letters.add(letter)
                        else:
                            raise StorageError('No free letters for block device name remains')

                return device
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:35,代码来源:storage.py


示例4: __init__

    def __init__(self):
        if 'gce' == node.__node__['platform']:
            self.ensure_pid_directory()

        self.mysql_cli = MySQLClient()


        if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
            initd_script = ('/usr/sbin/service', 'mysql')
        else:
            initd_script = firstmatched(os.path.exists, ('/etc/init.d/mysqld', '/etc/init.d/mysql'))

        pid_file = None
        try:
            out = system2("my_print_defaults mysqld", shell=True, silent=True)
            m = re.search("--pid[-_]file=(.*)", out[0], re.MULTILINE)
            if m:
                pid_file = m.group(1)
            m = re.search("--socket=(.*)", out[0], re.MULTILINE)
            if m:
                self.socket_file = m.group(1)
        except:
            pass

        initdv2.ParametrizedInitScript.__init__(self, SERVICE_NAME,
                        initd_script, pid_file, socks=[initdv2.SockParam(MYSQL_DEFAULT_PORT, timeout=3600)])
开发者ID:yoyama,项目名称:scalarizr,代码行数:26,代码来源:mysql.py


示例5: __init__

 def __init__(self):
     initd_script = None
     if linux.os.ubuntu and linux.os['version'] >= (10, 4):
         initd_script = ('/usr/sbin/service', 'redis-server')
     else:
         initd_script = firstmatched(os.path.exists, ('/etc/init.d/redis', '/etc/init.d/redis-server'))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME,
             initd_script=initd_script)
开发者ID:chenleji,项目名称:scalarizr,代码行数:8,代码来源:redis.py


示例6: __init__

 def __init__(self):
     initd_script = None
     if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
         initd_script = ('/usr/sbin/service', 'redis-server')
     else:
         initd_script = firstmatched(os.path.exists, ('/etc/init.d/redis', '/etc/init.d/redis-server'))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME,
             initd_script=initd_script)
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:8,代码来源:redis.py


示例7: test_1

    def test_1(self):
        v1 = Storage.create(device='/dev/sdo')
        v2 = Storage.create(device='/dev/sdm')
        table = Storage.volume_table()
        self.assertEqual(len(table), 2)
        v1row = firstmatched(lambda row: row['device'] == '/dev/sdo', table)
        self.assertTrue(v1row)
        self.assertEqual(v1row['volume_id'], v1.id)
        self.assertEqual(v1row['device'], v1.device)
        self.assertEqual(v1row['type'], v1.type)
        self.assertEqual(v1row['state'], 'attached')

        v2.detach()
        table = Storage.volume_table()
        self.assertEqual(len(table), 2)
        v2row = firstmatched(lambda row: row['device'] == '/dev/sdm', table)
        self.assertEqual(v2row['state'], 'detached')
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:17,代码来源:test.py


示例8: _init

def _init():
	optparser = bus.optparser
	bus.base_path = os.path.realpath(os.path.dirname(__file__) + "/../..")
	
	#dynimp.setup()
	
	_init_logging()
	logger = logging.getLogger(__name__)	
	
	# Initialize configuration
	if not bus.etc_path:
		etc_places = [
			"/etc/scalr",
			"/etc/scalarizr", 
			"/usr/etc/scalarizr", 
			"/usr/local/etc/scalarizr",
			os.path.join(bus.base_path, 'etc')
		]
		if optparser and optparser.values.etc_path:
			# Insert command-line passed etc_path into begining
			etc_places.insert(0, optparser.values.etc_path)
			
		bus.etc_path = firstmatched(lambda p: os.access(p, os.F_OK), etc_places)
		if not bus.etc_path:
			raise ScalarizrError('Cannot find scalarizr configuration dir. Search path: %s' % ':'.join(etc_places))
	cnf = ScalarizrCnf(bus.etc_path)
	if not os.path.exists(cnf.private_path()):
		os.makedirs(cnf.private_path())
	bus.cnf = cnf
	
	
	# Find shared resources dir
	if not bus.share_path:
		share_places = [
			'/usr/share/scalr',
			'/usr/local/share/scalr',
			os.path.join(bus.base_path, 'share')
		]
		bus.share_path = firstmatched(lambda p: os.access(p, os.F_OK), share_places)
		if not bus.share_path:
			raise ScalarizrError('Cannot find scalarizr share dir. Search path: %s' % ':'.join(share_places))

	
	# Registering in init.d
	initdv2.explore("scalarizr", ScalarizrInitScript)
开发者ID:golovast,项目名称:scalarizr,代码行数:45,代码来源:__init__.py


示例9: block_devs_mapping

 def block_devs_mapping(self):
     keys = self._get_property("block-device-mapping").split("\n")
     ret = list()
     for key in keys:
         try:
             ret.append((key, self._get_property("block-device-mapping/" + key)))
         except PlatformError, e:
             if key == 'ephemeral0' and str(e).find('HTTP Error 500') >= 0:
                 ret.append((key, firstmatched(lambda x: os.path.exists(x), ('/dev/sda2', '/dev/sdb'))))
             else:
                 raise
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:11,代码来源:eucalyptus.py


示例10: _change_master

    def _change_master(self, host, user, password, log_file, log_pos, timeout=None):

        LOG.info("Changing replication Master to server %s (log_file: %s, log_pos: %s)",
                        host, log_file, log_pos)

        timeout = timeout or int(__mysql__['change_master_timeout'])

        # Changing replication master
        self.root_client.stop_slave()
        self.root_client.change_master_to(host, user, password, log_file, log_pos)

        # Starting slave
        result = self.root_client.start_slave()
        LOG.debug('Start slave returned: %s' % result)
        if result and 'ERROR' in result:
            raise HandlerError('Cannot start mysql slave: %s' % result)

        time_until = time.time() + timeout
        status = None
        while time.time() <= time_until:
            status = self.root_client.slave_status()
            if status['Slave_IO_Running'] == 'Yes' and \
                    status['Slave_SQL_Running'] == 'Yes':
                break
            time.sleep(5)
        else:
            if status:
                if not status['Last_Error']:
                    logfile = firstmatched(lambda p: os.path.exists(p),
                                                            ('/var/log/mysqld.log', '/var/log/mysql.log'))
                    if logfile:
                        gotcha = '[ERROR] Slave I/O thread: '
                        size = os.path.getsize(logfile)
                        fp = open(logfile, 'r')
                        try:
                            fp.seek(max((0, size - 8192)))
                            lines = fp.read().split('\n')
                            for line in lines:
                                if gotcha in line:
                                    status['Last_Error'] = line.split(gotcha)[-1]
                        finally:
                            fp.close()

                msg = "Cannot change replication Master server to '%s'. "  \
                                "Slave_IO_Running: %s, Slave_SQL_Running: %s, " \
                                "Last_Errno: %s, Last_Error: '%s'" % (
                                host, status['Slave_IO_Running'], status['Slave_SQL_Running'],
                                status['Last_Errno'], status['Last_Error'])
                raise HandlerError(msg)
            else:
                raise HandlerError('Cannot change replication master to %s' % (host))


        LOG.debug('Replication master is changed to host %s', host)
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:54,代码来源:mysql2.py


示例11: __init__

    def __init__(self):
        self._logger = logging.getLogger(__name__)

        if disttool.is_redhat_based():
            init_script = ('/sbin/service', 'sshd')
        elif disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
            init_script = ('/usr/sbin/service', 'ssh')
        else:
            init_script = firstmatched(os.path.exists, ('/etc/init.d/ssh', '/etc/init.d/sshd'))
        self._sshd_init = ParametrizedInitScript('sshd', init_script)

        bus.on(init=self.on_init)
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:12,代码来源:ssh_auth_keys.py


示例12: test_pv_add_remove_vg

    def test_pv_add_remove_vg(self):
        self.vg0 = self.lvm.create_vg('test', [self.ph_device])
        pvi = self.lvm.pv_info(self.ph_device)
        self.assertEqual(pvi.vg, 'test')

        pvi = firstmatched(lambda pvi: 'test' in pvi.vg, self.lvm.pv_status())
        self.assertEqual(pvi.pv, self.ph_device)

        self.lvm.remove_vg(self.vg0)
        self.vg0 = None
        pvi = self.lvm.pv_info(self.ph_device)
        self.assertEqual(pvi.vg, '')
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:12,代码来源:test_lvm2.py


示例13: get_block_device_mapping

 def get_block_device_mapping(self):
     keys = self._get_property("block-device-mapping").split("\n")
     ret = {}
     for key in keys:
         try:
             ret[key] = self._get_property('block-device-mapping/' + key)
         except PlatformError, e:
             # Workaround
             if key == 'ephemeral0' and str(e).find('HTTP Error 500') >= 0:
                 ret[key] = firstmatched(lambda x: os.path.exists(x), ('/dev/sda2', '/dev/sdb'))
             else:
                 raise
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:12,代码来源:eucalyptus.py


示例14: __init__

    def __init__(self):
        self._logger = logging.getLogger(__name__)

        if linux.os.redhat_family:
            init_script = ('/sbin/service', 'sshd')
        elif linux.os.ubuntu and linux.os['version'] >= (10, 4):
            init_script = ('/usr/sbin/service', 'ssh')
        else:
            init_script = firstmatched(os.path.exists, ('/etc/init.d/ssh', '/etc/init.d/sshd'))
        self._sshd_init = ParametrizedInitScript('sshd', init_script)

        bus.on(init=self.on_init)
开发者ID:chenleji,项目名称:scalarizr,代码行数:12,代码来源:ssh_auth_keys.py


示例15: __init__

 def __init__(self):
     initd_script = None
     # if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
     if linux.os.debian_family:
         initd_script = ('/usr/sbin/service', 'postgresql')
     else:
         initd_script = firstmatched(os.path.exists, (
                     '/etc/init.d/postgresql-9.0', 
                     '/etc/init.d/postgresql-9.1',
                     '/etc/init.d/postgresql-9.2',
                     '/etc/init.d/postgresql'))
     assert initd_script is not None
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME, 
             initd_script=initd_script)
开发者ID:yoyama,项目名称:scalarizr,代码行数:14,代码来源:postgresql.py


示例16: _destroy_layout

    def _destroy_layout(self, vg, data_lv):
        # Find PV
        pv = None
        pvi = firstmatched(lambda pvi: vg in pvi.vg, self._lvm.pv_status())
        if pvi:
            pv = pvi.pv

        # Remove storage VG
        self._lvm.change_lv(data_lv, available=False)
        self._lvm.remove_vg(vg)

        if pv:
            # Remove PV if it doesn't belongs to any other VG
            pvi = self._lvm.pv_info(pv)
            if not pvi.vg:
                self._lvm.remove_pv(pv)
开发者ID:notbrain,项目名称:scalarizr,代码行数:16,代码来源:eph.py


示例17: _result

	def _result(self, e=None):
		try:
			msg = self.runnable.create_command_result(self)
			msg.status = all([n.req_ok for n in self.context.nodes]) and self.RESP_OK or self.RESP_ERROR

			if e:
				msg.last_error = str(e)
			else:
				self._logger.debug(str(self.context.results))
				failed_row = firstmatched(lambda row: row.has_key('last_error') and row['last_error'], self.context.results.values())
				if failed_row:
					msg.last_error = failed_row['last_error']
			msg.rows = self.context.results
			self.send_message(msg)
		finally:
			self.context = None
开发者ID:golovast,项目名称:scalarizr,代码行数:16,代码来源:cassandra.py


示例18: _handle_response

	def _handle_response(self, resp_message):
		current_node_respond = resp_message.from_host == self.context.current_node.host
		ndata = firstmatched(lambda n: n.host == resp_message.from_host, self.context.nodes)
		if not ndata:
			self._logger.error('Received response %s from unknown node %s', 
					resp_message.name, getattr(resp_message, 'from_host', '*unknown*'))
			return
		
		if current_node_respond:
			self._stop_node_timer(ndata)

		self.context.results[ndata.index] = resp_message.body
		ndata.req_ok = resp_message.status == self.RESP_OK
		if self.RESP_ERROR == resp_message.status:
			self.context.queue.put(ndata.index)
			
		self._request_next_node()
开发者ID:golovast,项目名称:scalarizr,代码行数:17,代码来源:cassandra.py


示例19: __init__

	def __init__(self):
		Platform.__init__(self)
		
		# Find the virtual router.
		eth0leases = util.firstmatched(lambda x: os.path.exists(x), 
									['/var/lib/dhcp/dhclient.eth0.leases',
									'/var/lib/dhcp3/dhclient.eth0.leases',
									'/var/lib/dhclient/dhclient-eth0.leases'],
									'/var/lib/dhclient/dhclient-eth0.leases') 
		if not os.path.exists(eth0leases):
			raise PlatformError("Can't find virtual router. file %s not exists" % eth0leases)
		
		router = None
		for line in open(eth0leases):
			if 'dhcp-server-identifier' in line:
				router = filter(None, line.split(';')[0].split(' '))[2]
		LOG.debug('Meta-data server: %s', router)
		self._router = router
	
		self._metadata = {}
开发者ID:golovast,项目名称:scalarizr,代码行数:20,代码来源:__init__.py


示例20: firstmatched

from scalarizr import handlers, linux
from scalarizr.bus import bus
from scalarizr.linux import pkgmgr, execute
from scalarizr.messaging import Messages
from scalarizr.util import initdv2, firstmatched
from scalarizr.node import __node__


LOG = logging.getLogger(__name__)

__tomcat__ = __node__['tomcat']
__tomcat__.update({
    'catalina_home_dir': None,
    'java_home': firstmatched(lambda path: os.access(path, os.X_OK), [
            linux.system('echo $JAVA_HOME', shell=True)[0].strip(),
            '/usr/java/default'], 
            '/usr'),
    'config_dir': None,
    'install_type': None
})

def get_handlers():
    return [TomcatHandler()]


class KeytoolExec(execute.BaseExec):
    executable = '{0}/bin/keytool'.format(__tomcat__['java_home'])

    # keytool uses long args with a short prefix
    def _default_handler(self, key, value, cmd_args):
        cmd_args.append('-{0}'.format(key))
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:31,代码来源:tomcat.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.system2函数代码示例发布时间:2022-05-27
下一篇:
Python storage2.volume函数代码示例发布时间: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