Author: tomaz
Date: Fri Mar 29 17:01:47 2013
New Revision: 1462534
URL: http://svn.apache.org/r1462534
Log:
Add new ScriptFileDeployment deployment class which reads deploy script
from a file.
Contributed by Rudolf J Streif, part of LIBCLOUD-311.
Modified:
libcloud/trunk/CHANGES
libcloud/trunk/libcloud/compute/deployment.py
libcloud/trunk/libcloud/test/compute/test_deployment.py
Modified: libcloud/trunk/CHANGES
URL:
http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1462534&r1=1462533&r2=1462534&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Fri Mar 29 17:01:47 2013
@@ -17,6 +17,10 @@ Changes with Apache Libcloud in developm
the right value.
[Tomaz Muraus]
+ - Add new ScriptFileDeployment deployment class which reads deploy script
+ from a file.
+ [Rudolf J Streif]
+
Changes with Apache Libcloud 0.12.3:
*) General
Modified: libcloud/trunk/libcloud/compute/deployment.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/deployment.py?rev=1462534&r1=1462533&r2=1462534&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/deployment.py (original)
+++ libcloud/trunk/libcloud/compute/deployment.py Fri Mar 29 17:01:47 2013
@@ -123,7 +123,8 @@ class ScriptDeployment(Deployment):
@keyword script: Contents of the script to run
@type name: C{str}
- @keyword name: Name of the script to upload it as, if not specified, a
random name will be choosen.
+ @keyword name: Name of the script to upload it as, if not specified,
+ a random name will be choosen.
@type delete: C{bool}
@keyword delete: Whether to delete the script on completion.
@@ -167,6 +168,31 @@ class ScriptDeployment(Deployment):
return node
+class ScriptFileDeployment(ScriptDeployment):
+ """
+ Runs an arbitrary Shell Script task from a file.
+ """
+
+ def __init__(self, script_file, name=None, delete=False):
+ """
+ @type script_file: C{str}
+ @keyword script_file: Path to a file containing the script to run
+
+ @type name: C{str}
+ @keyword name: Name of the script to upload it as, if not specified,
+ a random name will be choosen.
+
+ @type delete: C{bool}
+ @keyword delete: Whether to delete the script on completion.
+ """
+ with open(script_file, 'rb') as fp:
+ content = fp.read()
+
+ super(ScriptFileDeployment, self).__init__(script=content,
+ name=name,
+ delete=delete)
+
+
class MultiStepDeployment(Deployment):
"""
Runs a chain of Deployment steps.
Modified: libcloud/trunk/libcloud/test/compute/test_deployment.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/test_deployment.py?rev=1462534&r1=1462533&r2=1462534&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_deployment.py (original)
+++ libcloud/trunk/libcloud/test/compute/test_deployment.py Fri Mar 29 17:01:47
2013
@@ -24,7 +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.deployment import ScriptFileDeployment, FileDeployment
from libcloud.compute.base import Node
from libcloud.compute.types import NodeState, DeploymentError, LibcloudError
from libcloud.compute.ssh import BaseSSHClient
@@ -111,6 +111,14 @@ class DeploymentTests(unittest.TestCase)
self.assertEqual(self.node, sd2.run(node=self.node,
client=MockClient(hostname='localhost')))
+ def test_script_file_deployment(self):
+ file_path = os.path.abspath(__file__)
+ with open(file_path, 'rb') as fp:
+ content = fp.read()
+
+ sfd1 = ScriptFileDeployment(script_file=file_path)
+ self.assertEqual(sfd1.script, content)
+
def test_script_deployment_relative_path(self):
client = Mock()
client.put.return_value = '/home/ubuntu/relative.sh'