scope ec2 image parsing to providers

This commit is contained in:
Adrian Cole 2011-01-26 16:30:44 -08:00
parent bb90123914
commit 81796fafb0
32 changed files with 1084 additions and 1495 deletions

View File

@ -20,8 +20,6 @@
package org.jclouds.ec2.compute.config; package org.jclouds.ec2.compute.config;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX;
import static org.jclouds.compute.domain.OsFamily.CENTOS;
import java.util.Map; import java.util.Map;
@ -31,16 +29,12 @@ import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.ec2.compute.EC2ComputeService; import org.jclouds.ec2.compute.EC2ComputeService;
import org.jclouds.ec2.compute.domain.RegionAndName; import org.jclouds.ec2.compute.domain.RegionAndName;
import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier; import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier;
import org.jclouds.location.Provider;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -57,18 +51,6 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
super.configure(); super.configure();
} }
@Override
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
// TODO: move this into the dependent modules
String provider = injector.getInstance(Key.get(String.class, Provider.class));
if ("aws-ec2".equals(provider))
return template.osFamily(AMZN_LINUX).os64Bit(true);
else if ("nova-ec2".equals(provider))
return super.provideTemplate(injector, template);
else
return template.osFamily(CENTOS);
}
@Provides @Provides
@Singleton @Singleton
protected Supplier<Map<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache( protected Supplier<Map<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(

View File

@ -20,25 +20,21 @@
package org.jclouds.ec2.compute.functions; package org.jclouds.ec2.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrNull; import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrUnrecognized;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.ec2.domain.Image.Architecture;
import org.jclouds.ec2.domain.Image.ImageType;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
@ -46,6 +42,9 @@ import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
import org.jclouds.ec2.domain.Image.Architecture;
import org.jclouds.ec2.domain.Image.ImageType;
import org.jclouds.location.Provider; import org.jclouds.location.Provider;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
@ -59,49 +58,29 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class ImageParser implements Function<org.jclouds.ec2.domain.Image, Image> { public class EC2ImageParser implements Function<org.jclouds.ec2.domain.Image, Image> {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
// nebula/ubuntu-karmic
// nebula/karmic-large
public static final Pattern NEBULA_PATTERN = Pattern.compile("nebula/(ubuntu-)?(.*)(-.*)?");
// 137112412989/amzn-ami-0.9.7-beta.i386-ebs
// 137112412989/amzn-ami-0.9.7-beta.x86_64-ebs
// amzn-ami-us-east-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml
// amzn-ami-us-east-1/amzn-ami-0.9.7-beta.i386.manifest.xml
public static final Pattern AMZN_PATTERN = Pattern
.compile(".*/amzn-ami-(.*)\\.(i386|x86_64)(-ebs|\\.manifest.xml)?");
public static final Pattern CANONICAL_PATTERN = Pattern.compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?");
// ex rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml
public static final Pattern RIGHTSCALE_PATTERN = Pattern
.compile("[^/]*/([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?");
// ex 411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha
// 411009282317/RightImage_Windows_2008_x64_v5.5.5
public static final Pattern RIGHTIMAGE_PATTERN = Pattern
.compile("[^/]*/RightImage[_ ]([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?");
private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider; private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider;
private final Supplier<Set<? extends Location>> locations; private final Supplier<Set<? extends Location>> locations;
private final Supplier<Location> defaultLocation; private final Supplier<Location> defaultLocation;
private final String provider; private final String provider;
private final Map<OsFamily, Map<String, String>> osVersionMap; private final Map<OsFamily, Map<String, String>> osVersionMap;
private final ReviseParsedImage reviseParsedImage;
@Inject @Inject
ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, public
Map<OsFamily, Map<String, String>> osVersionMap, @Memoized Supplier<Set<? extends Location>> locations, EC2ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
Supplier<Location> defaultLocation, @Provider String provider) { Map<OsFamily, Map<String, String>> osVersionMap, @Memoized Supplier<Set<? extends Location>> locations,
Supplier<Location> defaultLocation, @Provider String provider, ReviseParsedImage reviseParsedImage) {
this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider"); this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation"); this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
this.provider = checkNotNull(provider, "provider"); this.provider = checkNotNull(provider, "provider");
this.osVersionMap = checkNotNull(osVersionMap, "utils"); this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap");
this.reviseParsedImage = checkNotNull(reviseParsedImage, "reviseParsedImage");
} }
@Override @Override
@ -115,33 +94,18 @@ public class ImageParser implements Function<org.jclouds.ec2.domain.Image, Image
builder.id(from.getRegion() + "/" + from.getId()); builder.id(from.getRegion() + "/" + from.getId());
builder.description(from.getDescription() != null ? from.getDescription() : from.getImageLocation()); builder.description(from.getDescription() != null ? from.getDescription() : from.getImageLocation());
builder.userMetadata(ImmutableMap.<String, String> of("owner", from.getImageOwnerId(), "rootDeviceType", from builder.userMetadata(ImmutableMap.<String, String> of("owner", from.getImageOwnerId(), "rootDeviceType", from
.getRootDeviceType().toString())); .getRootDeviceType().toString()));
OsFamily osFamily = parseOsFamilyOrNull(provider, from.getImageLocation()); OperatingSystemBuilder osBuilder = new OperatingSystemBuilder();
String osName = null; osBuilder.is64Bit(from.getArchitecture() == Architecture.X86_64);
String osArch = from.getVirtualizationType(); OsFamily family = parseOsFamilyOrUnrecognized(provider, from.getImageLocation());
String osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, from.getImageLocation(), osBuilder.family(family);
osVersionMap); osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, from.getImageLocation(),
String osDescription = from.getImageLocation(); osVersionMap));
boolean is64Bit = from.getArchitecture() == Architecture.X86_64; osBuilder.description(from.getImageLocation());
try { osBuilder.arch(from.getVirtualizationType());
Matcher matcher = getMatcherAndFind(from.getImageLocation());
if (matcher.pattern() == AMZN_PATTERN) { reviseParsedImage.reviseParsedImage(from, builder, family, osBuilder);
osFamily = OsFamily.AMZN_LINUX;
osVersion = matcher.group(1);
builder.version(osVersion);
} else if (matcher.pattern() == NEBULA_PATTERN) {
osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(2), osVersionMap);
} else {
osFamily = OsFamily.fromValue(matcher.group(1));
osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(2), osVersionMap);
builder.version(matcher.group(3).replace(".manifest.xml", ""));
}
} catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", from.getImageLocation());
} catch (NoSuchElementException e) {
logger.debug("<< didn't match at all(%s)", from.getImageLocation());
}
builder.defaultCredentials(credentialProvider.execute(from)); builder.defaultCredentials(credentialProvider.execute(from));
@ -157,24 +121,10 @@ public class ImageParser implements Function<org.jclouds.ec2.domain.Image, Image
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
System.err.printf("unknown region %s for image %s; not in %s", from.getRegion(), from.getId(), locations); System.err.printf("unknown region %s for image %s; not in %s", from.getRegion(), from.getId(), locations);
builder.location(new LocationImpl(LocationScope.REGION, from.getRegion(), from.getRegion(), defaultLocation builder.location(new LocationImpl(LocationScope.REGION, from.getRegion(), from.getRegion(), defaultLocation
.get().getParent())); .get().getParent()));
} }
builder.operatingSystem(new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit)); builder.operatingSystem(osBuilder.build());
return builder.build(); return builder.build();
} }
/**
*
* @throws NoSuchElementException
* if no configured matcher matches the manifest.
*/
private Matcher getMatcherAndFind(String manifest) {
for (Pattern pattern : new Pattern[] { AMZN_PATTERN, NEBULA_PATTERN, CANONICAL_PATTERN, RIGHTIMAGE_PATTERN,
RIGHTSCALE_PATTERN }) {
Matcher matcher = pattern.matcher(manifest);
if (matcher.find())
return matcher;
}
throw new NoSuchElementException(manifest);
}
} }

View File

@ -45,11 +45,11 @@ public final class RegionAndIdToImage implements Function<RegionAndName, Image>
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final ImageParser parser; private final EC2ImageParser parser;
private final EC2Client sync; private final EC2Client sync;
@Inject @Inject
public RegionAndIdToImage(ImageParser parser, EC2Client sync) { public RegionAndIdToImage(EC2ImageParser parser, EC2Client sync) {
this.parser = parser; this.parser = parser;
this.sync = sync; this.sync = sync;
} }

View File

@ -0,0 +1,49 @@
/**
*
/**
*
* Copyright (C) 2010 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.compute.strategy;
import javax.inject.Singleton;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import com.google.inject.ImplementedBy;
/**
*
* @author Adrian Cole
*/
@ImplementedBy(ReviseParsedImage.NoopReviseParsedImage.class)
public interface ReviseParsedImage {
void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family,
OperatingSystemBuilder osBuilder);
@Singleton
public static class NoopReviseParsedImage implements ReviseParsedImage {
@Override
public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family,
OperatingSystemBuilder osBuilder) {
}
}
}

View File

@ -58,7 +58,7 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.ec2.compute.domain.RegionAndName; import org.jclouds.ec2.compute.domain.RegionAndName;
import org.jclouds.ec2.compute.functions.ImageParser; import org.jclouds.ec2.compute.functions.EC2ImageParser;
import org.jclouds.ec2.compute.strategy.DescribeImagesParallel; import org.jclouds.ec2.compute.strategy.DescribeImagesParallel;
import org.jclouds.ec2.options.DescribeImagesOptions; import org.jclouds.ec2.options.DescribeImagesOptions;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
@ -86,13 +86,13 @@ public class RegionAndNameToImageSupplier implements Supplier<Map<RegionAndName,
private final DescribeImagesParallel describer; private final DescribeImagesParallel describer;
private final String[] ccAmis; private final String[] ccAmis;
private final String[] amiOwners; private final String[] amiOwners;
private final ImageParser parser; private final EC2ImageParser parser;
private final Map<RegionAndName, Image> images; private final Map<RegionAndName, Image> images;
@Inject @Inject
RegionAndNameToImageSupplier(@Region Set<String> regions, DescribeImagesParallel describer, RegionAndNameToImageSupplier(@Region Set<String> regions, DescribeImagesParallel describer,
@Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis, @Named(PROPERTY_EC2_AMI_OWNERS) final String[] amiOwners, @Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis, @Named(PROPERTY_EC2_AMI_OWNERS) final String[] amiOwners,
final ImageParser parser, final Map<RegionAndName, Image> images) { final EC2ImageParser parser, final Map<RegionAndName, Image> images) {
this.regions = regions; this.regions = regions;
this.describer = describer; this.describer = describer;
this.ccAmis = ccAmis; this.ccAmis = ccAmis;

View File

@ -0,0 +1,92 @@
/**
*
* Copyright (C) 2010 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.compute.functions;
import static org.testng.Assert.assertEquals;
import java.util.Map;
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.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.xml.DescribeImagesResponseHandlerTest;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.base.Predicates;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
public class EC2ImageParserTest {
public void testParseAmznImage() {
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(
"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(
"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(
ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
}
static Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null);
public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class));
Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map,
Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
.ofInstance(defaultLocation), "ec2", new ReviseParsedImage.NoopReviseParsedImage());
return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
}
}

View File

@ -1,233 +0,0 @@
/**
*
* Copyright (C) 2010 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.compute.functions;
import static org.testng.Assert.assertEquals;
import java.util.Map;
import java.util.Set;
import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.xml.DescribeImagesResponseHandlerTest;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.base.Predicates;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.inject.Guice;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ImageParserTest {
public void testParseAlesticCanonicalImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/alestic_canonical.xml");
assertEquals(
Iterables.get(result, 0),
new ImageBuilder()
.operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("8.04")
.description("ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml")
.is64Bit(false).build())
.description("ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml")
.defaultCredentials(new Credentials("ubuntu", null)).id("us-east-1/ami-7e28ca17")
.providerId("ami-7e28ca17").location(defaultLocation).version("20091130")
.userMetadata(ImmutableMap.of("owner", "099720109477", "rootDeviceType", "instance-store")).build());
assertEquals(
Iterables.get(result, 4),
new ImageBuilder()
.operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("8.04")
.description("alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml").is64Bit(false)
.build()).description("alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml")
.defaultCredentials(new Credentials("ubuntu", null)).id("us-east-1/ami-c0fa1ea9")
.providerId("ami-c0fa1ea9").location(defaultLocation).version("20080905")
.userMetadata(ImmutableMap.of("owner", "063491364108", "rootDeviceType", "instance-store")).build());
assertEquals(
Iterables.get(result, 6),
new ImageBuilder()
.operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("10.04")
.description("099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827")
.is64Bit(false).build())
.description("099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827")
.defaultCredentials(new Credentials("ubuntu", null)).id("us-east-1/ami-10f3a255")
.providerId("ami-10f3a255").location(defaultLocation).version("20100827")
.userMetadata(ImmutableMap.of("owner", "099720109477", "rootDeviceType", "ebs")).build());
}
public void testParseVostokImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/vostok.xml");
assertEquals(
Iterables.get(result, 0),
new ImageBuilder()
.operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("")
.description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml")
.is64Bit(false).build())
.description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml")
.defaultCredentials(new Credentials("root", null)).id("us-east-1/ami-870de2ee")
.providerId("ami-870de2ee").location(defaultLocation).version("5622")
.userMetadata(ImmutableMap.of("owner", "133804938231", "rootDeviceType", "instance-store")).build());
}
public void testParseCCImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/describe_images_cc.xml");
assertEquals(
Iterables.get(result, 0),
new ImageBuilder()
.operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("hvm").version("5.4")
.description("amazon/EC2 CentOS 5.4 HVM AMI").is64Bit(true).build())
.description("EC2 CentOS 5.4 HVM AMI").defaultCredentials(new Credentials("root", null))
.id("us-east-1/ami-7ea24a17").providerId("ami-7ea24a17").location(defaultLocation)
.userMetadata(ImmutableMap.of("owner", "206029621532", "rootDeviceType", "ebs")).build());
}
public void testParseRightScaleImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/rightscale_images.xml");
assertEquals(
Iterables.get(result, 0),
new ImageBuilder()
.operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.4")
.description("rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml").is64Bit(true)
.build()).description("rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml")
.defaultCredentials(new Credentials("root", null)).id("us-east-1/ami-ccb35ea5")
.providerId("ami-ccb35ea5").location(defaultLocation).version("4.4.10")
.userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build());
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\",\"providerId\":\"ami-c19db6b5\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
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\",\"providerId\":\"ami-710c2605\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
}
public void testParseEucalyptusImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/eucalyptus_images.xml");
assertEquals(
Iterables.get(result, 0),
new ImageBuilder()
.operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.3")
.description("centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml").is64Bit(true)
.build()).description("centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml")
.defaultCredentials(new Credentials("root", null)).id("us-east-1/emi-9ACB1363")
.providerId("emi-9ACB1363").location(defaultLocation)
.userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build());
}
public void testParseAmznImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/amzn_images.xml");
assertEquals(
Iterables.get(result, 0),
new ImageBuilder()
.operatingSystem(
new OperatingSystemBuilder().family(OsFamily.AMZN_LINUX).arch("paravirtual")
.version("0.9.7-beta").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).version("0.9.7-beta")
.userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
assertEquals(
Iterables.get(result, 3),
new ImageBuilder()
.operatingSystem(
new OperatingSystemBuilder().family(OsFamily.AMZN_LINUX).arch("paravirtual")
.version("0.9.7-beta")
.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).version("0.9.7-beta")
.userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
}
public void testParseNovaImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/nova_images.xml");
assertEquals(
new Gson().toJson(Iterables.get(result, 0)),
"{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"nasacms/image.manifest.xml\",\"is64Bit\":true},\"description\":\"nasacms/image.manifest.xml\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-h30p5im0\",\"type\":\"IMAGE\",\"providerId\":\"ami-h30p5im0\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"foo\",\"rootDeviceType\":\"instance-store\"}}");
assertEquals(
new Gson().toJson(Iterables.get(result, 1)),
"{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"nebula/tiny\",\"is64Bit\":true},\"description\":\"nebula/tiny\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-tiny\",\"type\":\"IMAGE\",\"providerId\":\"ami-tiny\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"vishvananda\",\"rootDeviceType\":\"instance-store\"}}");
assertEquals(
new Gson().toJson(Iterables.get(result, 2)),
"{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"demos/mediawiki\",\"is64Bit\":true},\"description\":\"demos/mediawiki\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-630A130F\",\"type\":\"IMAGE\",\"providerId\":\"ami-630A130F\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"admin\",\"rootDeviceType\":\"instance-store\"}}");
assertEquals(
new Gson().toJson(Iterables.get(result, 3)),
"{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"pinglet/instances\",\"is64Bit\":true},\"description\":\"pinglet/instances\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-pinginst\",\"type\":\"IMAGE\",\"providerId\":\"ami-pinginst\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"admin\",\"rootDeviceType\":\"instance-store\"}}");
}
static Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null);
public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class));
Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map,
Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)),
Suppliers.ofInstance(defaultLocation), "ec2");
return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
}
}

View File

@ -49,7 +49,7 @@ public class RegionAndIdToImageTest {
@Test @Test
public void testApply() { public void testApply() {
ImageParser parser = createMock(ImageParser.class); EC2ImageParser parser = createMock(EC2ImageParser.class);
EC2Client caller = createMock(EC2Client.class); EC2Client caller = createMock(EC2Client.class);
AMIClient client = createMock(AMIClient.class); AMIClient client = createMock(AMIClient.class);
org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class); org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class);
@ -80,7 +80,7 @@ public class RegionAndIdToImageTest {
@Test @Test
public void testApplyNotFound() { public void testApplyNotFound() {
ImageParser parser = createMock(ImageParser.class); EC2ImageParser parser = createMock(EC2ImageParser.class);
EC2Client caller = createMock(EC2Client.class); EC2Client caller = createMock(EC2Client.class);
AMIClient client = createMock(AMIClient.class); AMIClient client = createMock(AMIClient.class);
org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class); org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class);
@ -111,7 +111,7 @@ public class RegionAndIdToImageTest {
@Test @Test
public void testApplyNoSuchElementException() { public void testApplyNoSuchElementException() {
ImageParser parser = createMock(ImageParser.class); EC2ImageParser parser = createMock(EC2ImageParser.class);
EC2Client caller = createMock(EC2Client.class); EC2Client caller = createMock(EC2Client.class);
AMIClient client = createMock(AMIClient.class); AMIClient client = createMock(AMIClient.class);
org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class); org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class);

View File

@ -24,7 +24,7 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import java.util.Set; import java.util.Set;
import org.jclouds.ec2.compute.functions.ImageParserTest; import org.jclouds.ec2.compute.functions.EC2ImageParserTest;
import org.jclouds.ec2.domain.Image; import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.domain.Image.Architecture; import org.jclouds.ec2.domain.Image.Architecture;
import org.jclouds.ec2.domain.Image.EbsBlockDevice; import org.jclouds.ec2.domain.Image.EbsBlockDevice;
@ -100,7 +100,7 @@ public class DescribeImagesResponseHandlerTest {
} }
public static Set<Image> parseImages(String resource) { public static Set<Image> parseImages(String resource) {
InputStream is = ImageParserTest.class.getResourceAsStream(resource); InputStream is = EC2ImageParserTest.class.getResourceAsStream(resource);
return createParser().parse(is); return createParser().parse(is);
} }
} }

View File

@ -134,7 +134,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
Set<Reservation<? extends RunningInstance>> contents = Sets.newLinkedHashSet(); Set<Reservation<? extends RunningInstance>> contents = Sets.newLinkedHashSet();
contents.add(new Reservation<RunningInstance>(defaultRegion, ImmutableSet.of("default"), ImmutableSet contents.add(new Reservation<RunningInstance>(defaultRegion, ImmutableSet.of("default"), ImmutableSet
.of(new RunningInstance(defaultRegion, ImmutableSet.<String> of(), "0", null, "ami-25CB1213", "i-9slweygo", .of(new RunningInstance(defaultRegion, ImmutableSet.<String> of(), "0", null, "ami-82e4b5c7", "i-9slweygo",
InstanceState.TERMINATED, InstanceType.M1_SMALL, null, null, "nebulatanimislam", dateService InstanceState.TERMINATED, InstanceType.M1_SMALL, null, null, "nebulatanimislam", dateService
.iso8601SecondsDateParse("2010-09-09T18:09:42Z"), null, null, null, "paravirtual", null, null, .iso8601SecondsDateParse("2010-09-09T18:09:42Z"), null, null, null, "paravirtual", null, null,
"10.128.207.5", ImmutableSet.<String> of("None"), null, null, null, null, null, "10.128.207.5", ImmutableSet.<String> of("None"), null, null, null, null, null,

View File

@ -11,7 +11,7 @@
<dnsName /> <dnsName />
<launchTime>2010-09-09T18:09:42Z</launchTime> <launchTime>2010-09-09T18:09:42Z</launchTime>
<instanceId>i-9slweygo</instanceId> <instanceId>i-9slweygo</instanceId>
<imageId>ami-25CB1213</imageId> <imageId>ami-82e4b5c7</imageId>
<instanceState> <instanceState>
<code>1</code> <code>1</code>
<name>shutdown</name> <name>shutdown</name>

View File

@ -1,49 +0,0 @@
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2010-06-15/">
<requestId>2564fc86-9a73-4727-9298-f0b9eb9b57c8</requestId>
<imagesSet>
<item>
<imageId>emi-9ACB1363</imageId>
<imageLocation>centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>machine</imageType>
<kernelId>eki-6CBD12F2</kernelId>
<ramdiskId>eri-A97113E4</ramdiskId>
</item>
<item>
<imageId>eri-A97113E4</imageId>
<imageLocation>initrd-64/initrd.img-2.6.28-11-generic.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>ramdisk</imageType>
</item>
<item>
<imageId>eki-6CBD12F2</imageId>
<imageLocation>kernel-64/vmlinuz-2.6.28-11-generic.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>kernel</imageType>
</item>
<item>
<imageId>emi-B5C5103A</imageId>
<imageLocation>shashi-test/RTestSmall.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>machine</imageType>
<kernelId>eki-6CBD12F2</kernelId>
<ramdiskId>eri-A97113E4</ramdiskId>
</item>
</imagesSet>
</DescribeImagesResponse>

View File

@ -1,179 +0,0 @@
<?xml version="1.0" ?>
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
<requestId>RX9NL9IWKIR11XL8ZLFR</requestId>
<imagesSet>
<item>
<imageOwnerId>foo</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-h30p5im0</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nasacms/image.manifest.xml</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ari-lucid</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nebula/lucid-ramdisk</imageLocation>
<type>ramdisk</type>
</item>
<item>
<imageOwnerId>vishvananda</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-tiny</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nebula/tiny</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-630A130F</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>demos/mediawiki</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<imageId>aki-edge</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nebula/bleeding-edge-kernel</imageLocation>
<type>kernel</type>
</item>
<item>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ari-edge</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nebula/bleeding-edge-ramdisk</imageLocation>
<type>ramdisk</type>
</item>
<item>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<imageId>aki-lucid</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nebula/lucid-kernel</imageLocation>
<type>kernel</type>
</item>
<item>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-pinginst</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>pinglet/instances</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>rkumar2</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-alqbihe2</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>bucket/testbuntu.manifest.xml</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>ykliu</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-i0aemtfp</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>gfortran-bucket/gfortran.manifest.xml
</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ari-22F211EF</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nebula/ramdisk</imageLocation>
<type>ramdisk</type>
</item>
<item>
<imageOwnerId>foo</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-2ig7w1bh</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>grinder/grinder-analyzer.manifest.xml
</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<imageId>aki-EAB510D9</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nebula/kernel</imageLocation>
<type>kernel</type>
</item>
<item>
<imageOwnerId>vishvananda</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-lucid</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nebula/lucid</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-karmiclg</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nebula/karmic-large</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>jyothi</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-8jen8kdn</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>jo/qa-grinder.manifest.xml</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>vishvananda</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-lucidlg</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nebula/lucid-large</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-6CD61336</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>demos/wordpress</imageLocation>
<type>machine</type>
</item>
<item>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<imageId>ami-25CB1213</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>nebula/ubuntu-karmic</imageLocation>
<type>machine</type>
</item>
</imagesSet>
</DescribeImagesResponse>

View File

@ -20,7 +20,7 @@
package org.jclouds.vcloud.compute.functions; package org.jclouds.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrNull; import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrUnrecognized;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -81,7 +81,7 @@ public class ImageForVCloudExpressVAppTemplate implements Function<VCloudExpress
protected OperatingSystem parseOs(VCloudExpressVAppTemplate from) { protected OperatingSystem parseOs(VCloudExpressVAppTemplate from) {
OperatingSystemBuilder builder = new OperatingSystemBuilder(); OperatingSystemBuilder builder = new OperatingSystemBuilder();
OsFamily osFamily = parseOsFamilyOrNull("vcloudexpress", checkNotNull(from, "vapp template").getName()); OsFamily osFamily = parseOsFamilyOrUnrecognized("vcloudexpress", checkNotNull(from, "vapp template").getName());
builder.family(osFamily); builder.family(osFamily);
builder.description(from.getName()); builder.description(from.getName());
builder.is64Bit(from.getName().indexOf("64") != -1); builder.is64Bit(from.getName().indexOf("64") != -1);

View File

@ -132,7 +132,7 @@ public class ComputeServiceUtils {
return total; return total;
} }
public static org.jclouds.compute.domain.OsFamily parseOsFamilyOrNull(String provider, String in) { public static org.jclouds.compute.domain.OsFamily parseOsFamilyOrUnrecognized(String provider, String in) {
org.jclouds.compute.domain.OsFamily myOs = null; org.jclouds.compute.domain.OsFamily myOs = null;
for (org.jclouds.compute.domain.OsFamily os : org.jclouds.compute.domain.OsFamily.values()) { for (org.jclouds.compute.domain.OsFamily os : org.jclouds.compute.domain.OsFamily.values()) {
if (in.toLowerCase().replaceAll("\\s", "").indexOf(os.toString()) != -1) { if (in.toLowerCase().replaceAll("\\s", "").indexOf(os.toString()) != -1) {
@ -142,7 +142,7 @@ public class ComputeServiceUtils {
if (myOs == null && provider.indexOf("nebula") != -1) { if (myOs == null && provider.indexOf("nebula") != -1) {
myOs = OsFamily.UBUNTU; myOs = OsFamily.UBUNTU;
} }
return myOs; return OsFamily.UNRECOGNIZED;
} }
public static String createExecutionErrorMessage(Map<?, Exception> executionExceptions) { public static String createExecutionErrorMessage(Map<?, Exception> executionExceptions) {

View File

@ -62,7 +62,7 @@ aws-s3.propertiesbuilder=org.jclouds.aws.s3.AWSS3PropertiesBuilder
ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder
ec2.propertiesbuilder=org.jclouds.ec2.EC2PropertiesBuilder ec2.propertiesbuilder=org.jclouds.ec2.EC2PropertiesBuilder
aws-ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder aws-ec2.contextbuilder=org.jclouds.aws.ec2.AWSEC2ContextBuilder
aws-ec2.propertiesbuilder=org.jclouds.aws.ec2.AWSEC2PropertiesBuilder aws-ec2.propertiesbuilder=org.jclouds.aws.ec2.AWSEC2PropertiesBuilder
rimuhosting.contextbuilder=org.jclouds.rimuhosting.miro.RimuHostingContextBuilder rimuhosting.contextbuilder=org.jclouds.rimuhosting.miro.RimuHostingContextBuilder
@ -95,8 +95,8 @@ vcloudexpress.propertiesbuilder=org.jclouds.vcloud.VCloudExpressPropertiesBuilde
eucalyptus.contextbuilder=org.jclouds.ec2.EC2ContextBuilder eucalyptus.contextbuilder=org.jclouds.ec2.EC2ContextBuilder
eucalyptus.propertiesbuilder=org.jclouds.eucalyptus.EucalyptusPropertiesBuilder eucalyptus.propertiesbuilder=org.jclouds.eucalyptus.EucalyptusPropertiesBuilder
eucalyptus-partnercloud-ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder eucalyptus-partnercloud-ec2.contextbuilder=org.jclouds.epc.EucalyptusPartnerCloudContextBuilder
eucalyptus-partnercloud-ec2.propertiesbuilder=org.jclouds.epc.EucalyptusPartnerCloudEucalyptusPropertiesBuilder eucalyptus-partnercloud-ec2.propertiesbuilder=org.jclouds.epc.EucalyptusPartnerCloudPropertiesBuilder
nova-ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder nova-ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder
nova-ec2.propertiesbuilder=org.jclouds.nova.ec2.NovaEC2PropertiesBuilder nova-ec2.propertiesbuilder=org.jclouds.nova.ec2.NovaEC2PropertiesBuilder

View File

@ -0,0 +1,45 @@
/**
*
* Copyright (C) 2010 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.aws.ec2;
import java.util.List;
import java.util.Properties;
import org.jclouds.aws.ec2.config.AWSEC2ComputeServiceContextModule;
import org.jclouds.ec2.EC2ContextBuilder;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
*/
public class AWSEC2ContextBuilder extends EC2ContextBuilder {
public AWSEC2ContextBuilder(Properties props) {
super(props);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new AWSEC2ComputeServiceContextModule());
}
}

View File

@ -0,0 +1,48 @@
/**
*
* Copyright (C) 2010 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.aws.ec2.config;
import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX;
import org.jclouds.aws.ec2.strategy.AWSEC2ReviseParsedImage;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule;
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
import com.google.inject.Injector;
/**
*
* @author Adrian Cole
*/
public class AWSEC2ComputeServiceContextModule extends EC2ComputeServiceContextModule {
@Override
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
return template.osFamily(AMZN_LINUX).os64Bit(true);
}
@Override
protected void configure() {
super.configure();
bind(ReviseParsedImage.class).to(AWSEC2ReviseParsedImage.class);
}
}

View File

@ -0,0 +1,121 @@
/**
*
* Copyright (C) 2010 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.aws.ec2.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
import org.jclouds.logging.Logger;
/**
* @author Adrian Cole
*/
@Singleton
public class AWSEC2ReviseParsedImage implements ReviseParsedImage {
// 137112412989/amzn-ami-0.9.7-beta.i386-ebs
// 137112412989/amzn-ami-0.9.7-beta.x86_64-ebs
// amzn-ami-us-east-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml
// amzn-ami-us-east-1/amzn-ami-0.9.7-beta.i386.manifest.xml
public static final Pattern AMZN_PATTERN = Pattern
.compile(".*/amzn-ami-(.*)\\.(i386|x86_64)(-ebs|\\.manifest.xml)?");
// amazon/EC2 CentOS 5.4 HVM AMI
public static final Pattern AMAZON_PATTERN = Pattern.compile("amazon/EC2 ([^ ]+) ([^ ]+).*");
public static final Pattern CANONICAL_PATTERN = Pattern.compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?");
// ex rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml
public static final Pattern RIGHTSCALE_PATTERN = Pattern
.compile("[^/]*/([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?");
// ex 411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha
// 411009282317/RightImage_Windows_2008_x64_v5.5.5
public static final Pattern RIGHTIMAGE_PATTERN = Pattern
.compile("[^/]*/RightImage[_ ]([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?");
private final Map<OsFamily, Map<String, String>> osVersionMap;
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
@Inject
public AWSEC2ReviseParsedImage(Map<OsFamily, Map<String, String>> osVersionMap) {
this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap");
}
@Override
public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family,
OperatingSystemBuilder osBuilder) {
try {
Matcher matcher = getMatcherAndFind(from.getImageLocation());
if (matcher.pattern() == AMZN_PATTERN) {
osBuilder.family(OsFamily.AMZN_LINUX);
osBuilder.version(matcher.group(1));
builder.version(matcher.group(1));
} else if (matcher.pattern() == AMAZON_PATTERN) {
family = OsFamily.fromValue(matcher.group(1));
osBuilder.family(family);
osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, matcher.group(2),
osVersionMap));
} else {
family = OsFamily.fromValue(matcher.group(1));
osBuilder.family(family);
osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, matcher.group(2),
osVersionMap));
builder.version(matcher.group(3).replace(".manifest.xml", ""));
}
} catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", from.getImageLocation());
} catch (NoSuchElementException e) {
logger.debug("<< didn't match at all(%s)", from.getImageLocation());
}
}
/**
*
* @throws NoSuchElementException
* if no configured matcher matches the manifest.
*/
private Matcher getMatcherAndFind(String manifest) {
for (Pattern pattern : new Pattern[] { AMZN_PATTERN, AMAZON_PATTERN, CANONICAL_PATTERN, RIGHTIMAGE_PATTERN,
RIGHTSCALE_PATTERN }) {
Matcher matcher = pattern.matcher(manifest);
if (matcher.find())
return matcher;
}
throw new NoSuchElementException(manifest);
}
}

View File

@ -0,0 +1,170 @@
/**
*
* Copyright (C) 2010 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.aws.ec2.strategy;
import static org.testng.Assert.assertEquals;
import java.util.Map;
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.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.ec2.compute.functions.EC2ImageParser;
import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.xml.DescribeImagesResponseHandlerTest;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.base.Predicates;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.inject.Guice;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
public class AWSEC2ImageParserTest {
public void testParseAlesticCanonicalImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/alestic_canonical.xml");
assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("8.04").description(
"ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml").is64Bit(false).build())
.description("ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml").defaultCredentials(
new Credentials("ubuntu", null)).id("us-east-1/ami-7e28ca17").providerId("ami-7e28ca17")
.location(defaultLocation).version("20091130").userMetadata(
ImmutableMap.of("owner", "099720109477", "rootDeviceType", "instance-store")).build());
assertEquals(Iterables.get(result, 4), new ImageBuilder().operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("8.04").description(
"alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml").is64Bit(false).build()).description(
"alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml").defaultCredentials(
new Credentials("ubuntu", null)).id("us-east-1/ami-c0fa1ea9").providerId("ami-c0fa1ea9").location(
defaultLocation).version("20080905").userMetadata(
ImmutableMap.of("owner", "063491364108", "rootDeviceType", "instance-store")).build());
assertEquals(Iterables.get(result, 6), new ImageBuilder().operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("10.04").description(
"099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827").is64Bit(false)
.build()).description("099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827")
.defaultCredentials(new Credentials("ubuntu", null)).id("us-east-1/ami-10f3a255").providerId(
"ami-10f3a255").location(defaultLocation).version("20100827").userMetadata(
ImmutableMap.of("owner", "099720109477", "rootDeviceType", "ebs")).build());
}
public void testParseVostokImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/vostok.xml");
assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description(
"vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml").is64Bit(false).build())
.description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml").defaultCredentials(
new Credentials("root", null)).id("us-east-1/ami-870de2ee").providerId("ami-870de2ee")
.location(defaultLocation).version("5622").userMetadata(
ImmutableMap.of("owner", "133804938231", "rootDeviceType", "instance-store")).build());
}
public void testParseCCImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/describe_images_cc.xml");
assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("hvm").version("5.4").description(
"amazon/EC2 CentOS 5.4 HVM AMI").is64Bit(true).build()).description("EC2 CentOS 5.4 HVM AMI")
.defaultCredentials(new Credentials("root", null)).id("us-east-1/ami-7ea24a17").providerId(
"ami-7ea24a17").location(defaultLocation).userMetadata(
ImmutableMap.of("owner", "206029621532", "rootDeviceType", "ebs")).build());
}
public void testParseRightScaleImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/rightscale_images.xml");
assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.4").description(
"rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml").is64Bit(true).build()).description(
"rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml").defaultCredentials(
new Credentials("root", null)).id("us-east-1/ami-ccb35ea5").providerId("ami-ccb35ea5").location(
defaultLocation).version("4.4.10").userMetadata(
ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build());
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\",\"providerId\":\"ami-c19db6b5\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
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\",\"providerId\":\"ami-710c2605\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
}
public void testParseAmznImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/amzn_images.xml");
assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem(
new OperatingSystemBuilder().family(OsFamily.AMZN_LINUX).arch("paravirtual").version("0.9.7-beta")
.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).version("0.9.7-beta").userMetadata(
ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
assertEquals(Iterables.get(result, 3), new ImageBuilder().operatingSystem(
new OperatingSystemBuilder().family(OsFamily.AMZN_LINUX).arch("paravirtual").version("0.9.7-beta")
.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).version("0.9.7-beta").userMetadata(
ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
}
static Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null);
public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class));
Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map,
Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
.ofInstance(defaultLocation), "ec2", new AWSEC2ReviseParsedImage(map));
return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
}
}

View File

@ -0,0 +1,86 @@
<?xml version="1.0"?>
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
<requestId>6104eee1-affd-49d7-92a0-516cab8a8ba6</requestId>
<imagesSet>
<item>
<imageId>ami-82e4b5c7</imageId>
<imageLocation>137112412989/amzn-ami-0.9.7-beta.i386-ebs</imageLocation>
<imageState>available</imageState>
<imageOwnerId>137112412989</imageOwnerId>
<isPublic>true</isPublic>
<architecture>i386</architecture>
<imageType>machine</imageType>
<kernelId>aki-99a0f1dc</kernelId>
<name>amzn-ami-0.9.7-beta.i386-ebs</name>
<description>Amazon</description>
<rootDeviceType>ebs</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<blockDeviceMapping>
<item>
<deviceName>/dev/sda1</deviceName>
<ebs>
<snapshotId>snap-e98b7b82</snapshotId>
<volumeSize>10</volumeSize>
<deleteOnTermination>true</deleteOnTermination>
</ebs>
</item>
</blockDeviceMapping>
<virtualizationType>paravirtual</virtualizationType>
</item>
<item>
<imageId>ami-8ce4b5c9</imageId>
<imageLocation>137112412989/amzn-ami-0.9.7-beta.x86_64-ebs</imageLocation>
<imageState>available</imageState>
<imageOwnerId>137112412989</imageOwnerId>
<isPublic>true</isPublic>
<architecture>x86_64</architecture>
<imageType>machine</imageType>
<kernelId>aki-9ba0f1de</kernelId>
<name>amzn-ami-0.9.7-beta.x86_64-ebs</name>
<description>Amazon</description>
<rootDeviceType>ebs</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<blockDeviceMapping>
<item>
<deviceName>/dev/sda1</deviceName>
<ebs>
<snapshotId>snap-8d8b7be6</snapshotId>
<volumeSize>10</volumeSize>
<deleteOnTermination>true</deleteOnTermination>
</ebs>
</item>
</blockDeviceMapping>
<virtualizationType>paravirtual</virtualizationType>
</item>
<item>
<imageId>ami-f0e4b5b5</imageId>
<imageLocation>amzn-ami-us-west-1/amzn-ami-0.9.7-beta.i386.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>137112412989</imageOwnerId>
<isPublic>true</isPublic>
<architecture>i386</architecture>
<imageType>machine</imageType>
<kernelId>aki-99a0f1dc</kernelId>
<name>amzn-ami-0.9.7-beta.i386-S3</name>
<description>Amazon Linux AMI i386 S3</description>
<rootDeviceType>instance-store</rootDeviceType>
<blockDeviceMapping/>
<virtualizationType>paravirtual</virtualizationType>
</item>
<item>
<imageId>ami-f2e4b5b7</imageId>
<imageLocation>amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>137112412989</imageOwnerId>
<isPublic>true</isPublic>
<architecture>x86_64</architecture>
<imageType>machine</imageType>
<kernelId>aki-9ba0f1de</kernelId>
<name>amzn-ami-0.9.7-beta.x86_64-S3</name>
<description>Amazon Linux AMI x86_64 S3</description>
<rootDeviceType>instance-store</rootDeviceType>
<blockDeviceMapping/>
<virtualizationType>paravirtual</virtualizationType>
</item>
</imagesSet>
</DescribeImagesResponse>

View File

@ -0,0 +1,45 @@
/**
*
* Copyright (C) 2010 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.epc;
import java.util.List;
import java.util.Properties;
import org.jclouds.ec2.EC2ContextBuilder;
import org.jclouds.epc.config.EucalyptusPartnerCloudComputeServiceContextModule;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
*/
public class EucalyptusPartnerCloudContextBuilder extends EC2ContextBuilder {
public EucalyptusPartnerCloudContextBuilder(Properties props) {
super(props);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new EucalyptusPartnerCloudComputeServiceContextModule());
}
}

View File

@ -30,7 +30,7 @@ import org.jclouds.eucalyptus.EucalyptusPropertiesBuilder;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class EucalyptusPartnerCloudEucalyptusPropertiesBuilder extends EucalyptusPropertiesBuilder { public class EucalyptusPartnerCloudPropertiesBuilder extends EucalyptusPropertiesBuilder {
@Override @Override
protected Properties defaultProperties() { protected Properties defaultProperties() {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
@ -38,7 +38,7 @@ public class EucalyptusPartnerCloudEucalyptusPropertiesBuilder extends Eucalyptu
return properties; return properties;
} }
public EucalyptusPartnerCloudEucalyptusPropertiesBuilder(Properties properties) { public EucalyptusPartnerCloudPropertiesBuilder(Properties properties) {
super(properties); super(properties);
} }

View File

@ -0,0 +1,48 @@
/**
*
* Copyright (C) 2010 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.epc.config;
import static org.jclouds.compute.domain.OsFamily.CENTOS;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule;
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
import org.jclouds.epc.strategy.EucalyptusPartnerCloudReviseParsedImage;
import com.google.inject.Injector;
/**
*
* @author Adrian Cole
*/
public class EucalyptusPartnerCloudComputeServiceContextModule extends EC2ComputeServiceContextModule {
@Override
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
return template.osFamily(CENTOS);
}
@Override
protected void configure() {
super.configure();
bind(ReviseParsedImage.class).to(EucalyptusPartnerCloudReviseParsedImage.class);
}
}

View File

@ -0,0 +1,90 @@
/**
*
* Copyright (C) 2010 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.epc.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
import org.jclouds.logging.Logger;
/**
* @author Adrian Cole
*/
@Singleton
public class EucalyptusPartnerCloudReviseParsedImage implements ReviseParsedImage {
// centos-5.3-x86_64-xen/centos.5-3.x86-64.img.manifest.xml
public static final Pattern PATTERN = Pattern.compile("^([^-]+)-([^-]+)-.*");
public static final Pattern WINDOWS = Pattern.compile("^windows-([^/]+)/.*");
private final Map<OsFamily, Map<String, String>> osVersionMap;
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
@Inject
public EucalyptusPartnerCloudReviseParsedImage(Map<OsFamily, Map<String, String>> osVersionMap) {
this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap");
}
@Override
public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family,
OperatingSystemBuilder osBuilder) {
try {
if (from.getImageLocation().startsWith("windows")) {
family = OsFamily.WINDOWS;
osBuilder.family(family);
Matcher matcher = WINDOWS.matcher(from.getImageLocation());
if (matcher.find()) {
osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, matcher.group(1).replace(
'-', ' ').replace('s', 'S'), osVersionMap));
}
} else {
Matcher matcher = PATTERN.matcher(from.getImageLocation());
if (matcher.find()) {
family = OsFamily.fromValue(matcher.group(1));
osBuilder.family(family);
osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, matcher.group(2),
osVersionMap));
}
}
} catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", from.getImageLocation());
} catch (NoSuchElementException e) {
logger.debug("<< didn't match at all(%s)", from.getImageLocation());
}
}
}

View File

@ -0,0 +1,104 @@
/**
*
* Copyright (C) 2010 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.epc.compute.strategy;
import static org.testng.Assert.assertEquals;
import java.util.Map;
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.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.ec2.compute.functions.EC2ImageParser;
import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.xml.DescribeImagesResponseHandlerTest;
import org.jclouds.epc.strategy.EucalyptusPartnerCloudReviseParsedImage;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.base.Predicates;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
public class EucalyptusPartnerCloudReviseParsedImageTest {
public void testParseEucalyptusImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/eucalyptus_images.xml");
assertEquals(result.size(), 3);
assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.3").description(
"centos-5.3-x86_64-xen/centos.5-3.x86-64.img.manifest.xml").is64Bit(true).build()).description(
"centos-5.3-x86_64-xen/centos.5-3.x86-64.img.manifest.xml").defaultCredentials(
new Credentials("root", null)).id("us-east-1/emi-F96014E1").providerId("emi-F96014E1").location(
defaultLocation).userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store"))
.build());
assertEquals(Iterables.get(result, 1), new ImageBuilder().operatingSystem(
new OperatingSystemBuilder().family(OsFamily.WINDOWS).arch("paravirtual").version("2008").description(
"windows-2008-server/windows.my2008server.img.manifest.xml").is64Bit(true).build())
.description("windows-2008-server/windows.my2008server.img.manifest.xml").defaultCredentials(
new Credentials("root", null)).id("us-east-1/emi-767B178C").providerId("emi-767B178C")
.location(defaultLocation).userMetadata(
ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build());
assertEquals(Iterables.get(result, 2), new ImageBuilder().operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.3").description(
"centos-5.3-x86_64-kvm/centos.5-3.x86-64.img.manifest.xml").is64Bit(true).build()).description(
"centos-5.3-x86_64-kvm/centos.5-3.x86-64.img.manifest.xml").defaultCredentials(
new Credentials("root", null)).id("us-east-1/emi-F9ED14E7").providerId("emi-F9ED14E7").location(
defaultLocation).userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store"))
.build());
}
static Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null);
public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class));
Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map,
Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
.ofInstance(defaultLocation), "ec2", new EucalyptusPartnerCloudReviseParsedImage(map));
return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
}
}

View File

@ -0,0 +1,108 @@
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2010-06-15/">
<requestId>0bd968c0-b1d2-41bd-ad04-fc35017b5110</requestId>
<imagesSet>
<item>
<imageId>eri-91061322</imageId>
<imageLocation>initrd-64-xen/initrd-2.6.27.21-0.1-xen.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>ramdisk</imageType>
<platform>linux</platform>
</item>
<item>
<imageId>emi-F96014E1</imageId>
<imageLocation>centos-5.3-x86_64-xen/centos.5-3.x86-64.img.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>machine</imageType>
<kernelId>eki-AE7F138B</kernelId>
<ramdiskId>eri-91061322</ramdiskId>
<platform>linux</platform>
</item>
<item>
<imageId>emi-767B178C</imageId>
<imageLocation>windows-2008-server/windows.my2008server.img.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>machine</imageType>
<platform>windows</platform>
</item>
<item>
<imageId>eki-AE7F138B</imageId>
<imageLocation>kernel-64-xen/vmlinuz-2.6.27.21-0.1-xen.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>kernel</imageType>
<platform>linux</platform>
</item>
<item>
<imageId>eki-101E1514</imageId>
<imageLocation>kernel-deb-ec2-32bit/vmlinuz-2.6.32-308-ec2.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>i386</architecture>
<imageType>kernel</imageType>
<platform>linux</platform>
</item>
<item>
<imageId>emi-F9ED14E7</imageId>
<imageLocation>centos-5.3-x86_64-kvm/centos.5-3.x86-64.img.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>machine</imageType>
<kernelId>eki-C9BE147B</kernelId>
<ramdiskId>eri-0AEE155E</ramdiskId>
<platform>linux</platform>
</item>
<item>
<imageId>eki-C9BE147B</imageId>
<imageLocation>kernel-64-kvm/vmlinuz-2.6.28-11-generic.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>kernel</imageType>
<platform>linux</platform>
</item>
<item>
<imageId>eri-0AEE155E</imageId>
<imageLocation>initrd-64-kvm/initrd.img-2.6.28-11-generic.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>ramdisk</imageType>
<platform>linux</platform>
</item>
<item>
<imageId>eki-9383133A</imageId>
<imageLocation>kernel-deb-ec2/vmlinuz-2.6.32-308-ec2.manifest.xml</imageLocation>
<imageState>available</imageState>
<imageOwnerId>admin</imageOwnerId>
<isPublic>true</isPublic>
<productCodes />
<architecture>x86_64</architecture>
<imageType>kernel</imageType>
<platform>linux</platform>
</item>
</imagesSet>
</DescribeImagesResponse>