Simple runscript example with jclouds and clojure (or even just jclouds)

154 views Asked by At

I have this clojure code

(let [group-name "my-test-group"
      compute (compute-service provider user password)
      node (create-node compute group-name)
      node-id (.getId node)]
  (.runScriptOnNode compute node-id ??)
  (destroy-node compute node-id))

and I would like to run ls on my instance just as an example. What do I put in the ?? to make that work?

Reading the Jclouds docs it says I'm supposed to put a Statement object there but I do not know how to create a statement object for the ls command in Clojure or Java. I'd accept an example in Clojure or Java (as I can easily translate between the two).

1

There are 1 answers

0
Ignasi Barrera On BEST ANSWER

The runScriptOnNode has several forms. As defined in the ComputeService interface, the script can be provided as a Statement object or as a simple String.

If you want to use the Statement then you can build it by using the helper methods in the Statements class (something like: Statements.exec("ls")), but it is up to you to use the Statement or the String form.

And here are the examples using the two methods (with String and with Statement) assuming the example code from the OP surrounds this code:

(.runScriptOnNode compute node-id "ls")
(.runScriptOnNode compute node-id (Statements/exec "ls"))