From 537691226e93d6fbb1726857f1077c3a9ee8e3a2 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 8 Jul 2011 02:09:36 -0700 Subject: [PATCH] added hypervisor property to ec2 image --- .../ec2/compute/functions/EC2ImageParser.java | 5 +- .../org/jclouds/ec2/domain/Hypervisor.java | 51 +++++++++++++++++++ .../java/org/jclouds/ec2/domain/Image.java | 17 ++++++- .../xml/DescribeImagesResponseHandler.java | 7 ++- .../compute/functions/EC2ImageParserTest.java | 6 +-- .../DescribeImagesResponseHandlerTest.java | 8 +-- .../strategy/AWSEC2ImageParserTest.java | 4 +- ...ptusPartnerCloudReviseParsedImageTest.java | 11 ++-- 8 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 apis/ec2/src/main/java/org/jclouds/ec2/domain/Hypervisor.java diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java index 55a23af62a..1e4b4b213b 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java @@ -87,8 +87,9 @@ public class EC2ImageParser implements Function of("owner", from.getImageOwnerId(), "rootDeviceType", from - .getRootDeviceType().toString())); + builder.userMetadata(ImmutableMap. 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); diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Hypervisor.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Hypervisor.java new file mode 100644 index 0000000000..b067e99a6f --- /dev/null +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Hypervisor.java @@ -0,0 +1,51 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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; + } + } +} diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Image.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Image.java index 66cb20ccb4..d5e83a7542 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Image.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Image.java @@ -66,11 +66,17 @@ public class Image implements Comparable { 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 productCodes, @Nullable String kernelId, @Nullable String platform, @Nullable String ramdiskId, RootDeviceType rootDeviceType, @Nullable String rootDeviceName, - Map ebsBlockDevices, VirtualizationType virtualizationType) { + Map 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 { 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 { 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 { 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 { + ", kernelId=" + kernelId + ", name=" + name + ", platform=" + platform + ", productCodes=" + productCodes + ", ramdiskId=" + ramdiskId + ", region=" + region + ", rootDeviceName=" + rootDeviceName + ", rootDeviceType=" + rootDeviceType + ", virtualizationType=" + virtualizationType - + "]"; + + ", hypervisor=" + hypervisor + "]"; } } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeImagesResponseHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeImagesResponseHandler.java index 33584f08f7..e96b555608 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeImagesResponseHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeImagesResponseHandler.java @@ -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; } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/EC2ImageParserTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/EC2ImageParserTest.java index c842506485..dcbb78e3fb 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/EC2ImageParserTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/EC2ImageParserTest.java @@ -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 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( diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeImagesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeImagesResponseHandlerTest.java index f1eb11c12e..54c5332edc 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeImagesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeImagesResponseHandlerTest.java @@ -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. newHashSet("9961934F"), "aki-4438dd2d", null, "ari-4538dd2c", RootDeviceType.INSTANCE_STORE, null, ImmutableMap. of(), - VirtualizationType.PARAVIRTUAL)); + VirtualizationType.PARAVIRTUAL, Hypervisor.XEN)); Set 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. newHashSet("5771E9A6"), null, "windows", null, RootDeviceType.INSTANCE_STORE, null, ImmutableMap. of(), - VirtualizationType.PARAVIRTUAL)); + VirtualizationType.PARAVIRTUAL, Hypervisor.XEN)); + Set result = parseImages("/describe_images_windows.xml"); @@ -81,7 +83,7 @@ public class DescribeImagesResponseHandlerTest { ImageState.AVAILABLE, ImageType.MACHINE, true, Sets. newHashSet(), null, "windows", null, RootDeviceType.EBS, "/dev/sda1", ImmutableMap. of("/dev/sda1", new EbsBlockDevice("snap-d01272b9", 30, true), "xvdf", new EbsBlockDevice("snap-d31272ba", 250, - false)), VirtualizationType.HVM)); + false)), VirtualizationType.HVM, Hypervisor.XEN)); Set result = parseImages("/describe_images_ebs.xml"); diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java index b4879582ec..539ca04da4 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java @@ -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() { diff --git a/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/strategy/EucalyptusPartnerCloudReviseParsedImageTest.java b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/strategy/EucalyptusPartnerCloudReviseParsedImageTest.java index db061a6a74..aff487a339 100644 --- a/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/strategy/EucalyptusPartnerCloudReviseParsedImageTest.java +++ b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/strategy/EucalyptusPartnerCloudReviseParsedImageTest.java @@ -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()); }