From 1b408509d699394ae3ad8c847fd302af9a18f675 Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Mon, 25 Feb 2013 12:34:16 -0800 Subject: [PATCH] CLOUDSTACK-1332: Add IPv6 DNS for Zone --- .../apache/cloudstack/api/ApiConstants.java | 2 + .../api/command/admin/zone/CreateZoneCmd.java | 14 ++++++ .../api/command/admin/zone/UpdateZoneCmd.java | 14 ++++++ .../entity/api/db/EngineDataCenterVO.java | 28 +++++++++++- .../provisioning/test/ProvisioningTest.java | 2 +- .../storage/test/DirectAgentTest.java | 2 +- .../storage/test/volumeServiceTest.java | 2 +- .../cloudstack/storage/test/VolumeTest.java | 4 +- .../configuration/ConfigurationManager.java | 4 +- .../ConfigurationManagerImpl.java | 44 ++++++++++++------- server/src/com/cloud/dc/DataCenterVO.java | 28 +++++++++++- .../vpc/MockConfigurationManagerImpl.java | 2 +- setup/db/db/schema-40to410.sql | 3 ++ 13 files changed, 123 insertions(+), 26 deletions(-) diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java index 8b4bb98e06c..0e4cbe1298f 100755 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -59,6 +59,8 @@ public class ApiConstants { public static final String DISPLAY_TEXT = "displaytext"; public static final String DNS1 = "dns1"; public static final String DNS2 = "dns2"; + public static final String IP6_DNS1 = "ip6dns1"; + public static final String IP6_DNS2 = "ip6dns2"; public static final String DOMAIN = "domain"; public static final String DOMAIN_ID = "domainid"; public static final String DURATION = "duration"; diff --git a/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java b/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java index 1aa620ccd20..5cc905227ab 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java @@ -46,6 +46,12 @@ public class CreateZoneCmd extends BaseCmd { @Parameter(name=ApiConstants.DNS2, type=CommandType.STRING, description="the second DNS for the Zone") private String dns2; + @Parameter(name=ApiConstants.IP6_DNS1, type=CommandType.STRING, description="the first DNS for IPv6 network in the Zone") + private String ip6Dns1; + + @Parameter(name=ApiConstants.IP6_DNS2, type=CommandType.STRING, description="the second DNS for IPv6 network in the Zone") + private String ip6Dns2; + @Parameter(name=ApiConstants.GUEST_CIDR_ADDRESS, type=CommandType.STRING, description="the guest CIDR address for the Zone") private String guestCidrAddress; @@ -89,6 +95,14 @@ public class CreateZoneCmd extends BaseCmd { return dns2; } + public String getIp6Dns1() { + return ip6Dns1; + } + + public String getIp6Dns2() { + return ip6Dns2; + } + public String getGuestCidrAddress() { return guestCidrAddress; } diff --git a/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java b/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java index 81bdead221e..16c334eebc8 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java @@ -48,6 +48,12 @@ public class UpdateZoneCmd extends BaseCmd { @Parameter(name=ApiConstants.DNS2, type=CommandType.STRING, description="the second DNS for the Zone") private String dns2; + @Parameter(name=ApiConstants.IP6_DNS1, type=CommandType.STRING, description="the first DNS for IPv6 network in the Zone") + private String ip6Dns1; + + @Parameter(name=ApiConstants.IP6_DNS2, type=CommandType.STRING, description="the second DNS for IPv6 network in the Zone") + private String ip6Dns2; + @Parameter(name=ApiConstants.GUEST_CIDR_ADDRESS, type=CommandType.STRING, description="the guest CIDR address for the Zone") private String guestCidrAddress; @@ -105,6 +111,14 @@ public class UpdateZoneCmd extends BaseCmd { return id; } + public String getIp6Dns1() { + return ip6Dns1; + } + + public String getIp6Dns2() { + return ip6Dns2; + } + public String getInternalDns1() { return internalDns1; } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineDataCenterVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineDataCenterVO.java index 5080481dfc0..15bed6f8c1d 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineDataCenterVO.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineDataCenterVO.java @@ -61,6 +61,12 @@ public class EngineDataCenterVO implements EngineDataCenter, Identity { @Column(name="dns2") private String dns2 = null; + @Column(name="ip6Dns1") + private String ip6Dns1 = null; + + @Column(name="ip6Dns2") + private String ip6Dns2 = null; + @Column(name="internal_dns1") private String internalDns1 = null; @@ -201,13 +207,13 @@ public class EngineDataCenterVO implements EngineDataCenter, Identity { } public EngineDataCenterVO(long id, String name, String description, String dns1, String dns2, String dns3, String dns4, String guestCidr, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix) { - this(name, description, dns1, dns2, dns3, dns4, guestCidr, domain, domainId, zoneType, zoneToken, domainSuffix, false, false); + this(name, description, dns1, dns2, dns3, dns4, guestCidr, domain, domainId, zoneType, zoneToken, domainSuffix, false, false, null, null); this.id = id; this.allocationState = Grouping.AllocationState.Enabled; this.uuid = UUID.randomUUID().toString(); } - public EngineDataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String guestCidr, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix, boolean securityGroupEnabled, boolean localStorageEnabled) { + public EngineDataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String guestCidr, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix, boolean securityGroupEnabled, boolean localStorageEnabled, String ip6Dns1, String ip6Dns2) { this.name = name; this.description = description; this.dns1 = dns1; @@ -477,4 +483,22 @@ public class EngineDataCenterVO implements EngineDataCenter, Identity { public State getState() { return engineState; } + + @Override + public String getIp6Dns1() { + return ip6Dns1; + } + + public void setIp6Dns1(String ip6Dns1) { + this.ip6Dns1 = ip6Dns1; + } + + @Override + public String getIp6Dns2() { + return ip6Dns2; + } + + public void setIp6Dns2(String ip6Dns2) { + this.ip6Dns2 = ip6Dns2; + } } diff --git a/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java b/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java index 25a37eb3710..a3ef2768287 100644 --- a/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java +++ b/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java @@ -74,7 +74,7 @@ public class ProvisioningTest extends TestCase { @Before public void setUp() { EngineDataCenterVO dc = new EngineDataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", - null, null, NetworkType.Basic, null, null, true, true); + null, null, NetworkType.Basic, null, null, true, true, null, null); Mockito.when(dcDao.findByUuid(Mockito.anyString())).thenReturn(dc); Mockito.when(dcDao.persist((EngineDataCenterVO) Mockito.anyObject())).thenReturn(dc); diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentTest.java index 20ac94611e7..2d6b94fdfaf 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentTest.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentTest.java @@ -77,7 +77,7 @@ public class DirectAgentTest extends CloudStackTestNGBase { } //create data center DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", - null, null, NetworkType.Basic, null, null, true, true); + null, null, NetworkType.Basic, null, null, true, true, null, null); dc = dcDao.persist(dc); dcId = dc.getId(); //create pod diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java index 85421a53b56..d8d187c0ce5 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java @@ -138,7 +138,7 @@ public class volumeServiceTest extends CloudStackTestNGBase { } //create data center DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", - null, null, NetworkType.Basic, null, null, true, true); + null, null, NetworkType.Basic, null, null, true, true, null, null); dc = dcDao.persist(dc); dcId = dc.getId(); //create pod diff --git a/plugins/storage/volume/solidfire/test/org/apache/cloudstack/storage/test/VolumeTest.java b/plugins/storage/volume/solidfire/test/org/apache/cloudstack/storage/test/VolumeTest.java index 6f0b2e73d3a..91c446fe5ae 100644 --- a/plugins/storage/volume/solidfire/test/org/apache/cloudstack/storage/test/VolumeTest.java +++ b/plugins/storage/volume/solidfire/test/org/apache/cloudstack/storage/test/VolumeTest.java @@ -79,7 +79,7 @@ public class VolumeTest { public void setUp() { //create data center DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", - null, null, NetworkType.Basic, null, null, true, true); + null, null, NetworkType.Basic, null, null, true, true, null, null); dc = dcDao.persist(dc); dcId = dc.getId(); //create pod @@ -148,4 +148,4 @@ public class VolumeTest { public void createPrimaryDataStoreTest() { createPrimaryDataStore(); } -} \ No newline at end of file +} diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 7193928ca33..20e98845ac0 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -129,12 +129,14 @@ public interface ConfigurationManager extends ConfigurationService, Manager { * TODO * @param isSecurityGroupEnabled * TODO + * @param ip6Dns1 TODO + * @param ip6Dns2 TODO * @return * @throws * @throws */ DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String guestCidr, String domain, Long domainId, NetworkType zoneType, String allocationState, - String networkDomain, boolean isSecurityGroupEnabled, boolean isLocalStorageEnabled); + String networkDomain, boolean isSecurityGroupEnabled, boolean isLocalStorageEnabled, String ip6Dns1, String ip6Dns2); /** * Deletes a VLAN from the database, along with all of its IP addresses. Will not delete VLANs that have allocated diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index cf3a9080a1f..44d9e0db335 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1092,7 +1092,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } - private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, boolean checkForDuplicates, Long domainId, String allocationStateStr) { + private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, boolean checkForDuplicates, Long domainId, String allocationStateStr, + String ip6Dns1, String ip6Dns2) { if (checkForDuplicates) { // Check if a zone with the specified name already exists if (validZone(zoneName)) { @@ -1127,6 +1128,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Please enter a valid IP address for internal DNS2"); } + if (ip6Dns1 != null && ip6Dns1.length() > 0 && !NetUtils.isValidIpv6(ip6Dns1)) { + throw new InvalidParameterValueException("Please enter a valid IPv6 address for IP6 DNS1"); + } + + if (ip6Dns2 != null && ip6Dns2.length() > 0 && !NetUtils.isValidIpv6(ip6Dns2)) { + throw new InvalidParameterValueException("Please enter a valid IPv6 address for IP6 DNS2"); + } + Grouping.AllocationState allocationState = null; if (allocationStateStr != null && !allocationStateStr.isEmpty()) { try { @@ -1396,6 +1405,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String zoneName = cmd.getZoneName(); String dns1 = cmd.getDns1(); String dns2 = cmd.getDns2(); + String ip6Dns1 = cmd.getIp6Dns1(); + String ip6Dns2 = cmd.getIp6Dns2(); String internalDns1 = cmd.getInternalDns1(); String internalDns2 = cmd.getInternalDns2(); String guestCidr = cmd.getGuestCidrAddress(); @@ -1473,6 +1484,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati dns2 = zone.getDns2(); } + if (ip6Dns1 == null) { + ip6Dns1 = zone.getIp6Dns1(); + } + + if (ip6Dns2 == null) { + ip6Dns2 = zone.getIp6Dns2(); + } + if (internalDns1 == null) { internalDns1 = zone.getInternalDns1(); } @@ -1495,20 +1514,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } boolean checkForDuplicates = !zoneName.equals(oldZoneName); - checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates, null, allocationStateStr);// not - // allowing - // updating - // domain - // associated - // with - // a - // zone, - // once - // created + checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates, null, allocationStateStr, ip6Dns1, ip6Dns2);// not allowing updating domain associated with a zone, once created zone.setName(zoneName); zone.setDns1(dns1); zone.setDns2(dns2); + zone.setIp6Dns1(ip6Dns1); + zone.setIp6Dns2(ip6Dns2); zone.setInternalDns1(internalDns1); zone.setInternalDns2(internalDns2); zone.setGuestNetworkCidr(guestCidr); @@ -1588,7 +1600,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @DB public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String guestCidr, String domain, Long domainId, - NetworkType zoneType, String allocationStateStr, String networkDomain, boolean isSecurityGroupEnabled, boolean isLocalStorageEnabled) { + NetworkType zoneType, String allocationStateStr, String networkDomain, boolean isSecurityGroupEnabled, boolean isLocalStorageEnabled, String ip6Dns1, String ip6Dns2) { // checking the following params outside checkzoneparams method as we do // not use these params for updatezone @@ -1606,7 +1618,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } } - checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId, allocationStateStr); + checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId, allocationStateStr, ip6Dns1, ip6Dns2); byte[] bytes = (zoneName + System.currentTimeMillis()).getBytes(); String zoneToken = UUID.nameUUIDFromBytes(bytes).toString(); @@ -1614,7 +1626,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati try { txn.start(); // Create the new zone in the database - DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, guestCidr, domain, domainId, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled, isLocalStorageEnabled); + DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, guestCidr, domain, domainId, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled, isLocalStorageEnabled, ip6Dns1, ip6Dns2); if (allocationStateStr != null && !allocationStateStr.isEmpty()) { Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr); zone.setAllocationState(allocationState); @@ -1686,6 +1698,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String zoneName = cmd.getZoneName(); String dns1 = cmd.getDns1(); String dns2 = cmd.getDns2(); + String ip6Dns1 = cmd.getIp6Dns1(); + String ip6Dns2 = cmd.getIp6Dns2(); String internalDns1 = cmd.getInternalDns1(); String internalDns2 = cmd.getInternalDns2(); String guestCidr = cmd.getGuestCidrAddress(); @@ -1729,7 +1743,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, guestCidr, domainVO != null ? domainVO.getName() : null, domainId, zoneType, allocationState, networkDomain, - isSecurityGroupEnabled, isLocalStorageEnabled); + isSecurityGroupEnabled, isLocalStorageEnabled, ip6Dns1, ip6Dns2); } @Override diff --git a/server/src/com/cloud/dc/DataCenterVO.java b/server/src/com/cloud/dc/DataCenterVO.java index 28fb11f8cc0..6d609cf8305 100644 --- a/server/src/com/cloud/dc/DataCenterVO.java +++ b/server/src/com/cloud/dc/DataCenterVO.java @@ -59,6 +59,12 @@ public class DataCenterVO implements DataCenter { @Column(name="dns2") private String dns2 = null; + @Column(name="ip6_dns1") + private String ip6Dns1 = null; + + @Column(name="ip6_dns2") + private String ip6Dns2 = null; + @Column(name="internal_dns1") private String internalDns1 = null; @@ -177,17 +183,19 @@ public class DataCenterVO implements DataCenter { } public DataCenterVO(long id, String name, String description, String dns1, String dns2, String dns3, String dns4, String guestCidr, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix) { - this(name, description, dns1, dns2, dns3, dns4, guestCidr, domain, domainId, zoneType, zoneToken, domainSuffix, false, false); + this(name, description, dns1, dns2, dns3, dns4, guestCidr, domain, domainId, zoneType, zoneToken, domainSuffix, false, false, null, null); this.id = id; this.allocationState = Grouping.AllocationState.Enabled; this.uuid = UUID.randomUUID().toString(); } - public DataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String guestCidr, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix, boolean securityGroupEnabled, boolean localStorageEnabled) { + public DataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String guestCidr, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix, boolean securityGroupEnabled, boolean localStorageEnabled, String ip6Dns1, String ip6Dns2) { this.name = name; this.description = description; this.dns1 = dns1; this.dns2 = dns2; + this.ip6Dns1 = ip6Dns1; + this.ip6Dns2 = ip6Dns2; this.internalDns1 = dns3; this.internalDns2 = dns4; this.guestNetworkCidr = guestCidr; @@ -431,4 +439,20 @@ public class DataCenterVO implements DataCenter { public void setMacAddress(long macAddress) { this.macAddress = macAddress; } + + public String getIp6Dns1() { + return ip6Dns1; + } + + public void setIp6Dns1(String ip6Dns1) { + this.ip6Dns1 = ip6Dns1; + } + + public String getIp6Dns2() { + return ip6Dns2; + } + + public void setIp6Dns2(String ip6Dns2) { + this.ip6Dns2 = ip6Dns2; + } } diff --git a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java index e93b2a14c52..d96e831cfeb 100644 --- a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java +++ b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java @@ -608,7 +608,7 @@ public class MockConfigurationManagerImpl extends ManagerBase implements Configu */ @Override public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String guestCidr, String domain, Long domainId, NetworkType zoneType, - String allocationState, String networkDomain, boolean isSecurityGroupEnabled, boolean isLocalStorageEnabled) { + String allocationState, String networkDomain, boolean isSecurityGroupEnabled, boolean isLocalStorageEnabled, String ip6Dns1, String ip6Dns2) { // TODO Auto-generated method stub return null; } diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql index 74f0dba08ee..7c11c56d33f 100644 --- a/setup/db/db/schema-40to410.sql +++ b/setup/db/db/schema-40to410.sql @@ -490,6 +490,9 @@ ALTER TABLE `cloud`.`vlan` ADD COLUMN `ip6_gateway` varchar(255); ALTER TABLE `cloud`.`vlan` ADD COLUMN `ip6_cidr` varchar(255); ALTER TABLE `cloud`.`vlan` ADD COLUMN `ip6_range` varchar(255); +ALTER TABLE `cloud`.`data_center` ADD COLUMN `ip6_dns1` varchar(255); +ALTER TABLE `cloud`.`data_center` ADD COLUMN `ip6_dns2` varchar(255); + -- DB views for list api DROP VIEW IF EXISTS `cloud`.`user_vm_view`;