Ich fange an, jclouds zu verwenden, um EC2-Instanzen zu manipulieren. Daher habe ich die folgende Methode:Verwenden der vorhandenen SecurityGroup- und PEM-Datei in jclouds - Java
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("------------------------------------------------------");
}
}
Gehen Sie davon aus, dass die Authentifizierung korrekt ist und groupname = default
. Als ich
this.compute.add(1);
Auch wenn eine einzelne Instanz erstellt wird, wird ein neues jclouds
security group
und key pair
jedes Mal erstellen. Ich habe meine bestehende foo.pem
Datei und die default
Sicherheitsgruppe. Zum Beispiel: security group = jclouds#default
. Wie kann ich meine vorhandene Sicherheitsgruppe und den Schlüsselwert nutzen?