mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 18:43:26 +01:00
CLOUDSTACK-6854: Fix inconsistent IPv6 address formats
fc00:0003:1373::0002 should be treated the same as fc00:3:1373::2.
This commit is contained in:
parent
aa1ce9a363
commit
a93a30595d
@ -16,6 +16,7 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.admin.vlan;
|
||||
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
@ -166,28 +167,28 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
|
||||
if (startIpv6 == null) {
|
||||
return null;
|
||||
}
|
||||
return startIpv6.toLowerCase();
|
||||
return NetUtils.standardizeIp6Address(startIpv6);
|
||||
}
|
||||
|
||||
public String getEndIpv6() {
|
||||
if (endIpv6 == null) {
|
||||
return null;
|
||||
}
|
||||
return endIpv6.toLowerCase();
|
||||
return NetUtils.standardizeIp6Address(endIpv6);
|
||||
}
|
||||
|
||||
public String getIp6Gateway() {
|
||||
if (ip6Gateway == null) {
|
||||
return null;
|
||||
}
|
||||
return ip6Gateway.toLowerCase();
|
||||
return NetUtils.standardizeIp6Address(ip6Gateway);
|
||||
}
|
||||
|
||||
public String getIp6Cidr() {
|
||||
if (ip6Cidr == null) {
|
||||
return null;
|
||||
}
|
||||
return ip6Cidr.toLowerCase();
|
||||
return NetUtils.standardizeIp6Cidr(ip6Cidr);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.network;
|
||||
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
@ -254,28 +255,28 @@ public class CreateNetworkCmd extends BaseCmd {
|
||||
if (startIpv6 == null) {
|
||||
return null;
|
||||
}
|
||||
return startIpv6.toLowerCase();
|
||||
return NetUtils.standardizeIp6Address(startIpv6);
|
||||
}
|
||||
|
||||
public String getEndIpv6() {
|
||||
if (endIpv6 == null) {
|
||||
return null;
|
||||
}
|
||||
return endIpv6.toLowerCase();
|
||||
return NetUtils.standardizeIp6Address(endIpv6);
|
||||
}
|
||||
|
||||
public String getIp6Gateway() {
|
||||
if (ip6Gateway == null) {
|
||||
return null;
|
||||
}
|
||||
return ip6Gateway.toLowerCase();
|
||||
return NetUtils.standardizeIp6Address(ip6Gateway);
|
||||
}
|
||||
|
||||
public String getIp6Cidr() {
|
||||
if (ip6Cidr == null) {
|
||||
return null;
|
||||
}
|
||||
return ip6Cidr.toLowerCase();
|
||||
return NetUtils.standardizeIp6Cidr(ip6Cidr);
|
||||
}
|
||||
|
||||
public Long getAclId() {
|
||||
|
||||
@ -16,16 +16,25 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.vm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.IpAddresses;
|
||||
import com.cloud.offering.DiskOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.affinity.AffinityGroupResponse;
|
||||
import org.apache.cloudstack.api.ACL;
|
||||
@ -48,25 +57,15 @@ import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.IpAddresses;
|
||||
import com.cloud.offering.DiskOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
|
||||
@ -353,7 +352,7 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd {
|
||||
String requestedIp = ips.get("ip");
|
||||
String requestedIpv6 = ips.get("ipv6");
|
||||
if (requestedIpv6 != null) {
|
||||
requestedIpv6 = requestedIpv6.toLowerCase();
|
||||
requestedIpv6 = NetUtils.standardizeIp6Address(requestedIpv6);
|
||||
}
|
||||
IpAddresses addrs = new IpAddresses(requestedIp, requestedIpv6);
|
||||
ipToNetworkMap.put(networkId, addrs);
|
||||
@ -367,7 +366,7 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd {
|
||||
if (ip6Address == null) {
|
||||
return null;
|
||||
}
|
||||
return ip6Address.toLowerCase();
|
||||
return NetUtils.standardizeIp6Address(ip6Address);
|
||||
}
|
||||
|
||||
public List<Long> getAffinityGroupIdList() {
|
||||
|
||||
@ -19,6 +19,16 @@
|
||||
|
||||
package com.cloud.utils.net;
|
||||
|
||||
import com.cloud.utils.IteratorUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.googlecode.ipv6.IPv6Address;
|
||||
import com.googlecode.ipv6.IPv6AddressRange;
|
||||
import com.googlecode.ipv6.IPv6Network;
|
||||
import org.apache.commons.lang.SystemUtils;
|
||||
import org.apache.commons.net.util.SubnetUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@ -41,17 +51,6 @@ import java.util.TreeSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang.SystemUtils;
|
||||
import org.apache.commons.net.util.SubnetUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.utils.IteratorUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.googlecode.ipv6.IPv6Address;
|
||||
import com.googlecode.ipv6.IPv6AddressRange;
|
||||
import com.googlecode.ipv6.IPv6Network;
|
||||
|
||||
public class NetUtils {
|
||||
protected final static Logger s_logger = Logger.getLogger(NetUtils.class);
|
||||
public final static String HTTP_PORT = "80";
|
||||
@ -1372,6 +1371,14 @@ public class NetUtils {
|
||||
return resultIp;
|
||||
}
|
||||
|
||||
public static String standardizeIp6Address(String ip6Addr) {
|
||||
return IPv6Address.fromString(ip6Addr).toString();
|
||||
}
|
||||
|
||||
public static String standardizeIp6Cidr(String ip6Cidr){
|
||||
return IPv6Network.fromString(ip6Cidr).toString();
|
||||
}
|
||||
|
||||
static final String VLAN_PREFIX = "vlan://";
|
||||
static final int VLAN_PREFIX_LENGTH = VLAN_PREFIX.length();
|
||||
|
||||
|
||||
@ -19,6 +19,14 @@
|
||||
|
||||
package com.cloud.utils.net;
|
||||
|
||||
import com.googlecode.ipv6.IPv6Address;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@ -31,15 +39,6 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.googlecode.ipv6.IPv6Address;
|
||||
|
||||
public class NetUtilsTest {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(NetUtilsTest.class);
|
||||
@ -198,6 +197,12 @@ public class NetUtilsTest {
|
||||
assertFalse(NetUtils.isIp6RangeOverlap("1234:5678::f-1234:5678::f", "1234:5678::2-1234:5678::e"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardizeIp6Address() {
|
||||
assertEquals(NetUtils.standardizeIp6Address("1234:0000:0000:5678:0000:000:ABCD:0001"), "1234::5678:0:0:abcd:1");
|
||||
assertEquals(NetUtils.standardizeIp6Cidr("1234:0000:0000:5678:0000:000:ABCD:0001/64"), "1234::5678:0:0:0:0/64");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateUriForPvlan() {
|
||||
assertEquals("pvlan://123-i456", NetUtils.generateUriForPvlan("123", "456").toString());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user