mirror of https://github.com/apache/jclouds.git
Issue 895: Filtering out non-MACHINE images from Nova-EC2 responses (note 2009-04-04 EC2 API didn't support filtering at the machine end)
This commit is contained in:
parent
0d43c1dd46
commit
1e3a8b04b6
|
@ -22,8 +22,10 @@ import org.jclouds.compute.domain.OperatingSystem;
|
||||||
import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule;
|
import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule;
|
||||||
import org.jclouds.ec2.compute.loaders.CreateSecurityGroupIfNeeded;
|
import org.jclouds.ec2.compute.loaders.CreateSecurityGroupIfNeeded;
|
||||||
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
|
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
|
||||||
|
import org.jclouds.ec2.xml.DescribeImagesResponseHandler;
|
||||||
import org.jclouds.openstack.nova.ec2.loaders.NovaCreateSecurityGroupIfNeeded;
|
import org.jclouds.openstack.nova.ec2.loaders.NovaCreateSecurityGroupIfNeeded;
|
||||||
import org.jclouds.openstack.nova.ec2.strategy.NovaReviseParsedImage;
|
import org.jclouds.openstack.nova.ec2.strategy.NovaReviseParsedImage;
|
||||||
|
import org.jclouds.openstack.nova.ec2.xml.NovaDescribeImagesResponseHandler;
|
||||||
import org.jclouds.openstack.nova.v1_1.compute.functions.ImageToOperatingSystem;
|
import org.jclouds.openstack.nova.v1_1.compute.functions.ImageToOperatingSystem;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -42,6 +44,7 @@ public class NovaEC2ComputeServiceContextModule extends EC2ComputeServiceContext
|
||||||
}).to(ImageToOperatingSystem.class);
|
}).to(ImageToOperatingSystem.class);
|
||||||
bind(ReviseParsedImage.class).to(NovaReviseParsedImage.class);
|
bind(ReviseParsedImage.class).to(NovaReviseParsedImage.class);
|
||||||
bind(CreateSecurityGroupIfNeeded.class).to(NovaCreateSecurityGroupIfNeeded.class);
|
bind(CreateSecurityGroupIfNeeded.class).to(NovaCreateSecurityGroupIfNeeded.class);
|
||||||
|
bind(DescribeImagesResponseHandler.class).to(NovaDescribeImagesResponseHandler.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
/**
|
||||||
|
* 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.xml;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.ec2.domain.Image;
|
||||||
|
import org.jclouds.ec2.domain.Image.ImageType;
|
||||||
|
import org.jclouds.ec2.xml.DescribeImagesResponseHandler;
|
||||||
|
import org.jclouds.location.Region;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adjusted to filter out non-MACHINE images
|
||||||
|
*
|
||||||
|
* @author Adam Lowe
|
||||||
|
*/
|
||||||
|
public class NovaDescribeImagesResponseHandler extends DescribeImagesResponseHandler {
|
||||||
|
@Inject
|
||||||
|
public NovaDescribeImagesResponseHandler(@Region Supplier<String> defaultRegion) {
|
||||||
|
super(defaultRegion);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Image> getResult() {
|
||||||
|
return ImmutableSet.copyOf(Iterables.filter(contents, new Predicate<Image>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(Image image) {
|
||||||
|
return image.getImageType() == ImageType.MACHINE;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* 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.services;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jclouds.ec2.domain.Image;
|
||||||
|
import org.jclouds.ec2.services.AMIClient;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.openstack.nova.ec2.internal.BaseNovaEC2RestClientExpectTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Lowe
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "NovaEC2ElasticBlockStoreClientTest")
|
||||||
|
public class NovaEC2AMIClientTest extends BaseNovaEC2RestClientExpectTest {
|
||||||
|
|
||||||
|
public void testDescribeImagesWithNonMachineTypes() {
|
||||||
|
AMIClient client = requestsSendResponses(
|
||||||
|
describeAvailabilityZonesRequest,
|
||||||
|
describeAvailabilityZonesResponse,
|
||||||
|
HttpRequest.builder().method("POST")
|
||||||
|
.endpoint(URI.create("http://localhost:8773/services/Cloud/"))
|
||||||
|
.headers(ImmutableMultimap.of("Host", "localhost:8773"))
|
||||||
|
.payload(payloadFromStringWithContentType("Action=DescribeImages&Signature=Z3q3jSutwlfgvbcINT0Ed3AjrjxM4WMvQloXu%2F1kd40%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2009-04-04&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(),
|
||||||
|
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nova_ec2_images_with_ramdisk.xml")).build()
|
||||||
|
).getAMIServices();
|
||||||
|
|
||||||
|
Set<? extends Image> images = client.describeImagesInRegion("nova");
|
||||||
|
|
||||||
|
assertEquals(images.size(), 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?xml version="1.0" ?>
|
||||||
|
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2009-04-04/">
|
||||||
|
<requestId>req-bfdac708-c6c4-48fb-9cba-be5bb0a05b49</requestId>
|
||||||
|
<imagesSet>
|
||||||
|
<item>
|
||||||
|
<description/>
|
||||||
|
<imageOwnerId/>
|
||||||
|
<isPublic>true</isPublic>
|
||||||
|
<imageId>aki-00000002</imageId>
|
||||||
|
<imageState>available</imageState>
|
||||||
|
<architecture/>
|
||||||
|
<imageLocation>None (cirros-0.3.0-x86_64-blank-kernel)</imageLocation>
|
||||||
|
<rootDeviceType>instance-store</rootDeviceType>
|
||||||
|
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||||
|
<imageType>kernel</imageType>
|
||||||
|
<name>cirros-0.3.0-x86_64-blank-kernel</name>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<description/>
|
||||||
|
<imageOwnerId/>
|
||||||
|
<isPublic>true</isPublic>
|
||||||
|
<imageId>ari-00000003</imageId>
|
||||||
|
<imageState>available</imageState>
|
||||||
|
<architecture/>
|
||||||
|
<imageLocation>None (cirros-0.3.0-x86_64-blank-ramdisk)</imageLocation>
|
||||||
|
<rootDeviceType>instance-store</rootDeviceType>
|
||||||
|
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||||
|
<imageType>ramdisk</imageType>
|
||||||
|
<name>cirros-0.3.0-x86_64-blank-ramdisk</name>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>cirros-0.3.0-x86_64-blank</name>
|
||||||
|
<imageOwnerId/>
|
||||||
|
<isPublic>true</isPublic>
|
||||||
|
<imageId>ami-00000001</imageId>
|
||||||
|
<imageState>available</imageState>
|
||||||
|
<rootDeviceType>instance-store</rootDeviceType>
|
||||||
|
<architecture/>
|
||||||
|
<imageLocation>None (cirros-0.3.0-x86_64-blank)</imageLocation>
|
||||||
|
<kernelId>aki-00000002</kernelId>
|
||||||
|
<ramdiskId>ari-00000003</ramdiskId>
|
||||||
|
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||||
|
<imageType>machine</imageType>
|
||||||
|
<description/>
|
||||||
|
</item>
|
||||||
|
</imagesSet>
|
||||||
|
</DescribeImagesResponse>
|
Loading…
Reference in New Issue