diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java index 88a2e8483f..af94acfb64 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java @@ -21,21 +21,17 @@ package org.jclouds.openstack.nova.v1_1.domain; import static com.google.common.base.Objects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Collection; import java.util.Date; import java.util.Map; import java.util.Set; +import com.google.common.collect.*; import org.jclouds.openstack.domain.Link; import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.nova.v1_1.domain.Address.Type; import org.jclouds.util.Multimaps2; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; import com.google.gson.annotations.SerializedName; /** @@ -354,7 +350,7 @@ public class Server extends Resource { * @return the private ip addresses assigned to the server */ public Set
getPrivateAddresses() { - Set
privateAddresses = addresses.get(Address.Type.PRIVATE); + Collection
privateAddresses = getAddresses().get(Address.Type.PRIVATE); if (privateAddresses == null) { return ImmutableSet.
of(); } else { @@ -366,7 +362,7 @@ public class Server extends Resource { * @return the public ip addresses assigned to the server */ public Set
getPublicAddresses() { - Set
publicAddrs = addresses.get(Address.Type.PUBLIC); + Collection
publicAddrs = getAddresses().get(Address.Type.PUBLIC); if (publicAddrs == null) { return ImmutableSet.
of(); } else { @@ -378,7 +374,29 @@ public class Server extends Resource { * @return the ip addresses assigned to the server */ public Multimap getAddresses() { - return Multimaps2.fromOldSchool(addresses); + ImmutableSetMultimap.Builder returnMapBuilder = new ImmutableSetMultimap.Builder(); + + Set
publicAddresses = addresses.get(Address.Type.PUBLIC); + Set
privateAddresses = addresses.get(Address.Type.PRIVATE); + + if (privateAddresses.size() > 1) { + if (publicAddresses != null) { + returnMapBuilder.putAll(Type.PUBLIC, publicAddresses); + } + for (Address address : privateAddresses) { + if (address.getAddr().startsWith("10.") || + address.getAddr().startsWith("192.168.") || + address.getAddr().matches("^172\\.(1[6-9]|2[0-9]|3[0-1])\\..*")) { + returnMapBuilder.put(Address.Type.PRIVATE, address); + } else { + returnMapBuilder.put(Address.Type.PUBLIC, address); + } + } + } else { + return Multimaps2.fromOldSchool(addresses); + } + + return returnMapBuilder.build(); } @Override