本文整理汇总了Java中com.amazonaws.services.ec2.model.DescribeImagesRequest类的典型用法代码示例。如果您正苦于以下问题:Java DescribeImagesRequest类的具体用法?Java DescribeImagesRequest怎么用?Java DescribeImagesRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DescribeImagesRequest类属于com.amazonaws.services.ec2.model包,在下文中一共展示了DescribeImagesRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveAMI
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
/**
* Checks whether image is present.
*
* @param amiID
* @return <code>Image </code> if the matches one of the amiID
*
*/
public Image resolveAMI(String amiID) throws APPlatformException {
LOGGER.debug("resolveAMI('{}') entered", amiID);
DescribeImagesRequest dir = new DescribeImagesRequest();
dir.withImageIds(amiID);
DescribeImagesResult describeImagesResult = getEC2()
.describeImages(dir);
List<Image> images = describeImagesResult.getImages();
for (Image image : images) {
LOGGER.debug(image.getImageId() + "==" + image.getImageLocation()
+ "==" + image.getName());
return image;
}
throw new APPlatformException(Messages.getAll("error_invalid_image")
+ amiID);
}
示例2: testResolveAMIFound
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
@Test
public void testResolveAMIFound() throws Exception {
ec2mock.createDescribeImagesResult("image1");
Image result = ec2comm.resolveAMI("image1");
assertEquals("image1", result.getImageId());
ArgumentCaptor<DescribeImagesRequest> argCaptor = ArgumentCaptor
.forClass(DescribeImagesRequest.class);
verify(ec2).describeImages(argCaptor.capture());
DescribeImagesRequest dir = argCaptor.getValue();
for (Filter filter : dir.getFilters()) {
if (filter.getName().equals("name")) {
assertEquals("image1", filter.getValues().get(0));
}
}
}
示例3: getSnapshotIdsFromImageId
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
List<String> getSnapshotIdsFromImageId(AmazonEC2Async client, ImageCreateRequest request, Context context) {
// LambdaLogger logger = context.getLogger();
String imageId = request.getImageId();
DescribeImagesResult result = client.describeImages(new DescribeImagesRequest().withImageIds(imageId));
List<String> snapshotIds = new ArrayList<String>();
for (Image image : result.getImages()) {
for (BlockDeviceMapping block : image.getBlockDeviceMappings()) {
snapshotIds.add(block.getEbs().getSnapshotId());
}
}
return snapshotIds;
}
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:17,代码来源:ImageStateCheckAndPargeFunction.java
示例4: isAmiWithTagExist
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
/**
* Validates if the given AMI has given tag and value.
*
* @return true if matches otherwise false
*/
public boolean isAmiWithTagExist(final String amiId, final String tagName, final String tagValue) {
final DescribeImagesRequest request = new DescribeImagesRequest()
.withFilters(new Filter().withName(tagName).withValues(tagValue))
.withFilters(new Filter().withName("image-id").withValues(amiId));
try {
final DescribeImagesResult result = ec2Client.describeImages(request);
return result.getImages().size() > 0;
} catch (final AmazonServiceException ase) {
if (ase.getErrorCode() == "InvalidAMIID.NotFound") {
return false;
}
throw ase;
}
}
示例5: isAmiWithTagExistTrue
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
@Test
public void isAmiWithTagExistTrue() {
AmazonEC2 ec2Client = mock(AmazonEC2.class);
AmiTagCheckService amiTagCheckService = new AmiTagCheckService(ec2Client);
String amiId = "ami-1234abcd";
String tagName = "sometag";
String tagValue = "someval";
when(ec2Client.describeImages(
new DescribeImagesRequest()
.withFilters(new Filter().withName(tagName).withValues(tagValue))
.withFilters(new Filter().withName("image-id").withValues(amiId))
)
).thenReturn(
new DescribeImagesResult().withImages(new Image())
);
// invoke method under test
assertTrue(amiTagCheckService.isAmiWithTagExist(amiId, tagName, tagValue));
}
示例6: isAmiWithTagExistFalse
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
@Test
public void isAmiWithTagExistFalse() {
AmazonEC2 ec2Client = mock(AmazonEC2.class);
AmiTagCheckService amiTagCheckService = new AmiTagCheckService(ec2Client);
String amiId = "ami-1234abcd";
String tagName = "sometag";
String tagValue = "someval";
when(ec2Client.describeImages(
new DescribeImagesRequest()
.withFilters(new Filter().withName(tagName).withValues(tagValue))
.withFilters(new Filter().withName("image-id").withValues(amiId))
)
).thenReturn(
new DescribeImagesResult()
);
// invoke method under test
assertFalse(amiTagCheckService.isAmiWithTagExist(amiId, tagName, tagValue));
}
示例7: isAmiWithTagExistNotFound
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
@Test
public void isAmiWithTagExistNotFound() {
AmazonEC2 ec2Client = mock(AmazonEC2.class);
AmiTagCheckService amiTagCheckService = new AmiTagCheckService(ec2Client);
String amiId = "ami-1234abcd";
String tagName = "sometag";
String tagValue = "someval";
AmazonServiceException ex = new AmazonServiceException("fake-exception");
ex.setErrorCode("InvalidAMIID.NotFound");
when(ec2Client.describeImages(
new DescribeImagesRequest()
.withFilters(new Filter().withName(tagName).withValues(tagValue))
.withFilters(new Filter().withName("image-id").withValues(amiId))
)
).thenThrow(ex);
// invoke method under test
assertFalse(amiTagCheckService.isAmiWithTagExist(amiId, tagName, tagValue));
}
示例8: isAmiWithTagExistThrowException
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
@Test
public void isAmiWithTagExistThrowException() {
AmazonEC2 ec2Client = mock(AmazonEC2.class);
AmiTagCheckService amiTagCheckService = new AmiTagCheckService(ec2Client);
String amiId = "ami-1234abcd";
String tagName = "sometag";
String tagValue = "someval";
String unknownAwsExMessage = "Unknown AWS exception message";
when(ec2Client.describeImages(
new DescribeImagesRequest()
.withFilters(new Filter().withName(tagName).withValues(tagValue))
.withFilters(new Filter().withName("image-id").withValues(amiId))
)
).thenThrow(new AmazonServiceException(unknownAwsExMessage));
try {
// invoke method under test
amiTagCheckService.isAmiWithTagExist(amiId, tagName, tagValue);
fail("Expected exception message '" + unknownAwsExMessage + "'not received");
} catch (AmazonServiceException ex) {
// pass
assertEquals(unknownAwsExMessage, ex.getErrorMessage());
}
}
示例9: getAmiDetails
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
@Override
@Cacheable(cacheNames = "ami-details", cacheManager = "oneDayTTLCacheManager")
public Map<String, String> getAmiDetails(final String accountId, final Region region, final String amiId) {
final ImmutableMap.Builder<String, String> result = ImmutableMap.builder();
result.put("ami_id", amiId);
final AmazonEC2Client ec2 = clientProvider.getClient(AmazonEC2Client.class, accountId, region);
final Optional<Image> ami = Optional.ofNullable(new DescribeImagesRequest().withImageIds(amiId))
.map(ec2::describeImages)
.map(DescribeImagesResult::getImages)
.map(List::stream)
.flatMap(Stream::findFirst);
ami.map(Image::getName).ifPresent(name -> result.put("ami_name", name));
ami.map(Image::getOwnerId).ifPresent(owner -> result.put("ami_owner_id", owner));
return result.build();
}
示例10: testApplyAmiFound
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
@Test
public void testApplyAmiFound() throws Exception {
when(ec2InstanceContextMock.getAmiId()).thenReturn(Optional.of(AMI_ID));
when(ec2InstanceContextMock.getClient(eq(AmazonEC2Client.class))).thenReturn(amazonEC2ClientMock);
final DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest().withImageIds(AMI_ID);
when(amazonEC2ClientMock.describeImages(eq(describeImagesRequest)))
.thenReturn(new DescribeImagesResult()
.withImages(newArrayList(new Image()
.withImageId(AMI_ID)
.withName(AMI_NAME))
)
);
final Optional<Image> result = amiProvider.apply(ec2InstanceContextMock);
assertThat(result).isPresent();
verify(ec2InstanceContextMock).getAmiId();
verify(ec2InstanceContextMock).getClient(eq(AmazonEC2Client.class));
verify(amazonEC2ClientMock).describeImages(eq(describeImagesRequest));
}
示例11: testApplyAmiNotFound
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
@Test
public void testApplyAmiNotFound() throws Exception {
when(ec2InstanceContextMock.getAmiId()).thenReturn(Optional.of(AMI_ID));
when(ec2InstanceContextMock.getClient(eq(AmazonEC2Client.class))).thenReturn(amazonEC2ClientMock);
final DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest().withImageIds(AMI_ID);
when(amazonEC2ClientMock.describeImages(eq(describeImagesRequest)))
.thenReturn(null);
final Optional<Image> result = amiProvider.apply(ec2InstanceContextMock);
assertThat(result).isEmpty();
verify(ec2InstanceContextMock).getAmiId();
verify(ec2InstanceContextMock).getClient(eq(AmazonEC2Client.class));
verify(amazonEC2ClientMock).describeImages(eq(describeImagesRequest));
}
示例12: testApplyAmiNotFoundWithException
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
@Test
public void testApplyAmiNotFoundWithException() throws Exception {
when(ec2InstanceContextMock.getAmiId()).thenReturn(Optional.of(AMI_ID));
when(ec2InstanceContextMock.getClient(eq(AmazonEC2Client.class))).thenReturn(amazonEC2ClientMock);
final DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest().withImageIds(AMI_ID);
when(amazonEC2ClientMock.describeImages(eq(describeImagesRequest)))
.thenThrow(new AmazonClientException("oops, I did it again... Britney"));
final Optional<Image> result = amiProvider.apply(ec2InstanceContextMock);
assertThat(result).isEmpty();
verify(ec2InstanceContextMock).getAmiId();
verify(ec2InstanceContextMock).getClient(eq(AmazonEC2Client.class));
verify(amazonEC2ClientMock).describeImages(eq(describeImagesRequest));
}
示例13: listImages
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
public List<VirtualMachineImage> listImages(String ... imageIds)
{
checkNotNull(imageIds);
checkArgument(imageIds.length >= 1);
List<Image> images = newArrayList();
try
{
images = ec2_.describeImages(new DescribeImagesRequest().withImageIds(imageIds)).getImages();
}
catch (AmazonClientException exception)
{
LOG.error(exception.getMessage());
}
return IMAGES_FUNCTION.apply(images);
}
示例14: lookupImageId
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
String lookupImageId(String imgName)
{
DescribeImagesRequest req = new DescribeImagesRequest();
if(imgName == null || imgName.length() == 0)
return null;
req.setRequestCredentials(creds);
DescribeImagesResult result = ec2Client.describeImages();
for(Image image : result.getImages()) {
if(image.getName() != null && image.getName().equals(imgName))
return image.getImageId();
}
return null;
}
示例15: describeAMIs
import com.amazonaws.services.ec2.model.DescribeImagesRequest; //导入依赖的package包/类
@Override
public List<AbstractResource<?>> describeAMIs(Account account, Region region, DateTime dt, Ec2Filter... filters) {
AmazonEC2 ec2 = findClient(account, region);
DescribeImagesRequest req = new DescribeImagesRequest();
for (Ec2Filter filter : filters) {
Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues());
req.withFilters(f);
}
log.debug("start describing amis for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region);
DescribeImagesResult res = ec2.describeImages(req);
List<List<LaunchPermission>> imageLaunchPermissions = new ArrayList<>();
for (Image image : res.getImages()) {
imageLaunchPermissions.add(findImageLaunchPermissions(account, region, image.getImageId()));
}
return converter.toEc2AMIs(res.getImages(), imageLaunchPermissions, account.getId(), region, dt);
}