mirror of https://github.com/apache/jclouds.git
added missing provider id field, default location to hardware/image, fixed packages
This commit is contained in:
parent
4cc5e03ae8
commit
4581b924cf
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.compute.strategy;
|
||||
package org.jclouds.openstack.nova.v1_1.compute;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -75,6 +75,8 @@ public class NovaComputeServiceAdapter implements ComputeServiceAdapter<Server,
|
|||
public NodeAndInitialCredentials<Server> createNodeWithGroupEncodedIntoName(String tag, String name, Template template)
|
||||
{
|
||||
ServerClient serverClient = template.getLocation() != null ? novaClient.getServerClientForRegion(template.getLocation().getId()) : defaultLocationServerClient;
|
||||
// TODO: make NovaTemplateOptions with the following:
|
||||
// security group, key pair, floating ip (attach post server-create?)
|
||||
Server server = serverClient.createServer(name, template.getImage().getId(), template.getHardware().getId());
|
||||
return new NodeAndInitialCredentials<Server>(server, server.getId() + "", LoginCredentials.builder().password(server.getAdminPass()).build());
|
||||
}
|
|
@ -28,11 +28,11 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
|
||||
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.NovaComputeServiceAdapter;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.FlavorToHardware;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.NovaImageToImage;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.NovaImageToOperatingSystem;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.ServerToNodeMetadata;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.strategy.NovaComputeServiceAdapter;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Flavor;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
||||
|
||||
|
|
|
@ -18,13 +18,17 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Flavor;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
* A function for transforming the nova specific Flavor object to the generic Hardware object.
|
||||
|
@ -33,15 +37,27 @@ import com.google.common.base.Function;
|
|||
*/
|
||||
public class FlavorToHardware implements Function<Flavor, Hardware>
|
||||
{
|
||||
|
||||
private final Supplier<Location> defaultLocation;
|
||||
|
||||
@Inject
|
||||
public FlavorToHardware(Supplier<Location> defaultLocation)
|
||||
{
|
||||
this.defaultLocation = defaultLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hardware apply(Flavor flavor)
|
||||
{
|
||||
return new HardwareBuilder()
|
||||
// TODO: scope id to region, if there's a chance for conflict
|
||||
.id(flavor.getId())
|
||||
.providerId(flavor.getId())
|
||||
.name(flavor.getName())
|
||||
.ram(flavor.getRam())
|
||||
.processor(new Processor(flavor.getVcpus(), 1.0))
|
||||
.volume(new VolumeImpl(Float.valueOf(flavor.getDisk()), true, true))
|
||||
.location(defaultLocation.get())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,10 @@ import javax.inject.Inject;
|
|||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
* A function for transforming a nova-specific Image into a generic Image object.
|
||||
|
@ -34,21 +36,26 @@ import com.google.common.base.Function;
|
|||
public class NovaImageToImage implements Function<org.jclouds.openstack.nova.v1_1.domain.Image, Image>
|
||||
{
|
||||
private final Function<org.jclouds.openstack.nova.v1_1.domain.Image, OperatingSystem> imageToOs;
|
||||
private final Supplier<Location> defaultLocation;
|
||||
|
||||
@Inject
|
||||
public NovaImageToImage(Function<org.jclouds.openstack.nova.v1_1.domain.Image, OperatingSystem> imageToOs)
|
||||
public NovaImageToImage(Function<org.jclouds.openstack.nova.v1_1.domain.Image, OperatingSystem> imageToOs, Supplier<Location> defaultLocation)
|
||||
{
|
||||
this.imageToOs = imageToOs;
|
||||
this.defaultLocation = defaultLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image apply(org.jclouds.openstack.nova.v1_1.domain.Image image)
|
||||
{
|
||||
return new ImageBuilder()
|
||||
// TODO: scope id to region, if there's a chance for conflict
|
||||
.id(image.getId())
|
||||
.providerId(image.getId())
|
||||
.name(image.getName())
|
||||
.operatingSystem(imageToOs.apply(image))
|
||||
.description(image.getName())
|
||||
.location(defaultLocation.get())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,9 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata>
|
|||
public NodeMetadata apply(Server server)
|
||||
{
|
||||
return new NodeMetadataBuilder()
|
||||
// TODO: scope id to region, if there's a chance for conflict
|
||||
.id(server.getId())
|
||||
.providerId(server.getId())
|
||||
.name(server.getName())
|
||||
.publicAddresses(Iterables.transform(server.getPublicAddresses(), new AddressToStringTransformationFunction()))
|
||||
.privateAddresses(Iterables.transform(server.getPrivateAddresses(), new AddressToStringTransformationFunction()))
|
||||
|
|
|
@ -43,9 +43,10 @@ import com.google.common.collect.LinkedHashMultimap;
|
|||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* A server is a virtual machine instance in the compute system. Flavor and
|
||||
* image are requisite elements when creating a server.
|
||||
* A server is a virtual machine instance in the compute system. Flavor and image are requisite
|
||||
* elements when creating a server.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a href=
|
||||
|
@ -178,8 +179,7 @@ public class Server extends Resource {
|
|||
* @see Server#getAddresses()
|
||||
*/
|
||||
public Builder addresses(Multimap<Address.Type, Address> addresses) {
|
||||
this.addresses = ImmutableMultimap.copyOf(checkNotNull(addresses,
|
||||
"addresses"));
|
||||
this.addresses = ImmutableMultimap.copyOf(checkNotNull(addresses, "addresses"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -187,16 +187,15 @@ public class Server extends Resource {
|
|||
* @see Server#getPrivateAddresses()
|
||||
*/
|
||||
public Builder privateAddresses(Address... privateAddresses) {
|
||||
return privateAddresses(ImmutableSet.copyOf(checkNotNull(
|
||||
privateAddresses, "privateAddresses")));
|
||||
return privateAddresses(ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Server#getPrivateAddresses()
|
||||
*/
|
||||
public Builder privateAddresses(Set<Address> privateAddresses) {
|
||||
this.addresses.replaceValues(Address.Type.PRIVATE, ImmutableSet
|
||||
.copyOf(checkNotNull(privateAddresses, "privateAddresses")));
|
||||
this.addresses.replaceValues(Address.Type.PRIVATE, ImmutableSet.copyOf(checkNotNull(privateAddresses,
|
||||
"privateAddresses")));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -204,16 +203,15 @@ public class Server extends Resource {
|
|||
* @see Server#getPublicAddresses()
|
||||
*/
|
||||
public Builder publicAddresses(Address... publicAddresses) {
|
||||
return publicAddresses(ImmutableSet.copyOf(checkNotNull(
|
||||
publicAddresses, "publicAddresses")));
|
||||
return publicAddresses(ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Server#getPublicAddresses()
|
||||
*/
|
||||
public Builder publicAddresses(Set<Address> publicAddresses) {
|
||||
this.addresses.replaceValues(Address.Type.PUBLIC, ImmutableSet
|
||||
.copyOf(checkNotNull(publicAddresses, "publicAddresses")));
|
||||
this.addresses.replaceValues(Address.Type.PUBLIC, ImmutableSet.copyOf(checkNotNull(publicAddresses,
|
||||
"publicAddresses")));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -227,9 +225,8 @@ public class Server extends Resource {
|
|||
|
||||
public Server build() {
|
||||
// return new Server(id, name, links, addresses);
|
||||
return new Server(id, name, links, tenantId, userId, updated,
|
||||
created, hostId, accessIPv4, accessIPv6, status, progress,
|
||||
image, flavor, adminPass, addresses, metadata);
|
||||
return new Server(id, name, links, tenantId, userId, updated, created, hostId, accessIPv4, accessIPv6, status,
|
||||
progress, image, flavor, adminPass, addresses, metadata);
|
||||
}
|
||||
|
||||
public Builder fromServer(Server in) {
|
||||
|
@ -287,11 +284,10 @@ public class Server extends Resource {
|
|||
protected final Map<Address.Type, Set<Address>> addresses;
|
||||
protected Map<String, String> metadata;
|
||||
|
||||
protected Server(String id, String name, Set<Link> links, String tenantId,
|
||||
String userId, Date updated, Date created, String hostId,
|
||||
String accessIPv4, String accessIPv6, ServerStatus status,
|
||||
int progress, Resource image, Resource flavor, String adminPass,
|
||||
Multimap<Address.Type, Address> addresses, Map<String, String> metadata) {
|
||||
protected Server(String id, String name, Set<Link> links, String tenantId, String userId, Date updated,
|
||||
Date created, String hostId, String accessIPv4, String accessIPv6, ServerStatus status, int progress,
|
||||
Resource image, Resource flavor, String adminPass, Multimap<Address.Type, Address> addresses,
|
||||
Map<String, String> metadata) {
|
||||
super(id, name, links);
|
||||
this.tenantId = tenantId;
|
||||
this.userId = userId;
|
||||
|
@ -305,8 +301,7 @@ public class Server extends Resource {
|
|||
this.image = image;
|
||||
this.flavor = flavor;
|
||||
this.metadata = Maps.newHashMap(metadata);
|
||||
this.addresses = Multimaps2.toOldSchool(ImmutableMultimap
|
||||
.copyOf(checkNotNull(addresses, "addresses")));
|
||||
this.addresses = Multimaps2.toOldSchool(ImmutableMultimap.copyOf(checkNotNull(addresses, "addresses")));
|
||||
this.adminPass = adminPass;
|
||||
}
|
||||
|
||||
|
@ -386,27 +381,27 @@ public class Server extends Resource {
|
|||
* @return the ip addresses assigned to the server
|
||||
*/
|
||||
public Multimap<Type, Address> getAddresses() {
|
||||
ImmutableSetMultimap.Builder returnMapBuilder = new ImmutableSetMultimap.Builder<Type, Address>();
|
||||
ImmutableSetMultimap.Builder<Type, Address> returnMapBuilder = new ImmutableSetMultimap.Builder<Type, Address>();
|
||||
|
||||
Set<Address> publicAddresses = addresses.get(Address.Type.PUBLIC);
|
||||
Set<Address> privateAddresses = addresses.get(Address.Type.PRIVATE);
|
||||
|
||||
if (privateAddresses.size() > 1) {
|
||||
if (publicAddresses != null) {
|
||||
returnMapBuilder.putAll(Address.Type.PUBLIC, Iterables.filter(publicAddresses, Predicates.not(IsPrivateAddress.INSTANCE)));
|
||||
returnMapBuilder.putAll(Address.Type.PUBLIC, Iterables.filter(publicAddresses, Predicates
|
||||
.not(IsPrivateAddress.INSTANCE)));
|
||||
}
|
||||
if (privateAddresses != null) {
|
||||
returnMapBuilder.putAll(Address.Type.PRIVATE, Iterables.filter(privateAddresses, IsPrivateAddress.INSTANCE));
|
||||
returnMapBuilder.putAll(Address.Type.PUBLIC, Iterables.filter(privateAddresses, Predicates.not(IsPrivateAddress.INSTANCE)));
|
||||
} else {
|
||||
return Multimaps2.fromOldSchool(addresses);
|
||||
returnMapBuilder.putAll(Address.Type.PUBLIC, Iterables.filter(privateAddresses, Predicates
|
||||
.not(IsPrivateAddress.INSTANCE)));
|
||||
}
|
||||
ImmutableSetMultimap<Type, Address> returnMap = returnMapBuilder.build();
|
||||
|
||||
return returnMapBuilder.build();
|
||||
return returnMap.size() > 0 ? returnMap : Multimaps2.fromOldSchool(addresses);
|
||||
}
|
||||
|
||||
private static enum IsPrivateAddress implements Predicate<Address> {
|
||||
INSTANCE;
|
||||
public boolean apply (Address in) {
|
||||
public boolean apply(Address in) {
|
||||
return InetAddresses2.IsPrivateIPAddress.INSTANCE.apply(in.getAddr());
|
||||
}
|
||||
}
|
||||
|
@ -420,14 +415,10 @@ public class Server extends Resource {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toStringHelper("").add("id", id).add("name", name)
|
||||
.add("tenantId", tenantId).add("userId", userId).add("hostId", hostId)
|
||||
.add("updated", updated).add("created", created)
|
||||
.add("accessIPv4", accessIPv4).add("accessIPv6", accessIPv6)
|
||||
.add("status", status).add("progress", progress)
|
||||
.add("image", image).add("flavor", flavor)
|
||||
.add("metadata", metadata)
|
||||
.add("links", links).add("addresses", addresses)
|
||||
.add("adminPass",adminPass).toString();
|
||||
return toStringHelper("").add("id", id).add("name", name).add("tenantId", tenantId).add("userId", userId).add(
|
||||
"hostId", hostId).add("updated", updated).add("created", created).add("accessIPv4", accessIPv4).add(
|
||||
"accessIPv6", accessIPv6).add("status", status).add("progress", progress).add("image", image).add(
|
||||
"flavor", flavor).add("metadata", metadata).add("links", links).add("addresses", addresses).add(
|
||||
"adminPass", adminPass).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.features;
|
||||
package org.jclouds.openstack.nova.v1_1.compute;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.functions;
|
||||
package org.jclouds.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
@ -25,10 +25,13 @@ import static org.testng.Assert.assertNotNull;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.FlavorToHardware;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Flavor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
|
||||
/**
|
||||
* Tests the function used to transform Flavor objects into Hardware objects
|
||||
*
|
||||
|
@ -48,10 +51,11 @@ public class FlavorToHardwareTest
|
|||
.vcpus(16)
|
||||
.build();
|
||||
|
||||
Hardware converted = new FlavorToHardware().apply(flavorToConvert);
|
||||
Hardware converted = new FlavorToHardware(Suppliers.<Location>ofInstance(null)).apply(flavorToConvert);
|
||||
|
||||
assertEquals(converted.getName(), flavorToConvert.getName());
|
||||
assertEquals(converted.getId(), flavorToConvert.getId());
|
||||
assertEquals(converted.getProviderId(), flavorToConvert.getId());
|
||||
assertEquals(converted.getRam(), flavorToConvert.getRam());
|
||||
|
||||
assertNotNull(converted.getProcessors());
|
||||
|
@ -61,5 +65,6 @@ public class FlavorToHardwareTest
|
|||
assertNotNull(converted.getVolumes());
|
||||
assertFalse(converted.getVolumes().isEmpty());
|
||||
assertEquals(converted.getVolumes().iterator().next().getSize(), Float.valueOf(flavorToConvert.getDisk()));
|
||||
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.functions;
|
||||
package org.jclouds.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
|
@ -26,11 +26,13 @@ import javax.annotation.Nullable;
|
|||
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.NovaImageToImage;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Image;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Suppliers;
|
||||
|
||||
/**
|
||||
* Tests the function that transforms nova-specific images to generic images.
|
||||
|
@ -45,10 +47,12 @@ public class NovaImageToImageTest
|
|||
UUID id = UUID.randomUUID();
|
||||
Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).build();
|
||||
OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86", "My Test OS", true);
|
||||
NovaImageToImage converter = new NovaImageToImage(new MockImageToOsConverter(operatingSystem));
|
||||
NovaImageToImage converter = new NovaImageToImage(new MockImageToOsConverter(operatingSystem),Suppliers.<Location>ofInstance(null));
|
||||
org.jclouds.compute.domain.Image convertedImage = converter.apply(novaImageToConvert);
|
||||
|
||||
assertEquals(convertedImage.getId(), novaImageToConvert.getId());
|
||||
assertEquals(convertedImage.getProviderId(), novaImageToConvert.getId());
|
||||
|
||||
assertEquals(convertedImage.getName(), novaImageToConvert.getName());
|
||||
assertEquals(convertedImage.getOperatingSystem(), operatingSystem);
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.functions;
|
||||
package org.jclouds.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.functions;
|
||||
package org.jclouds.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
@ -45,7 +45,7 @@ public class ServerToNodeMetadataTest
|
|||
.id(id.toString())
|
||||
.name("Test Server " + id)
|
||||
.privateAddresses(Address.createV4("10.0.0.1"))
|
||||
.publicAddresses(Address.createV4("10.0.1.1"))
|
||||
.publicAddresses(Address.createV4("1.0.1.1"))
|
||||
.status(ServerStatus.ACTIVE)
|
||||
.build();
|
||||
|
||||
|
@ -54,6 +54,7 @@ public class ServerToNodeMetadataTest
|
|||
NodeMetadata convertedNodeMetadata = converter.apply(serverToConvert);
|
||||
|
||||
assertEquals(serverToConvert.getId(), convertedNodeMetadata.getId());
|
||||
assertEquals(serverToConvert.getId(), convertedNodeMetadata.getProviderId());
|
||||
assertEquals(serverToConvert.getName(), convertedNodeMetadata.getName());
|
||||
assertEquals(serverToConvert.getStatus().getNodeState(), convertedNodeMetadata.getState());
|
||||
|
||||
|
@ -63,6 +64,6 @@ public class ServerToNodeMetadataTest
|
|||
|
||||
assertNotNull(convertedNodeMetadata.getPublicAddresses());
|
||||
assertEquals(convertedNodeMetadata.getPublicAddresses().size(), 1);
|
||||
assertEquals(convertedNodeMetadata.getPublicAddresses().iterator().next(), "10.0.1.1");
|
||||
assertEquals(convertedNodeMetadata.getPublicAddresses().iterator().next(), "1.0.1.1");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue