mirror of https://github.com/apache/jclouds.git
added hypervisor property to ec2 image
This commit is contained in:
parent
c8ebbc2f02
commit
537691226e
|
@ -87,8 +87,9 @@ public class EC2ImageParser implements Function<org.jclouds.ec2.domain.Image, Im
|
|||
builder.providerId(from.getId());
|
||||
builder.id(from.getRegion() + "/" + from.getId());
|
||||
builder.description(from.getDescription() != null ? from.getDescription() : from.getImageLocation());
|
||||
builder.userMetadata(ImmutableMap.<String, String> of("owner", from.getImageOwnerId(), "rootDeviceType", from
|
||||
.getRootDeviceType().toString()));
|
||||
builder.userMetadata(ImmutableMap.<String, String> builder().put("owner", from.getImageOwnerId()).put(
|
||||
"rootDeviceType", from.getRootDeviceType().value()).put("virtualizationType",
|
||||
from.getVirtualizationType().value()).put("hypervisor", from.getHypervisor().value()).build());
|
||||
|
||||
OperatingSystem.Builder osBuilder = OperatingSystem.builder();
|
||||
osBuilder.is64Bit(from.getArchitecture() == Architecture.X86_64);
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.ec2.domain;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
/**
|
||||
* Hypervisor of the image.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum Hypervisor {
|
||||
|
||||
XEN,
|
||||
/**
|
||||
* Oracle VM Server
|
||||
*/
|
||||
OVM, UNRECOGNIZED;
|
||||
|
||||
public String value() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static Hypervisor fromValue(String v) {
|
||||
try {
|
||||
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, v));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -66,11 +66,17 @@ public class Image implements Comparable<Image> {
|
|||
return virtualizationType;
|
||||
}
|
||||
|
||||
private final Hypervisor hypervisor;
|
||||
|
||||
public Hypervisor getHypervisor() {
|
||||
return hypervisor;
|
||||
}
|
||||
|
||||
public Image(String region, Architecture architecture, @Nullable String name, @Nullable String description,
|
||||
String imageId, String imageLocation, String imageOwnerId, ImageState imageState, ImageType imageType,
|
||||
boolean isPublic, Iterable<String> productCodes, @Nullable String kernelId, @Nullable String platform,
|
||||
@Nullable String ramdiskId, RootDeviceType rootDeviceType, @Nullable String rootDeviceName,
|
||||
Map<String, EbsBlockDevice> ebsBlockDevices, VirtualizationType virtualizationType) {
|
||||
Map<String, EbsBlockDevice> ebsBlockDevices, VirtualizationType virtualizationType, Hypervisor hypervisor) {
|
||||
this.region = checkNotNull(region, "region");
|
||||
this.architecture = checkNotNull(architecture, "architecture");
|
||||
this.imageId = checkNotNull(imageId, "imageId");
|
||||
|
@ -89,6 +95,7 @@ public class Image implements Comparable<Image> {
|
|||
this.rootDeviceType = checkNotNull(rootDeviceType, "rootDeviceType");
|
||||
this.ebsBlockDevices.putAll(checkNotNull(ebsBlockDevices, "ebsBlockDevices"));
|
||||
this.virtualizationType = checkNotNull(virtualizationType, "virtualizationType");
|
||||
this.hypervisor = checkNotNull(hypervisor, "hypervisor");
|
||||
}
|
||||
|
||||
/** The serialVersionUID */
|
||||
|
@ -353,6 +360,7 @@ public class Image implements Comparable<Image> {
|
|||
result = prime * result + ((rootDeviceName == null) ? 0 : rootDeviceName.hashCode());
|
||||
result = prime * result + ((rootDeviceType == null) ? 0 : rootDeviceType.hashCode());
|
||||
result = prime * result + ((virtualizationType == null) ? 0 : virtualizationType.hashCode());
|
||||
result = prime * result + ((hypervisor == null) ? 0 : hypervisor.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -452,6 +460,11 @@ public class Image implements Comparable<Image> {
|
|||
return false;
|
||||
} else if (!virtualizationType.equals(other.virtualizationType))
|
||||
return false;
|
||||
if (hypervisor == null) {
|
||||
if (other.hypervisor != null)
|
||||
return false;
|
||||
} else if (!hypervisor.equals(other.hypervisor))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -463,7 +476,7 @@ public class Image implements Comparable<Image> {
|
|||
+ ", kernelId=" + kernelId + ", name=" + name + ", platform=" + platform + ", productCodes="
|
||||
+ productCodes + ", ramdiskId=" + ramdiskId + ", region=" + region + ", rootDeviceName="
|
||||
+ rootDeviceName + ", rootDeviceType=" + rootDeviceType + ", virtualizationType=" + virtualizationType
|
||||
+ "]";
|
||||
+ ", hypervisor=" + hypervisor + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import javax.annotation.Resource;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.aws.util.AWSUtils;
|
||||
import org.jclouds.ec2.domain.Hypervisor;
|
||||
import org.jclouds.ec2.domain.Image;
|
||||
import org.jclouds.ec2.domain.RootDeviceType;
|
||||
import org.jclouds.ec2.domain.VirtualizationType;
|
||||
|
@ -86,6 +87,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
|
|||
private String deviceName;
|
||||
private String snapshotId;
|
||||
private VirtualizationType virtualizationType = VirtualizationType.PARAVIRTUAL;
|
||||
private Hypervisor hypervisor = Hypervisor.XEN;
|
||||
|
||||
private int volumeSize;
|
||||
private boolean deleteOnTermination = true;// correct default is true.
|
||||
|
@ -150,6 +152,8 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
|
|||
rootDeviceName = currentText.toString().trim();
|
||||
} else if (qName.equals("virtualizationType")) {
|
||||
virtualizationType = VirtualizationType.fromValue(currentText.toString().trim());
|
||||
} else if (qName.equals("hypervisor")) {
|
||||
hypervisor = Hypervisor.fromValue(currentText.toString().trim());
|
||||
} else if (qName.equals("item")) {
|
||||
if (inBlockDeviceMapping) {
|
||||
ebsBlockDevices.put(deviceName, new Image.EbsBlockDevice(snapshotId, volumeSize, deleteOnTermination));
|
||||
|
@ -164,7 +168,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
|
|||
region = defaultRegion;
|
||||
contents.add(new Image(region, architecture, this.name, description, imageId, imageLocation,
|
||||
imageOwnerId, imageState, imageType, isPublic, productCodes, kernelId, platform, ramdiskId,
|
||||
rootDeviceType, rootDeviceName, ebsBlockDevices, virtualizationType));
|
||||
rootDeviceType, rootDeviceName, ebsBlockDevices, virtualizationType, hypervisor));
|
||||
} catch (NullPointerException e) {
|
||||
logger.warn(e, "malformed image: %s", imageId);
|
||||
}
|
||||
|
@ -185,6 +189,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
|
|||
this.rootDeviceName = null;
|
||||
this.ebsBlockDevices = Maps.newHashMap();
|
||||
this.virtualizationType = VirtualizationType.PARAVIRTUAL;
|
||||
this.hypervisor = Hypervisor.XEN;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.Set;
|
|||
|
||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystemBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Credentials;
|
||||
|
@ -59,14 +59,14 @@ public class EC2ImageParserTest {
|
|||
Set<org.jclouds.compute.domain.Image> result = convertImages("/amzn_images.xml");
|
||||
|
||||
assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description(
|
||||
new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description(
|
||||
"137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).description("Amazon")
|
||||
.defaultCredentials(new Credentials("ec2-user", null)).id("us-east-1/ami-82e4b5c7").providerId(
|
||||
"ami-82e4b5c7").location(defaultLocation).userMetadata(
|
||||
ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
|
||||
|
||||
assertEquals(Iterables.get(result, 3), new ImageBuilder().operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description(
|
||||
new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description(
|
||||
"amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml").is64Bit(true).build())
|
||||
.description("Amazon Linux AMI x86_64 S3").defaultCredentials(new Credentials("ec2-user", null)).id(
|
||||
"us-east-1/ami-f2e4b5b7").providerId("ami-f2e4b5b7").location(defaultLocation).userMetadata(
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.io.InputStream;
|
|||
import java.util.Set;
|
||||
|
||||
import org.jclouds.ec2.compute.functions.EC2ImageParserTest;
|
||||
import org.jclouds.ec2.domain.Hypervisor;
|
||||
import org.jclouds.ec2.domain.Image;
|
||||
import org.jclouds.ec2.domain.RootDeviceType;
|
||||
import org.jclouds.ec2.domain.VirtualizationType;
|
||||
|
@ -56,7 +57,7 @@ public class DescribeImagesResponseHandlerTest {
|
|||
"ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml", "206029621532", ImageState.AVAILABLE,
|
||||
ImageType.MACHINE, false, Sets.<String> newHashSet("9961934F"), "aki-4438dd2d", null, "ari-4538dd2c",
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(),
|
||||
VirtualizationType.PARAVIRTUAL));
|
||||
VirtualizationType.PARAVIRTUAL, Hypervisor.XEN));
|
||||
|
||||
Set<Image> result = parseImages("/describe_images.xml");
|
||||
|
||||
|
@ -68,7 +69,8 @@ public class DescribeImagesResponseHandlerTest {
|
|||
"aws-solutions-amis/SqlSvrStd2003r2-x86_64-Win_SFWBasic5.1-v1.0.manifest.xml", "771350841976",
|
||||
ImageState.AVAILABLE, ImageType.MACHINE, true, Sets.<String> newHashSet("5771E9A6"), null, "windows",
|
||||
null, RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(),
|
||||
VirtualizationType.PARAVIRTUAL));
|
||||
VirtualizationType.PARAVIRTUAL, Hypervisor.XEN));
|
||||
|
||||
|
||||
Set<Image> result = parseImages("/describe_images_windows.xml");
|
||||
|
||||
|
@ -81,7 +83,7 @@ public class DescribeImagesResponseHandlerTest {
|
|||
ImageState.AVAILABLE, ImageType.MACHINE, true, Sets.<String> newHashSet(), null, "windows", null,
|
||||
RootDeviceType.EBS, "/dev/sda1", ImmutableMap.<String, EbsBlockDevice> of("/dev/sda1",
|
||||
new EbsBlockDevice("snap-d01272b9", 30, true), "xvdf", new EbsBlockDevice("snap-d31272ba", 250,
|
||||
false)), VirtualizationType.HVM));
|
||||
false)), VirtualizationType.HVM, Hypervisor.XEN));
|
||||
|
||||
Set<Image> result = parseImages("/describe_images_ebs.xml");
|
||||
|
||||
|
|
|
@ -125,11 +125,11 @@ public class AWSEC2ImageParserTest {
|
|||
|
||||
assertEquals(
|
||||
new Gson().toJson(Iterables.get(result, 1)),
|
||||
"{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-c19db6b5\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
|
||||
"{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-c19db6b5\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"paravirtual\",\"hypervisor\":\"xen\"}}");
|
||||
|
||||
assertEquals(
|
||||
new Gson().toJson(Iterables.get(result, 2)),
|
||||
"{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-710c2605\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
|
||||
"{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-710c2605\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"hvm\",\"hypervisor\":\"xen\"}}");
|
||||
}
|
||||
|
||||
public void testParseAmznImage() {
|
||||
|
|
|
@ -66,7 +66,8 @@ public class EucalyptusPartnerCloudReviseParsedImageTest {
|
|||
"debian-6.0-x86_64/debian.6-0.x86-64.img.manifest.xml")
|
||||
.defaultCredentials(new Credentials("root", null)).id("us-east-1/emi-892C130F").providerId(
|
||||
"emi-892C130F").location(defaultLocation).userMetadata(
|
||||
ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build().toString());
|
||||
ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store", "virtualizationType",
|
||||
"paravirtual", "hypervisor", "xen")).build().toString());
|
||||
|
||||
assertEquals(Iterables.get(result, 1).toString(), new ImageBuilder().operatingSystem(
|
||||
OperatingSystem.builder().family(OsFamily.CENTOS).arch("paravirtual").version("5.5").description(
|
||||
|
@ -74,15 +75,17 @@ public class EucalyptusPartnerCloudReviseParsedImageTest {
|
|||
"centos-5.5-x86_64/centos.5-5.x86-64.img.manifest.xml")
|
||||
.defaultCredentials(new Credentials("root", null)).id("us-east-1/emi-9B751369").providerId(
|
||||
"emi-9B751369").location(defaultLocation).userMetadata(
|
||||
ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build().toString());
|
||||
ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store", "virtualizationType",
|
||||
"paravirtual", "hypervisor", "xen")).build().toString());
|
||||
|
||||
assertEquals(Iterables.get(result, 2).toString(), new ImageBuilder().operatingSystem(
|
||||
OperatingSystem.builder().family(OsFamily.UBUNTU).arch("paravirtual").version("10.04").description(
|
||||
"ubuntu-10.04-x86_64/ubuntu.10-04.x86-64.img.manifest.xml").is64Bit(true).build()).description(
|
||||
"ubuntu-10.04-x86_64/ubuntu.10-04.x86-64.img.manifest.xml").defaultCredentials(
|
||||
new Credentials("root", null)).id("us-east-1/emi-E0641459").providerId("emi-E0641459").location(
|
||||
defaultLocation).userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store"))
|
||||
.build().toString());
|
||||
defaultLocation).userMetadata(
|
||||
ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store", "virtualizationType",
|
||||
"paravirtual", "hypervisor", "xen")).build().toString());
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue