mirror of https://github.com/apache/jclouds.git
handling cases where Nova returns all addresses as private rather than private and public
This commit is contained in:
parent
0613f3390c
commit
967926dc28
|
@ -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<Address> getPrivateAddresses() {
|
||||
Set<Address> privateAddresses = addresses.get(Address.Type.PRIVATE);
|
||||
Collection<Address> privateAddresses = getAddresses().get(Address.Type.PRIVATE);
|
||||
if (privateAddresses == null) {
|
||||
return ImmutableSet.<Address> of();
|
||||
} else {
|
||||
|
@ -366,7 +362,7 @@ public class Server extends Resource {
|
|||
* @return the public ip addresses assigned to the server
|
||||
*/
|
||||
public Set<Address> getPublicAddresses() {
|
||||
Set<Address> publicAddrs = addresses.get(Address.Type.PUBLIC);
|
||||
Collection<Address> publicAddrs = getAddresses().get(Address.Type.PUBLIC);
|
||||
if (publicAddrs == null) {
|
||||
return ImmutableSet.<Address> of();
|
||||
} else {
|
||||
|
@ -378,7 +374,29 @@ public class Server extends Resource {
|
|||
* @return the ip addresses assigned to the server
|
||||
*/
|
||||
public Multimap<Type, Address> getAddresses() {
|
||||
return Multimaps2.fromOldSchool(addresses);
|
||||
ImmutableSetMultimap.Builder 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(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
|
||||
|
|
Loading…
Reference in New Issue