List of usage examples for com.amazonaws.services.ec2.model RegisterImageResult getImageId
public String getImageId()
The ID of the newly registered AMI.
From source file:com.dowdandassociates.gentoo.bootstrap.DefaultTestImageProvider.java
License:Apache License
public Optional<Image> get() { if (!testSnapshot.isPresent()) { log.info("test snapshot not present"); return Optional.absent(); }//from w w w .j a va 2 s . co m StringBuilder name = new StringBuilder(); name.append(prefix.get()); if (StringUtils.isNotBlank(dateFormat.get())) { name.append(DateFormatUtils.formatUTC(System.currentTimeMillis(), dateFormat.get())); } String architecture = imageInformation.getArchitecture(); String virtualizationType = imageInformation.getVirtualizationType(); RegisterImageRequest registerImageRequest = new RegisterImageRequest().withArchitecture(architecture) .withVirtualizationType(virtualizationType).withDescription(description.get()) .withName(name.toString()).withRootDeviceName(rootDeviceName.get()); if ("paravirtual".equals(virtualizationType)) { if (!kernelImage.isPresent()) { log.info("kernel image not present"); return Optional.absent(); } registerImageRequest = registerImageRequest.withKernelId(kernelImage.get().getImageId()); } if ("i386".equals(architecture)) { registerImageRequest = registerImageRequest.withBlockDeviceMappings( new BlockDeviceMapping().withDeviceName(rootDeviceName.get()) .withEbs(new EbsBlockDevice().withSnapshotId(testSnapshot.get().getSnapshotId())), new BlockDeviceMapping().withDeviceName("/dev/sda2").withVirtualName("ephemeral0"), new BlockDeviceMapping().withDeviceName("/dev/sda3").withVirtualName("ephemeral1")); } else { registerImageRequest = registerImageRequest.withBlockDeviceMappings( new BlockDeviceMapping().withDeviceName(rootDeviceName.get()) .withEbs(new EbsBlockDevice().withSnapshotId(testSnapshot.get().getSnapshotId())), new BlockDeviceMapping().withDeviceName("/dev/sdb").withVirtualName("ephemeral0"), new BlockDeviceMapping().withDeviceName("/dev/sdc").withVirtualName("ephemeral1"), new BlockDeviceMapping().withDeviceName("/dev/sdd").withVirtualName("ephemeral2"), new BlockDeviceMapping().withDeviceName("/dev/sde").withVirtualName("ephemeral3")); } RegisterImageResult registerImageResult = ec2Client.registerImage(registerImageRequest); String imageId = registerImageResult.getImageId(); DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest().withImageIds(imageId); try { while (true) { log.info("Sleeping for " + sleep.get() + " ms"); Thread.sleep(sleep.get()); DescribeImagesResult describeImagesResult = ec2Client.describeImages(describeImagesRequest); if (describeImagesResult.getImages().isEmpty()) { return Optional.absent(); } Image image = describeImagesResult.getImages().get(0); String state = image.getState(); log.info("Image state = " + state); if ("pending".equals(state)) { continue; } if (!"available".equals(state)) { return Optional.absent(); } return Optional.fromNullable(image); } } catch (InterruptedException e) { return Optional.absent(); } }
From source file:com.zotoh.cloudapi.aws.AMImage.java
License:Open Source License
@Override public String registerMachineImage(String location) throws CloudException, InternalException { tstEStrArg("image-location", location); RegisterImageResult res = _svc.getCloud().getEC2() .registerImage(new RegisterImageRequest().withImageLocation(location)); return res == null ? null : res.getImageId(); }