From c7840cf91f215988f8e02d2d33f389e461afc49b Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Wed, 16 Jan 2013 15:10:27 +0530 Subject: [PATCH 1/8] reverting the earlier commit 432ea9c7d4aff3f7e682f2951f49ed3e95778d9f done for bug CLOUDSTACK-265 due to IP clearence issues. --- api/src/com/cloud/network/Network.java | 1 - .../com/cloud/offering/NetworkOffering.java | 2 - .../ConfigurationManagerImpl.java | 34 +++------- .../cloud/network/rules/RulesManagerImpl.java | 35 ++-------- .../cloud/offerings/NetworkOfferingVO.java | 28 +------- .../cloud/server/ConfigurationServerImpl.java | 3 +- .../com/cloud/upgrade/dao/Upgrade40to41.java | 40 +---------- .../src/com/cloud/vm/UserVmManagerImpl.java | 68 ++++++------------- setup/db/create-schema.sql | 1 - setup/db/db/schema-40to410.sql | 1 - 10 files changed, 39 insertions(+), 174 deletions(-) diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index 39a0b26c76a..c91f6a9b80d 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -170,7 +170,6 @@ public interface Network extends ControlledEntity, InternalIdentity, Identity { public static final Capability AllowDnsSuffixModification = new Capability("AllowDnsSuffixModification"); public static final Capability RedundantRouter = new Capability("RedundantRouter"); public static final Capability ElasticIp = new Capability("ElasticIp"); - public static final Capability AssociatePublicIP = new Capability("AssociatePublicIP"); public static final Capability ElasticLb = new Capability("ElasticLb"); public static final Capability AutoScaleCounters = new Capability("AutoScaleCounters"); public static final Capability InlineMode = new Capability("InlineMode"); diff --git a/api/src/com/cloud/offering/NetworkOffering.java b/api/src/com/cloud/offering/NetworkOffering.java index b69ad886eaa..f2c4de520a1 100644 --- a/api/src/com/cloud/offering/NetworkOffering.java +++ b/api/src/com/cloud/offering/NetworkOffering.java @@ -105,8 +105,6 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity, boolean getElasticIp(); - boolean getAssociatePublicIP(); - boolean getElasticLb(); boolean getSpecifyIpRanges(); diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index b21c5a38bb7..95262797c0d 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -3163,33 +3163,20 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura void validateStaticNatServiceCapablities(Map staticNatServiceCapabilityMap) { if (staticNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) { - if (staticNatServiceCapabilityMap.keySet().size() > 2) { - throw new InvalidParameterValueException("Only " + Capability.ElasticIp.getName() + " and " + Capability.AssociatePublicIP.getName() + " capabilitiy can be sepcified for static nat service"); + if (staticNatServiceCapabilityMap.keySet().size() > 1) { + throw new InvalidParameterValueException("Only " + Capability.ElasticIp.getName() + " capability can be specified for static nat service"); } - boolean eipEnabled = false; - boolean eipDisabled = false; - boolean associatePublicIP = true; + for (Capability capability : staticNatServiceCapabilityMap.keySet()) { String value = staticNatServiceCapabilityMap.get(capability); if (capability == Capability.ElasticIp) { - eipEnabled = value.contains("true"); - eipDisabled = value.contains("false"); - if (!eipEnabled && !eipDisabled) { + boolean enabled = value.contains("true"); + boolean disabled = value.contains("false"); + if (!enabled && !disabled) { throw new InvalidParameterValueException("Unknown specified value for " + Capability.ElasticIp.getName()); } - } else if (capability == Capability.AssociatePublicIP) { - if (value.contains("true")) { - associatePublicIP = true; - } else if (value.contains("false")) { - associatePublicIP = false; - } else { - throw new InvalidParameterValueException("Unknown specified value for " + Capability.AssociatePublicIP.getName()); - } } else { - throw new InvalidParameterValueException("Only " + Capability.ElasticIp.getName() + " and " + Capability.AssociatePublicIP.getName() + " capabilitiy can be sepcified for static nat service"); - } - if (eipDisabled && associatePublicIP) { - throw new InvalidParameterValueException("Capability " + Capability.AssociatePublicIP.getName() + " can only be set when capability " + Capability.ElasticIp.getName() + " is true"); + throw new InvalidParameterValueException("Only " + Capability.ElasticIp.getName() + " capability can be specified for static nat service"); } } } @@ -3243,7 +3230,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura boolean sharedSourceNat = false; boolean redundantRouter = false; boolean elasticIp = false; - boolean associatePublicIp = false; boolean inline = false; if (serviceCapabilityMap != null && !serviceCapabilityMap.isEmpty()) { Map lbServiceCapabilityMap = serviceCapabilityMap.get(Service.Lb); @@ -3293,17 +3279,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String param = staticNatServiceCapabilityMap.get(Capability.ElasticIp); if (param != null) { elasticIp = param.contains("true"); - String associatePublicIP = staticNatServiceCapabilityMap.get(Capability.AssociatePublicIP); - if (associatePublicIP != null) { - associatePublicIp = associatePublicIP.contains("true"); - } } } } NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, - sharedSourceNat, redundantRouter, elasticIp, elasticLb, associatePublicIp, specifyIpRanges, inline); + sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline); if (serviceOfferingId != null) { offering.setServiceOfferingId(serviceOfferingId); diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index dd091740021..a75aca3a522 100755 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -16,18 +16,6 @@ // under the License. package com.cloud.network.rules; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.ejb.Local; -import javax.naming.ConfigurationException; - -import org.apache.cloudstack.api.command.user.firewall.ListPortForwardingRulesCmd; -import org.apache.log4j.Logger; - import com.cloud.configuration.ConfigurationManager; import com.cloud.domain.dao.DomainDao; import com.cloud.event.ActionEvent; @@ -65,13 +53,8 @@ import com.cloud.utils.Pair; import com.cloud.utils.Ternary; import com.cloud.utils.component.Inject; import com.cloud.utils.component.Manager; -import com.cloud.utils.db.DB; -import com.cloud.utils.db.Filter; -import com.cloud.utils.db.JoinBuilder; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.*; import com.cloud.utils.db.SearchCriteria.Op; -import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.Ip; import com.cloud.vm.Nic; @@ -80,6 +63,7 @@ import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; +import org.apache.cloudstack.api.command.user.firewall.ListPortForwardingRulesCmd; import org.apache.log4j.Logger; import javax.ejb.Local; @@ -1189,12 +1173,11 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { Network guestNetwork = _networkMgr.getNetwork(ipAddress.getAssociatedWithNetworkId()); NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); if (offering.getElasticIp()) { - if (offering.getAssociatePublicIP()) { - getSystemIpAndEnableStaticNatForVm(_vmDao.findById(vmId), true); - return true; - } + getSystemIpAndEnableStaticNatForVm(_vmDao.findById(vmId), true); + return true; + } else { + return disableStaticNat(ipId, caller, ctx.getCallerUserId(), false); } - return disableStaticNat(ipId, caller, ctx.getCallerUserId(), false); } @Override @@ -1380,11 +1363,6 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { Network guestNetwork = _networkMgr.getNetwork(nic.getNetworkId()); NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); if (offering.getElasticIp()) { - boolean isSystemVM = (vm.getType() == Type.ConsoleProxy || vm.getType() == Type.SecondaryStorageVm); - // for user VM's associate public IP only if offering is marked to associate a public IP by default on start of VM - if (!isSystemVM && !offering.getAssociatePublicIP()) { - continue; - } // check if there is already static nat enabled if (_ipAddressDao.findByAssociatedVmId(vm.getId()) != null && !getNewIp) { s_logger.debug("Vm " + vm + " already has ip associated with it in guest network " + guestNetwork); @@ -1399,6 +1377,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { s_logger.debug("Allocated system ip " + ip + ", now enabling static nat on it for vm " + vm); + boolean isSystemVM = (vm.getType() == Type.ConsoleProxy || vm.getType() == Type.SecondaryStorageVm); try { success = enableStaticNat(ip.getId(), vm.getId(), guestNetwork.getId(), isSystemVM); } catch (NetworkRuleConflictException ex) { diff --git a/server/src/com/cloud/offerings/NetworkOfferingVO.java b/server/src/com/cloud/offerings/NetworkOfferingVO.java index 8de93d87b54..efaca764020 100755 --- a/server/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/server/src/com/cloud/offerings/NetworkOfferingVO.java @@ -16,26 +16,10 @@ // under the License. package com.cloud.offerings; -import com.cloud.network.Networks; - -import java.util.Date; -import java.util.UUID; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.apache.cloudstack.api.Identity; import com.cloud.network.Network; import com.cloud.network.Networks.TrafficType; import com.cloud.offering.NetworkOffering; import com.cloud.utils.db.GenericDao; -import org.apache.cloudstack.api.InternalIdentity; import javax.persistence.*; import java.util.Date; @@ -129,9 +113,6 @@ public class NetworkOfferingVO implements NetworkOffering { @Column(name = "elastic_lb_service") boolean elasticLb; - @Column(name = "eip_associate_public_ip") - boolean eipAssociatePublicIp; - @Column(name = "inline") boolean inline; @@ -295,21 +276,19 @@ public class NetworkOfferingVO implements NetworkOffering { this.redundantRouter = false; this.elasticIp = false; this.elasticLb = false; - this.eipAssociatePublicIp = true; this.inline = false; this.specifyIpRanges = specifyIpRanges; } public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault, Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean dedicatedLb, boolean sharedSourceNat, boolean redundantRouter, boolean elasticIp, boolean elasticLb, - boolean associatePublicIP, boolean specifyIpRanges, boolean inline) { + boolean specifyIpRanges, boolean inline) { this(name, displayText, trafficType, systemOnly, specifyVlan, rateMbps, multicastRateMbps, isDefault, availability, tags, guestType, conserveMode, specifyIpRanges); this.dedicatedLB = dedicatedLb; this.sharedSourceNat = sharedSourceNat; this.redundantRouter = redundantRouter; this.elasticIp = elasticIp; this.elasticLb = elasticLb; - this.eipAssociatePublicIp = associatePublicIP; this.inline = inline; } @@ -372,11 +351,6 @@ public class NetworkOfferingVO implements NetworkOffering { return elasticIp; } - @Override - public boolean getAssociatePublicIP() { - return eipAssociatePublicIp; - } - @Override public boolean getElasticLb() { return elasticLb; diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 7e5f42445d5..5d246281630 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -70,7 +70,6 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; import com.cloud.utils.script.Script; -import com.cloud.uuididentity.dao.IdentityDao; import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; @@ -972,7 +971,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, false, true, null, null, true, Availability.Optional, - null, Network.GuestType.Shared, true, false, false, false, true, true, true, true, false); + null, Network.GuestType.Shared, true, false, false, false, true, true, true, false); defaultNetscalerNetworkOffering.setState(NetworkOffering.State.Enabled); defaultNetscalerNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetscalerNetworkOffering); diff --git a/server/src/com/cloud/upgrade/dao/Upgrade40to41.java b/server/src/com/cloud/upgrade/dao/Upgrade40to41.java index e23837d49f8..cd9e20c6a46 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade40to41.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade40to41.java @@ -22,12 +22,6 @@ import com.cloud.utils.script.Script; import java.io.File; import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.script.Script; /** * @author htrippaers @@ -84,7 +78,7 @@ public class Upgrade40to41 implements DbUpgrade { */ @Override public void performDataMigration(Connection conn) { - upgradeEIPNetworkOfferings(conn); + } /* (non-Javadoc) @@ -95,36 +89,4 @@ public class Upgrade40to41 implements DbUpgrade { return new File[0]; } - private void upgradeEIPNetworkOfferings(Connection conn) { - PreparedStatement pstmt = null; - ResultSet rs = null; - - try { - pstmt = conn.prepareStatement("select id, elastic_ip_service from `cloud`.`network_offerings` where traffic_type='Guest'"); - rs = pstmt.executeQuery(); - while (rs.next()) { - long id = rs.getLong(1); - // check if elastic IP service is enabled for network offering - if (rs.getLong(2) != 0) { - //update network offering with eip_associate_public_ip set to true - pstmt = conn.prepareStatement("UPDATE `cloud`.`network_offerings` set eip_associate_public_ip=? where id=?"); - pstmt.setBoolean(1, true); - pstmt.setLong(2, id); - pstmt.executeUpdate(); - } - } - } catch (SQLException e) { - throw new CloudRuntimeException("Unable to set elastic_ip_service for network offerings with EIP service enabled.", e); - } finally { - try { - if (rs != null) { - rs.close(); - } - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { - } - } - } } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index f3aca68172f..a6fbdb17915 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -16,32 +16,6 @@ // under the License. package com.cloud.vm; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import javax.ejb.Local; -import javax.naming.ConfigurationException; - -import org.apache.cloudstack.api.command.user.template.CreateTemplateCmd; -import org.apache.cloudstack.api.command.user.vm.*; -import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd; -import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd; -import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd; -import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd; -import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; - -import org.apache.cloudstack.acl.ControlledEntity.ACLType; -import org.apache.cloudstack.acl.SecurityChecker.AccessType; import com.cloud.agent.AgentManager; import com.cloud.agent.api.*; import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer; @@ -53,17 +27,6 @@ import com.cloud.alert.AlertManager; import com.cloud.api.ApiDBUtils; import com.cloud.api.query.dao.UserVmJoinDao; import com.cloud.api.query.vo.UserVmJoinVO; - -import org.apache.cloudstack.api.BaseCmd; -import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd; -import org.apache.cloudstack.api.command.user.vm.DeployVMCmd; -import org.apache.cloudstack.api.command.user.vm.DestroyVMCmd; -import org.apache.cloudstack.api.command.user.vm.RebootVMCmd; -import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd; -import org.apache.cloudstack.api.command.user.vm.ResetVMPasswordCmd; -import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd; -import org.apache.cloudstack.api.command.user.vm.UpdateVMCmd; -import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd; import com.cloud.async.AsyncJobExecutor; import com.cloud.async.AsyncJobManager; import com.cloud.async.AsyncJobVO; @@ -151,12 +114,7 @@ import com.cloud.utils.component.Inject; import com.cloud.utils.component.Manager; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.crypt.RSAHelper; -import com.cloud.utils.db.DB; -import com.cloud.utils.db.Filter; -import com.cloud.utils.db.GlobalLock; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.*; import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.ExecutionException; @@ -164,6 +122,26 @@ import com.cloud.utils.fsm.NoTransitionException; import com.cloud.utils.net.NetUtils; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.dao.*; +import org.apache.cloudstack.acl.ControlledEntity.ACLType; +import org.apache.cloudstack.acl.SecurityChecker.AccessType; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd; +import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd; +import org.apache.cloudstack.api.command.user.template.CreateTemplateCmd; +import org.apache.cloudstack.api.command.user.vm.*; +import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd; +import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd; +import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd; +import org.apache.commons.codec.binary.Base64; +import org.apache.log4j.Logger; + +import javax.ejb.Local; +import javax.naming.ConfigurationException; +import java.util.*; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; @Local(value = { UserVmManager.class, UserVmService.class }) public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager { @@ -2788,10 +2766,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (ip != null && ip.getSystem()) { UserContext ctx = UserContext.current(); try { - long networkId = ip.getAssociatedWithNetworkId(); - Network guestNetwork = _networkMgr.getNetwork(networkId); - NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); - assert (offering.getAssociatePublicIP() == true) : "User VM should not have system owned public IP associated with it when offering configured not to associate public IP."; _rulesMgr.disableStaticNat(ip.getId(), ctx.getCaller(), ctx.getCallerUserId(), true); } catch (Exception ex) { s_logger.warn("Failed to disable static nat and release system ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ", ex); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 37d52539f16..174f53cd7ba 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -306,7 +306,6 @@ CREATE TABLE `cloud`.`network_offerings` ( `state` char(32) COMMENT 'state of the network offering that has Disabled value by default', `guest_type` char(32) COMMENT 'type of guest network that can be shared or isolated', `elastic_ip_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network offering provides elastic ip service', - `eip_associate_public_ip` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if public IP is associated with user VM creation by default when EIP service is enabled.', `elastic_lb_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network offering provides elastic lb service', `specify_ip_ranges` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network offering provides an ability to define ip ranges', `inline` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Is this network offering LB provider is in inline mode', diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql index bf3fb303e5b..c115135d006 100644 --- a/setup/db/db/schema-40to410.sql +++ b/setup/db/db/schema-40to410.sql @@ -58,7 +58,6 @@ ALTER TABLE `cloud`.`snapshots` ADD COLUMN `s3_id` bigint unsigned COMMENT 'S3 t ALTER TABLE `cloud`.`snapshots` ADD CONSTRAINT `fk_snapshots__s3_id` FOREIGN KEY `fk_snapshots__s3_id` (`s3_id`) REFERENCES `s3` (`id`); -ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `eip_associate_public_ip` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if public IP is associated with user VM creation by default when EIP service is enabled.' AFTER `elastic_ip_service`; ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `inline` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Is this network offering LB provider is in inline mode'; ALTER TABLE `cloud`.`external_load_balancer_devices` DROP COLUMN `is_inline`; From 156ed7a336643963040aa485406da8cd0e0564ed Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Wed, 16 Jan 2013 15:58:44 +0530 Subject: [PATCH 2/8] Revert "Summary: partical check-in for L4-L7 network services in the shared" Reverting due to IP clearance issued for the commit done as part of CLOUDSTACK-312 This reverts commit d4c604cfd8ec6b385de7abf694a936e89add0f38. --- .../com/cloud/network/NetworkManagerImpl.java | 80 +++++++------------ 1 file changed, 29 insertions(+), 51 deletions(-) diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 206392dce49..47db4cb82ae 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -980,14 +980,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "allocating Ip", create = true) - public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId) + public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { - if (networkId != null) { Network network = _networksDao.findById(networkId); if (network == null) { throw new InvalidParameterValueException("Invalid network id is given"); } + if (network.getGuestType() == Network.GuestType.Shared) { DataCenter zone = _configMgr.getZone(zoneId); if (zone == null) { @@ -1002,9 +1002,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (s_logger.isDebugEnabled()) { s_logger.debug("Associate IP address called by the user " + callerUserId + " account " + ipOwner.getId()); } - return allocateIp(ipOwner, false, caller, zone); + return allocateIp(ipOwner, false, caller, callerUserId, zone); } else { - throw new InvalidParameterValueException("Associate IP address can only be called on the shared networks in the advanced zone" + + throw new InvalidParameterValueException("Associate IP address can only called on the shared networks in the advanced zone" + " with Firewall/Source Nat/Static Nat/Port Forwarding/Load balancing services enabled"); } } @@ -1022,11 +1022,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag DataCenter zone = _configMgr.getZone(zoneId); - return allocateIp(ipOwner, isSystem, caller, zone); + return allocateIp(ipOwner, isSystem, caller, callerUserId, zone); } @DB - public IpAddress allocateIp(Account ipOwner, boolean isSystem, Account caller, DataCenter zone) + public IpAddress allocateIp(Account ipOwner, boolean isSystem, Account caller, long callerUserId, DataCenter zone) throws ConcurrentOperationException, ResourceAllocationException, InsufficientAddressCapacityException { @@ -1047,7 +1047,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Account accountToLock = null; try { if (s_logger.isDebugEnabled()) { - s_logger.debug("Associate IP address called by the user " + caller.getId()); + s_logger.debug("Associate IP address called by the user " + callerUserId + " account " + ipOwner.getId()); } accountToLock = _accountDao.acquireInLockTable(ipOwner.getId()); if (accountToLock == null) { @@ -1133,13 +1133,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } DataCenter zone = _configMgr.getZone(network.getDataCenterId()); - if (network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced) { - if (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) { - _accountMgr.checkAccess(UserContext.current().getCaller(), AccessType.UseNetwork, false, network); - } else { - throw new InvalidParameterValueException("IP can be associated with guest network of 'shared' type only if" + - "network service Source Nat, Static Nat, Port Forwarding, Load balancing, firewall are enabled in the network"); - } + if (network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced && isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) { + _accountMgr.checkAccess(UserContext.current().getCaller(), AccessType.UseNetwork, false, network); } else { _accountMgr.checkAccess(caller, null, true, ipToAssoc); } @@ -2011,11 +2006,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - @Override - public boolean equals(Object o) { - return super.equals(o); //To change body of overridden methods use File | Settings | File Templates. - } - private void implementNetworkElementsAndResources(DeployDestination dest, ReservationContext context, NetworkVO network, NetworkOfferingVO offering) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException { @@ -2510,36 +2500,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - private void checkSharedNetworkCidrOverlap(Long zoneId, long physicalNetworkId, String cidr) { - if (zoneId == null || cidr == null) { + private void checkSharedNetworkCidrOverlap(Long zoneId, String cidr) { + if (zoneId == null) { return; } - DataCenter zone = _dcDao.findById(zoneId); - List networks = _networksDao.listByZone(zoneId); - Map networkToCidr = new HashMap(); - - // check for CIDR overlap with all possible CIDR for isolated guest networks - // in the zone when using external networking - PhysicalNetworkVO pNetwork = _physicalNetworkDao.findById(physicalNetworkId); - if (pNetwork.getVnet() != null) { - String vlanRange[] = pNetwork.getVnet().split("-"); - int lowestVlanTag = Integer.valueOf(vlanRange[0]); - int highestVlanTag = Integer.valueOf(vlanRange[1]); - for (int vlan=lowestVlanTag; vlan <= highestVlanTag; ++vlan) { - int offset = vlan - lowestVlanTag; - String globalVlanBits = _configDao.getValue(Config.GuestVlanBits.key()); - int cidrSize = 8 + Integer.parseInt(globalVlanBits); - String guestNetworkCidr = zone.getGuestNetworkCidr(); - String[] cidrTuple = guestNetworkCidr.split("\\/"); - long newCidrAddress = (NetUtils.ip2Long(cidrTuple[0]) & 0xff000000) | (offset << (32 - cidrSize)); - if (NetUtils.isNetworksOverlap(NetUtils.long2Ip(newCidrAddress), cidr)) { - throw new InvalidParameterValueException("Specified CIDR for shared network conflict with CIDR that is reserved for zone vlan " + vlan); - } - } + if (cidr == null) { + return; } - // check for CIDR overlap with all CIDR's of the shared networks in the zone + List networks = _networksDao.listByZone(zoneId); + Map networkToCidr = new HashMap(); for (NetworkVO network : networks) { if (network.getGuestType() == GuestType.Isolated) { continue; @@ -2548,15 +2519,22 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag networkToCidr.put(network.getId(), network.getCidr()); } } - if (networkToCidr != null && !networkToCidr.isEmpty()) { - for (long networkId : networkToCidr.keySet()) { - String ntwkCidr = networkToCidr.get(networkId); - if (NetUtils.isNetworksOverlap(ntwkCidr, cidr)) { - throw new InvalidParameterValueException("Specified CIDR for shared network conflict with CIDR of a shared network in the zone."); - } + + //TODO: check for CIDR overlap with all possible CIDR for guest networks in the zone + //when using external networking + + if (networkToCidr == null || networkToCidr.isEmpty()) { + return; + } + + for (long networkId : networkToCidr.keySet()) { + String ntwkCidr = networkToCidr.get(networkId); + if (NetUtils.isNetworksOverlap(ntwkCidr, cidr)) { + throw new InvalidParameterValueException("Warning: The specified existing network has conflict CIDR subnets with new network!"); } } } + public void checkVirtualNetworkCidrOverlap(Long zoneId, String cidr) { if (zoneId == null) { return; @@ -2784,7 +2762,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (ntwkOff.getGuestType() == GuestType.Shared && (zone.getNetworkType() == NetworkType.Advanced) && isSharedNetworkOfferingWithServices(networkOfferingId)) { // validate if CIDR specified overlaps with any of the CIDR's allocated for isolated networks and shared networks in the zone - checkSharedNetworkCidrOverlap(zoneId, pNtwk.getId(), cidr); + checkSharedNetworkCidrOverlap(zoneId, cidr); } else { throw new InvalidParameterValueException("Cannot specify CIDR when using network offering with external devices!"); } From 316c5267ccc182e18c4201a72cdf8ccc739e130a Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Wed, 16 Jan 2013 16:04:14 +0530 Subject: [PATCH 3/8] Revert " Summary: check-in for L4-L7 network services in the shared network in" This reverts commit 7fcfcdf91e49d64375171c9ae7fe61067aa59b6e. Reverting due to IP clearance issued for the commit done as part of CLOUDSTACK-312 --- .../com/cloud/network/NetworkManagerImpl.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 47db4cb82ae..f378aa4fd5a 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -2951,11 +2951,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId); } } else { - //don't allow to creating shared network with given Vlan ID, if there already exists a isolated network or - //shared network with same Vlan ID in the zone - if (_networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Isolated) > 0 || - _networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Shared) > 0) { - throw new InvalidParameterValueException("There is a isolated/shared network with vlan id: " + vlanId + " already exists " + "in zone " + zoneId); + //don't allow to create Shared network with Vlan that already exists in the zone for Isolated networks + if (_networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Isolated) > 0) { + throw new InvalidParameterValueException("Isolated network with vlan " + vlanId + " already exists " + + "in zone " + zoneId); } } } @@ -3543,13 +3542,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag applyProfileToNetwork(network, profile); - DataCenterVO zone = _dcDao.findById(network.getDataCenterId()); - if (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId()) && (zone.getNetworkType() == NetworkType.Advanced)) { - network.setState(Network.State.Setup); - } else { - network.setState(Network.State.Allocated); - } - + network.setState(Network.State.Allocated); network.setRestartRequired(false); _networksDao.update(network.getId(), network); _networksDao.clearCheckForGc(networkId); From 88a0b5ac488c6ec3b8a501ee1254a6a962db47fe Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Wed, 16 Jan 2013 16:05:17 +0530 Subject: [PATCH 4/8] Revert "Summary: partical check-in for L4-L7 network services in the shared" This reverts commit 6657246cd44629c30e6ea21cc4bbd43a42788e12. Reverting due to IP clearance issued for the commit done as part of CLOUDSTACK-312 --- .../cloud/network/element/F5ExternalLoadBalancerElement.java | 2 +- .../network/element/JuniperSRXExternalFirewallElement.java | 3 +-- .../src/com/cloud/network/element/NetscalerElement.java | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java b/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java index b9739ec21df..70faaccc461 100644 --- a/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java +++ b/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java @@ -122,7 +122,7 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan ConfigurationDao _configDao; private boolean canHandle(Network config) { - if ((config.getGuestType() != Network.GuestType.Isolated && config.getGuestType() != Network.GuestType.Shared) || config.getTrafficType() != TrafficType.Guest) { + if (config.getGuestType() != Network.GuestType.Isolated || config.getTrafficType() != TrafficType.Guest) { s_logger.trace("Not handling network with Type " + config.getGuestType() + " and traffic type " + config.getTrafficType()); return false; } diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java b/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java index 6e9d32daa99..ead2af9396d 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java @@ -130,8 +130,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan private boolean canHandle(Network network, Service service) { DataCenter zone = _configMgr.getZone(network.getDataCenterId()); - if ((zone.getNetworkType() == NetworkType.Advanced && !(network.getGuestType() == Network.GuestType.Isolated || network.getGuestType() == Network.GuestType.Shared )) - || (zone.getNetworkType() == NetworkType.Basic && network.getGuestType() != Network.GuestType.Shared)) { + if ((zone.getNetworkType() == NetworkType.Advanced && network.getGuestType() != Network.GuestType.Isolated) || (zone.getNetworkType() == NetworkType.Basic && network.getGuestType() != Network.GuestType.Shared)) { s_logger.trace("Element " + getProvider().getName() + "is not handling network type = " + network.getGuestType()); return false; } diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java index a1782107e19..c0f91bb42d2 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java +++ b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java @@ -154,8 +154,7 @@ StaticNatServiceProvider { private boolean canHandle(Network config, Service service) { DataCenter zone = _dcDao.findById(config.getDataCenterId()); - boolean handleInAdvanceZone = (zone.getNetworkType() == NetworkType.Advanced && - (config.getGuestType() == Network.GuestType.Isolated || config.getGuestType() == Network.GuestType.Shared) && config.getTrafficType() == TrafficType.Guest); + boolean handleInAdvanceZone = (zone.getNetworkType() == NetworkType.Advanced && config.getGuestType() == Network.GuestType.Isolated && config.getTrafficType() == TrafficType.Guest); boolean handleInBasicZone = (zone.getNetworkType() == NetworkType.Basic && config.getGuestType() == Network.GuestType.Shared && config.getTrafficType() == TrafficType.Guest); if (!(handleInAdvanceZone || handleInBasicZone)) { From 4b67340d8cda021394892d8e4b0adfba493b42dd Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Wed, 16 Jan 2013 16:43:37 +0530 Subject: [PATCH 5/8] Revert "Summary: partical check-in for L4-L7 network services in the shared" This reverts commits 0de5a145e4f06420a4eb1867309af674c16ace7c, 28bbf6c52798c9bd298952844250fbc3cb92dce0 Reverting due to IP clearance issues for the commits done as part of CLOUDSTACK-312 --- api/src/com/cloud/network/NetworkService.java | 2 +- .../user/address/AssociateIPAddrCmd.java | 2 +- .../com/cloud/network/NetworkManagerImpl.java | 251 +++--------------- .../cloud/network/MockNetworkManagerImpl.java | 2 +- .../com/cloud/vpc/MockNetworkManagerImpl.java | 35 +-- 5 files changed, 51 insertions(+), 241 deletions(-) diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index 39a746e6776..b3332a345b3 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -41,7 +41,7 @@ public interface NetworkService { List getIsolatedNetworksOwnedByAccountInZone(long zoneId, Account owner); - IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId) throws ResourceAllocationException, + IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException; boolean releaseIpAddress(long ipAddressId) throws InsufficientAddressCapacityException; diff --git a/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java index 024ba74e8b4..93bb2401d8f 100644 --- a/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java @@ -213,7 +213,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { @Override public void create() throws ResourceAllocationException{ try { - IpAddress ip = _networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()), getZoneId(), getNetworkId()); + IpAddress ip = _networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()), false, getZoneId()); if (ip != null) { this.setEntityId(ip.getId()); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index f378aa4fd5a..0a1fcd7e66d 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -16,58 +16,19 @@ // under the License. package com.cloud.network; -import java.net.URI; -import java.security.InvalidParameterException; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.TreeSet; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import javax.ejb.Local; -import javax.naming.ConfigurationException; - -import com.cloud.utils.db.*; -import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd; -import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd; -import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd; -import org.apache.log4j.Logger; - -import org.apache.cloudstack.acl.ControlledEntity.ACLType; -import org.apache.cloudstack.acl.SecurityChecker.AccessType; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; import com.cloud.agent.api.*; import com.cloud.agent.api.to.NicTO; import com.cloud.alert.AlertManager; import com.cloud.api.ApiDBUtils; - -import org.apache.cloudstack.api.command.user.network.ListNetworksCmd; import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.Resource.ResourceType; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.*; import com.cloud.dc.DataCenter.NetworkType; -import com.cloud.dc.DataCenterVO; -import com.cloud.dc.Pod; -import com.cloud.dc.PodVlanMapVO; -import com.cloud.dc.Vlan; import com.cloud.dc.Vlan.VlanType; -import com.cloud.dc.VlanVO; import com.cloud.dc.dao.AccountVlanMapDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.PodVlanMapDao; @@ -110,13 +71,6 @@ import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy; import com.cloud.network.lb.LoadBalancingRulesManager; import com.cloud.network.rules.*; import com.cloud.network.rules.FirewallRule.Purpose; -import com.cloud.network.rules.FirewallRuleVO; -import com.cloud.network.rules.PortForwardingRule; -import com.cloud.network.rules.PortForwardingRuleVO; -import com.cloud.network.rules.RulesManager; -import com.cloud.network.rules.StaticNat; -import com.cloud.network.rules.StaticNatRule; -import com.cloud.network.rules.StaticNatRuleImpl; import com.cloud.network.rules.dao.PortForwardingRulesDao; import com.cloud.network.vpc.NetworkACLManager; import com.cloud.network.vpc.PrivateIpVO; @@ -145,30 +99,38 @@ import com.cloud.utils.component.Adapters; import com.cloud.utils.component.Inject; import com.cloud.utils.component.Manager; import com.cloud.utils.concurrency.NamedThreadFactory; +import com.cloud.utils.db.*; import com.cloud.utils.db.JoinBuilder.JoinType; import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.Ip; import com.cloud.utils.net.NetUtils; -import com.cloud.vm.Nic; -import com.cloud.vm.NicProfile; -import com.cloud.vm.NicVO; -import com.cloud.vm.ReservationContext; -import com.cloud.vm.ReservationContextImpl; -import com.cloud.vm.SecondaryStorageVmVO; -import com.cloud.vm.UserVmVO; -import com.cloud.vm.VMInstanceVO; -import com.cloud.vm.VirtualMachine; +import com.cloud.vm.*; import com.cloud.vm.VirtualMachine.Type; -import com.cloud.vm.VirtualMachineProfile; -import com.cloud.vm.VirtualMachineProfileImpl; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.VMInstanceDao; import edu.emory.mathcs.backport.java.util.Collections; +import org.apache.cloudstack.acl.ControlledEntity.ACLType; +import org.apache.cloudstack.acl.SecurityChecker.AccessType; +import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd; +import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd; +import org.apache.cloudstack.api.command.user.network.ListNetworksCmd; +import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd; +import org.apache.log4j.Logger; +import javax.ejb.Local; +import javax.naming.ConfigurationException; +import java.net.URI; +import java.security.InvalidParameterException; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.*; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; /** * NetworkManagerImpl implements NetworkManager. @@ -980,39 +942,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "allocating Ip", create = true) - public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId) - throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { - if (networkId != null) { - Network network = _networksDao.findById(networkId); - if (network == null) { - throw new InvalidParameterValueException("Invalid network id is given"); - } - - if (network.getGuestType() == Network.GuestType.Shared) { - DataCenter zone = _configMgr.getZone(zoneId); - if (zone == null) { - throw new InvalidParameterValueException("Invalid zone Id is given"); - } - - // if shared network in the advanced zone, then check the caller against the network for 'AccessType.UseNetwork' - if (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId()) && zone.getNetworkType() == NetworkType.Advanced) { - Account caller = UserContext.current().getCaller(); - long callerUserId = UserContext.current().getCallerUserId(); - _accountMgr.checkAccess(caller, AccessType.UseNetwork, false, network); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Associate IP address called by the user " + callerUserId + " account " + ipOwner.getId()); - } - return allocateIp(ipOwner, false, caller, callerUserId, zone); - } else { - throw new InvalidParameterValueException("Associate IP address can only called on the shared networks in the advanced zone" + - " with Firewall/Source Nat/Static Nat/Port Forwarding/Load balancing services enabled"); - } - } - } - - return allocateIP(ipOwner, false, zoneId); - } - public IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { Account caller = UserContext.current().getCaller(); @@ -1127,17 +1056,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag IPAddressVO ipToAssoc = _ipAddressDao.findById(ipId); if (ipToAssoc != null) { - Network network = _networksDao.findById(networkId); - if (network == null) { - throw new InvalidParameterValueException("Invalid network id is given"); - } - - DataCenter zone = _configMgr.getZone(network.getDataCenterId()); - if (network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced && isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) { - _accountMgr.checkAccess(UserContext.current().getCaller(), AccessType.UseNetwork, false, network); - } else { - _accountMgr.checkAccess(caller, null, true, ipToAssoc); - } + _accountMgr.checkAccess(caller, null, true, ipToAssoc); owner = _accountMgr.getAccount(ipToAssoc.getAllocatedToAccountId()); } else { s_logger.debug("Unable to find ip address by id: " + ipId); @@ -1164,20 +1083,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag throw new InvalidParameterValueException("Ip address can be associated to the network with trafficType " + TrafficType.Guest); } - // Check that network belongs to IP owner - skip this check - // - if zone is basic zone as there is just one guest network, - // - if shared network in Advanced zone - // - and it belongs to the system - if (network.getAccountId() != owner.getId()) { - if (zone.getNetworkType() != NetworkType.Basic && !(zone.getNetworkType() == NetworkType.Advanced && network.getGuestType() == Network.GuestType.Shared)) { - throw new InvalidParameterValueException("The owner of the network is not the same as owner of the IP"); - } + // Check that network belongs to IP owner - skip this check for Basic zone as there is just one guest network, + // and it belongs to the system + if (zone.getNetworkType() != NetworkType.Basic && network.getAccountId() != owner.getId()) { + throw new InvalidParameterValueException("The owner of the network is not the same as owner of the IP"); } - // In Advance zone only allow to do IP assoc - // - for Isolated networks with source nat service enabled - // - for shared networks with source nat service enabled - if (zone.getNetworkType() == NetworkType.Advanced && (!areServicesSupportedInNetwork(network.getId(), Service.SourceNat))) { + // In Advance zone only allow to do IP assoc for Isolated networks with source nat service enabled + if (zone.getNetworkType() == NetworkType.Advanced && + !(network.getGuestType() == GuestType.Isolated && areServicesSupportedInNetwork(network.getId(), + Service.SourceNat))) { throw new InvalidParameterValueException("In zone of type " + NetworkType.Advanced + " ip address can be associated only to the network of guest type " + GuestType.Isolated + " with the " + Service.SourceNat.getName() + " enabled"); @@ -1948,21 +1863,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag try { NetworkGuru guru = _networkGurus.get(network.getGuruName()); Network.State state = network.getState(); - if (state == Network.State.Implemented || state == Network.State.Implementing) { + if (state == Network.State.Implemented || state == Network.State.Setup || state == Network.State.Implementing) { s_logger.debug("Network id=" + networkId + " is already implemented"); implemented.set(guru, network); return implemented; } - if (state == Network.State.Setup) { - DataCenterVO zone = _dcDao.findById(network.getDataCenterId()); - if (!isSharedNetworkOfferingWithServices(network.getNetworkOfferingId()) || (zone.getNetworkType() == NetworkType.Basic)) { - s_logger.debug("Network id=" + networkId + " is already implemented"); - implemented.set(guru, network); - return implemented; - } - } - if (s_logger.isDebugEnabled()) { s_logger.debug("Asking " + guru.getName() + " to implement " + network); } @@ -2010,16 +1916,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkVO network, NetworkOfferingVO offering) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException { - // Associate a source NAT IP (if one isn't already associated with the network) if this is a - // 1) 'Isolated' or 'Shared' guest virtual network in the advance zone - // 2) network has sourceNat service - // 3) network offering does not support a shared source NAT rule + // If this is a 1) guest virtual network 2) network has sourceNat service 3) network offering does not support a + // Shared source NAT rule, + // associate a source NAT IP (if one isn't already associated with the network) boolean sharedSourceNat = offering.getSharedSourceNat(); DataCenter zone = _dcDao.findById(network.getDataCenterId()); - if (!sharedSourceNat && areServicesSupportedInNetwork(network.getId(), Service.SourceNat) - && (network.getGuestType() == Network.GuestType.Isolated || - (network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced))) { + if (network.getGuestType() == Network.GuestType.Isolated + && areServicesSupportedInNetwork(network.getId(), Service.SourceNat) + && !sharedSourceNat) { List ips = null; if (network.getVpcId() != null) { @@ -2500,70 +2405,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - private void checkSharedNetworkCidrOverlap(Long zoneId, String cidr) { - if (zoneId == null) { - return; - } - - if (cidr == null) { - return; - } - - List networks = _networksDao.listByZone(zoneId); - Map networkToCidr = new HashMap(); - for (NetworkVO network : networks) { - if (network.getGuestType() == GuestType.Isolated) { - continue; - } - if (network.getCidr() != null) { - networkToCidr.put(network.getId(), network.getCidr()); - } - } - - //TODO: check for CIDR overlap with all possible CIDR for guest networks in the zone - //when using external networking - - if (networkToCidr == null || networkToCidr.isEmpty()) { - return; - } - - for (long networkId : networkToCidr.keySet()) { - String ntwkCidr = networkToCidr.get(networkId); - if (NetUtils.isNetworksOverlap(ntwkCidr, cidr)) { - throw new InvalidParameterValueException("Warning: The specified existing network has conflict CIDR subnets with new network!"); - } - } - } - - public void checkVirtualNetworkCidrOverlap(Long zoneId, String cidr) { - if (zoneId == null) { - return; - } - if (cidr == null) { - return; - } - List networks = _networksDao.listByZone(zoneId); - Map networkToCidr = new HashMap(); - for (NetworkVO network : networks) { - if (network.getGuestType() != GuestType.Isolated) { - continue; - } - if (network.getCidr() != null) { - networkToCidr.put(network.getId(), network.getCidr()); - } - } - if (networkToCidr == null || networkToCidr.isEmpty()) { - return; - } - - for (long networkId : networkToCidr.keySet()) { - String ntwkCidr = networkToCidr.get(networkId); - if (NetUtils.isNetworksOverlap(ntwkCidr, cidr)) { - throw new InvalidParameterValueException("Warning: The specified existing network has conflict CIDR subnets with new network!"); - } - } - } - @Override @DB @ActionEvent(eventType = EventTypes.EVENT_NETWORK_CREATE, eventDescription = "creating network") @@ -2759,16 +2600,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Collection ntwkProviders = finalizeServicesAndProvidersForNetwork(ntwkOff, physicalNetworkId).values(); if (cidr != null && providersConfiguredForExternalNetworking(ntwkProviders)) { - if (ntwkOff.getGuestType() == GuestType.Shared && (zone.getNetworkType() == NetworkType.Advanced) && - isSharedNetworkOfferingWithServices(networkOfferingId)) { - // validate if CIDR specified overlaps with any of the CIDR's allocated for isolated networks and shared networks in the zone - checkSharedNetworkCidrOverlap(zoneId, cidr); - } else { - throw new InvalidParameterValueException("Cannot specify CIDR when using network offering with external devices!"); - } + throw new InvalidParameterValueException("Cannot specify CIDR when using network offering with external devices!"); } - // Vlan is created in 2 cases - works in Advance zone only: // 1) GuestType is Shared // 2) GuestType is Isolated, but SourceNat service is disabled @@ -4488,19 +4322,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return false; } - public boolean isSharedNetworkOfferingWithServices(long networkOfferingId) { - NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId); - if ( (networkOffering.getGuestType() == Network.GuestType.Shared) && ( - areServicesSupportedByNetworkOffering(networkOfferingId, Service.SourceNat) || - areServicesSupportedByNetworkOffering(networkOfferingId, Service.StaticNat) || - areServicesSupportedByNetworkOffering(networkOfferingId, Service.Firewall) || - areServicesSupportedByNetworkOffering(networkOfferingId, Service.PortForwarding) || - areServicesSupportedByNetworkOffering(networkOfferingId, Service.Lb))) { - return true; - } - return false; - } - @Override public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services) { return (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(networkOfferingId, services)); diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index 874e01767a9..28d1a604c44 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -797,7 +797,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS * @see com.cloud.network.NetworkService#allocateIP(com.cloud.user.Account, long, Long) */ @Override - public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { + public IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { // TODO Auto-generated method stub return null; } diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java index bd8d8bc3a69..642ea10c7ca 100644 --- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java @@ -16,22 +16,6 @@ // under the License. package com.cloud.vpc; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.ejb.Local; -import javax.naming.ConfigurationException; - -import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd; -import org.apache.cloudstack.api.command.user.network.ListNetworksCmd; -import org.apache.log4j.Logger; - -import org.apache.cloudstack.acl.ControlledEntity.ACLType; -import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd; -import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd; import com.cloud.dc.DataCenter; import com.cloud.dc.Vlan; import com.cloud.dc.Vlan.VlanType; @@ -48,12 +32,7 @@ import com.cloud.network.Network.Service; import com.cloud.network.Networks.TrafficType; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.NetworkServiceMapDao; -import com.cloud.network.element.LoadBalancingServiceProvider; -import com.cloud.network.element.NetworkElement; -import com.cloud.network.element.RemoteAccessVPNServiceProvider; -import com.cloud.network.element.Site2SiteVpnServiceProvider; -import com.cloud.network.element.StaticNatServiceProvider; -import com.cloud.network.element.UserDataServiceProvider; +import com.cloud.network.element.*; import com.cloud.network.guru.NetworkGuru; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.FirewallRule.Purpose; @@ -70,6 +49,16 @@ import com.cloud.utils.component.Inject; import com.cloud.utils.component.Manager; import com.cloud.vm.*; import com.cloud.vpc.dao.MockVpcVirtualRouterElement; +import org.apache.cloudstack.acl.ControlledEntity.ACLType; +import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd; +import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd; +import org.apache.cloudstack.api.command.user.network.ListNetworksCmd; +import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd; +import org.apache.log4j.Logger; + +import javax.ejb.Local; +import javax.naming.ConfigurationException; +import java.util.*; @Local(value = { NetworkManager.class, NetworkService.class }) public class MockNetworkManagerImpl implements NetworkManager, Manager{ @@ -1481,7 +1470,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager{ * @see com.cloud.network.NetworkService#allocateIP(com.cloud.user.Account, boolean, long) */ @Override - public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { + public IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { // TODO Auto-generated method stub return null; } From 310d35f88edd6d75499b2089813cfc8b3dd08652 Mon Sep 17 00:00:00 2001 From: Marcus Sorensen Date: Wed, 16 Jan 2013 10:24:14 -0700 Subject: [PATCH 6/8] Summary: Change template details in devcloud-kvm sql file Signed-off-by: Marcus Sorensen 1358357054 -0700 --- tools/devcloud-kvm/devcloud-kvm.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/devcloud-kvm/devcloud-kvm.sql b/tools/devcloud-kvm/devcloud-kvm.sql index 97478834bf3..6d559a9c91a 100644 --- a/tools/devcloud-kvm/devcloud-kvm.sql +++ b/tools/devcloud-kvm/devcloud-kvm.sql @@ -17,7 +17,7 @@ INSERT INTO `cloud`.`disk_offering` (id, name, uuid, display_text, created, use_local_storage, type, disk_size) VALUES (17, 'tinyOffering', UUID(), 'tinyOffering', NOW(), 1, 'Service', 0); -INSERT INTO `cloud`.`service_offering` (id, cpu, speed, ram_size) VALUES (17, 1, 100, 100); +INSERT INTO `cloud`.`service_offering` (id, cpu, speed, ram_size) VALUES (17, 1, 100, 128); INSERT INTO `cloud`.`disk_offering` (id, name, uuid, display_text, created, type, disk_size) VALUES (18, 'tinyDiskOffering', UUID(), 'tinyDiskOffering', NOW(), 'Disk', 1073741824); INSERT INTO `cloud`.`configuration` (instance, name,value) VALUE('DEFAULT','router.ram.size', '100'); INSERT INTO `cloud`.`configuration` (instance, name,value) VALUE('DEFAULT','router.cpu.mhz','100'); @@ -37,4 +37,5 @@ INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'se UPDATE `cloud`.`configuration` SET value='10' where name = 'storage.overprovisioning.factor'; UPDATE `cloud`.`configuration` SET value='10' where name = 'cpu.overprovisioning.factor'; UPDATE `cloud`.`configuration` SET value='10' where name = 'mem.overprovisioning.factor'; -UPDATE `cloud`.`vm_template` SET unique_name="tiny Linux",name="tiny Linux",url="http://marcus.mlsorensen.com/cloudstack-extras/ttylinux_pv.qcow2",checksum="81dcf4b4ca05a3b637a040e851568f29",display_text="tiny Linux",format='QCOW2',hypervisor_type='KVM' where id=5; +UPDATE `cloud`.`vm_template` SET unique_name="tiny CentOS 6.3",name="tiny CentOS 6.3",url="http://marcus.mlsorensen.com/cloudstack-extras/tiny-centos-63.qcow2",checksum="4bbb806aa8570f4dfac13b4c38ea1603",display_text="tiny CentOS 6.3",format='QCOW2',hypervisor_type='KVM' where id=5; +UPDATE `cloud`.`vm_template` SET url="http://dontdownloadthistemplate" where id=4; From 4f479e2b23cbbc42247531bd8abb005fc1b89591 Mon Sep 17 00:00:00 2001 From: Marcus Sorensen Date: Wed, 16 Jan 2013 10:30:31 -0700 Subject: [PATCH 7/8] Summary: Modifying integration tests to use 128MB service offerings Detail: The default devcloud tiny template is set up via devcloud.sql to have at least 100MB RAM, changing the tests as well. This will also allow the builtin devcloud-kvm tiny template to work for tests as it requires a bit more. Signed-off-by: Marcus Sorensen 1358357431 -0700 --- test/integration/smoke/test_routers.py | 2 +- test/integration/smoke/test_service_offerings.py | 2 +- test/integration/smoke/test_templates.py | 2 +- test/integration/smoke/test_vm_life_cycle.py | 2 +- test/integration/smoke/test_volumes.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/integration/smoke/test_routers.py b/test/integration/smoke/test_routers.py index 93dc7606ace..435c7e41a43 100644 --- a/test/integration/smoke/test_routers.py +++ b/test/integration/smoke/test_routers.py @@ -41,7 +41,7 @@ class Services: "displaytext": "Tiny Instance", "cpunumber": 1, "cpuspeed": 100, # in MHz - "memory": 64, # In MBs + "memory": 128, # In MBs }, "virtual_machine": { diff --git a/test/integration/smoke/test_service_offerings.py b/test/integration/smoke/test_service_offerings.py index 3a8a9e156b9..7f4d130ee80 100644 --- a/test/integration/smoke/test_service_offerings.py +++ b/test/integration/smoke/test_service_offerings.py @@ -39,7 +39,7 @@ class Services: "displaytext": "Service Offering", "cpunumber": 1, "cpuspeed": 100, # MHz - "memory": 64, # in MBs + "memory": 128, # in MBs }, } diff --git a/test/integration/smoke/test_templates.py b/test/integration/smoke/test_templates.py index d450a5d8122..663b174ed78 100644 --- a/test/integration/smoke/test_templates.py +++ b/test/integration/smoke/test_templates.py @@ -52,7 +52,7 @@ class Services: "displaytext": "Tiny Instance", "cpunumber": 1, "cpuspeed": 100, # in MHz - "memory": 64, # In MBs + "memory": 128, # In MBs }, "disk_offering": { "displaytext": "Small", diff --git a/test/integration/smoke/test_vm_life_cycle.py b/test/integration/smoke/test_vm_life_cycle.py index f6fe4e002a1..0bd4f959bc3 100644 --- a/test/integration/smoke/test_vm_life_cycle.py +++ b/test/integration/smoke/test_vm_life_cycle.py @@ -80,7 +80,7 @@ class Services: "displaytext": "Tiny Instance", "cpunumber": 1, "cpuspeed": 100, # in MHz - "memory": 64, # In MBs + "memory": 128, # In MBs }, "small": { diff --git a/test/integration/smoke/test_volumes.py b/test/integration/smoke/test_volumes.py index 2d0cd491672..3fe68ec5621 100644 --- a/test/integration/smoke/test_volumes.py +++ b/test/integration/smoke/test_volumes.py @@ -53,7 +53,7 @@ class Services: "displaytext": "Tiny Instance", "cpunumber": 1, "cpuspeed": 100, # in MHz - "memory": 64, # In MBs + "memory": 128, # In MBs }, "disk_offering": { "displaytext": "Small", From a69e7f9bf605079968a7e3a7facdede167504aa4 Mon Sep 17 00:00:00 2001 From: Pranav Saxena Date: Thu, 17 Jan 2013 00:02:11 +0530 Subject: [PATCH 8/8] CLOUDSTACK-972:The template will disappear after reordering in template section --- ui/scripts/ui/widgets/listView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/scripts/ui/widgets/listView.js b/ui/scripts/ui/widgets/listView.js index 85523ea5e7a..9e16ec2ae54 100644 --- a/ui/scripts/ui/widgets/listView.js +++ b/ui/scripts/ui/widgets/listView.js @@ -560,8 +560,8 @@ return $(this).index() == index; }); - if ($target.index() > $tr.index()) $target.after($tr); - else $target.before($tr); + // if ($target.index() > $tr.index()) $target.after($tr); + // else $target.before($tr); $tr.closest('.list-view').scrollTop($tr.position().top - $tr.height() * 2);