Revert dynamic cidr change

This commit is contained in:
Sheng Yang 2012-02-08 15:09:35 -08:00
parent 18ec438793
commit 9317eb6bc3
9 changed files with 45 additions and 61 deletions

View File

@ -286,8 +286,6 @@ public interface Network extends ControlledEntity {
ACLType getAclType();
boolean isSpecifiedCidr();
boolean isRestartRequired();
boolean getSpecifyIpRanges();

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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) {

View File

@ -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<? extends VirtualMachine> 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);

View File

@ -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

View File

@ -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',

View File

@ -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';