Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ComputeServiceContext computeContext = new ComputeServiceContextFactory().createContext(
- config.getProvider(),
- config.getAccount(),
- config.getKey(),
- ImmutableSet.of(
- new Log4JLoggingModule(),
- new JschSshClientModule()));
- ComputeService computeService = computeContext.getComputeService();
- Map<? extends NodeMetadata, ExecResponse> responses = computeService.runScriptOnNodesMatching(
- NodePredicates.withTag(config.getTag()),
- Payloads.newStringPayload(createScript()),
- RunScriptOptions.Builder.runAsRoot(true));
- for(Map.Entry<? extends NodeMetadata, ExecResponse> response : responses.entrySet())
- {
- System.out.println(response.getKey().getId() + " " + response.getKey().getName() + " " + response.getKey().getTag());
- System.out.println(response.getValue().getExitCode());
- System.out.println(response.getValue().getError());
- System.out.println(response.getValue().getOutput());
- }
- }
- private String createScript()
- {
- return Statements.newStatementList(
- Statements.createFile(
- "root.was.here",
- ImmutableList.of(
- "root.was.here"
- )),
- Statements.exec("apt get foo"),
- Statements.exec("apt install foo")
- ).render(OsFamily.UNIX);
- }
- '
- /**
- * build a shell script that invokes the contents of the http request in bash.
- *
- * @return a shell script that will invoke the http request
- */
- public static String buildCurluntar(String destination, HttpRequest request) {
- String headers = Joiner.on(' ').join(
- Iterables.transform(request.getHeaders().entries(), new Function<Entry<String, String>, String>() {
- @Override
- public String apply(Entry<String, String> from) {
- return String.format("-H \"%s: %s\"", from.getKey(), from.getValue());
- }
- }));
- return String.format("mkdir -p "+ destination+ ";cd "+ destination+ ";curl -s --retry 20 %s %s |tar -xzf -\n", headers, request.getEndpoint().toASCIIString());
- }
Add Comment
Please, Sign In to add comment