Skip to content

Instantly share code, notes, and snippets.

@tk421
Created February 17, 2015 22:23
Show Gist options
  • Save tk421/7c0f33294d329dd12ce2 to your computer and use it in GitHub Desktop.
Save tk421/7c0f33294d329dd12ce2 to your computer and use it in GitHub Desktop.
JClouds destroying gce
final String POLL_PERIOD_TWENTY_SECONDS = String.valueOf(SECONDS.toMillis(20));
Properties overrides = new Properties();
overrides.setProperty(ComputeServiceProperties.POLL_INITIAL_PERIOD, POLL_PERIOD_TWENTY_SECONDS);
overrides.setProperty(ComputeServiceProperties.POLL_MAX_PERIOD, POLL_PERIOD_TWENTY_SECONDS);
Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule(), new SLF4JLoggingModule());
ComputeServiceContext context = ContextBuilder.newBuilder("google-compute-engine")
.credentials("valid user", "valid password")
.modules(modules)
.overrides(overrides)
.buildView(ComputeServiceContext.class);
ComputeService computeService = context.getComputeService();
// version 1
computeService.destroyNode("nodeid"); // nodeid is nodeMetadata.getId()
// version 2
Set<? extends NodeMetadata> servers = computeService.destroyNodesMatching(inGroup("servername"));
for (NodeMetadata server : servers) {
log.info("Deleted %s%n", server);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment