本文整理汇总了Java中com.amazonaws.services.ec2.model.DescribeVolumesResult.getVolumes方法的典型用法代码示例。如果您正苦于以下问题:Java DescribeVolumesResult.getVolumes方法的具体用法?Java DescribeVolumesResult.getVolumes怎么用?Java DescribeVolumesResult.getVolumes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.model.DescribeVolumesResult
的用法示例。
在下文中一共展示了DescribeVolumesResult.getVolumes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVolumes
import com.amazonaws.services.ec2.model.DescribeVolumesResult; //导入方法依赖的package包/类
/**
* Describe All Volume.
*
* @return Collection Volume
*/
protected final List<Volume> getVolumes() {
List<Volume> volumes = null;
DescribeVolumesRequest req = new DescribeVolumesRequest();
req.setMaxResults(20);
DescribeVolumesResult result = amazonEC2Client.describeVolumes(req);
if (result != null && !result.getVolumes().isEmpty()) {
volumes = result.getVolumes();
log.info("Page Size : " + volumes.size());
}
while(result.getNextToken() != null) {
req.setNextToken(result.getNextToken());
result = amazonEC2Client.describeVolumes(req);
if (result != null && !result.getVolumes().isEmpty()) {
volumes = result.getVolumes();
log.info("Page Size : " + volumes.size());
}
}
return volumes;
}
示例2: getAwsDisksByIds
import com.amazonaws.services.ec2.model.DescribeVolumesResult; //导入方法依赖的package包/类
/**
* Method to get Disk details directly from Amazon
*/
public static List<Volume> getAwsDisksByIds(AmazonEC2AsyncClient client,
VerificationHost host, List<String> diskIds) throws Throwable {
try {
host.log("Getting disks with ids " + diskIds
+ " from the AWS endpoint using the EC2 client.");
DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest()
.withVolumeIds(diskIds);
DescribeVolumesResult describeVolumesResult = client
.describeVolumes(describeVolumesRequest);
return describeVolumesResult.getVolumes();
} catch (Exception e) {
if (e instanceof AmazonEC2Exception
&& ((AmazonEC2Exception) e).getErrorCode()
.equalsIgnoreCase(AWS_INVALID_VOLUME_ID_ERROR_CODE)) {
return null;
}
}
return new ArrayList<>();
}
示例3: getAllEBSVolumes
import com.amazonaws.services.ec2.model.DescribeVolumesResult; //导入方法依赖的package包/类
/**
* This method returns all the volumes.
* @return returns list of EBS volumes.
*/
public List<Volume> getAllEBSVolumes() throws AmazonClientException {
List<Volume> allEBSVolumes;
try {
DescribeVolumesResult describeVolumesResult = this.amazonEc2.describeVolumes();
allEBSVolumes = describeVolumesResult.getVolumes();
} catch(AmazonClientException e) {
System.out.println("ERROR : fetching volumes.");
e.printStackTrace();
throw e;
}
List<String> allVolumesIds = allEBSVolumes.stream().map(e -> e.getVolumeId()).collect(Collectors.toList());
System.out.println("INFO : All Volumes Ids : " + allVolumesIds);
return allEBSVolumes;
}
示例4: getVolumes
import com.amazonaws.services.ec2.model.DescribeVolumesResult; //导入方法依赖的package包/类
/**
* Get EBS volumes attached to the specified virtual instance id.
*
* @return list of ebs volumes
*/
@VisibleForTesting
List<Volume> getVolumes(String virtualInstanceId) {
String ec2InstanceId = getOnlyElement(
getEC2InstanceIdsByVirtualInstanceId(
Collections.singletonList(virtualInstanceId)
).values()
);
InstanceAttribute instanceAttribute =
describeInstanceAttribute(ec2InstanceId, InstanceAttributeName.BlockDeviceMapping);
List<InstanceBlockDeviceMapping> blockDeviceMappings =
instanceAttribute.getBlockDeviceMappings();
List<String> volumeIds = Lists.newArrayList();
for (InstanceBlockDeviceMapping mapping : blockDeviceMappings) {
volumeIds.add(mapping.getEbs().getVolumeId());
}
DescribeVolumesResult volumeResults = client.describeVolumes(
new DescribeVolumesRequest().withVolumeIds(volumeIds)
);
return volumeResults.getVolumes();
}
示例5: describeVolume
import com.amazonaws.services.ec2.model.DescribeVolumesResult; //导入方法依赖的package包/类
public Volume describeVolume(AwsProcessClient awsProcessClient, String volumeId) {
// 単一ボリュームの参照
DescribeVolumesRequest request = new DescribeVolumesRequest();
request.withVolumeIds(volumeId);
DescribeVolumesResult result = awsProcessClient.getEc2Client().describeVolumes(request);
List<Volume> volumes = result.getVolumes();
// API実行結果チェック
if (volumes.size() == 0) {
// ボリュームが存在しない場合
throw new AutoException("EPROCESS-000110", volumeId);
} else if (volumes.size() > 1) {
// ボリュームを複数参照できた場合
AutoException exception = new AutoException("EPROCESS-000111", volumeId);
exception.addDetailInfo("result=" + volumes);
throw exception;
}
return volumes.get(0);
}
示例6: describeVolumes
import com.amazonaws.services.ec2.model.DescribeVolumesResult; //导入方法依赖的package包/类
@Override
public List<AbstractResource<?>> describeVolumes(Account account, Region region, DateTime dt, Ec2Filter... filters) {
AmazonEC2 ec2 = findClient(account, region);
DescribeVolumesRequest req = new DescribeVolumesRequest();
for (Ec2Filter filter : filters) {
Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues());
req.withFilters(f);
}
log.debug("start describing volumes for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region);
DescribeVolumesResult res = ec2.describeVolumes(req);
List<Boolean> autoEnableIOs = new ArrayList<>();
List<List<ProductCode>> productCodes = new ArrayList<>();
for (Volume volume : res.getVolumes()) {
autoEnableIOs.add(findAutoEnableIO(account, region, volume.getVolumeId()));
productCodes.add(findProductCodes(account, region, volume.getVolumeId()));
}
return converter.toEc2Volumes(res.getVolumes(), autoEnableIOs, productCodes, account.getId(), region, dt);
}
示例7: describeBackupVolumes
import com.amazonaws.services.ec2.model.DescribeVolumesResult; //导入方法依赖的package包/类
List<Volume> describeBackupVolumes(AmazonEC2Async client, TagNameRequest target) {
Filter tagKey = new Filter().withName("tag-key").withValues("Backup");
Filter tagValue = new Filter().withName("tag-value").withValues(target.getTagName());
DescribeVolumesRequest req = new DescribeVolumesRequest().withFilters(tagKey, tagValue);
DescribeVolumesResult result = client.describeVolumes(req);
return result.getVolumes();
}
示例8: testRunInstancesWithBlockDevices
import com.amazonaws.services.ec2.model.DescribeVolumesResult; //导入方法依赖的package包/类
@Test
public void testRunInstancesWithBlockDevices() throws Exception {
// TODO: maybe we should also test for spot instances
BlockDevice blockDevice = mock(BlockDevice.class);
when(blockDevice.getSize()).thenReturn(8); // TODO: understand why it doesn't work for smaller volumes
when(blockDevice.getName()).thenReturn("/dev/sda1");
BlockDevice blockDevice2 = mock(BlockDevice.class);
when(blockDevice2.getSize()).thenReturn(16);
when(blockDevice2.getName()).thenReturn("/dev/sda4");
when(hardware.getBlockDevices()).thenReturn(Lists.newArrayList(blockDevice, blockDevice2));
activity.execute(execution);
Uninterruptibles.sleepUninterruptibly(30, TimeUnit.SECONDS);
@SuppressWarnings("unchecked")
List<String> instanceIds = (List<String>) collector.getVariable(ProcessVariables.INSTANCE_IDS);
DescribeInstancesResult result = client.describeInstances(new DescribeInstancesRequest()
.withInstanceIds(instanceIds));
Instance instance = result.getReservations().get(0).getInstances().get(0);
List<InstanceBlockDeviceMapping> bdm = instance.getBlockDeviceMappings();
assertThat(bdm).hasSize(2);
List<String> volumeIds = Lists.newArrayList();
for (int i = 0; i < bdm.size(); i++) {
assertThat(bdm.get(i).getDeviceName()).isEqualTo("/dev/sda" + ((i + 1) * (i + 1)));
assertThat(bdm.get(i).getEbs().getDeleteOnTermination()).isTrue();
volumeIds.add(bdm.get(i).getEbs().getVolumeId());
}
DescribeVolumesResult volumesResult = client.describeVolumes(
new DescribeVolumesRequest().withVolumeIds(volumeIds));
for (Volume volume : volumesResult.getVolumes()) {
assertThat(volume.getState()).isIn(Lists.newArrayList("creating", "available", "in-use"));
}
assertThat(volumesResult.getVolumes().get(0).getSize())
.isNotEqualTo(volumesResult.getVolumes().get(1).getSize());
}