-
-
Save kiuby88/6052da2ad1bd9499661e09ca44111e06 to your computer and use it in GitHub Desktop.
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
String accesskeyid = ... | |
String secretkey = ... | |
String provider = ... //e.g., "aws-ec2" | |
ComputeServiceContext context = ContextBuilder.newBuilder("aws-ec2") | |
.credentials(accesskeyid, secretkey) | |
.buildView(ComputeServiceContext.class); | |
Optional<SecurityGroupExtension> optional = context.getComputeService().getSecurityGroupExtension(); | |
if(optional.isPresent()) { | |
SecurityGroupExtension securityGroupExtension = optional.get(); | |
String nodeId= ... //e.g. "eu-west-1/i-ecf0037a" | |
ComputeMetadata node = context.getComputeService().getNodeMetadata(nodeId); | |
Set<SecurityGroup> sgForNode = securityGroupExtension | |
.listSecurityGroupsForNode(node.getId()); | |
//delete Node and wait | |
destroyNodeAndWait(nodeId); | |
for (SecurityGroup group : sgForNode) { | |
//delete security groups (it would be necessary to check if another node is using it currenlty) | |
securityGroupExtension.removeSecurityGroup(group.getId()); | |
} | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment