Search in sources :

Example 6 with DescribeImagesResult

use of com.amazonaws.services.ec2.model.DescribeImagesResult in project cloudbreak by hortonworks.

the class AwsResourceConnector method getRootDeviceName.

private String getRootDeviceName(AuthenticatedContext ac, CloudStack cloudStack) {
    AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
    DescribeImagesResult images = ec2Client.describeImages(new DescribeImagesRequest().withImageIds(cloudStack.getImage().getImageName()));
    if (images.getImages().isEmpty()) {
        throw new CloudConnectorException(String.format("AMI is not available: '%s'.", cloudStack.getImage().getImageName()));
    }
    Image image = images.getImages().get(0);
    if (image == null) {
        throw new CloudConnectorException(String.format("Couldn't describe AMI '%s'.", cloudStack.getImage().getImageName()));
    }
    return image.getRootDeviceName();
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) DescribeImagesResult(com.amazonaws.services.ec2.model.DescribeImagesResult) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) DescribeImagesRequest(com.amazonaws.services.ec2.model.DescribeImagesRequest) Image(com.amazonaws.services.ec2.model.Image)

Aggregations

DescribeImagesRequest (com.amazonaws.services.ec2.model.DescribeImagesRequest)4 DescribeImagesResult (com.amazonaws.services.ec2.model.DescribeImagesResult)4 Image (com.amazonaws.services.ec2.model.Image)4 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 BlockDeviceMapping (com.amazonaws.services.ec2.model.BlockDeviceMapping)2 EbsBlockDevice (com.amazonaws.services.ec2.model.EbsBlockDevice)2 Filter (com.amazonaws.services.ec2.model.Filter)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 SdkClientException (com.amazonaws.SdkClientException)1 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 InstanceBlockDeviceMapping (com.amazonaws.services.ec2.model.InstanceBlockDeviceMapping)1 Placement (com.amazonaws.services.ec2.model.Placement)1 RunInstancesRequest (com.amazonaws.services.ec2.model.RunInstancesRequest)1 RunInstancesResult (com.amazonaws.services.ec2.model.RunInstancesResult)1 TagSpecification (com.amazonaws.services.ec2.model.TagSpecification)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 AWSNicContext (com.vmware.photon.controller.model.adapters.awsadapter.AWSInstanceContext.AWSNicContext)1