Example usage for com.amazonaws.services.ec2.model Image getImageLocation

List of usage examples for com.amazonaws.services.ec2.model Image getImageLocation

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model Image getImageLocation.

Prototype


public String getImageLocation() 

Source Link

Document

The location of the AMI.

Usage

From source file:com.dowdandassociates.gentoo.bootstrap.LatestImageProvider.java

License:Apache License

@Override
public Optional<Image> get() {
    DescribeImagesResult result = ec2Client.describeImages(getRequest());

    Map<String, Image> imageMap = new HashMap<String, Image>();

    for (Image image : result.getImages()) {
        String imageLocation = StringUtils.substringAfterLast(image.getImageLocation(), "/");
        if (StringUtils.isBlank(imageLocation)) {
            imageLocation = image.getImageLocation();
        }// w  w w  .  j a v a2  s  . com
        log.info("imageLocation = " + imageLocation);
        imageMap.put(imageLocation, image);
    }

    if (imageMap.isEmpty()) {
        return Optional.absent();
    }

    SortedSet<String> sortedKeySet = new TreeSet<String>();
    sortedKeySet.addAll(imageMap.keySet());
    String[] keys = sortedKeySet.toArray(new String[0]);
    log.info("key = " + keys[keys.length - 1]);
    return Optional.fromNullable(imageMap.get(keys[keys.length - 1]));
}

From source file:com.zotoh.cloudapi.aws.AMImage.java

License:Open Source License

private MachineImage toMI(Image i) {
    MachineImage m = null;//from ww  w  . j a va 2s .  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:jp.aws.test.ec2.EC2Instance.java

License:Apache License

/**
 * AMI?//from   www . j  av a2s.  c om
 *
 * @param HashMap
 *            <String,String> filterMap : ID: ownerid => self, amazon,
 *            redhat, 00000000  root-device-type => ebs, instance-store
 *            architecture => i386, x86_64 name => amzn-ami*
 * @return
 * @throws Exception
 * @note - ????????
 */
public List<AMIItem> ami_list(HashMap<String, String> filterMap) {

    List<AMIItem> amiItemList = new ArrayList<AMIItem>();

    // 
    this.clientManager.changeRegion();

    // AMI??
    DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest();
    List<String> ownersList = new ArrayList<String>();

    // OwnerID?(self, amazon, redhat, 00000000)
    ownersList.add(filterMap.get("ownerid"));
    describeImagesRequest.setOwners(ownersList);

    // AMI????????Filter?
    ArrayList<Filter> filters = new ArrayList<Filter>();

    Filter filter = new Filter();
    filter.setName("image-type");

    // machine
    List<String> valueList = new ArrayList<String>();
    valueList.add("machine");
    filter.setValues(valueList);

    // Filter
    filters.add(filter);

    // 
    for (Iterator<String> it = filterMap.keySet().iterator(); it.hasNext();) {
        String key = it.next();
        Log.d("ami_list", String.format("key:%s, value:%s", key, filterMap.get(key)));
        if (key.toLowerCase().equals("ownerid"))
            continue;
        filters.add(new Filter().withName(key).withValues(filterMap.get(key)));
    }

    // Filter
    describeImagesRequest.setFilters(filters);

    // ????AMI??
    DescribeImagesResult describeImagesResult = this.clientManager.ec2().describeImages(describeImagesRequest);

    // AMI?List?(Image?com.amazonaws.services.ec2.model?Image???)
    List<Image> amiList = describeImagesResult.getImages();

    // ?AMI??
    for (Image image : amiList) {
        // http://docs.amazonwebservices.com/AWSAndroidSDK/latest/javadoc/com/amazonaws/services/ec2/model/Image.html
        AMIItem amiItem = new AMIItem();

        StringBuilder builder = new StringBuilder();

        amiItem.imageId = image.getImageId();
        amiItem.imageType = image.getImageType();
        amiItem.imageLocation = image.getImageLocation();
        amiItem.name = image.getName();
        amiItem.architecture = image.getArchitecture();
        amiItem.platform = image.getPlatform();
        amiItem.state = image.getState();
        amiItem.ownerId = image.getOwnerId();
        amiItem.rootDeviceType = image.getRootDeviceType();
        amiItem.rootDeviceName = image.getRootDeviceName();
        amiItem.description = image.getDescription();
        builder.setLength(0); // ?
        List<Tag> tags = image.getTags(); // tag
        for (Tag tag : tags) {
            builder.append(tag.getValue());
            builder.append(", ");
        }

        // ?
        amiItemList.add(amiItem);
    }

    return amiItemList;
}

From source file:org.gridgain.grid.spi.cloud.ec2lite.GridEc2LiteCloudSpi.java

License:GNU General Public License

/**
 * Gets image resource from EC2 image./* www .j  a va 2 s.  c o  m*/
 *
 * @param img EC2 image.
 * @return Image resource.
 */
private GridCloudSpiResourceAdapter createImageResource(Image img) {
    assert img != null;

    Map<String, String> params = new HashMap<String, String>();

    params.put(IMG_ARCH, img.getArchitecture());
    params.put(IMG_LOC, img.getImageLocation());
    params.put(IMG_STATE, img.getState());
    params.put(INST_TYPE, img.getImageType());
    params.put(IMG_KERNEL_ID, img.getKernelId());
    params.put(OWNER_ID, img.getOwnerId());
    params.put(INST_PLATFORM, img.getPlatform());
    params.put(IMG_RAMDISK_ID, img.getRamdiskId());
    params.put(IMG_PUBLIC, String.valueOf(img.isPublic()));

    params.put(PRODUCT_CODE_IDS, F.concat(F.transform(img.getProductCodes(), new C1<ProductCode, String>() {
        @Override
        public String apply(ProductCode e) {
            return e.getProductCodeId();
        }
    }), VAL_DELIM));

    return new GridCloudSpiResourceAdapter(img.getImageId(), CLD_IMAGE, cloudId, params);
}