【发布时间】:2016-09-17 21:03:09
【问题描述】:
我开始使用 jclouds 来操作 EC2 实例。因此,我有以下方法:
private ComputeService compute;
public void add(Integer instances) {
try {
logger.info("------------------------------------------------------");
logger.info(String.format(">> adding node to group %s%n", this.groupname));
// Default template chooses the smallest size on an operating system
// that tested to work with java, which tends to be Ubuntu or CentOS
TemplateBuilder templateBuilder = this.compute.templateBuilder();
// note this will create a user with the same name as you on the
// node. ex. you can connect via ssh publicip
Statement bootInstructions = AdminAccess.standard();
// to run commands as root, we use the runScript option in the template.
templateBuilder.options(runScript(bootInstructions));
Template template = templateBuilder.build();
// add a custom security group
NodeMetadata node = getOnlyElement(this.compute.createNodesInGroup(this.groupname, instances, template));
logger.info(String.format("<< node %s: %s%n", node.getId(),
concat(node.getPrivateAddresses(), node.getPublicAddresses())));
logger.info("------------------------------------------------------");
} catch (Exception e) {
logger.error(e.getMessage());
logger.info("------------------------------------------------------");
}
}
请假设验证是正确的并且
groupname = default。当我执行
this.compute.add(1);
即使创建了一个实例,jclouds 也会每次都创建一个新的security group 和key pair。我确实有我现有的foo.pem 文件和default 安全组。例如:
security group = jclouds#default。如何利用现有的安全组和密钥值?
【问题讨论】:
标签: java amazon-web-services amazon-ec2 jclouds