Java Code Examples for com.amazonaws.services.ec2.AmazonEC2#describeVolumes()

The following examples show how to use com.amazonaws.services.ec2.AmazonEC2#describeVolumes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InventoryUtil.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
 * Fetch volumet info.
 *
 * @param temporaryCredentials the temporary credentials
 * @param skipRegions the skip regions
 * @param accountId the accountId
 * @param accountName the account name
 * @return the map
 */
public static Map<String,List<Volume>> fetchVolumetInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) {
	Map<String,List<Volume>> volumeList = new LinkedHashMap<>();
	AmazonEC2 ec2Client ;
	String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Volume\" , \"region\":\"" ;
	for(Region region : RegionUtils.getRegions()){
		try{
			if(!skipRegions.contains(region.getName())){
				ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
				DescribeVolumesResult  rslt = ec2Client.describeVolumes(); // No need to paginate as all volumes will be returned.
				List<Volume> volumeListTemp = rslt.getVolumes();

				if( !volumeListTemp.isEmpty() ) {
					log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Volume "+region.getName() + " >> "+volumeListTemp.size());
					volumeList.put(accountId+delimiter+accountName+delimiter+region.getName(),volumeListTemp);
				}
			}

		}catch(Exception e){
			log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}");
			ErrorManageUtil.uploadError(accountId,region.getName(),"volume",e.getMessage());
		}
	}
	return volumeList;
}
 
Example 2
Source File: Ec2Utils.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Collect all volumes.
 *
 * @param ec2ServiceClient the ec 2 service client
 * @param region the region
 * @return the list
 */
public static List<Volume> collectAllVolumes(AmazonEC2 ec2ServiceClient,Region region){
	DescribeVolumesRequest request = new DescribeVolumesRequest();
	DescribeVolumesResult result;
	String nextToken;
	List<Volume> volumes=new ArrayList<Volume>();
	do{
		result = ec2ServiceClient.describeVolumes(request);
		volumes.addAll(result.getVolumes());
		nextToken = result.getNextToken();
	    request.setNextToken(nextToken);
	}while(null!=nextToken);
	return volumes;
}
 
Example 3
Source File: PacmanEc2Utils.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param ec2ServiceClient
 * @param request
 * @return
 */
public static List<Volume> collectAllVolumes(AmazonEC2 ec2ServiceClient,
        DescribeVolumesRequest request) {
    DescribeVolumesResult result;
    String nextToken;
    List<Volume> volumes = new ArrayList<>();
    do {
        result = ec2ServiceClient.describeVolumes(request);
        volumes.addAll(result.getVolumes());
        nextToken = result.getNextToken();
        request.setNextToken(nextToken);
    } while (null != nextToken);
    return volumes;
}