List of usage examples for com.amazonaws.services.ec2.model Image getVirtualizationType
public String getVirtualizationType()
The type of virtualization of the AMI.
From source file:com.cloudera.director.aws.ec2.EC2InstanceTemplateConfigurationValidator.java
License:Apache License
/** * Validates the configured AMI./*from ww w.j a v a 2 s . c om*/ * * @param client the EC2 client * @param configuration the configuration to be validated * @param accumulator the exception condition accumulator * @param localizationContext the localization context */ @VisibleForTesting @SuppressWarnings("PMD.CollapsibleIfStatements") void checkImage(AmazonEC2Client client, Configured configuration, PluginExceptionConditionAccumulator accumulator, LocalizationContext localizationContext) { String imageName = configuration.getConfigurationValue(IMAGE, localizationContext); String type = configuration.getConfigurationValue(TYPE, localizationContext); int conditionCount = accumulator.getConditionsByKey().size(); if (!imageName.startsWith("ami-")) { addError(accumulator, IMAGE, localizationContext, null, INVALID_AMI_NAME_MSG, imageName); return; } LOG.info(">> Describing AMI '{}'", imageName); DescribeImagesResult result = null; try { result = client.describeImages(new DescribeImagesRequest().withImageIds(imageName)); checkCount(accumulator, IMAGE, localizationContext, imageName, result.getImages()); } catch (AmazonServiceException e) { if (e.getErrorCode().startsWith(INVALID_AMI_ID)) { addError(accumulator, IMAGE, localizationContext, null, INVALID_AMI_MSG, imageName); } else { throw Throwables.propagate(e); } } if ((result == null) || (accumulator.getConditionsByKey().size() > conditionCount)) { return; } Image image = Iterables.getOnlyElement(result.getImages()); if (!SIXTY_FOUR_BIT_ARCHITECTURE.equals(image.getArchitecture())) { addError(accumulator, IMAGE, localizationContext, null, INVALID_AMI_ARCHITECTURE_MSG, imageName, image.getArchitecture()); } AWSFilters imageFilters = templateFilters.getSubfilters(IMAGE.unwrap().getConfigKey()); boolean useSpotInstances = Boolean .parseBoolean(configuration.getConfigurationValue(USE_SPOT_INSTANCES, localizationContext)); String ownerId = image.getOwnerId(); if (ownerId != null) { String blacklistValue = imageFilters.getBlacklistValue(IMAGE_OWNER_ID_BLACKLIST_KEY, ownerId.toLowerCase()); if (blacklistValue != null) { addError(accumulator, IMAGE, localizationContext, null, INVALID_AMI_OWNER_MSG, imageName, ownerId, blacklistValue); } else { if (useSpotInstances) { blacklistValue = imageFilters.getBlacklistValue(IMAGE_SPOT_OWNER_ID_BLACKLIST_KEY, ownerId.toLowerCase()); if (blacklistValue != null) { addError(accumulator, IMAGE, localizationContext, null, INVALID_AMI_OWNER_SPOT_MSG, imageName, ownerId, blacklistValue); } } } } String platform = image.getPlatform(); if (platform != null) { String blacklistValue = imageFilters.getBlacklistValue(IMAGE_PLATFORM_BLACKLIST_KEY, platform.toLowerCase()); if (blacklistValue != null) { addError(accumulator, IMAGE, localizationContext, null, INVALID_AMI_PLATFORM_MSG, imageName, platform, blacklistValue); } else { if (useSpotInstances) { blacklistValue = imageFilters.getBlacklistValue(IMAGE_SPOT_PLATFORM_BLACKLIST_KEY, platform.toLowerCase()); if (blacklistValue != null) { addError(accumulator, IMAGE, localizationContext, null, INVALID_AMI_PLATFORM_SPOT_MSG, imageName, platform, blacklistValue); } } } } if (!AVAILABLE_STATE.equals(image.getState())) { addError(accumulator, IMAGE, localizationContext, null, INVALID_AMI_STATE_MSG, imageName, image.getState()); } if (!provider.getVirtualizationMappings().apply(image.getVirtualizationType()).contains(type)) { addError(accumulator, IMAGE, localizationContext, null, INVALID_AMI_INSTANCE_TYPE_COMPATIBILITY_MSG, type, image.getVirtualizationType(), imageName); } if (!ROOT_DEVICE_TYPE.equals(image.getRootDeviceType())) { addError(accumulator, IMAGE, localizationContext, null, INVALID_AMI_ROOT_DEVICE_TYPE_MSG, imageName, image.getRootDeviceType()); } }
From source file:com.norbl.cbp.ppe.AmiDescription.java
License:Open Source License
public static boolean isParavirtual(Image img) { return (img.getVirtualizationType().equals("paravirtual")); }
From source file:com.norbl.cbp.ppe.AmiDescription.java
License:Open Source License
public static boolean isHvm(Image img) { return (img.getVirtualizationType().equals("hvm")); }
From source file:com.norbl.cbp.ppe.Ec2Wrangler.java
License:Open Source License
public boolean isHVM(String imageID) { DescribeImagesRequest req = new DescribeImagesRequest(); List<String> iids = new ArrayList<String>(); iids.add(imageID);/* w ww . j a v a 2 s .c o m*/ req.setImageIds(iids); DescribeImagesResult res = ec2Client.describeImages(req); for (Image img : res.getImages()) { if (img.getImageId().equals(imageID)) { return (img.getVirtualizationType().equals("hvm")); } } return (false); }
From source file:com.norbl.cbp.ppe.UtilEc2.java
License:Open Source License
static boolean supportsHvm(String ami, AmazonEC2Client ec2) { Image img = AmiDescription.getImageInfo(ec2, ami); return (img.getVirtualizationType().toLowerCase().equals("hvm")); }
From source file:com.norbl.cbp.ppe.UtilEc2.java
License:Open Source License
static boolean supportsPv(String ami, AmazonEC2Client ec2) { Image img = AmiDescription.getImageInfo(ec2, ami); return (img.getVirtualizationType().toLowerCase().equals("paravirtual")); }
From source file:com.zotoh.cloudapi.aws.AMImage.java
License:Open Source License
private MachineImage toMI(Image i) { MachineImage m = null;//from w w w. j a v a2 s . c o m if (i != null) { m = new MachineImage(); m.setProviderRegionId(_svc.getCloud().getContext().getRegionId()); m.setArchitecture(toArch(i.getArchitecture())); m.setCurrentState(toImageState(i.getState())); m.setProviderMachineImageId(i.getImageId()); m.setName(i.getName()); m.setProviderOwnerId(i.getOwnerId()); m.setSoftware(""); m.setType(toImageType(i.getRootDeviceType())); m.addTag("manifest-location", nsb(i.getImageLocation())); m.addTag("hypervisor", nsb(i.getHypervisor())); m.addTag("alias", nsb(i.getImageOwnerAlias())); m.addTag("kernel", nsb(i.getKernelId())); m.addTag("public", i.getPublic() ? "true" : "false"); m.addTag("ramdisk", nsb(i.getRamdiskId())); m.addTag("root-dev-name", nsb(i.getRootDeviceName())); m.addTag("state-reason", nsb(i.getStateReason())); m.addTag("virtualization-type", nsb(i.getVirtualizationType())); m.setDescription(i.getDescription()); m.setPlatform(nsb(i.getPlatform()).toLowerCase().indexOf("windows") >= 0 ? Platform.WINDOWS : Platform.UBUNTU); } return m; }
From source file:de.unibi.cebitec.bibigrid.meta.aws.ValidateIntentAWS.java
private boolean checkImages() { log.info("Checking Images..."); boolean allCheck = true; /*/* w w w .ja va2s. c o m*/ * Checking for Images in Config File */ try { DescribeImagesRequest imageRequest = new DescribeImagesRequest() .withImageIds(Arrays.asList(conf.getMasterImage(), conf.getSlaveImage())); DescribeImagesResult imageResult = ec2.describeImages(imageRequest); boolean slave = false, master = false; boolean masterClusterType = conf.getMasterInstanceType().getSpec().clusterInstance; boolean slaveClusterType = conf.getSlaveInstanceType().getSpec().clusterInstance; /* * Checking if both are hvm or paravirtual types */ if (masterClusterType != slaveClusterType) { log.error("If cluster instances are used please create a homogeneous group."); allCheck = false; } else if (masterClusterType) { /* * If master instance is a cluster instance check if the types are the same */ if (conf.getMasterInstanceType() != conf.getSlaveInstanceType()) { log.error("If cluster instances are used please create a homogeneous group."); allCheck = false; } } for (Image image : imageResult.getImages()) { /* * Checking if Master Image is available. */ if (image.getImageId().equals(conf.getMasterImage())) { master = true; if (image.getVirtualizationType().equals("hvm")) { // Image detected is of HVM Type if (conf.getMasterInstanceType().getSpec().hvm) { log.info(I, "Master instance can use HVM images."); // Instance and Image is HVM type } else if (conf.getMasterInstanceType().getSpec().pvm) { log.error("Master Instance type does not support hardware-assisted virtualization."); // HVM Image but instance type is not correct allCheck = false; } } else { if (conf.getMasterInstanceType().getSpec().pvm) { log.info(I, "Master instance can use paravirtual images."); // Instance and Image fits. } else if (conf.getMasterInstanceType().getSpec().hvm) { log.error("Master Instance type does not support paravirtual images."); // Paravirtual Image but cluster instance type allCheck = false; } } } /* * Checking if Slave Image is available. */ if (image.getImageId().equals(conf.getSlaveImage())) { slave = true; if (image.getVirtualizationType().equals("hvm")) { // Image detected is of HVM Type if (conf.getSlaveInstanceType().getSpec().hvm) { log.info(I, "Slave instance can use HVM images."); // Instance and Image is HVM type } else if (conf.getSlaveInstanceType().getSpec().pvm) { log.error("Slave Instance type does not support hardware-assisted virtualization."); // HVM Image but instance type is not correct allCheck = false; } } else { if (conf.getSlaveInstanceType().getSpec().pvm) { log.info(I, "Slave instance can use paravirtual images."); // Instance and Image fits. } else if (conf.getSlaveInstanceType().getSpec().hvm) { log.error("Slave Instance type does not support paravirtual images."); // Paravirtual Image but cluster instance type allCheck = false; } } } } if (slave && master) { log.info(I, "Master and Slave AMIs have been found."); } else { log.error("Master and Slave AMIs could not be found."); allCheck = false; } return allCheck; } catch (AmazonServiceException e) { log.error("Master and Slave AMIs could not be found. Check if the ID is malformed (ami-XXXXXXXX)."); allCheck = false; return allCheck; } }