Author: tomaz
Date: Thu Jun 23 10:00:00 2011
New Revision: 1138806

URL: http://svn.apache.org/viewvc?rev=1138806&view=rev
Log:
Make sure the file is closed after reading the content in the ex_import_keypair 
method in the EC2 compute driver.

Modified:
    libcloud/trunk/libcloud/compute/drivers/ec2.py

Modified: libcloud/trunk/libcloud/compute/drivers/ec2.py
URL: 
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/ec2.py?rev=1138806&r1=1138805&r2=1138806&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/ec2.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/ec2.py Thu Jun 23 10:00:00 2011
@@ -16,6 +16,8 @@
 """
 Amazon EC2 driver
 """
+from __future__ import with_statement
+
 import base64
 import hmac
 import os
@@ -452,8 +454,10 @@ class EC2NodeDriver(NodeDriver):
         @param keyfile: The filename with path of the public key to import.
 
         """
+        with open(os.path.expanduser(keyfile)) as fh:
+            content = fh.read()
 
-        base64key = base64.b64encode(open(os.path.expanduser(keyfile)).read())
+        base64key = base64.b64encode(content)
 
         params = {'Action': 'ImportKeyPair',
                   'KeyName': name,


Reply via email to