本文整理汇总了Python中swiftclient.client.get_account函数的典型用法代码示例。如果您正苦于以下问题:Python get_account函数的具体用法?Python get_account怎么用?Python get_account使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_account函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_one_node_fails
def test_one_node_fails(self):
# Create container1
# Kill container1 servers excepting two of the primaries
# Delete container1
# Restart other container1 primary server
# Create container1/object1 (allowed because at least server thinks the
# container exists)
# Get to a final state
# Assert all container1 servers indicate container1 is alive and
# well with object1
# Assert account level also indicates container1 is alive and
# well with object1
container1 = 'container-%s' % uuid4()
cpart, cnodes = self.container_ring.get_nodes(self.account, container1)
client.put_container(self.url, self.token, container1)
kill_nonprimary_server(cnodes, self.port2server, self.pids)
kill_server(cnodes[0]['port'], self.port2server, self.pids)
client.delete_container(self.url, self.token, container1)
start_server(cnodes[0]['port'], self.port2server, self.pids)
client.put_object(self.url, self.token, container1, 'object1', '123')
get_to_final_state()
for cnode in cnodes:
self.assertEquals(
[o['name'] for o in direct_client.direct_get_container(
cnode, cpart, self.account, container1)[1]],
['object1'])
headers, containers = client.get_account(self.url, self.token)
self.assertEquals(headers['x-account-container-count'], '1')
self.assertEquals(headers['x-account-object-count'], '1')
self.assertEquals(headers['x-account-bytes-used'], '3')
示例2: containerview
def containerview(request):
""" Returns a list of all containers in current account. """
storage_url = request.session.get('storage_url', '')
auth_token = request.session.get('auth_token', '')
if not storage_url or not auth_token:
return redirect(login)
try:
account_stat, containers = client.get_account(storage_url, auth_token)
except client.ClientException as exc:
traceback.print_exc()
if exc.http_status == 403:
account_stat = {}
containers = []
base_url = get_base_url(request)
msg = 'Container listing failed. You can manually choose a known '
msg += 'container by appending the name to the URL, for example: '
msg += '<a href="%s/objects/containername">' % base_url
msg += '%s/objects/containername</a>' % base_url
messages.add_message(request, messages.ERROR, msg)
else:
return redirect(login)
account_stat = replace_hyphens(account_stat)
return render_to_response('containerview.html', {
'account_stat': account_stat,
'containers': containers,
'session': request.session,
}, context_instance=RequestContext(request))
示例3: containerview
def containerview(request):
""" Returns a list of all containers in current account. """
if not request.session.get('project_id'):
messages.add_message(request, messages.ERROR, _('Select a project'))
return HttpResponseRedirect(reverse('dashboard'))
storage_url = get_endpoint(request, 'adminURL')
auth_token = get_token_id(request)
http_conn = client.http_connection(storage_url,
insecure=settings.SWIFT_INSECURE)
page = request.GET.get('page', 1)
try:
account_stat, containers = client.get_account(storage_url, auth_token,
http_conn=http_conn)
except client.ClientException as err:
log.exception('{}{}'.format(_('Exception:').encode('UTF-8'), err))
messages.add_message(request, messages.ERROR,
_('Unable to list containers'))
account_stat = {}
containers = []
containers = _hide_containers_with_prefixes(containers)
account_stat = replace_hyphens(account_stat)
context = utils.update_default_context(request, {
'account_stat': account_stat,
'containers': utils.generic_pagination(containers, page),
})
return render_to_response('containerview.html', context,
context_instance=RequestContext(request))
示例4: get_temp_key
def get_temp_key(storage_url, auth_token, container):
""" Tries to get meta-temp-url key from account.
If not set, generate tempurl and save it to acocunt.
This requires at least account owner rights. """
try:
account = client.get_account(storage_url, auth_token)
except client.ClientException:
#Try to get the container temp url key instead
try:
container = client.get_container(
storage_url, auth_token, container)
return container[0].get('x-container-meta-temp-url-key')
except client.ClientException:
return None
return None
key = account[0].get('x-account-meta-temp-url-key')
if not key:
chars = string.ascii_lowercase + string.digits
key = ''.join(random.choice(chars) for x in range(32))
headers = {'x-account-meta-temp-url-key': key}
try:
client.post_account(storage_url, auth_token, headers)
except client.ClientException:
return None
return key
示例5: test_two_nodes_fail
def test_two_nodes_fail(self):
# Create container1
# Kill container1 servers excepting one of the primaries
# Delete container1 directly to the one primary still up
# Restart other container1 servers
# Get to a final state
# Assert all container1 servers indicate container1 is gone (happens
# because the one node that knew about the delete replicated to the
# others.)
# Assert account level also indicates container1 is gone
container1 = 'container-%s' % uuid4()
cpart, cnodes = self.container_ring.get_nodes(self.account, container1)
client.put_container(self.url, self.token, container1)
cnp_port = kill_nonprimary_server(cnodes, self.port2server, self.pids)
kill_server(cnodes[0]['port'], self.port2server, self.pids)
kill_server(cnodes[1]['port'], self.port2server, self.pids)
direct_client.direct_delete_container(cnodes[2], cpart, self.account,
container1)
start_server(cnodes[0]['port'], self.port2server, self.pids)
start_server(cnodes[1]['port'], self.port2server, self.pids)
start_server(cnp_port, self.port2server, self.pids)
get_to_final_state()
for cnode in cnodes:
exc = None
try:
direct_client.direct_get_container(cnode, cpart, self.account,
container1)
except client.ClientException as err:
exc = err
self.assertEquals(exc.http_status, 404)
headers, containers = client.get_account(self.url, self.token)
self.assertEquals(headers['x-account-container-count'], '0')
self.assertEquals(headers['x-account-object-count'], '0')
self.assertEquals(headers['x-account-bytes-used'], '0')
示例6: test_first_two_nodes_fail
def test_first_two_nodes_fail(self):
container = 'container-%s' % uuid4()
client.put_container(self.url, self.token, container)
self.assert_(container in [c['name'] for c in
client.get_account(self.url, self.token)[1]])
object1 = 'object1'
client.put_object(self.url, self.token, container, object1, 'test')
self.assert_(container in [c['name'] for c in
client.get_account(self.url, self.token)[1]])
self.assert_(object1 in [o['name'] for o in
client.get_container(self.url, self.token, container)[1]])
cpart, cnodes = self.container_ring.get_nodes(self.account, container)
for x in xrange(2):
kill(self.pids[self.port2server[cnodes[x]['port']]], SIGTERM)
client.delete_object(self.url, self.token, container, object1)
self.assert_(container in [c['name'] for c in
client.get_account(self.url, self.token)[1]])
self.assert_(object1 not in [o['name'] for o in
client.get_container(self.url, self.token, container)[1]])
for x in xrange(2):
self.pids[self.port2server[cnodes[x]['port']]] = \
Popen(['swift-container-server',
'/etc/swift/container-server/%d.conf' %
((cnodes[x]['port'] - 6001) / 10)]).pid
sleep(2)
self.assert_(container in [c['name'] for c in
client.get_account(self.url, self.token)[1]])
# This okay because the first node hasn't got the update that the
# object was deleted yet.
self.assert_(object1 in [o['name'] for o in
direct_client.direct_get_container(cnodes[0], cpart,
self.account, container)[1]])
# This fails because all three nodes have to indicate deletion before
# we tell the user it worked. Since the first node 409s (it hasn't got
# the update that the object was deleted yet), the whole must 503
# (until every is synced up, then the delete would work).
exc = None
try:
client.delete_container(self.url, self.token, container)
except client.ClientException, err:
exc = err
示例7: list_container
def list_container(self):
"""
List all available containers.
:return: list of container names.
"""
container_info = sc.get_account(self.storage_location, self.ks.auth_token)
container_list = [container_info[1][count]['name'] for count in range(len(container_info[1]))]
return container_list
示例8: get_containers
def get_containers(storage_url, auth_token):
containers = []
try:
account_stat, containers = client.get_account(storage_url, auth_token)
except ClientException as exc:
logger.exception("Could not get containers")
if exc.http_status == 403:
logger.warn("Container listing failed")
except:
logger.exception("Could not get containers")
return containers
示例9: containers_list
def containers_list(request, project_id):
if request.method == 'GET':
token = get_token_connection(request)
url = settings.SWIFT_URL + "/AUTH_" + project_id
_, containers = swift_client.get_account(url, token)
for c_id in reversed(range(len(containers))):
if containers[c_id]['name'] in ('.dependency', '.storlet'):
del containers[c_id]
return JSONResponse(containers, status=status.HTTP_200_OK)
return JSONResponse('Method ' + str(request.method) + ' not allowed.', status=status.HTTP_405_METHOD_NOT_ALLOWED)
示例10: get_account_containers
def get_account_containers(storage_url, auth_token):
""" List all containers in an account"""
container_list = []
http_conn = client.http_connection(storage_url,
insecure=settings.SWIFT_INSECURE)
_, containers = client.get_account(storage_url, auth_token,
http_conn=http_conn)
for container in containers:
container_list.append(container['name'])
return container_list
示例11: delete_account_cont
def delete_account_cont(self, account_url, token):
cnx = sclient.http_connection(account_url)
al = sclient.get_account(None, token,
http_conn=cnx,
full_listing=True)
for container in [c['name'] for c in al[1]]:
ci = sclient.get_container(None, token,
container, http_conn=cnx,
full_listing=True)
on = [od['name'] for od in ci[1]]
for obj in on:
sclient.delete_object('', token, container,
obj, http_conn=cnx)
sclient.delete_container('', token, container, http_conn=cnx)
示例12: get_account
def get_account(self, deep=True):
if not self.http_conn:
self.connect()
account_info = swift.head_account(url=self.swift_url, token=self.token, http_conn=self.http_conn)
account_head, containers = swift.get_account(url=self.swift_url, token=self.token, http_conn=self.http_conn)
if self.debug:
print(account_info)
print(account_head)
for container in containers:
print(container)
print
if deep:
self.get_containers(containers)
示例13: test_two_nodes_fail
def test_two_nodes_fail(self):
# Create container1
container1 = 'container-%s' % uuid4()
cpart, cnodes = self.container_ring.get_nodes(self.account, container1)
client.put_container(self.url, self.token, container1)
# Kill container1 servers excepting one of the primaries
cnp_ipport = kill_nonprimary_server(cnodes, self.ipport2server,
self.pids)
kill_server((cnodes[0]['ip'], cnodes[0]['port']),
self.ipport2server, self.pids)
kill_server((cnodes[1]['ip'], cnodes[1]['port']),
self.ipport2server, self.pids)
# Delete container1 directly to the one primary still up
direct_client.direct_delete_container(cnodes[2], cpart, self.account,
container1)
# Restart other container1 servers
start_server((cnodes[0]['ip'], cnodes[0]['port']),
self.ipport2server, self.pids)
start_server((cnodes[1]['ip'], cnodes[1]['port']),
self.ipport2server, self.pids)
start_server(cnp_ipport, self.ipport2server, self.pids)
# Get to a final state
self.get_to_final_state()
# Assert all container1 servers indicate container1 is gone (happens
# because the one node that knew about the delete replicated to the
# others.)
for cnode in cnodes:
try:
direct_client.direct_get_container(cnode, cpart, self.account,
container1)
except ClientException as err:
self.assertEqual(err.http_status, 404)
else:
self.fail("Expected ClientException but didn't get it")
# Assert account level also indicates container1 is gone
headers, containers = client.get_account(self.url, self.token)
self.assertEqual(headers['x-account-container-count'], '0')
self.assertEqual(headers['x-account-object-count'], '0')
self.assertEqual(headers['x-account-bytes-used'], '0')
示例14: handle_uploaded_file
def handle_uploaded_file(request):
f = request.FILES["file"]
# with open('E:/sample.txt', 'wb+') as destination:
# for chunk in f.chunks():
# destination.write(chunk)
token = request.session.get("token")
tenant_id = request.session.get("tenant_id")
print "token:%s***tenant:%s" % (token, tenant_id)
url = "http://192.168.0.55:8888/v1/AUTH_" + str(tenant_id)
container = "Publish"
containers = c.get_account(url, token)[1]
print containers
if get_container(containers, container):
pass
else:
print "put container %s" % (container)
c.put_container(url, token, container)
c.put_object(url, token, container, name=f.name, contents=f)
示例15: containerview
def containerview(request):
""" Returns a list of all containers in current account. """
storage_url = request.session.get('storage_url', '')
auth_token = request.session.get('auth_token', '')
try:
account_stat, containers = client.get_account(storage_url, auth_token)
except client.ClientException:
return redirect(login)
account_stat = replace_hyphens(account_stat)
return render_to_response('containerview.html', {
'account_stat': account_stat,
'containers': containers,
'session': request.session,
}, context_instance=RequestContext(request))