Author: tomaz
Date: Sun May 13 03:07:41 2012
New Revision: 1337758
URL: http://svn.apache.org/viewvc?rev=1337758&view=rev
Log:
Add FileDeployment class to libcloud.compute.deployment module. This can be used
as a replacemtnt for ex_files argument if the provider supports deployment
functionality. This patch has been contributed by Jay Doane and is part of
LIBCLOUD-190.
Modified:
libcloud/trunk/CHANGES
libcloud/trunk/libcloud/compute/deployment.py
libcloud/trunk/test/compute/test_deployment.py
Modified: libcloud/trunk/CHANGES
URL:
http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1337758&r1=1337757&r2=1337758&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Sun May 13 03:07:41 2012
@@ -72,6 +72,11 @@ Changes with Apache Libcloud in developm
if the password auth is used.
[Juan Carlos Moreno]
+ - Add FileDeployment class to libcloud.compute.deployment module. This can
+ be used as a replacemtnt for ex_files argument if the provider supports
+ deployment functionality.
+ [Jay Doane]
+
*) Storage
- Large object upload support for CloudFiles driver
Modified: libcloud/trunk/libcloud/compute/deployment.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/deployment.py?rev=1337758&r1=1337757&r2=1337758&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/deployment.py (original)
+++ libcloud/trunk/libcloud/compute/deployment.py Sun May 13 03:07:41 2012
@@ -77,6 +77,38 @@ class SSHKeyDeployment(Deployment):
return node
+class FileDeployment(Deployment):
+ """
+ Installs a file.
+ """
+
+ def __init__(self, source, target):
+ """
+ @type source: C{str}
+ @keyword source: Local path of file to be installed
+
+ @type target: C{str}
+ @keyword target: Path to install file on node
+ """
+ self.source = source
+ self.target = target
+
+ def run(self, node, client):
+ """
+ Upload the file, retaining permissions
+
+ See also L{Deployment.run}
+ """
+ perms = int(oct(os.stat(self.source).st_mode)[4:], 8)
+
+ with open(self.source, 'rb') as fp:
+ content = fp.read()
+
+ client.put(path=self.target, chmod=perms,
+ contents=content)
+ return node
+
+
class ScriptDeployment(Deployment):
"""
Runs an arbitrary Shell Script task.
Modified: libcloud/trunk/test/compute/test_deployment.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_deployment.py?rev=1337758&r1=1337757&r2=1337758&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_deployment.py (original)
+++ libcloud/trunk/test/compute/test_deployment.py Sun May 13 03:07:41 2012
@@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import os
import sys
import time
import unittest
@@ -23,6 +24,7 @@ from libcloud.utils.py3 import u
from libcloud.compute.deployment import MultiStepDeployment, Deployment
from libcloud.compute.deployment import SSHKeyDeployment, ScriptDeployment
+from libcloud.compute.deployment import FileDeployment
from libcloud.compute.base import Node
from libcloud.compute.types import NodeState, DeploymentError, LibcloudError
from libcloud.compute.ssh import BaseSSHClient
@@ -84,6 +86,15 @@ class DeploymentTests(unittest.TestCase)
self.assertEqual(self.node, sshd.run(node=self.node,
client=MockClient(hostname='localhost')))
+ def test_file_deployment(self):
+ # use this file (__file__) for obtaining permissions
+ target = os.path.join('/tmp', os.path.basename(__file__))
+ fd = FileDeployment(__file__, target)
+ self.assertEqual(target, fd.target)
+ self.assertEqual(__file__, fd.source)
+ self.assertEqual(self.node, fd.run(
+ node=self.node, client=MockClient(hostname='localhost')))
+
def test_script_deployment(self):
sd1 = ScriptDeployment(script='foobar', delete=True)
sd2 = ScriptDeployment(script='foobar', delete=False)