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