Author: tomaz
Date: Sat Dec 3 15:57:54 2011
New Revision: 1209937
URL: http://svn.apache.org/viewvc?rev=1209937&view=rev
Log:
More progress.
Modified:
libcloud/branches/py3k/libcloud/common/openstack.py
libcloud/branches/py3k/libcloud/compute/base.py
libcloud/branches/py3k/libcloud/compute/deployment.py
libcloud/branches/py3k/libcloud/compute/drivers/openstack.py
libcloud/branches/py3k/libcloud/py3.py
libcloud/branches/py3k/test/compute/test_deployment.py
Modified: libcloud/branches/py3k/libcloud/common/openstack.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/common/openstack.py?rev=1209937&r1=1209936&r2=1209937&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/common/openstack.py (original)
+++ libcloud/branches/py3k/libcloud/common/openstack.py Sat Dec 3 15:57:54 2011
@@ -16,8 +16,10 @@
"""
Common utilities for OpenStack
"""
-import httplib
-from urllib2 import urlparse
+from libcloud.py3 import httplib
+from libcloud.py3 import urllib2
+from libcloud.py3 import urlparse
+
from libcloud.common.base import ConnectionUserAndKey, Response
from libcloud.compute.types import LibcloudError, InvalidCredsError,
MalformedResponseError
@@ -147,12 +149,14 @@ class OpenStackAuthConnection(Connection
else:
try:
body = json.loads(resp.body)
- except Exception, e:
+ except Exception:
+ e = sys.exc_info()[1]
raise MalformedResponseError('Failed to parse JSON', e)
try:
self.auth_token = body['auth']['token']['id']
self.urls = body['auth']['serviceCatalog']
- except KeyError, e:
+ except KeyError:
+ e = sys.exc_info()[1]
raise MalformedResponseError('Auth JSON response is missing
required elements', e)
def authenticate_2_0_with_apikey(self):
@@ -181,7 +185,8 @@ class OpenStackAuthConnection(Connection
else:
try:
body = json.loads(resp.body)
- except Exception, e:
+ except Exception:
+ e = sys.exc_info()[1]
raise MalformedResponseError('Failed to parse JSON', e)
try:
@@ -189,7 +194,8 @@ class OpenStackAuthConnection(Connection
token = access['token']
self.auth_token = token['id']
self.urls = access['serviceCatalog']
- except KeyError, e:
+ except KeyError:
+ e = sys.exc_info()[1]
raise MalformedResponseError('Auth JSON response is missing
required elements', e)
class OpenStackBaseConnection(ConnectionUserAndKey):
Modified: libcloud/branches/py3k/libcloud/compute/base.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/compute/base.py?rev=1209937&r1=1209936&r2=1209937&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/compute/base.py (original)
+++ libcloud/branches/py3k/libcloud/compute/base.py Sat Dec 3 15:57:54 2011
@@ -22,6 +22,7 @@ import hashlib
import os
import socket
import struct
+import binascii
from libcloud.py3 import b
@@ -527,7 +528,7 @@ class NodeDriver(BaseDriver):
'deploy_node not implemented for this driver')
if 'auth' not in kwargs:
- kwargs['auth'] = NodeAuthPassword(os.urandom(16).encode('hex'))
+ kwargs['auth'] =
NodeAuthPassword(binascii.hexlify(os.urandom(16)))
if 'ssh_key' not in kwargs:
password = kwargs['auth'].password
@@ -590,7 +591,7 @@ class NodeDriver(BaseDriver):
while time.time() < end:
nodes = self.list_nodes()
- nodes = filter(lambda n: n.uuid == node.uuid, nodes)
+ nodes = list(filter(lambda n: n.uuid == node.uuid, nodes))
if len(nodes) == 0:
raise LibcloudError(value=('Booted node[%s] ' % node
Modified: libcloud/branches/py3k/libcloud/compute/deployment.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/compute/deployment.py?rev=1209937&r1=1209936&r2=1209937&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/compute/deployment.py (original)
+++ libcloud/branches/py3k/libcloud/compute/deployment.py Sat Dec 3 15:57:54
2011
@@ -17,6 +17,9 @@
Provides generic deployment steps for machines post boot.
"""
import os
+import binascii
+
+from libcloud.py3 import basestring
class Deployment(object):
"""
@@ -35,8 +38,8 @@ class Deployment(object):
@return: L{Node}
"""
- raise NotImplementedError, \
- 'run not implemented for this deployment'
+ raise NotImplementedError(
+ 'run not implemented for this deployment')
def _get_string_value(self, argument_name, argument_value):
if not isinstance(argument_value, basestring) and \
@@ -98,7 +101,7 @@ class ScriptDeployment(Deployment):
self.delete = delete
self.name = name
if self.name is None:
- self.name = "/root/deployment_%s.sh" %
(os.urandom(4).encode('hex'))
+ self.name = "/root/deployment_%s.sh" %
(binascii.hexlify(os.urandom(4)))
def run(self, node, client):
"""
@@ -106,7 +109,8 @@ class ScriptDeployment(Deployment):
See also L{Deployment.run}
"""
- client.put(path=self.name, chmod=0755, contents=self.script)
+
+ client.put(path=self.name, chmod=int('755', 8), contents=self.script)
self.stdout, self.stderr, self.exit_status = client.run(self.name)
if self.delete:
client.delete(self.name)
Modified: libcloud/branches/py3k/libcloud/compute/drivers/openstack.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/compute/drivers/openstack.py?rev=1209937&r1=1209936&r2=1209937&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/compute/drivers/openstack.py (original)
+++ libcloud/branches/py3k/libcloud/compute/drivers/openstack.py Sat Dec 3
15:57:54 2011
@@ -16,6 +16,8 @@
OpenStack driver
"""
+import binascii
+
try:
import simplejson as json
except ImportError:
@@ -127,7 +129,7 @@ class OpenStackComputeConnection(OpenSta
headers = {'Content-Type': self.default_content_type}
if method == "GET":
- params['cache-busting'] = os.urandom(8).encode('hex')
+ params['cache-busting'] = binascii.hexlify(os.urandom(8))
return super(OpenStackComputeConnection, self).request(
action=action,
Modified: libcloud/branches/py3k/libcloud/py3.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/py3.py?rev=1209937&r1=1209936&r2=1209937&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/py3.py (original)
+++ libcloud/branches/py3k/libcloud/py3.py Sat Dec 3 15:57:54 2011
@@ -31,6 +31,8 @@ if sys.version_info >= (3, 0):
urllib.quote = urlparse.quote
urllib.urlencode = urlparse.urlencode
+ basestring = str
+
# Taken from django.utils.py3
bytes = __builtins__['bytes']
def b(s):
@@ -54,6 +56,8 @@ else:
import urllib2
import urlparse
+ basestring = unicode = str
+
# Taken from django.utils.py3
b = bytes = str
def byte(n):
Modified: libcloud/branches/py3k/test/compute/test_deployment.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/test/compute/test_deployment.py?rev=1209937&r1=1209936&r2=1209937&view=diff
==============================================================================
--- libcloud/branches/py3k/test/compute/test_deployment.py (original)
+++ libcloud/branches/py3k/test/compute/test_deployment.py Sat Dec 3 15:57:54
2011
@@ -17,7 +17,9 @@
import sys
import time
import unittest
+
from libcloud.py3 import httplib
+from libcloud.py3 import u
from libcloud.compute.deployment import MultiStepDeployment, Deployment
from libcloud.compute.deployment import SSHKeyDeployment, ScriptDeployment
@@ -99,11 +101,11 @@ class DeploymentTests(unittest.TestCase)
return 'bar'
ScriptDeployment(script='foobar')
- ScriptDeployment(script=unicode('foobar'))
+ ScriptDeployment(script=u('foobar'))
ScriptDeployment(script=FileObject('test'))
SSHKeyDeployment(key='foobar')
- SSHKeyDeployment(key=unicode('foobar'))
+ SSHKeyDeployment(key=u('foobar'))
SSHKeyDeployment(key=FileObject('test'))
try:
@@ -137,7 +139,8 @@ class DeploymentTests(unittest.TestCase)
try:
self.driver._wait_until_running(node=self.node, wait_period=0.5,
timeout=1)
- except LibcloudError, e:
+ except LibcloudError:
+ e = sys.exc_info()[1]
self.assertTrue(e.value.find('Timed out') != -1)
else:
self.fail('Exception was not thrown')
@@ -149,7 +152,8 @@ class DeploymentTests(unittest.TestCase)
try:
self.driver._wait_until_running(node=self.node, wait_period=0.5,
timeout=1)
- except LibcloudError, e:
+ except LibcloudError:
+ e = sys.exc_info()[1]
self.assertTrue(e.value.find('is missing from list_nodes') != -1)
else:
self.fail('Exception was not thrown')
@@ -160,7 +164,8 @@ class DeploymentTests(unittest.TestCase)
try:
self.driver._wait_until_running(node=self.node, wait_period=0.5,
timeout=1)
- except LibcloudError, e:
+ except LibcloudError:
+ e = sys.exc_info()[1]
self.assertTrue(e.value.find('multiple nodes have same UUID') !=
-1)
else:
self.fail('Exception was not thrown')
@@ -182,7 +187,8 @@ class DeploymentTests(unittest.TestCase)
try:
self.driver._ssh_client_connect(ssh_client=mock_ssh_client,
timeout=1)
- except LibcloudError, e:
+ except LibcloudError:
+ e = sys.exc_info()[1]
self.assertTrue(e.value.find('Giving up') != -1)
else:
self.fail('Exception was not thrown')
@@ -208,7 +214,8 @@ class DeploymentTests(unittest.TestCase)
node=self.node,
ssh_client=ssh_client,
max_tries=2)
- except LibcloudError, e:
+ except LibcloudError:
+ e = sys.exc_info()[1]
self.assertTrue(e.value.find('Failed after 2 tries') != -1)
else:
self.fail('Exception was not thrown')
@@ -239,7 +246,8 @@ class DeploymentTests(unittest.TestCase)
try:
self.driver.deploy_node(deploy=deploy)
- except DeploymentError, e:
+ except DeploymentError:
+ e = sys.exc_info()[1]
self.assertTrue(e.node.id, self.node.id)
else:
self.fail('Exception was not thrown')
@@ -258,7 +266,8 @@ class DeploymentTests(unittest.TestCase)
try:
self.driver.deploy_node(deploy=deploy)
- except DeploymentError, e:
+ except DeploymentError:
+ e = sys.exc_info()[1]
self.assertTrue(e.node.id, self.node.id)
else:
self.fail('Exception was not thrown')
@@ -309,7 +318,8 @@ class DeploymentTests(unittest.TestCase)
try:
self.driver.deploy_node(deploy=Mock())
- except RuntimeError, e:
+ except RuntimeError:
+ e = sys.exc_info()[1]
self.assertTrue(str(e).find('paramiko is not installed') != -1)
else:
self.fail('Exception was not thrown')