本文整理汇总了Python中oio.container.client.ContainerClient.container_list方法的典型用法代码示例。如果您正苦于以下问题:Python ContainerClient.container_list方法的具体用法?Python ContainerClient.container_list怎么用?Python ContainerClient.container_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oio.container.client.ContainerClient
的用法示例。
在下文中一共展示了ContainerClient.container_list方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestContentFactory
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_list [as 别名]
#.........这里部分代码省略.........
def test_change_content_with_same_policy(self):
data = random_data(10)
old_content = self._new_content("TWOCOPIES", data)
changed_content = self.content_factory.change_policy(
old_content.container_id, old_content.content_id, "TWOCOPIES")
self.assertEqual(old_content.content_id, changed_content.content_id)
def test_change_policy_unknown_content(self):
self.assertRaises(ContentNotFound, self.content_factory.change_policy,
self.container_id, "1234", "SINGLE")
def test_change_policy_unknown_storage_policy(self):
data = random_data(10)
old_content = self._new_content("TWOCOPIES", data)
self.assertRaises(ClientException, self.content_factory.change_policy,
self.container_id, old_content.content_id, "UnKnOwN")
def _test_move_chunk(self, policy):
data = random_data(self.chunk_size)
content = self._new_content(policy, data)
chunk_id = content.chunks.filter(metapos=0)[0].id
chunk_url = content.chunks.filter(metapos=0)[0].url
chunk_meta, chunk_stream = self.blob_client.chunk_get(chunk_url)
chunk_hash = md5_stream(chunk_stream)
new_chunk = content.move_chunk(chunk_id)
content_updated = self.content_factory.get(self.container_id,
content.content_id)
hosts = []
for c in content_updated.chunks.filter(metapos=0):
self.assertThat(hosts, Not(Contains(c.host)))
self.assertNotEquals(c.id, chunk_id)
hosts.append(c.host)
new_chunk_meta, new_chunk_stream = self.blob_client.chunk_get(
new_chunk["url"])
new_chunk_hash = md5_stream(new_chunk_stream)
self.assertEqual(new_chunk_hash, chunk_hash)
del chunk_meta["chunk_id"]
del new_chunk_meta["chunk_id"]
self.assertEqual(new_chunk_meta, chunk_meta)
def test_single_move_chunk(self):
self._test_move_chunk("SINGLE")
def test_twocopies_move_chunk(self):
self._test_move_chunk("TWOCOPIES")
def test_rain_move_chunk(self):
if len(self.conf['rawx']) < 9:
self.skipTest("Need more than 8 rawx")
self._test_move_chunk("RAIN")
def test_move_chunk_not_in_content(self):
data = random_data(self.chunk_size)
content = self._new_content("TWOCOPIES", data)
with ExpectedException(OrphanChunk):
content.move_chunk("1234")
def test_strange_paths(self):
strange_paths = [
"Annual report.txt",
"foo+bar=foobar.txt",
"100%_bug_free.c",
"forward/slash/allowed",
"I\\put\\backslashes\\and$dollar$signs$in$file$names",
"Je suis tombé sur la tête, mais ça va bien.",
"%s%f%u%d%%",
"carriage\rreturn",
"line\nfeed",
"ta\tbu\tla\ttion",
"controlchars",
]
answers = dict()
for cname in strange_paths:
content = self._new_content("SINGLE", "nobody cares", cname)
answers[cname] = content
listing = self.container_client.container_list(self.account,
self.container_name)
obj_set = {k["name"].encode("utf8", "ignore")
for k in listing["objects"]}
try:
# Ensure the saved path is the one we gave the object
for cname in answers:
self.assertEqual(cname, answers[cname].path)
# Ensure all objects appear in listing
for cname in strange_paths:
self.assertIn(cname, obj_set)
finally:
# Cleanup
for cname in answers:
try:
content.delete()
except:
pass
示例2: StorageTiererWorker
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_list [as 别名]
class StorageTiererWorker(object):
def __init__(self, conf, logger):
self.conf = conf
self.logger = logger
self.account = conf[CONF_ACCOUNT]
self.container_client = ContainerClient(self.conf)
self.account_client = AccountClient(self.conf)
self.content_factory = ContentFactory(self.conf)
self.passes = 0
self.errors = 0
self.last_reported = 0
self.contents_run_time = 0
self.total_contents_processed = 0
self.report_interval = int_value(
conf.get('report_interval'), 3600)
self.max_contents_per_second = int_value(
conf.get('contents_per_second'), 30)
self.container_fetch_limit = int_value(
conf.get('container_fetch_limit'), 100)
self.content_fetch_limit = int_value(
conf.get('content_fetch_limit'), 100)
self.outdated_threshold = int_value(
conf.get(CONF_OUTDATED_THRESHOLD), 9999999999)
self.new_policy = conf.get(CONF_NEW_POLICY)
def _list_containers(self):
container = None
while True:
resp = self.account_client.containers_list(
self.account, marker=container,
limit=self.container_fetch_limit)
if len(resp["listing"]) == 0:
break
for container, _, _, _ in resp["listing"]:
yield container
def _list_contents(self):
for container in self._list_containers():
marker = None
while True:
try:
resp = self.container_client.container_list(
acct=self.account, ref=container,
limit=self.content_fetch_limit, marker=marker)
except NotFound:
self.logger.warn("Container %s in account "
"but not found" % container)
break
if len(resp["objects"]) == 0:
break
for obj in resp["objects"]:
marker = obj["name"]
if obj["mtime"] > time.time() - self.outdated_threshold:
continue
if obj["policy"] == self.new_policy:
continue
container_id = cid_from_name(self.account, container)
yield (container_id, obj["content"])
def run(self):
start_time = report_time = time.time()
total_errors = 0
for (container_id, content_id) in self._list_contents():
self.safe_change_policy(container_id, content_id)
self.contents_run_time = ratelimit(
self.contents_run_time,
self.max_contents_per_second
)
self.total_contents_processed += 1
now = time.time()
if now - self.last_reported >= self.report_interval:
self.logger.info(
'%(start_time)s '
'%(passes)d '
'%(errors)d '
'%(c_rate).2f '
'%(total).2f ' % {
'start_time': time.ctime(report_time),
'passes': self.passes,
'errors': self.errors,
'c_rate': self.passes / (now - report_time),
'total': (now - start_time)
}
)
report_time = now
total_errors += self.errors
self.passes = 0
self.errors = 0
self.last_reported = now
elapsed = (time.time() - start_time) or 0.000001
self.logger.info(
'%(elapsed).02f '
'%(errors)d '
'%(content_rate).2f ' % {
'elapsed': elapsed,
#.........这里部分代码省略.........