From 9317eb6bc3380ccd09c3ea01700813513ec7c9bd Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Wed, 8 Feb 2012 15:09:35 -0800 Subject: [PATCH] Revert dynamic cidr change --- api/src/com/cloud/network/Network.java | 2 - api/src/com/cloud/network/NetworkProfile.java | 11 --- .../com/cloud/network/NetworkManagerImpl.java | 2 +- server/src/com/cloud/network/NetworkVO.java | 14 ---- .../cloud/network/guru/DirectNetworkGuru.java | 1 - .../guru/ExternalGuestNetworkGuru.java | 73 +++++++++++-------- .../cloud/network/guru/GuestNetworkGuru.java | 1 - setup/db/create-schema.sql | 1 - setup/db/db/schema-2214to30.sql | 1 - 9 files changed, 45 insertions(+), 61 deletions(-) diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index dc7daec2dff..4e74b817a99 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -286,8 +286,6 @@ public interface Network extends ControlledEntity { ACLType getAclType(); - boolean isSpecifiedCidr(); - boolean isRestartRequired(); boolean getSpecifyIpRanges(); diff --git a/api/src/com/cloud/network/NetworkProfile.java b/api/src/com/cloud/network/NetworkProfile.java index c8a4fe014b2..7c702cd994e 100644 --- a/api/src/com/cloud/network/NetworkProfile.java +++ b/api/src/com/cloud/network/NetworkProfile.java @@ -47,7 +47,6 @@ public class NetworkProfile implements Network { private Network.GuestType guestType; private Long physicalNetworkId; private ACLType aclType; - private boolean specifiedCidr; private boolean restartRequired; private boolean specifyIpRanges; @@ -72,7 +71,6 @@ public class NetworkProfile implements Network { this.guestType = network.getGuestType(); this.physicalNetworkId = network.getPhysicalNetworkId(); this.aclType = network.getAclType(); - this.specifiedCidr = network.isSpecifiedCidr(); this.restartRequired = network.isRestartRequired(); this.specifyIpRanges = network.getSpecifyIpRanges(); } @@ -202,15 +200,6 @@ public class NetworkProfile implements Network { return aclType; } - @Override - public boolean isSpecifiedCidr() { - return specifiedCidr; - } - - public void setSpecifiedCidr(boolean specifiedCidr) { - this.specifiedCidr = specifiedCidr; - } - @Override public boolean isRestartRequired() { // TODO Auto-generated method stub diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 3002ead0912..1d56a8d9d1a 100644 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -3908,7 +3908,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } if (networkOfferingId != oldNetworkOfferingId) { - if (network.isSpecifiedCidr() && networkOfferingIsConfiguredForExternalNetworking(networkOfferingId)) { + if (networkOfferingIsConfiguredForExternalNetworking(networkOfferingId)) { throw new InvalidParameterValueException("Network offering " + networkOffering + " contained external network elements, can't be upgraded from a CIDR specify network!"); } // check if the network is upgradable diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index 2441140915c..4cd27cefcec 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -142,9 +142,6 @@ public class NetworkVO implements Network, Identity { @Enumerated(value=EnumType.STRING) ControlledEntity.ACLType aclType; - @Column(name="specified_cidr") - boolean specifiedCidr; - @Column(name="restart_required") boolean restartRequired = false; @@ -193,7 +190,6 @@ public class NetworkVO implements Network, Identity { state = State.Allocated; } this.uuid = UUID.randomUUID().toString(); - this.specifiedCidr = that.isSpecifiedCidr(); } /** @@ -224,7 +220,6 @@ public class NetworkVO implements Network, Identity { this.networkDomain = networkDomain; this.uuid = UUID.randomUUID().toString(); this.guestType = guestType; - this.specifiedCidr = false; this.specifyIpRanges = specifyIpRanges; } @@ -470,15 +465,6 @@ public class NetworkVO implements Network, Identity { return aclType; } - @Override - public boolean isSpecifiedCidr() { - return specifiedCidr; - } - - public void setSpecifiedCidr(boolean specifiedCidr) { - this.specifiedCidr = specifiedCidr; - } - public void setRestartRequired(boolean restartRequired) { this.restartRequired = restartRequired; } diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java index c18730d69d6..b07f31cb405 100755 --- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java +++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java @@ -121,7 +121,6 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru { if (userSpecified.getCidr() != null) { config.setCidr(userSpecified.getCidr()); config.setGateway(userSpecified.getGateway()); - config.setSpecifiedCidr(true); } if (userSpecified.getBroadcastUri() != null) { diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java index 62803eeae68..d11f15493b0 100644 --- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java @@ -89,6 +89,9 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { NetworkVO config = (NetworkVO) super.design(offering, plan, userSpecified, owner); if (config == null) { return null; + } else if (_networkMgr.networkIsConfiguredForExternalNetworking(plan.getDataCenterId(), config.getId())) { + /* In order to revert userSpecified network setup */ + config.setState(State.Allocated); } return config; @@ -102,6 +105,10 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { return null; } + if (!_networkMgr.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId())) { + return super.implement(config, offering, dest, context); + } + DataCenter zone = dest.getDataCenter(); NetworkVO implemented = new NetworkVO(config.getTrafficType(), config.getMode(), config.getBroadcastDomainType(), config.getNetworkOfferingId(), State.Allocated, config.getDataCenterId(), config.getPhysicalNetworkId()); @@ -194,7 +201,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { - if (nic != null && nic.getRequestedIp() != null) { + if (_networkMgr.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId()) && nic != null && nic.getRequestedIp() != null) { throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + nic); } @@ -204,11 +211,12 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { return null; } - profile.setStrategy(ReservationStrategy.Start); - profile.setGateway(null); - profile.setNetmask(null); - /* We won't clear IP address, because router may set gateway as it IP, and it would be updated properly later */ - //profile.setIp4Address(null); + if (_networkMgr.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId())) { + profile.setStrategy(ReservationStrategy.Start); + profile.setIp4Address(null); + profile.setGateway(null); + profile.setNetmask(null); + } return profile; } @@ -221,11 +229,13 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { return; } - nic.setIp4Address(null); - nic.setGateway(null); - nic.setNetmask(null); - nic.setBroadcastUri(null); - nic.setIsolationUri(null); + if (_networkMgr.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId())) { + nic.setIp4Address(null); + nic.setGateway(null); + nic.setNetmask(null); + nic.setBroadcastUri(null); + nic.setIsolationUri(null); + } } @Override @@ -237,26 +247,31 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { } DataCenter dc = _dcDao.findById(config.getDataCenterId()); - - nic.setBroadcastUri(config.getBroadcastUri()); - nic.setIsolationUri(config.getBroadcastUri()); - nic.setDns1(dc.getDns1()); - nic.setDns2(dc.getDns2()); - nic.setNetmask(NetUtils.cidr2Netmask(config.getCidr())); - long cidrAddress = NetUtils.ip2Long(config.getCidr().split("/")[0]); - int cidrSize = getGloballyConfiguredCidrSize(); - nic.setGateway(config.getGateway()); - if (nic.getIp4Address() == null) { - String guestIp = _networkMgr.acquireGuestIpAddress(config, null); - if (guestIp == null) { - throw new InsufficientVirtualNetworkCapcityException("Unable to acquire guest IP address for network " + config, DataCenter.class, dc.getId()); + if (_networkMgr.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId())) { + nic.setBroadcastUri(config.getBroadcastUri()); + nic.setIsolationUri(config.getBroadcastUri()); + nic.setDns1(dc.getDns1()); + nic.setDns2(dc.getDns2()); + nic.setNetmask(NetUtils.cidr2Netmask(config.getCidr())); + long cidrAddress = NetUtils.ip2Long(config.getCidr().split("/")[0]); + int cidrSize = getGloballyConfiguredCidrSize(); + nic.setGateway(config.getGateway()); + + if (nic.getIp4Address() == null) { + + String guestIp = _networkMgr.acquireGuestIpAddress(config, null); + if (guestIp == null) { + throw new InsufficientVirtualNetworkCapcityException("Unable to acquire guest IP address for network " + config, DataCenter.class, dc.getId()); + } + + nic.setIp4Address(guestIp); + } else { + long ipMask = NetUtils.ip2Long(nic.getIp4Address()) & ~(0xffffffffffffffffl << (32 - cidrSize)); + nic.setIp4Address(NetUtils.long2Ip(cidrAddress | ipMask)); } - - nic.setIp4Address(guestIp); } else { - long ipMask = NetUtils.ip2Long(nic.getIp4Address()) & ~(0xffffffffffffffffl << (32 - cidrSize)); - nic.setIp4Address(NetUtils.long2Ip(cidrAddress | ipMask)); + super.reserve(nic, config, vm, dest, context); } } @@ -268,7 +283,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { NetworkVO network = _networkDao.findById(nic.getNetworkId()); - if (network != null) { + if (network != null && _networkMgr.networkIsConfiguredForExternalNetworking(network.getDataCenterId(), network.getId())) { return true; } else { return super.release(nic, vm, reservationId); diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index 91f4e377277..995563d3b1f 100755 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -134,7 +134,6 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { if (userSpecified.getCidr() != null) { network.setCidr(userSpecified.getCidr()); network.setGateway(userSpecified.getGateway()); - network.setSpecifiedCidr(true); } else { String guestNetworkCidr = dc.getGuestNetworkCidr(); // guest network cidr can be null for Basic zone diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index ec79740bf25..c1c8b9950d4 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -208,7 +208,6 @@ CREATE TABLE `cloud`.`networks` ( `network_domain` varchar(255) COMMENT 'domain', `reservation_id` char(40) COMMENT 'reservation id', `guest_type` char(32) COMMENT 'type of guest network that can be shared or isolated', - `specified_cidr` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if the CIDR/gateway/vlan are specified in this network', `restart_required` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if restart is required for the network', `created` datetime NOT NULL COMMENT 'date created', `removed` datetime COMMENT 'date removed if not null', diff --git a/setup/db/db/schema-2214to30.sql b/setup/db/db/schema-2214to30.sql index 105d92f6c38..0e46e18fbd4 100755 --- a/setup/db/db/schema-2214to30.sql +++ b/setup/db/db/schema-2214to30.sql @@ -627,7 +627,6 @@ ALTER TABLE `cloud`.`domain_network_ref` ADD COLUMN `subdomain_access` int(1) un UPDATE `cloud`.`networks` SET specify_ip_ranges=(SELECT specify_ip_ranges FROM network_offerings no where no.id=network_offering_id); -ALTER TABLE `cloud`.`networks` ADD COLUMN `specified_cidr` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if the CIDR/gateway/vlan are specified in this network'; DELETE FROM `cloud`.`configuration` WHERE name='network.redundantrouter'; UPDATE `cloud`.`configuration` SET category = 'Hidden' WHERE name = 'xen.public.network.device';