本文整理汇总了Python中swift.proxy.controllers.base.get_container_info函数的典型用法代码示例。如果您正苦于以下问题:Python get_container_info函数的具体用法?Python get_container_info怎么用?Python get_container_info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_container_info函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: object_request
def object_request(self, req, version, account, container, obj,
allow_versioned_writes):
account_name = unquote(account)
container_name = unquote(container)
object_name = unquote(obj)
container_info = None
resp = None
is_enabled = config_true_value(allow_versioned_writes)
if req.method in ('PUT', 'DELETE'):
container_info = get_container_info(
req.environ, self.app)
elif req.method == 'COPY' and 'Destination' in req.headers:
if 'Destination-Account' in req.headers:
account_name = req.headers.get('Destination-Account')
account_name = check_account_format(req, account_name)
container_name, object_name = check_destination_header(req)
req.environ['PATH_INFO'] = "/%s/%s/%s/%s" % (
version, account_name, container_name, object_name)
container_info = get_container_info(
req.environ, self.app)
if not container_info:
return self.app
# To maintain backwards compatibility, container version
# location could be stored as sysmeta or not, need to check both.
# If stored as sysmeta, check if middleware is enabled. If sysmeta
# is not set, but versions property is set in container_info, then
# for backwards compatibility feature is enabled.
object_versions = container_info.get(
'sysmeta', {}).get('versions-location')
if object_versions and isinstance(object_versions, unicode):
object_versions = object_versions.encode('utf-8')
elif not object_versions:
object_versions = container_info.get('versions')
# if allow_versioned_writes is not set in the configuration files
# but 'versions' is configured, enable feature to maintain
# backwards compatibility
if not allow_versioned_writes and object_versions:
is_enabled = True
if is_enabled and object_versions:
object_versions = unquote(object_versions)
vw_ctx = VersionedWritesContext(self.app, self.logger)
if req.method in ('PUT', 'COPY'):
policy_idx = req.headers.get(
'X-Backend-Storage-Policy-Index',
container_info['storage_policy'])
resp = vw_ctx.handle_obj_versions_put(
req, object_versions, object_name, policy_idx)
else: # handle DELETE
resp = vw_ctx.handle_obj_versions_delete(
req, object_versions, account_name,
container_name, object_name)
if resp:
return resp
else:
return self.app
开发者ID:bouncestorage,项目名称:swift,代码行数:59,代码来源:versioned_writes.py
示例2: __call__
def __call__(self, request):
try:
(version, account, container, objname) = split_path(
request.path_info, 1, 4, True)
except ValueError:
return self.app(environ, start_response)
if container and not objname:
if request.method in ('DELETE', 'HEAD'):
return self.app
if request.method == 'POST':
# Deny setting if there are any objects in base container
# Otherwise these objects won't be visible
if request.headers.get('X-Container-Meta-Storage-Path'):
container_info = get_container_info(request.environ, self.app)
objects = container_info.get('object_count')
if objects and int(objects) > 0:
return HTTPBadRequest()
# ACL set
groups = (request.remote_user or '').split(',')
account_name = groups[0].split(':')[0]
read_acl = request.environ.get('HTTP_X_CONTAINER_READ', '')
for target_account in read_acl.split(','):
target_account = target_account.split(':')[0]
target_storage_path = self._get_storage_path(request,
target_account)
if not target_storage_path or account_name == target_account:
continue
container_path = "/%s/%s/%s" % (version, account, container)
headers = {'X-Container-Meta-Storage-Path': container_path}
request_path = "%s/%s%s_%s" % (target_storage_path,
self.prefix,
account_name,
container)
req = make_pre_authed_request(request.environ, 'PUT',
request_path, headers=headers)
req.get_response(self.app)
if container:
container_info = get_container_info(request.environ, self.app)
meta = container_info.get('meta', {})
storage_path = meta.get('storage-path')
if storage_path:
if objname:
storage_path += '/' + objname
request.environ['PATH_INFO'] = storage_path
request.environ['RAW_PATH_INFO'] = storage_path
return self.app
开发者ID:cschwede,项目名称:swift-containeralias,代码行数:54,代码来源:middleware.py
示例3: apply_storage_quota
def apply_storage_quota(self, req, service_plan, account_info,
ver, account, container, obj):
if not obj:
quota = service_plan['containers']
# If "number of containers" = (quota + 1): deny PUT
# We don't want to deny overwrite of the last container
new_size = int(account_info['container_count'])
if 0 <= quota < new_size:
return bad_response(
req, None, 'Over quota: containers')
return None
content_length = (req.content_length or 0)
if req.method == 'COPY':
copy_from = container + '/' + obj
else:
copy_from = req.headers.get('X-Copy-From')
container_info = None
if copy_from:
copy_account = req.headers.get('X-Copy-From-Account', account)
path = '/' + ver + '/' + copy_account + '/' + copy_from.lstrip('/')
# We are copying from another account
# Let's not leak the existence of the remote object
# to the unauthorized user
if copy_account != account:
container_info = get_container_info(req.environ, self.app,
swift_source='litequota')
aresp = check_acl(req, container_info, 'read_acl')
if aresp:
return aresp
object_info = get_object_info(req.environ, self.app, path)
if not object_info or not object_info['length']:
content_length = 0
else:
content_length = int(object_info['length'])
new_size = int(account_info['bytes']) + content_length
quota = service_plan['bytes']
if 0 <= quota < new_size:
if not container_info:
container_info = get_container_info(req.environ, self.app,
swift_source='litequota')
return bad_response(req, container_info, 'Over quota: bytes')
# If "number of objects" == (quota + 1): deny PUT
# We don't want to deny overwrite of the last object
new_size = int(account_info['total_object_count'])
quota = service_plan['objects']
if 0 <= quota < new_size:
if not container_info:
container_info = get_container_info(req.environ, self.app,
swift_source='litequota')
return bad_response(req, container_info, 'Over quota: objects')
开发者ID:pkit,项目名称:liteauth,代码行数:51,代码来源:litequota.py
示例4: POST
def POST(self, env):
"""Handle posts dealing with metadata alteration"""
req = Request(env)
conn = HTTPConnection('%s:%s' % (self.mds_ip, self.mds_port))
headers = req.params
version, acc, con, obj = split_path(req.path, 1, 4, True)
if not con:
try:
info = get_account_info(env, self.app)
if info:
stor_policy = info['storage_policy']
headers['storage_policy'] = stor_policy
except:
pass
else:
try:
info = get_container_info(env, self.app)
if info:
stor_policy = info['storage_policy']
headers['storage_policy'] = stor_policy
except:
pass
conn.request('POST', req.path, headers=headers)
resp = conn.getresponse()
#confirm response then pass along the request
return self.app
开发者ID:2015-ucsc-hp,项目名称:swift,代码行数:26,代码来源:metadata.py
示例5: __call__
def __call__(self, env, start_response):
request = Request(env)
if request.method == "PUT":
# Ensure a possibly cached CONTENT_TYPE will be cleared
if env.get('CONTENT_TYPE'):
del env['CONTENT_TYPE']
container_info = get_container_info(
request.environ, self.app, swift_source='AM')
if not container_info or not is_success(container_info['status']):
return self.app(env, start_response)
meta = container_info.get('meta', {})
enabled = meta.get('automime')
if not enabled:
return self.app(env, start_response)
_type, encoding = mimetypes.guess_type(request.path)
if _type:
env['HTTP_CONTENT_TYPE'] = _type
if encoding:
env['HTTP_CONTENT_ENCODING'] = encoding
return self.app(env, start_response)
开发者ID:cschwede,项目名称:swift-automime,代码行数:25,代码来源:middleware.py
示例6: get_defaults
def get_defaults(self, req, req_type, format_args):
acct_sysmeta = get_account_info(req.environ, self.app)['sysmeta']
if req_type == 'object':
cont_sysmeta = get_container_info(req.environ, self.app)['sysmeta']
else:
cont_sysmeta = {}
defaults = {}
prefix = 'default-%s-' % req_type
for src in (self.conf, acct_sysmeta, cont_sysmeta):
for key, value in src.items():
if not key.lower().startswith(prefix):
continue
header_to_default = key[len(prefix):].lower()
if header_to_default.startswith(BLACKLIST_PREFIXES):
continue
if header_to_default in BLACKLIST:
continue
if self.conf['use_formatting']:
try:
value = value.format(**format_args)
except KeyError:
# This user may not have specified the default;
# don't fail because of someone else
pass
defaults[header_to_default] = value
return defaults
开发者ID:tipabu,项目名称:swift_defaulter,代码行数:27,代码来源:defaulter.py
示例7: test_get_container_info_no_cache
def test_get_container_info_no_cache(self):
swift.proxy.controllers.base.make_pre_authed_request = FakeRequest
req = Request.blank("/v1/AUTH_account/cont",
environ={'swift.cache': FakeCache({})})
resp = get_container_info(req.environ, 'xxx')
self.assertEquals(resp['bytes'], 6666)
self.assertEquals(resp['object_count'], 1000)
开发者ID:CiscoAS,项目名称:swift,代码行数:7,代码来源:test_base.py
示例8: get_container_info
def get_container_info(self, app):
"""
get_container_info will return a result dict of get_container_info
from the backend Swift.
:returns: a dictionary of container info from
swift.controllers.base.get_container_info
:raises: NoSuchBucket when the container doesn't exist
:raises: InternalError when the request failed without 404
"""
if self.is_authenticated:
# if we have already authenticated, yes we can use the account
# name like as AUTH_xxx for performance efficiency
sw_req = self.to_swift_req(app, self.container_name, None)
info = get_container_info(sw_req.environ, app)
if is_success(info['status']):
return info
elif info['status'] == 404:
raise NoSuchBucket(self.container_name)
else:
raise InternalError(
'unexpected status code %d' % info['status'])
else:
# otherwise we do naive HEAD request with the authentication
resp = self.get_response(app, 'HEAD', self.container_name, '')
return headers_to_container_info(
resp.sw_headers, resp.status_int) # pylint: disable-msg=E1101
开发者ID:notmyname,项目名称:swift3,代码行数:27,代码来源:request.py
示例9: test_get_container_info_no_auto_account
def test_get_container_info_no_auto_account(self):
app = FakeApp(statuses=[200])
req = Request.blank("/v1/.system_account/cont")
info = get_container_info(req.environ, app)
self.assertEqual(info['status'], 200)
self.assertEqual(info['bytes'], 6666)
self.assertEqual(info['object_count'], 1000)
开发者ID:mahak,项目名称:swift,代码行数:7,代码来源:test_base.py
示例10: _get_keys
def _get_keys(self, env):
"""
Returns the X-[Account|Container]-Meta-Temp-URL-Key[-2] header values
for the account or container, or an empty list if none are set.
Returns 0-4 elements depending on how many keys are set in the
account's or container's metadata.
Also validate that the request
path indicates a valid container; if not, no keys will be returned.
:param env: The WSGI environment for the request.
:returns: list of tempurl keys
"""
parts = env["PATH_INFO"].split("/", 4)
if len(parts) < 4 or parts[0] or parts[1] != "v1" or not parts[2] or not parts[3]:
return []
account_info = get_account_info(env, self.app, swift_source="FP")
account_keys = get_tempurl_keys_from_metadata(account_info["meta"])
container_info = get_container_info(env, self.app, swift_source="FP")
container_keys = get_tempurl_keys_from_metadata(container_info.get("meta", []))
return account_keys + container_keys
开发者ID:danieleguttadoro,项目名称:ovencswiftserver_onthefly,代码行数:25,代码来源:formpost.py
示例11: _get_keys
def _get_keys(self, env):
"""
Returns the X-[Account|Container]-Meta-Temp-URL-Key[-2] header values
for the account or container, or an empty list if none are set. Each
value comes as a 2-tuple (key, scope), where scope is either
CONTAINER_SCOPE or ACCOUNT_SCOPE.
Returns 0-4 elements depending on how many keys are set in the
account's or container's metadata.
:param env: The WSGI environment for the request.
:returns: [
(X-Account-Meta-Temp-URL-Key str value, ACCOUNT_SCOPE) if set,
(X-Account-Meta-Temp-URL-Key-2 str value, ACCOUNT_SCOPE if set,
(X-Container-Meta-Temp-URL-Key str value, CONTAINER_SCOPE) if set,
(X-Container-Meta-Temp-URL-Key-2 str value, CONTAINER_SCOPE if set,
]
"""
account_info = get_account_info(env, self.app, swift_source='TU')
account_keys = get_tempurl_keys_from_metadata(account_info['meta'])
container_info = get_container_info(env, self.app, swift_source='TU')
container_keys = get_tempurl_keys_from_metadata(
container_info.get('meta', []))
return ([(ak, ACCOUNT_SCOPE) for ak in account_keys] +
[(ck, CONTAINER_SCOPE) for ck in container_keys])
开发者ID:nadeemsyed,项目名称:swift,代码行数:27,代码来源:tempurl.py
示例12: test_get_container_info_no_cache
def test_get_container_info_no_cache(self):
req = Request.blank("/v1/AUTH_account/cont",
environ={'swift.cache': FakeCache({})})
resp = get_container_info(req.environ, FakeApp())
self.assertEqual(resp['storage_policy'], 0)
self.assertEqual(resp['bytes'], 6666)
self.assertEqual(resp['object_count'], 1000)
开发者ID:mahak,项目名称:swift,代码行数:7,代码来源:test_base.py
示例13: __call__
def __call__(self, env, start_response):
request = Request(env)
if not request.path.startswith(self.endpoints_path):
return self.app(env, start_response)
if request.method != 'GET':
return HTTPMethodNotAllowed(
req=request, headers={"Allow": "GET"})(env, start_response)
try:
version, account, container, obj = self._parse_path(request)
except ValueError as err:
return HTTPBadRequest(str(err))(env, start_response)
if account is not None:
account = unquote(account)
if container is not None:
container = unquote(container)
if obj is not None:
obj = unquote(obj)
storage_policy_index = None
if obj is not None:
container_info = get_container_info(
{'PATH_INFO': '/v1/%s/%s' % (account, container)},
self.app, swift_source='LE')
storage_policy_index = container_info['storage_policy']
obj_ring = self.get_object_ring(storage_policy_index)
partition, nodes = obj_ring.get_nodes(
account, container, obj)
endpoint_template = 'http://{ip}:{port}/{device}/{partition}/' + \
'{account}/{container}/{obj}'
elif container is not None:
partition, nodes = self.container_ring.get_nodes(
account, container)
endpoint_template = 'http://{ip}:{port}/{device}/{partition}/' + \
'{account}/{container}'
else:
partition, nodes = self.account_ring.get_nodes(
account)
endpoint_template = 'http://{ip}:{port}/{device}/{partition}/' + \
'{account}'
endpoints = []
for node in nodes:
endpoint = endpoint_template.format(
ip=node['ip'],
port=node['port'],
device=node['device'],
partition=partition,
account=quote(account),
container=quote(container or ''),
obj=quote(obj or ''))
endpoints.append(endpoint)
resp = self.response_map[version](
request, endpoints=endpoints,
storage_policy_index=storage_policy_index)
return resp(env, start_response)
开发者ID:bkolli,项目名称:swift,代码行数:59,代码来源:list_endpoints.py
示例14: get_container_size
def get_container_size(self, env):
rv = 0
container_info = get_container_info(
env, self.app, swift_source='RL')
if isinstance(container_info, dict):
rv = container_info.get(
'object_count', container_info.get('container_size', 0))
return rv
开发者ID:BReduardokramer,项目名称:swift,代码行数:8,代码来源:ratelimit.py
示例15: test_get_container_info_env
def test_get_container_info_env(self):
cache_key = get_cache_key("account", "cont")
req = Request.blank(
"/v1/account/cont",
environ={'swift.infocache': {cache_key: {'bytes': 3867}},
'swift.cache': FakeCache({})})
resp = get_container_info(req.environ, 'xxx')
self.assertEqual(resp['bytes'], 3867)
开发者ID:mahak,项目名称:swift,代码行数:8,代码来源:test_base.py
示例16: test_get_container_info_cache
def test_get_container_info_cache(self):
cached = {"status": 404, "bytes": 3333, "object_count": 10}
req = Request.blank("/v1/account/cont", environ={"swift.cache": FakeCache(cached)})
with patch("swift.proxy.controllers.base." "_prepare_pre_auth_info_request", FakeRequest):
resp = get_container_info(req.environ, "xxx")
self.assertEquals(resp["bytes"], 3333)
self.assertEquals(resp["object_count"], 10)
self.assertEquals(resp["status"], 404)
开发者ID:r0mik,项目名称:swift,代码行数:8,代码来源:test_base.py
示例17: test_get_container_info_no_auto_account
def test_get_container_info_no_auto_account(self):
responses = DynamicResponseFactory(404, 200)
app = FakeApp(responses)
req = Request.blank("/v1/.system_account/cont")
info = get_container_info(req.environ, app)
self.assertEqual(info['status'], 200)
self.assertEqual(info['bytes'], 6666)
self.assertEqual(info['object_count'], 1000)
开发者ID:bouncestorage,项目名称:swift,代码行数:8,代码来源:test_base.py
示例18: object_request
def object_request(self, req, api_version, account, container, obj,
allow_versioned_writes):
"""
Handle request for object resource.
Note that account, container, obj should be unquoted by caller
if the url path is under url encoding (e.g. %FF)
:param req: swift.common.swob.Request instance
:param api_version: should be v1 unless swift bumps api version
:param account: account name string
:param container: container name string
:param object: object name string
"""
resp = None
is_enabled = config_true_value(allow_versioned_writes)
container_info = get_container_info(
req.environ, self.app)
# To maintain backwards compatibility, container version
# location could be stored as sysmeta or not, need to check both.
# If stored as sysmeta, check if middleware is enabled. If sysmeta
# is not set, but versions property is set in container_info, then
# for backwards compatibility feature is enabled.
versions_cont = container_info.get(
'sysmeta', {}).get('versions-location')
versioning_mode = container_info.get(
'sysmeta', {}).get('versions-mode', 'stack')
if not versions_cont:
versions_cont = container_info.get('versions')
# if allow_versioned_writes is not set in the configuration files
# but 'versions' is configured, enable feature to maintain
# backwards compatibility
if not allow_versioned_writes and versions_cont:
is_enabled = True
if is_enabled and versions_cont:
versions_cont = wsgi_unquote(str_to_wsgi(
versions_cont)).split('/')[0]
vw_ctx = VersionedWritesContext(self.app, self.logger)
if req.method == 'PUT':
resp = vw_ctx.handle_obj_versions_put(
req, versions_cont, api_version, account,
obj)
# handle DELETE
elif versioning_mode == 'history':
resp = vw_ctx.handle_obj_versions_delete_push(
req, versions_cont, api_version, account,
container, obj)
else:
resp = vw_ctx.handle_obj_versions_delete_pop(
req, versions_cont, api_version, account,
container, obj)
if resp:
return resp
else:
return self.app
开发者ID:mahak,项目名称:swift,代码行数:58,代码来源:versioned_writes.py
示例19: get_controller
def get_controller(self, req):
"""
Get the controller to handle a request.
:param req: the request
:returns: tuple of (controller class, path dictionary)
:raises: ValueError (thrown by split_path) if given invalid path
"""
print 'req.path',req.path
if req.path == '/info':
d = dict(version=None,
expose_info=self.expose_info,
disallowed_sections=self.disallowed_sections,
admin_key=self.admin_key)
print 'd',d
return InfoController, d
version, account, container, obj = split_path(req.path, 1, 4, True)
d = dict(version=version,
account_name=account,
container_name=container,
object_name=obj)
print 'd',d
#print 'valid_api_version(version)',valid_api_version(version)
if account and not valid_api_version(version):
raise APIVersionError('Invalid path')
if obj and container and account:
info = get_container_info(req.environ, self)
print 'info of obj,Acc,Con',info
policy_index = req.headers.get('X-Backend-Storage-Policy-Index',
info['storage_policy'])
print 'policy_index',policy_index
policy = POLICIES.get_by_index(policy_index)
print 'policy',policy
if not policy:
# This indicates that a new policy has been created,
# with rings, deployed, released (i.e. deprecated =
# False), used by a client to create a container via
# another proxy that was restarted after the policy
# was released, and is now cached - all before this
# worker was HUPed to stop accepting new
# connections. There should never be an "unknown"
# index - but when there is - it's probably operator
# error and hopefully temporary.
raise HTTPServiceUnavailable('Unknown Storage Policy')
return self.obj_controller_router[policy], d
elif container and account:
print 'container & account, returning containercontroller',container,account
return ContainerController, d
elif account and not container and not obj:
print 'account, returning accountcontroller',account
return AccountController, d
return None, d
开发者ID:jannatunnoor,项目名称:test_swift,代码行数:54,代码来源:server.py
示例20: test_get_container_info_cache
def test_get_container_info_cache(self):
swift.proxy.controllers.base.make_pre_authed_request = FakeRequest
cached = {'status': 404,
'bytes': 3333,
'object_count': 10}
req = Request.blank("/v1/account/cont",
environ={'swift.cache': FakeCache(cached)})
resp = get_container_info(req.environ, 'xxx')
self.assertEquals(resp['bytes'], 3333)
self.assertEquals(resp['object_count'], 10)
self.assertEquals(resp['status'], 404)
开发者ID:CiscoAS,项目名称:swift,代码行数:11,代码来源:test_base.py
注:本文中的swift.proxy.controllers.base.get_container_info函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论