Search in sources :

Example 1 with EC2Client

use of org.jclouds.aws.ec2.EC2Client in project whirr by apache.

the class FirewallSettings method authorizeIngress.

private static void authorizeIngress(ComputeServiceContext computeServiceContext, Set<? extends NodeMetadata> nodes, ClusterSpec clusterSpec, List<String> cidrs, int... ports) {
    if (clusterSpec.getProvider().equals("ec2")) {
        // This code (or something like it) may be added to jclouds (see
        // http://code.google.com/p/jclouds/issues/detail?id=336).
        // Until then we need this temporary workaround.
        String region = EC2Utils.parseHandle(Iterables.get(nodes, 0).getId())[0];
        EC2Client ec2Client = EC2Client.class.cast(computeServiceContext.getProviderSpecificContext().getApi());
        String groupName = "jclouds#" + clusterSpec.getClusterName();
        for (String cidr : cidrs) {
            for (int port : ports) {
                ec2Client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(region, groupName, IpProtocol.TCP, port, port, cidr);
            }
        }
    }
}
Also used : EC2Client(org.jclouds.aws.ec2.EC2Client)

Example 2 with EC2Client

use of org.jclouds.aws.ec2.EC2Client 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);
    }
}
Also used : KeyPair(org.jclouds.ec2.domain.KeyPair) RunningInstance(org.jclouds.ec2.domain.RunningInstance) EC2AsyncClient(org.jclouds.ec2.EC2AsyncClient) EC2Client(org.jclouds.ec2.EC2Client)

Aggregations

EC2Client (org.jclouds.aws.ec2.EC2Client)1 EC2AsyncClient (org.jclouds.ec2.EC2AsyncClient)1 EC2Client (org.jclouds.ec2.EC2Client)1 KeyPair (org.jclouds.ec2.domain.KeyPair)1 RunningInstance (org.jclouds.ec2.domain.RunningInstance)1