use of org.jclouds.ec2.EC2AsyncClient in project legacy-jclouds-examples by jclouds.
the class MainApp method main.
public static void main(String[] args) throws TimeoutException {
if (args.length < PARAMETERS)
throw new IllegalArgumentException(INVALID_SYNTAX);
// Args
String accesskeyid = args[0];
String secretkey = args[1];
String command = args[2];
String name = args[3];
// Init
RestContext<EC2Client, EC2AsyncClient> context = ContextBuilder.newBuilder("aws-ec2").credentials(accesskeyid, secretkey).build();
// Get a synchronous client
EC2Client client = context.getApi();
try {
if (command.equals("create")) {
KeyPair pair = createKeyPair(client, name);
RunningInstance instance = createSecurityGroupKeyPairAndInstance(client, name);
System.out.printf("instance %s ready%n", instance.getId());
System.out.printf("ip address: %s%n", instance.getIpAddress());
System.out.printf("dns name: %s%n", instance.getDnsName());
System.out.printf("login identity:%n%s%n", pair.getKeyMaterial());
} else if (command.equals("destroy")) {
destroySecurityGroupKeyPairAndInstance(client, name);
} else {
throw new IllegalArgumentException(INVALID_SYNTAX);
}
} finally {
// Close connecton
context.close();
System.exit(0);
}
}
Aggregations