本文整理汇总了Python中scalarizr.util.firstmatched函数的典型用法代码示例。如果您正苦于以下问题:Python firstmatched函数的具体用法?Python firstmatched怎么用?Python firstmatched使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了firstmatched函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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
示例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)])
示例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)
示例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)
示例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')
示例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)
示例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
示例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)
示例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)
示例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, '')
示例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
示例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)
示例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)