Commit f0bddbda authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Fix problems with unicode HTTP headers

parent ee041529
......@@ -146,7 +146,7 @@ information is then printed to the standard output.
Print objects in default container
srv = cyclades.get_server_info(server_id)
print("Server Name: %s (with OS %s" % (srv['name'], srv['os']))
print("Server Name: %s (OS: %s)" % (srv['name'], srv['metadata']['os']))
obj_list = pithos.list_objects()
print("Objects in container '%s':" % pithos.container)
......@@ -160,7 +160,7 @@ information is then printed to the standard output.
$ python test_script.py
Server Name: A Debian Server (with OS Debian Base)
Server Name: A Debian Server (OS: debian)
Objects in container 'pithos':
lala.txt of 34 bytes
test.txt of 1232 bytes
......@@ -196,35 +196,38 @@ The following example concatenates examples 1.1 to 1.4 plus error handling
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)
except ClientError:
print('Failed to authenticate user token')
return 1
raise
try:
cyclades_endpoints = astakos.get_service_endpoints('compute')
cyclades_publicURL = cyclades_endpoints['publicURL']
CYCLADES_URL = cyclades_endpoints['publicURL']
except ClientError:
print('Failed to get endpoints for cyclades')
try:
cyclades = CycladesClient(cyclades_publicURL, token)
cyclades = CycladesClient(CYCLADES_URL, TOKEN)
except ClientError:
print('Failed to initialize Cyclades client')
try:
pithos_endpoints = astakos.get_service_endpoints('object-store')
pithos_publicURL = pithos_endpoints['publicURL']
PITHOS_URL = pithos_endpoints['publicURL']
except ClientError:
print('Failed to get endpoints for pithos')
try:
pithos = PithosClient(pithos_publicURL, token, account, container)
account, container = astakos.user_info['id'], 'pithos'
pithos = PithosClient(PITHOS_URL, TOKEN, account, container)
except ClientError:
print('Failed to initialize Pithos+ client')
try:
server_id = SERVER_ID
srv = cyclades.get_server_info(server_id)
print("Server Name: %s (with OS %s" % (srv['name'], srv['os']))
print("Server Name: %s (OS: %s)" % (srv['name'], srv['metadata']['os']))
obj_list = pithos.list_objects()
print('Objects in container %s:' % pithos.container)
for obj in obj_list:
print(' %s of %s bytes' % (obj['name'], obj['bytes']))
except ClientError as e:
......@@ -264,31 +267,19 @@ Batch-create servers
('My Ubuntu Server', 3, 'my-ubuntu-12-image-id'),
]
created = []
for name, flavor_id, image_id in servers:
cyclades.create_server(name, flavor_id, image_id)
Batch-create 4 servers of the same kind
'''''''''''''''''''''''''''''''''''''''
.. code-block:: python
new_vm = cyclades.create_server(name, flavor_id, image_id, networks=[])
created.append(new_vm)
#! /usr/bin/python
for vm in created:
print 'Wait while vm "%s" (%s) is being build' % (vm['name'], vm['id'])
cyclades.wait_server(vm['id'])
from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import CycladesClient
AUTHENTICATION_URL = 'https://accounts.example.com/identity/v2.0'
TOKEN = 'replace this with your token'
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)
CYCLADES_URL = astakos.get_service_endpoints('compute')['publicURL']
cyclades = CycladesClient(CYCLADES_URL, TOKEN)
for i in range(4):
name, flavor_id, image_id = 'Server %s' % (i + 1), 3, 'some-image-id'
cyclades.create_server(name, flavor_id, image_id)
.. note:: The `networks=[]` argument explicitly instructs `cyclades` to create
a virtual server without any network connections. If not used, `cyclades`
will apply the default policy (e.g., assign a public IP to the new virtual
server).
Register a banch of pre-uploaded images
'''''''''''''''''''''''''''''''''''''''
......@@ -310,7 +301,8 @@ Register a banch of pre-uploaded images
USER_UUID = astakos.user_info['id']
PITHOS_URL = astakos.get_service_endpoints('object-store')['publicURL']
pithos = PithosClient(PITHOS_URL, TOKEN, USER_UUID, IMAGE_CONTAINER)
pithos = PithosClient(
PITHOS_URL, TOKEN, account=USER_UUID, container=IMAGE_CONTAINER)
IMAGE_URL = astakos.get_service_endpoints('image')['publicURL']
plankton = ImageClient(IMAGE_URL, TOKEN)
......@@ -325,10 +317,8 @@ Register a banch of pre-uploaded images
except ClientError:
print 'Failed to register image %s' % IMAGE_PATH
.. note::
In `plankton.register`, the `location` argument can be either `a triplet`,
as shown above, or `a qualified URL` of the form
.. note:: In `plankton.register`, the `location` argument can be either
`a triplet`, as shown above, or `a qualified URL` of the form
``pithos://USER_UUID/IMAGE_CONTAINER/IMAGE_PATH``.
Two servers and a private network
......
......@@ -257,6 +257,7 @@ class ResponseManager(Logged):
from traceback import format_stack
recvlog.debug(
'\n'.join(['%s' % type(err)] + format_stack()))
raise
raise ClientError(
'Failed while http-connecting to %s (%s)' % (
self.request.url, err))
......@@ -418,11 +419,11 @@ class Client(Logged):
def set_header(self, name, value, iff=True):
"""Set a header 'name':'value'"""
if value is not None and iff:
self.headers[name] = unicode(value)
self.headers['%s' % name] = '%s' % value
def set_param(self, name, value=None, iff=True):
if iff:
self.params[name] = '%s' % value # unicode(value)
self.params[name] = '%s' % value
def request(
self, method, path,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment