Created
February 17, 2015 22:23
-
-
Save tk421/7c0f33294d329dd12ce2 to your computer and use it in GitHub Desktop.
JClouds destroying gce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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