Java 类com.amazonaws.services.ec2.model.Region 实例源码

项目:ec2-spot-jenkins-plugin    文件:EC2FleetCloud.java   
public ListBoxModel doFillRegionItems(@QueryParameter final String credentialsId,
                                      @QueryParameter final String region)
        throws IOException, ServletException {
    final List<Region> regionList;

    try {
        final AmazonEC2 client = connect(credentialsId, null);
        final DescribeRegionsResult regions=client.describeRegions();
        regionList=regions.getRegions();
    } catch(final Exception ex) {
        //Ignore bad exceptions
        return new ListBoxModel();
    }

    final ListBoxModel model = new ListBoxModel();
    for(final Region reg : regionList) {
        model.add(new ListBoxModel.Option(reg.getRegionName(), reg.getRegionName()));
    }
    return model;
}
项目:director-aws-plugin    文件:AmazonEC2ClientProvider.java   
private static String getEndpointForRegion(AmazonEC2Client client, String regionName) {
  requireNonNull(client, "client is null");
  requireNonNull(regionName, "regionName is null");

  LOG.info(">> Describing all regions to find endpoint for '{}'", regionName);

  DescribeRegionsResult result = client.describeRegions();
  List<String> regions = Lists.newArrayListWithExpectedSize(result.getRegions().size());

  for (Region candidate : result.getRegions()) {
    regions.add(candidate.getRegionName());

    if (candidate.getRegionName().equals(regionName)) {
      LOG.info("<< Found endpoint '{}' for region '{}'", candidate.getEndpoint(), regionName);

      return candidate.getEndpoint();
    }
  }

  throw new IllegalArgumentException(String.format("Unable to find an endpoint for region '%s'. "
      + "Choose one of the following regions: %s", regionName, Joiner.on(", ").join(regions)));
}
项目:ec2-plugin    文件:AmazonEC2Cloud.java   
public ListBoxModel doFillRegionItems(@QueryParameter boolean useInstanceProfileForCredentials,
        @QueryParameter String accessId, @QueryParameter String secretKey,
        @QueryParameter String region) throws IOException, ServletException {
    ListBoxModel model = new ListBoxModel();
    if (testMode) {
        model.add(DEFAULT_EC2_HOST);
        return model;
    }

    if (useInstanceProfileForCredentials || (!StringUtils.isEmpty(accessId) && !StringUtils.isEmpty(secretKey))) {
        AWSCredentialsProvider credentialsProvider = createCredentialsProvider(useInstanceProfileForCredentials, accessId, secretKey);
        AmazonEC2 client = connect(credentialsProvider, new URL("http://ec2.amazonaws.com"));
        DescribeRegionsResult regions = client.describeRegions();
        List<Region> regionList = regions.getRegions();
        for (Region r : regionList) {
            String name = r.getRegionName();
            model.add(name, name);
        }
    }
    return model;
}
项目:photon-model    文件:AWSReservedInstancePlanService.java   
public AWSReservedInstanceAsyncHandler(ServiceHost host, AtomicInteger count, Region region,
        AWSReservedInstanceContext context) {
    this.count = count;
    this.region = region;
    this.host = host;
    this.context = context;
}
项目:aws-doc-sdk-examples    文件:DescribeRegionsAndZones.java   
public static void main(String[] args)
{
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DescribeRegionsResult regions_response = ec2.describeRegions();

    for(Region region : regions_response.getRegions()) {
        System.out.printf(
            "Found region %s " +
            "with endpoint %s",
            region.getRegionName(),
            region.getEndpoint());
    }

    DescribeAvailabilityZonesResult zones_response =
        ec2.describeAvailabilityZones();

    for(AvailabilityZone zone : zones_response.getAvailabilityZones()) {
        System.out.printf(
            "Found availability zone %s " +
            "with status %s " +
            "in region %s",
            zone.getZoneName(),
            zone.getState(),
            zone.getRegionName());
    }
}
项目:primecloud-controller    文件:RegionConverter.java   
@Override
protected Region convertObject(RegionInfo from) {
    Region to = new Region();

    to.setRegionName(from.getName());
    to.setEndpoint(from.getUrl());

    return to;
}
项目:chassis    文件:ServerInstanceContext.java   
private String findRegion() {
    for (Region region : amazonEC2.describeRegions().getRegions()) {
        if (this.availabilityZone.startsWith(region.getRegionName())) {
            return region.getRegionName();
        }
    }
    throw new BootstrapException("Unable to determine region");
}
项目:chassis    文件:ServerInstanceContextTest.java   
private static com.amazonaws.regions.Region eqRegion(final com.amazonaws.regions.Region region) {
    EasyMock.reportMatcher(new IArgumentMatcher() {
        @Override
        public boolean matches(Object o) {
            com.amazonaws.regions.Region givenRegion = (com.amazonaws.regions.Region) o;
            return givenRegion.getName().equals(region.getName());
        }

        @Override
        public void appendTo(StringBuffer stringBuffer) {
            stringBuffer.append("eqReqion for ").append(region.getName());
        }
    });
    return region;
}
项目:vpc2vpc    文件:EC2Helper.java   
public HashMap<Region, List> listRegionInstances(AWSCredentials awsCreds) {

    AmazonEC2Client ec2Client = new AmazonEC2Client(awsCreds);
    List<Region> regions = new ArrayList();

    DescribeRegionsResult descRegionsResult = ec2Client.describeRegions();
    if (descRegionsResult != null) {
      regions = descRegionsResult.getRegions();
    }

    HashMap<Region, List> regionInstances = new HashMap();

    ExecutorService listInstanceExecutor = Executors.newFixedThreadPool(8);
    for (Region region : regions) {
      List<Instance> instances = new ArrayList();
      regionInstances.put(region, instances);

      Runnable worker = new ListInstanceRunnable(awsCreds, region, instances);
      listInstanceExecutor.execute(worker);
    }

    listInstanceExecutor.shutdown();
    try {
      listInstanceExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
    } catch (InterruptedException e) {
      LOG.error("Caught InterruptedException: " + e.getMessage());
    }

    return regionInstances;
  }
项目:vpc2vpc    文件:EC2Helper.java   
public ListInstanceRunnable(AWSCredentials awsCreds, Region region, List<Instance> instances) {
  this.region = region;
  this.instances = instances;
  ec2Client = new AmazonEC2Client(awsCreds);
  ec2Client.setEndpoint(region.getEndpoint());
  LOG.debug("Set endpoint to " + region.getEndpoint());
}
项目:vpc2vpc    文件:VPCHelper.java   
public List<Vpc> listVpcs(AWSCredentials awsCreds) {
  List<Vpc> vpcs = new ArrayList();

  HashMap<Region, List> regionVpcMap = listRegionVpcs(awsCreds);
  for (List<Vpc> regionVpcs : regionVpcMap.values()) {
    vpcs.addAll(regionVpcs);
  }

  return vpcs;
}
项目:vpc2vpc    文件:VPCHelper.java   
public HashMap<Region, List> listRegionVpcs(AWSCredentials awsCreds) {

    AmazonEC2Client ec2Client = new AmazonEC2Client(awsCreds);
    List<Region> regions = new ArrayList();

    DescribeRegionsResult descRegionsResult = ec2Client.describeRegions();
    if (descRegionsResult != null) {
      regions = descRegionsResult.getRegions();
    }

    HashMap<Region, List> regionVpcs = new HashMap();

    ExecutorService listVPCExecutor = Executors.newFixedThreadPool(8);
    for (Region region : regions) {
      List<Vpc> vpcs = new ArrayList();
      regionVpcs.put(region, vpcs);

      Runnable worker = new ListVPCRunnable(awsCreds, region, vpcs);
      listVPCExecutor.execute(worker);
    }

    listVPCExecutor.shutdown();
    try {
      listVPCExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
    } catch (InterruptedException e) {
      LOG.error("Caught InterruptedException: " + e.getMessage());
    }

    return regionVpcs;
  }
项目:vpc2vpc    文件:VPCHelper.java   
public List<Subnet> listSubnets(AWSCredentials awsCreds) {
  List<Subnet> subnets = new ArrayList();

  HashMap<Region, List> regionSubnetMap = listRegionSubnets(awsCreds);
  for (List<Subnet> regionSubnets : regionSubnetMap.values()) {
    subnets.addAll(regionSubnets);
  }

  return subnets;
}
项目:vpc2vpc    文件:VPCHelper.java   
public HashMap<Region, List> listRegionSubnets(AWSCredentials awsCreds) {
  AmazonEC2Client ec2Client = new AmazonEC2Client(awsCreds);
  List<Region> regions = new ArrayList();

  DescribeRegionsResult descRegionsResult = ec2Client.describeRegions();
  if (descRegionsResult != null) {
    regions = descRegionsResult.getRegions();
  }

  HashMap<Region, List> regionSubnetsMap = new HashMap();

  ExecutorService listSubnetExecutor = Executors.newFixedThreadPool(8);
  for (Region region : regions) {
    List<Subnet> subnets = new ArrayList();
    regionSubnetsMap.put(region, subnets);

    Runnable worker = new ListSubnetRunnable(awsCreds, region, subnets);
    listSubnetExecutor.execute(worker);
  }

  listSubnetExecutor.shutdown();
  try {
    listSubnetExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
  } catch (InterruptedException e) {
    LOG.error("Caught InterruptedException: " + e.getMessage());
  }

  return regionSubnetsMap;
}
项目:vpc2vpc    文件:VPCHelper.java   
public HashMap<Region, List> listRegionRouteTables(AWSCredentials awsCreds) {
  AmazonEC2Client ec2Client = new AmazonEC2Client(awsCreds);
  List<Region> regions = new ArrayList();

  DescribeRegionsResult descRegionsResult = ec2Client.describeRegions();
  if (descRegionsResult != null) {
    regions = descRegionsResult.getRegions();
  }

  HashMap<Region, List> regionRouteTablesMap = new HashMap();

  ExecutorService listRouteTablesExecutor = Executors.newFixedThreadPool(8);
  for (Region region : regions) {
    List<RouteTable> routeTables = new ArrayList();
    regionRouteTablesMap.put(region, routeTables);

    Runnable worker = new ListRouteTableRunnable(awsCreds, region, routeTables);
    listRouteTablesExecutor.execute(worker);
  }

  listRouteTablesExecutor.shutdown();
  try {
    listRouteTablesExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
  } catch (InterruptedException e) {
    LOG.error("Caught InterruptedException: " + e.getMessage());
  }

  return regionRouteTablesMap;
}
项目:vpc2vpc    文件:VPCHelper.java   
public ListVPCRunnable(AWSCredentials awsCreds, Region region, List<Vpc> vpcs) {
  this.region = region;
  this.vpcs = vpcs;
  ec2Client = new AmazonEC2Client(awsCreds);
  ec2Client.setEndpoint(region.getEndpoint());
  LOG.debug("Set endpoint to " + region.getEndpoint());
}
项目:vpc2vpc    文件:VPCHelper.java   
public ListSubnetRunnable(AWSCredentials awsCreds, Region region, List<Subnet> subnets) {
  this.region = region;
  this.subnets = subnets;
  ec2Client = new AmazonEC2Client(awsCreds);
  ec2Client.setEndpoint(region.getEndpoint());
  LOG.debug("Set endpoint to " + region.getEndpoint());
}
项目:vpc2vpc    文件:VPCHelper.java   
public ListRouteTableRunnable(AWSCredentials awsCreds, Region region, List<RouteTable> routeTables) {
  this.region = region;
  this.routeTables = routeTables;
  ec2Client = new AmazonEC2Client(awsCreds);
  ec2Client.setEndpoint(region.getEndpoint());
  LOG.debug("Set endpoint to " + region.getEndpoint());
}
项目:chassis    文件:ServerInstanceContext.java   
private void initAmazonClients() {
    amazonEC2.setRegion(com.amazonaws.regions.Region.getRegion(Regions.fromName(this.region)));
    amazonElasticLoadBalancing.setRegion(com.amazonaws.regions.Region.getRegion(Regions.fromName(this.region)));
}
项目:billow    文件:AWSDatabaseHolder.java   
public AWSDatabaseHolder(Config config) {
    maxAgeInMs = config.getDuration("maxAge", TimeUnit.MILLISECONDS);

    final DefaultAWSCredentialsProviderChain awsCredentialsProviderChain = new DefaultAWSCredentialsProviderChain();

    final ClientConfiguration clientConfig = new ClientConfiguration();
    clientConfig.setRetryPolicy(new RetryPolicy(null, null, config.getInt("maxErrorRetry"), true));

    final AmazonEC2Client bootstrapEC2Client = new AmazonEC2Client(awsCredentialsProviderChain);
    ec2Clients = Maps.newHashMap();
    rdsClients = Maps.newHashMap();
    sqsClients = Maps.newHashMap();
    dynamoDBClients = Maps.newHashMap();
    elasticacheClients = Maps.newHashMap();

    final List<Region> ec2Regions = bootstrapEC2Client.describeRegions().getRegions();
    for (Region region : ec2Regions) {
        final String regionName = region.getRegionName();
        final String endpoint = region.getEndpoint();
        log.debug("Adding ec2 region {}", region);

        final AmazonEC2Client ec2Client = new AmazonEC2Client(awsCredentialsProviderChain, clientConfig);
        ec2Client.setEndpoint(endpoint);
        ec2Clients.put(regionName, ec2Client);

        final AmazonRDSClient rdsClient = new AmazonRDSClient(awsCredentialsProviderChain, clientConfig);
        rdsClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "rds."));
        rdsClients.put(regionName, rdsClient);

        final AmazonDynamoDBClient dynamoDBClient =
            new AmazonDynamoDBClient(awsCredentialsProviderChain, clientConfig);
        dynamoDBClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "dynamodb."));
        dynamoDBClients.put(regionName, dynamoDBClient);

        final AmazonSQSClient sqsClient = new AmazonSQSClient(awsCredentialsProviderChain, clientConfig);
        sqsClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "sqs."));
        sqsClients.put(regionName, sqsClient);

        final AmazonElastiCacheClient elastiCacheClient = new AmazonElastiCacheClient
            (awsCredentialsProviderChain, clientConfig);
        elastiCacheClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "elasticache."));
        elasticacheClients.put(regionName, elastiCacheClient);
    }

    this.iamClient = new AmazonIdentityManagementClient(awsCredentialsProviderChain, clientConfig);

    if (config.hasPath("accountNumber")) {
        this.awsAccountNumber = config.getString("accountNumber");
    } else {
        this.awsAccountNumber = null;
    }

    rebuild();
}
项目:vpc2vpc    文件:VPNEndpoint.java   
public Region getRegion() {
  return region;
}
项目:vpc2vpc    文件:VPNEndpoint.java   
public void setRegion(Region region) {
  this.region = region;
}
项目:vpc2vpc    文件:CreateConnection.java   
private void launchInstances(List<VPNEndpoint> vpnEndpoints) throws Exception {

    ApplicationConfig appConfig = ApplicationConfig.getInstance();

    for (VPNEndpoint vpnEndpoint : vpnEndpoints) {
      Region region = vpnEndpoint.getRegion();
      ec2Client.setEndpoint(region.getEndpoint());

      // Get the AMI for the region
      String amiKey = "ami." + region.getRegionName();
      String amiId = appConfig.get(amiKey);
      if (amiId == null) {
        String msg = "Unable to find AMI in " + region.getRegionName();
        LOG.error(msg);
        throw new RuntimeException(msg);
      }

      // Get the security group for the instance
      String securityGroupId = vpnEndpoint.getSecurityGroupId();
      List<String> securityGroupIds = new ArrayList();
      securityGroupIds.add(securityGroupId);

      // Setup the instance request object
      LOG.debug("Setting up RunInstancesRequest for instance in " + vpnEndpoint.getVpc().getCidrBlock() + " - " + region.getEndpoint());
      RunInstancesRequest runInstancesRequest = new RunInstancesRequest();
      runInstancesRequest.setMinCount(1);
      runInstancesRequest.setMaxCount(1);
      runInstancesRequest.setImageId(amiId);
      runInstancesRequest.setSecurityGroupIds(securityGroupIds);
      runInstancesRequest.setInstanceType(InstanceType.T1Micro); // TODO: Make this configurable
      runInstancesRequest.setSubnetId(vpnEndpoint.getSubnet().getSubnetId());
      runInstancesRequest.setUserData(generateCloudInitScript(vpnEndpoint, vpnEndpoints));
      //runInstancesRequest.setKeyName("amazon"); // TODO: Remove this or make this configurable

      // Launch the instance
      LOG.debug("Issuing runInstances with: " + runInstancesRequest);
      RunInstancesResult result = ec2Client.runInstances(runInstancesRequest);
      Reservation reservation = result.getReservation();
      Instance instance = reservation.getInstances().get(0);  // Should be just one
      vpnEndpoint.setInstance(instance);
      LOG.debug("Launched instance: " + instance);
    }
  }