Issue 895:add openstack-nova-ec2 api

This commit is contained in:
Adrian Cole 2012-04-03 00:06:00 -07:00
parent 3923e78b9a
commit 128a906104
18 changed files with 926 additions and 3 deletions

View File

@ -23,7 +23,7 @@ our compute api supports: aws-ec2, gogrid, cloudservers-us, stub (in-memory), de
openhosting-east1, serverlove-z1-man, skalicloud-sdg-my, openhosting-east1, serverlove-z1-man, skalicloud-sdg-my,
greenhousedata-element-vcloud, softlayer, cloudsigma (generic), greenhousedata-element-vcloud, softlayer, cloudsigma (generic),
cloudstack (generic), ninefold-compute, openstack-nov (keystone), cloudstack (generic), ninefold-compute, openstack-nov (keystone),
hpcloud-compute, trystack-nova hpcloud-compute, trystack-nova, openstack-nova-ec2
* note * the pom dependency org.jclouds/jclouds-allcompute gives you access to * note * the pom dependency org.jclouds/jclouds-allcompute gives you access to
to all of these providers to all of these providers

View File

@ -110,7 +110,8 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equals("architecture")) { if (qName.equals("architecture")) {
architecture = Architecture.fromValue(currentText.toString().trim()); architecture = Architecture.fromValue(currentText.toString().trim());
} else if (qName.equals("name")) { // Nova Diablo uses the wrong name for this field
} else if (qName.equals("name") || qName.equals("displayName")) {
this.name = currentText.toString().trim(); this.name = currentText.toString().trim();
} else if (qName.equals("description")) { } else if (qName.equals("description")) {
description = currentText.toString().trim(); description = currentText.toString().trim();

View File

@ -93,6 +93,18 @@ public class DescribeImagesResponseHandlerTest {
assertEquals(result, contents); assertEquals(result, contents);
} }
public void testDiabloWithIncorrectDisplayNameField() {
Set<Image> contents = ImmutableSet.of(new Image("us-east-1", Architecture.X86_64, "CentOS 6.2 Server 64-bit 20120125", "", "ami-0000054e",
"local (CentOS 6.2 Server 64-bit 20120125)", "", ImageState.AVAILABLE,
ImageType.MACHINE, true, Sets.<String> newHashSet(), "aki-0000054c", null, "ari-0000054d",
RootDeviceType.INSTANCE_STORE, "/dev/sda1", ImmutableMap.<String, EbsBlockDevice> of(),
VirtualizationType.PARAVIRTUAL, Hypervisor.XEN));
Set<Image> result = parseImages("/describe_images_nova.xml");
assertEquals(result.toString(), contents.toString());
}
static ParseSax<Set<Image>> createParser() { static ParseSax<Set<Image>> createParser() {
Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() { Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {

View File

@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to jclouds, Inc. (jclouds) under one or more
contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. jclouds licenses this file
to you 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.5.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.api</groupId>
<artifactId>openstack-nova-ec2</artifactId>
<name>jclouds Eucalyptus api</name>
<description>EC2 implementation based on Eucalyptus</description>
<packaging>bundle</packaging>
<properties>
<test.openstack-nova-ec2.endpoint>http://localhost:8773/services/Cloud</test.openstack-nova-ec2.endpoint>
<test.openstack-nova-ec2.api-version>2010-06-15</test.openstack-nova-ec2.api-version>
<test.openstack-nova-ec2.build-version></test.openstack-nova-ec2.build-version>
<test.openstack-nova-ec2.identity>FIXME_IDENTITY</test.openstack-nova-ec2.identity>
<test.openstack-nova-ec2.credential>FIXME_CREDENTIAL</test.openstack-nova-ec2.credential>
<test.openstack-nova-ec2.image-id></test.openstack-nova-ec2.image-id>
<test.openstack-nova-ec2.image.login-user></test.openstack-nova-ec2.image.login-user>
<test.openstack-nova-ec2.image.authenticate-sudo></test.openstack-nova-ec2.image.authenticate-sudo>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>openstack-nova</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>ec2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>ec2</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-slf4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<test.openstack-nova-ec2.endpoint>${test.openstack-nova-ec2.endpoint}</test.openstack-nova-ec2.endpoint>
<test.openstack-nova-ec2.api-version>${test.openstack-nova-ec2.api-version}</test.openstack-nova-ec2.api-version>
<test.openstack-nova-ec2.build-version>${test.openstack-nova-ec2.build-version}</test.openstack-nova-ec2.build-version>
<test.openstack-nova-ec2.identity>${test.openstack-nova-ec2.identity}</test.openstack-nova-ec2.identity>
<test.openstack-nova-ec2.credential>${test.openstack-nova-ec2.credential}</test.openstack-nova-ec2.credential>
<test.openstack-nova-ec2.image-id>${test.openstack-nova-ec2.image-id}</test.openstack-nova-ec2.image-id>
<test.openstack-nova-ec2.image.login-user>${test.openstack-nova-ec2.image.login-user}</test.openstack-nova-ec2.image.login-user>
<test.openstack-nova-ec2.image.authenticate-sudo>${test.openstack-nova-ec2.image.authenticate-sudo}</test.openstack-nova-ec2.image.authenticate-sudo>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Export-Package>org.jclouds.openstack.nova.ec2*;version="${project.version}"</Export-Package>
<Import-Package>
org.jclouds.compute.internal;version="${project.version}",
org.jclouds.rest.internal;version="${project.version}",
org.jclouds*;version="${project.version}",
*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,60 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.openstack.nova.ec2;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.ec2.EC2ApiMetadata;
/**
* Implementation of {@link ApiMetadata} for Nova's EC2-clone API
*
* @author Adrian Cole
*/
public class NovaEC2ApiMetadata extends EC2ApiMetadata {
public NovaEC2ApiMetadata() {
this(builder().fromApiMetadata(new EC2ApiMetadata())
.id("openstack-nova-ec2")
.name("Nova's EC2-clone API"));
}
// below are so that we can reuse builders, toString, hashCode, etc.
// we have to set concrete classes here, as our base class cannot be
// concrete due to serviceLoader
protected NovaEC2ApiMetadata(ConcreteBuilder builder) {
super(builder);
}
private static class ConcreteBuilder extends EC2ApiMetadataBuilder<ConcreteBuilder> {
@Override
public NovaEC2ApiMetadata build() {
return new NovaEC2ApiMetadata(this);
}
}
private static ConcreteBuilder builder() {
return new ConcreteBuilder();
}
@Override
public ConcreteBuilder toBuilder() {
return builder().fromApiMetadata(this);
}
}

View File

@ -0,0 +1,51 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.openstack.nova.ec2;
import java.util.List;
import java.util.Properties;
import org.jclouds.ec2.EC2ContextBuilder;
import org.jclouds.openstack.nova.ec2.config.NovaEC2ComputeServiceContextModule;
import org.jclouds.openstack.nova.ec2.config.NovaEC2RestClientModule;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
*/
public class NovaEC2ContextBuilder extends EC2ContextBuilder {
public NovaEC2ContextBuilder(Properties props) {
super(props);
}
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new NovaEC2RestClientModule());
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new NovaEC2ComputeServiceContextModule());
}
}

View File

@ -0,0 +1,55 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.openstack.nova.ec2;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME;
import static org.jclouds.Constants.PROPERTY_TRUST_ALL_CERTS;
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.util.Properties;
import org.jclouds.ec2.EC2PropertiesBuilder;
/**
* Builds properties used in NovaEC2 Clients
*
* @author Adrian Cole
*/
public class NovaEC2PropertiesBuilder extends EC2PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_API_VERSION, "2009-04-04");
properties.setProperty(PROPERTY_ENDPOINT, "http://localhost:8773/services/Cloud");
properties.setProperty(PROPERTY_REGIONS, "nova");
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "admin");
// often, we are dealing with IP addresses, not hostnames
properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true");
properties.setProperty(PROPERTY_TRUST_ALL_CERTS, "true");
return properties;
}
public NovaEC2PropertiesBuilder(Properties properties) {
super(properties);
}
}

View File

@ -0,0 +1,44 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.openstack.nova.ec2.config;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule;
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
import org.jclouds.openstack.nova.ec2.strategy.NovaReviseParsedImage;
import org.jclouds.openstack.nova.v1_1.compute.functions.ImageToOperatingSystem;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
public class NovaEC2ComputeServiceContextModule extends EC2ComputeServiceContextModule {
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<org.jclouds.openstack.nova.v1_1.domain.Image, OperatingSystem>>() {
}).to(ImageToOperatingSystem.class);
bind(ReviseParsedImage.class).to(NovaReviseParsedImage.class);
}
}

View File

@ -0,0 +1,53 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.openstack.nova.ec2.config;
import org.jclouds.ec2.EC2AsyncClient;
import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.config.EC2RestClientModule;
import org.jclouds.ec2.suppliers.DescribeAvailabilityZonesInRegion;
import org.jclouds.http.RequiresHttp;
import org.jclouds.location.config.LocationModule;
import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier;
import org.jclouds.location.suppliers.ZoneIdsSupplier;
import org.jclouds.location.suppliers.derived.ZoneIdsFromRegionIdToZoneIdsValues;
import org.jclouds.rest.ConfiguresRestClient;
import com.google.inject.Scopes;
/**
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class NovaEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
public NovaEC2RestClientModule() {
super(EC2Client.class, EC2AsyncClient.class, DELEGATE_MAP);
}
@Override
protected void installLocations() {
install(new LocationModule());
bind(RegionIdToZoneIdsSupplier.class).to(DescribeAvailabilityZonesInRegion.class).in(Scopes.SINGLETON);
// there is only one region, and its endpoint is the same as the provider
bind(ZoneIdsSupplier.class).to(ZoneIdsFromRegionIdToZoneIdsValues.class).in(Scopes.SINGLETON);
}
}

View File

@ -0,0 +1,59 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.openstack.nova.ec2.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
import org.jclouds.openstack.nova.v1_1.domain.Image;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class NovaReviseParsedImage implements ReviseParsedImage {
private final Function<Image, OperatingSystem> imageToOs;
@Inject
public NovaReviseParsedImage(Function<Image, OperatingSystem> imageToOs) {
this.imageToOs = checkNotNull(imageToOs, "imageToOs");
}
@Override
public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family,
OperatingSystem.Builder osBuilder) {
Image image = Image.builder().id(from.getId()).name(from.getName()).build();
OperatingSystem os = imageToOs.apply(image);
osBuilder.description(os.getDescription());
osBuilder.family(os.getFamily());
osBuilder.name(os.getName());
osBuilder.is64Bit(os.is64Bit());
osBuilder.version(os.getVersion());
// arch is accurate already
}
}

View File

@ -0,0 +1 @@
org.jclouds.openstack.nova.ec2.NovaEC2ApiMetadata

View File

@ -0,0 +1,35 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.openstack.nova.ec2;
import org.jclouds.apis.ApiType;
import org.jclouds.apis.BaseApiMetadataTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "NovaEC2ApiMetadataTest")
public class NovaEC2ApiMetadataTest extends BaseApiMetadataTest {
public NovaEC2ApiMetadataTest() {
super(new NovaEC2ApiMetadata(), ApiType.COMPUTE);
}
}

View File

@ -0,0 +1,41 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.openstack.nova.ec2.compute;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.ec2.compute.EC2ComputeServiceLiveTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true, testName = "NovaEC2ComputeServiceLiveTest")
public class NovaEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
public NovaEC2ComputeServiceLiveTest() {
provider = "openstack-nova-ec2";
}
protected void checkResponseEqualsHostname(ExecResponse execResponse, NodeMetadata node1) {
// hostname is not predictable based on node metadata
assert execResponse.getOutput().trim().equals("ubuntu");
}
}

View File

@ -0,0 +1,98 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.openstack.nova.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.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.LoginCredentials;
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.jclouds.openstack.nova.v1_1.compute.functions.ImageToOperatingSystem;
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", testName = "NovaReviseParsedImageTest")
public class NovaReviseParsedImageTest {
public void test() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/nova_ec2_images.xml");
assertEquals(result.size(), 7);
assertEquals(
Iterables.get(result, 4).toString(),
new ImageBuilder()
.operatingSystem(
OperatingSystem.builder().family(OsFamily.UBUNTU).arch("paravirtual").version("10.10")
.name("Ubuntu Maverick 10.10 Server 64-bit 20111212")
.description("Ubuntu Maverick 10.10 Server 64-bit 20111212").is64Bit(true)
.build())
.name("Ubuntu Maverick 10.10 Server 64-bit 20111212")
.description("")
.defaultCredentials(new LoginCredentials("root", false))
.id("us-east-1/ami-000004d6")
.providerId("ami-000004d6")
.location(defaultLocation)
.userMetadata(
ImmutableMap.of("owner", "", "rootDeviceType", "instance-store", "virtualizationType",
"paravirtual", "hypervisor", "xen")).build().toString());
}
static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description(
"us-east-1").build();
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), new NovaReviseParsedImage(new ImageToOperatingSystem(map)));
return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
}
}

View File

@ -0,0 +1,259 @@
<?xml version="1.0" ?>
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2009-04-04/">
<requestId>b5ad23de-f77d-
4b66-bfc2-ab01ceccb97b</requestId>
<imagesSet>
<item>
<displayName>Debian Squeeze 6.0.3 Server 64-bit 20120123</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>ami-00000551</imageId>
<imageState>available</imageState>
<rootDeviceType>instance-store</rootDeviceType>
<architecture>amd64</architecture>
<imageLocation>local (Debian Squeeze 6.0.3 Server 64-bit
20120123)</imageLocation>
<kernelId>aki-0000054f</kernelId>
<ramdiskId>ari-00000550</ramdiskId>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>machine</imageType>
</item>
<item>
<displayName>Debian Squeeze 6.0.3 Server 64-bit 20120123
(Ramdisk)</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>ari-00000550</imageId>
<imageState>available</imageState>
<architecture>amd64</architecture>
<imageLocation>local (Debian Squeeze 6.0.3 Server 64-bit
20120123 (Ramdisk))</imageLocation>
<rootDeviceType>instance-store</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>ramdisk</imageType>
</item>
<item>
<displayName>Debian Squeeze 6.0.3 Server 64-bit 20120123
(Kernel)</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>aki-0000054f</imageId>
<imageState>available</imageState>
<architecture>amd64</architecture>
<imageLocation>local (Debian Squeeze 6.0.3 Server 64-bit
20120123 (Kernel))</imageLocation>
<rootDeviceType>instance-store</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>kernel</imageType>
</item>
<item>
<displayName>CentOS 6.2 Server 64-bit 20120125</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>ami-0000054e</imageId>
<imageState>available</imageState>
<rootDeviceType>instance-store</rootDeviceType>
<architecture>x86_64</architecture>
<imageLocation>local (CentOS 6.2 Server 64-bit 20120125)</imageLocation>
<kernelId>aki-0000054c</kernelId>
<ramdiskId>ari-0000054d</ramdiskId>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>machine</imageType>
</item>
<item>
<displayName>CentOS 6.2 Server 64-bit 20120125 (Ramdisk)</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>ari-0000054d</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>local (CentOS 6.2 Server 64-bit 20120125
(Ramdisk))</imageLocation>
<rootDeviceType>instance-store</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>ramdisk</imageType>
</item>
<item>
<displayName>CentOS 6.2 Server 64-bit 20120125 (Kernel)</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>aki-0000054c</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>local (CentOS 6.2 Server 64-bit 20120125
(Kernel))</imageLocation>
<rootDeviceType>instance-store</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>kernel</imageType>
</item>
<item>
<displayName>Ubuntu Oneiric 11.10 Server 64-bit 20111212</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>ami-000004da</imageId>
<imageState>available</imageState>
<rootDeviceType>instance-store</rootDeviceType>
<architecture>amd64</architecture>
<imageLocation>local (Ubuntu Oneiric 11.10 Server 64-bit
20111212)</imageLocation>
<kernelId>aki-000004d9</kernelId>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>machine</imageType>
</item>
<item>
<displayName>Ubuntu Oneiric 11.10 Server 64-bit 20111212
(Kernel)</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>aki-000004d9</imageId>
<imageState>available</imageState>
<architecture>amd64</architecture>
<imageLocation>local (Ubuntu Oneiric 11.10 Server 64-bit
20111212 (Kernel))</imageLocation>
<rootDeviceType>instance-store</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>kernel</imageType>
</item>
<item>
<displayName>Ubuntu Natty 11.04 Server 64-bit 20111212</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>ami-000004d8</imageId>
<imageState>available</imageState>
<rootDeviceType>instance-store</rootDeviceType>
<architecture>amd64</architecture>
<imageLocation>local (Ubuntu Natty 11.04 Server 64-bit
20111212)</imageLocation>
<kernelId>aki-000004d7</kernelId>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>machine</imageType>
</item>
<item>
<displayName>Ubuntu Natty 11.04 Server 64-bit 20111212
(Kernel)</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>aki-000004d7</imageId>
<imageState>available</imageState>
<architecture>amd64</architecture>
<imageLocation>local (Ubuntu Natty 11.04 Server 64-bit
20111212 (Kernel))</imageLocation>
<rootDeviceType>instance-store</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>kernel</imageType>
</item>
<item>
<displayName>Ubuntu Maverick 10.10 Server 64-bit 20111212</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>ami-000004d6</imageId>
<imageState>available</imageState>
<rootDeviceType>instance-store</rootDeviceType>
<architecture>amd64</architecture>
<imageLocation>local (Ubuntu Maverick 10.10 Server 64-bit
20111212)</imageLocation>
<kernelId>aki-000004d5</kernelId>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>machine</imageType>
</item>
<item>
<displayName>Ubuntu Maverick 10.10 Server 64-bit 20111212
(Kernel)</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>aki-000004d5</imageId>
<imageState>available</imageState>
<architecture>amd64</architecture>
<imageLocation>local (Ubuntu Maverick 10.10 Server 64-bit
20111212 (Kernel))</imageLocation>
<rootDeviceType>instance-store</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>kernel</imageType>
</item>
<item>
<displayName>Ubuntu Lucid 10.04 LTS Server 64-bit 20111212</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>ami-000004d4</imageId>
<imageState>available</imageState>
<rootDeviceType>instance-store</rootDeviceType>
<architecture>amd64</architecture>
<imageLocation>local (Ubuntu Lucid 10.04 LTS Server 64-bit
20111212)</imageLocation>
<kernelId>aki-000004d3</kernelId>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>machine</imageType>
</item>
<item>
<displayName>Ubuntu Lucid 10.04 LTS Server 64-bit 20111212
(Kernel)</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>aki-000004d3</imageId>
<imageState>available</imageState>
<architecture>amd64</architecture>
<imageLocation>local (Ubuntu Lucid 10.04 LTS Server 64-bit
20111212 (Kernel))</imageLocation>
<rootDeviceType>instance-store</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>kernel</imageType>
</item>
<item>
<displayName>CentOS 5.6 Server 64-bit 20111207</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>ami-000004d2</imageId>
<imageState>available</imageState>
<rootDeviceType>instance-store</rootDeviceType>
<architecture>x86_64</architecture>
<imageLocation>local (CentOS 5.6 Server 64-bit 20111207)</imageLocation>
<kernelId>aki-000004d0</kernelId>
<ramdiskId>ari-000004d1</ramdiskId>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>machine</imageType>
</item>
<item>
<displayName>CentOS 5.6 Server 64-bit 20111207 (Ramdisk)</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>ari-000004d1</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>local (CentOS 5.6 Server 64-bit 20111207
(Ramdisk))</imageLocation>
<rootDeviceType>instance-store</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>ramdisk</imageType>
</item>
<item>
<displayName>CentOS 5.6 Server 64-bit 20111207 (Kernel)</displayName>
<description />
<imageOwnerId />
<isPublic>true</isPublic>
<imageId>aki-000004d0</imageId>
<imageState>available</imageState>
<architecture>x86_64</architecture>
<imageLocation>local (CentOS 5.6 Server 64-bit 20111207
(Kernel))</imageLocation>
<rootDeviceType>instance-store</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<imageType>kernel</imageType>
</item>
</imagesSet>
</DescribeImagesResponse>

View File

@ -106,7 +106,7 @@ public class ImageToOperatingSystem implements Function<Image, OperatingSystem>
osFamily = OsFamily.UBUNTU; osFamily = OsFamily.UBUNTU;
osVersion = ubuntuVersion; osVersion = ubuntuVersion;
} else { } else {
logger.trace("could not parse operating system family for image(%s): %s", imageNameParts); logger.trace("could not parse operating system family for image(%s): %s", from.getId(), imageNameParts);
osFamily = OsFamily.UNRECOGNIZED; osFamily = OsFamily.UNRECOGNIZED;
} }
} }

View File

@ -48,6 +48,7 @@
<module>atmos</module> <module>atmos</module>
<module>nova</module> <module>nova</module>
<module>openstack-nova</module> <module>openstack-nova</module>
<module>openstack-nova-ec2</module>
<module>cloudwatch</module> <module>cloudwatch</module>
<module>cloudsigma</module> <module>cloudsigma</module>
<module>cloudstack</module> <module>cloudstack</module>

View File

@ -70,6 +70,9 @@ vcloud-director.propertiesbuilder=org.jclouds.vcloud.director.v1_5.VCloudDirecto
eucalyptus.contextbuilder=org.jclouds.ec2.EC2ContextBuilder eucalyptus.contextbuilder=org.jclouds.ec2.EC2ContextBuilder
eucalyptus.propertiesbuilder=org.jclouds.eucalyptus.EucalyptusPropertiesBuilder eucalyptus.propertiesbuilder=org.jclouds.eucalyptus.EucalyptusPropertiesBuilder
openstack-nova-ec2.contextbuilder=org.jclouds.openstack.nova.ec2.NovaEC2ContextBuilder
openstack-nova-ec2.propertiesbuilder=org.jclouds.openstack.nova.ec2.NovaEC2PropertiesBuilder
eucalyptus-partnercloud-ec2.contextbuilder=org.jclouds.epc.EucalyptusPartnerCloudContextBuilder eucalyptus-partnercloud-ec2.contextbuilder=org.jclouds.epc.EucalyptusPartnerCloudContextBuilder
eucalyptus-partnercloud-ec2.propertiesbuilder=org.jclouds.epc.EucalyptusPartnerCloudPropertiesBuilder eucalyptus-partnercloud-ec2.propertiesbuilder=org.jclouds.epc.EucalyptusPartnerCloudPropertiesBuilder