本文整理汇总了Python中oio.container.client.ContainerClient.content_prepare方法的典型用法代码示例。如果您正苦于以下问题:Python ContainerClient.content_prepare方法的具体用法?Python ContainerClient.content_prepare怎么用?Python ContainerClient.content_prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oio.container.client.ContainerClient
的用法示例。
在下文中一共展示了ContainerClient.content_prepare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ContentFactory
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import content_prepare [as 别名]
class ContentFactory(object):
DEFAULT_DATASEC = "plain", {"nb_copy": "1", "distance": "0"}
def __init__(self, conf):
self.conf = conf
self.logger = get_logger(conf)
self.container_client = ContainerClient(conf)
def get(self, container_id, content_id):
try:
meta, chunks = self.container_client.content_show(
cid=container_id, content=content_id)
except NotFound:
raise ContentNotFound("Content %s/%s not found" % (container_id,
content_id))
chunk_method = meta['chunk_method']
storage_method = STORAGE_METHODS.load(chunk_method)
cls = ECContent if storage_method.ec else PlainContent
return cls(self.conf, container_id, meta, chunks, storage_method)
def new(self, container_id, path, size, policy):
meta, chunks = self.container_client.content_prepare(
cid=container_id, path=path, size=size, stgpol=policy)
chunk_method = meta['chunk_method']
storage_method = STORAGE_METHODS.load(chunk_method)
cls = ECContent if storage_method.ec else PlainContent
return cls(self.conf, container_id, meta, chunks, storage_method)
def change_policy(self, container_id, content_id, new_policy):
old_content = self.get(container_id, content_id)
if old_content.stgpol == new_policy:
return old_content
new_content = self.new(container_id, old_content.path,
old_content.length, new_policy)
stream = old_content.fetch()
new_content.create(GeneratorIO(stream))
# the old content is automatically deleted because the new content has
# the same name (but not the same id)
return new_content
示例2: ContentFactory
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import content_prepare [as 别名]
class ContentFactory(object):
def __init__(self, conf):
self.conf = conf
self.logger = get_logger(conf)
self.cs_client = ConscienceClient(conf)
self.container_client = ContainerClient(conf)
self.ns_info = self.cs_client.info()
def _extract_datasec(self, stgpol_name):
try:
stgpol = self.ns_info["storage_policy"][stgpol_name]
except KeyError:
self.logger.error("Storage policy '%s' not found" % stgpol_name)
raise InconsistentContent("Storage policy not found")
stgclass_name, datasec_name, datatreat_name = stgpol.split(':')
if datasec_name == 'NONE':
return "DUP", {"nb_copy": "1", "distance": "0"}
try:
datasec = self.ns_info["data_security"][datasec_name]
except KeyError:
self.logger.error("Data security '%s' not found" % datasec_name)
raise InconsistentContent("Data security not found")
ds_type, ds_args = datasec.split(':')
args = {}
for arg in ds_args.split('|'):
key, value = arg.split('=')
args[key] = value
return ds_type, args
def get(self, container_id, content_id):
try:
meta, chunks = self.container_client.content_show(
cid=container_id, content=content_id)
except NotFound:
raise ContentNotFound("Content %s/%s not found" % (container_id,
content_id))
pol_type, pol_args = self._extract_datasec(meta['policy'])
if pol_type == "DUP":
return DupContent(self.conf, container_id, meta, chunks, pol_args)
elif pol_type == "RAIN":
return RainContent(self.conf, container_id, meta, chunks, pol_args)
raise InconsistentContent("Unknown storage policy")
def new(self, container_id, path, size, policy):
meta, chunks = self.container_client.content_prepare(
cid=container_id, path=path, size=size, stgpol=policy)
pol_type, pol_args = self._extract_datasec(meta['policy'])
if pol_type == "DUP":
return DupContent(self.conf, container_id, meta, chunks, pol_args)
elif pol_type == "RAIN":
return RainContent(self.conf, container_id, meta, chunks, pol_args)
raise InconsistentContent("Unknown storage policy")
def change_policy(self, container_id, content_id, new_policy):
old_content = self.get(container_id, content_id)
if old_content.stgpol_name == new_policy:
return old_content
new_content = self.new(container_id, old_content.path,
old_content.length, new_policy)
stream = old_content.download()
new_content.upload(GeneratorIO(stream))
# the old content is automatically deleted because the new content has
# the same name (but not the same id)
return new_content