-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Multiple networks support for vms in advanced zone with security group (and kvm support) #3639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e7f7af6
3b4721d
5434dbd
995b455
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
| import java.util.LinkedHashMap; | ||
|
|
@@ -166,6 +167,7 @@ | |
| import com.cloud.network.dao.NetworkDao; | ||
| import com.cloud.network.dao.NetworkVO; | ||
| import com.cloud.network.router.VirtualRouter; | ||
| import com.cloud.network.security.SecurityGroupManager; | ||
| import com.cloud.offering.DiskOffering; | ||
| import com.cloud.offering.DiskOfferingInfo; | ||
| import com.cloud.offering.NetworkOffering; | ||
|
|
@@ -333,6 +335,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac | |
| private NetworkOfferingDetailsDao networkOfferingDetailsDao; | ||
| @Inject | ||
| private NetworkDetailsDao networkDetailsDao; | ||
| @Inject | ||
| private SecurityGroupManager _securityGroupManager; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Java Naming Conventions does not recommend using _ (underscore) before variable name. Can you please remove it? |
||
|
|
||
| VmWorkJobHandlerProxy _jobHandlerProxy = new VmWorkJobHandlerProxy(this); | ||
|
|
||
|
|
@@ -3140,11 +3144,18 @@ private void orchestrateReboot(final String vmUuid, final Map<VirtualMachineProf | |
| try { | ||
|
|
||
| final Commands cmds = new Commands(Command.OnError.Stop); | ||
| cmds.addCommand(new RebootCommand(vm.getInstanceName(), getExecuteInSequence(vm.getHypervisorType()))); | ||
| RebootCommand rebootCmd = new RebootCommand(vm.getInstanceName(), getExecuteInSequence(vm.getHypervisorType())); | ||
| rebootCmd.setVirtualMachine(getVmTO(vm.getId())); | ||
| cmds.addCommand(rebootCmd); | ||
| _agentMgr.send(host.getId(), cmds); | ||
|
|
||
| final Answer rebootAnswer = cmds.getAnswer(RebootAnswer.class); | ||
| if (rebootAnswer != null && rebootAnswer.getResult()) { | ||
| if (dc.isSecurityGroupEnabled() && vm.getType() == VirtualMachine.Type.User) { | ||
| List<Long> affectedVms = new ArrayList<Long>(); | ||
| affectedVms.add(vm.getId()); | ||
| _securityGroupManager.scheduleRulesetUpdateToHosts(affectedVms, true, null); | ||
| } | ||
| return; | ||
| } | ||
| s_logger.info("Unable to reboot VM " + vm + " on " + dest.getHost() + " due to " + (rebootAnswer == null ? " no reboot answer" : rebootAnswer.getDetails())); | ||
|
|
@@ -3154,6 +3165,29 @@ private void orchestrateReboot(final String vmUuid, final Map<VirtualMachineProf | |
| } | ||
| } | ||
|
|
||
| protected VirtualMachineTO getVmTO(Long vmId) { | ||
| final VMInstanceVO vm = _vmDao.findById(vmId); | ||
| final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); | ||
| final List<NicVO> nics = _nicsDao.listByVmId(profile.getId()); | ||
| Collections.sort(nics, new Comparator<NicVO>() { | ||
| @Override | ||
| public int compare(NicVO nic1, NicVO nic2) { | ||
| Long nicId1 = Long.valueOf(nic1.getDeviceId()); | ||
| Long nicId2 = Long.valueOf(nic2.getDeviceId()); | ||
| return nicId1.compareTo(nicId2); | ||
| } | ||
| }); | ||
| for (final NicVO nic : nics) { | ||
| final Network network = _networkModel.getNetwork(nic.getNetworkId()); | ||
| final NicProfile nicProfile = | ||
| new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.isSecurityGroupSupportedInNetwork(network), | ||
| _networkModel.getNetworkTag(profile.getHypervisorType(), network)); | ||
| profile.addNic(nicProfile); | ||
| } | ||
| final VirtualMachineTO to = toVmTO(profile); | ||
| return to; | ||
| } | ||
|
|
||
| public Command cleanup(final VirtualMachine vm, Map<String, DpdkTO> dpdkInterfaceMapping) { | ||
| StopCommand cmd = new StopCommand(vm, getExecuteInSequence(vm.getHypervisorType()), false); | ||
| cmd.setControlIp(getControlNicIpForVM(vm)); | ||
|
|
@@ -3670,7 +3704,7 @@ private boolean orchestrateRemoveNicFromVm(final VirtualMachine vm, final Nic ni | |
|
|
||
| //3) Remove the nic | ||
| _networkMgr.removeNic(vmProfile, nic); | ||
| _nicsDao.expunge(nic.getId()); | ||
| _nicsDao.remove(nic.getId()); | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,7 @@ | |
| import com.cloud.agent.resource.virtualnetwork.VRScripts; | ||
| import com.cloud.agent.resource.virtualnetwork.VirtualRouterDeployer; | ||
| import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource; | ||
| import com.cloud.agent.api.SecurityGroupRulesCmd; | ||
| import com.cloud.dc.Vlan; | ||
| import com.cloud.exception.InternalErrorException; | ||
| import com.cloud.host.Host.Type; | ||
|
|
@@ -146,6 +147,7 @@ | |
| import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager; | ||
| import com.cloud.hypervisor.kvm.storage.KVMStorageProcessor; | ||
| import com.cloud.network.Networks.BroadcastDomainType; | ||
| import com.cloud.network.Networks.IsolationType; | ||
| import com.cloud.network.Networks.RouterPrivateIpStrategy; | ||
| import com.cloud.network.Networks.TrafficType; | ||
| import com.cloud.resource.RequestWrapper; | ||
|
|
@@ -3548,7 +3550,117 @@ public boolean destroyNetworkRulesForVM(final Connect conn, final String vmName) | |
| return true; | ||
| } | ||
|
|
||
| public boolean defaultNetworkRules(final Connect conn, final String vmName, final NicTO nic, final Long vmId, final String secIpStr) { | ||
| /** | ||
| * Function to destroy the security group rules applied to the nic's | ||
| * @param conn | ||
| * @param vmName | ||
| * @param nic | ||
| * @return | ||
| * true : If success | ||
| * false : If failure | ||
| */ | ||
| public boolean destroyNetworkRulesForNic(final Connect conn, final String vmName, final NicTO nic) { | ||
| if (!_canBridgeFirewall) { | ||
| return false; | ||
| } | ||
| final List<String> nicSecIps = nic.getNicSecIps(); | ||
| String secIpsStr; | ||
| final StringBuilder sb = new StringBuilder(); | ||
| if (nicSecIps != null) { | ||
| for (final String ip : nicSecIps) { | ||
| sb.append(ip).append(SecurityGroupRulesCmd.RULE_COMMAND_SEPARATOR); | ||
| } | ||
| secIpsStr = sb.toString(); | ||
| } else { | ||
| secIpsStr = "0" + SecurityGroupRulesCmd.RULE_COMMAND_SEPARATOR; | ||
| } | ||
| final List<InterfaceDef> intfs = getInterfaces(conn, vmName); | ||
| if (intfs.size() == 0 || intfs.size() < nic.getDeviceId()) { | ||
| return false; | ||
| } | ||
|
|
||
| final InterfaceDef intf = intfs.get(nic.getDeviceId()); | ||
| final String brname = intf.getBrName(); | ||
| final String vif = intf.getDevName(); | ||
|
|
||
| final Script cmd = new Script(_securityGroupPath, _timeout, s_logger); | ||
| cmd.add("destroy_network_rules_for_vm"); | ||
| cmd.add("--vmname", vmName); | ||
| if (nic.getIp() != null) { | ||
| cmd.add("--vmip", nic.getIp()); | ||
| } | ||
| cmd.add("--vmmac", nic.getMac()); | ||
| cmd.add("--vif", vif); | ||
| cmd.add("--nicsecips", secIpsStr); | ||
|
|
||
| final String result = cmd.execute(); | ||
| if (result != null) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Function to apply default network rules for a VM | ||
| * @param conn | ||
| * @param vm | ||
| * @param checkBeforeApply | ||
| * @return | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding documentation. Just a note: I don't think that |
||
| */ | ||
| public boolean applyDefaultNetworkRules(final Connect conn, final VirtualMachineTO vm, final boolean checkBeforeApply) { | ||
| NicTO[] nicTOs = new NicTO[] {}; | ||
| if (vm != null && vm.getNics() != null) { | ||
| s_logger.debug("Checking default network rules for vm " + vm.getName()); | ||
| nicTOs = vm.getNics(); | ||
| } | ||
| for (NicTO nic : nicTOs) { | ||
| if (vm.getType() != VirtualMachine.Type.User) { | ||
| nic.setPxeDisable(true); | ||
| } | ||
| } | ||
| boolean isFirstNic = true; | ||
| for (final NicTO nic : nicTOs) { | ||
| if (nic.isSecurityGroupEnabled() || nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) { | ||
| if (vm.getType() != VirtualMachine.Type.User) { | ||
| configureDefaultNetworkRulesForSystemVm(conn, vm.getName()); | ||
| break; | ||
| } | ||
| if (!applyDefaultNetworkRulesOnNic(conn, vm.getName(), vm.getId(), nic, isFirstNic, checkBeforeApply)) { | ||
| s_logger.error("Unable to apply default network rule for nic " + nic.getName() + " for VM " + vm.getName()); | ||
| return false; | ||
| } | ||
| isFirstNic = false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Function to apply default network rules for a NIC | ||
| * @param conn | ||
| * @param vmName | ||
| * @param vmId | ||
| * @param nic | ||
| * @param isFirstNic | ||
| * @param checkBeforeApply | ||
| * @return | ||
| */ | ||
| public boolean applyDefaultNetworkRulesOnNic(final Connect conn, final String vmName, final Long vmId, final NicTO nic, boolean isFirstNic, boolean checkBeforeApply) { | ||
| final List<String> nicSecIps = nic.getNicSecIps(); | ||
| String secIpsStr; | ||
| final StringBuilder sb = new StringBuilder(); | ||
| if (nicSecIps != null) { | ||
| for (final String ip : nicSecIps) { | ||
| sb.append(ip).append(SecurityGroupRulesCmd.RULE_COMMAND_SEPARATOR); | ||
| } | ||
| secIpsStr = sb.toString(); | ||
| } else { | ||
| secIpsStr = "0" + SecurityGroupRulesCmd.RULE_COMMAND_SEPARATOR; | ||
| } | ||
| return defaultNetworkRules(conn, vmName, nic, vmId, secIpsStr, isFirstNic, checkBeforeApply); | ||
| } | ||
|
|
||
| public boolean defaultNetworkRules(final Connect conn, final String vmName, final NicTO nic, final Long vmId, final String secIpStr, final boolean isFirstNic, final boolean checkBeforeApply) { | ||
| if (!_canBridgeFirewall) { | ||
| return false; | ||
| } | ||
|
|
@@ -3576,6 +3688,12 @@ public boolean defaultNetworkRules(final Connect conn, final String vmName, fina | |
| cmd.add("--vif", vif); | ||
| cmd.add("--brname", brname); | ||
| cmd.add("--nicsecips", secIpStr); | ||
| if (isFirstNic) { | ||
| cmd.add("--isFirstNic"); | ||
| } | ||
| if (checkBeforeApply) { | ||
| cmd.add("--check"); | ||
| } | ||
| final String result = cmd.execute(); | ||
| if (result != null) { | ||
| return false; | ||
|
|
@@ -3665,7 +3783,7 @@ public boolean addNetworkRules(final String vmName, final String vmId, final Str | |
| return true; | ||
| } | ||
|
|
||
| public boolean configureNetworkRulesVMSecondaryIP(final Connect conn, final String vmName, final String secIp, final String action) { | ||
| public boolean configureNetworkRulesVMSecondaryIP(final Connect conn, final String vmName, final String vmMac, final String secIp, final String action) { | ||
|
|
||
| if (!_canBridgeFirewall) { | ||
| return false; | ||
|
|
@@ -3674,6 +3792,7 @@ public boolean configureNetworkRulesVMSecondaryIP(final Connect conn, final Stri | |
| final Script cmd = new Script(_securityGroupPath, _timeout, s_logger); | ||
| cmd.add("network_rules_vmSecondaryIp"); | ||
| cmd.add("--vmname", vmName); | ||
| cmd.add("--vmmac", vmMac); | ||
| cmd.add("--nicsecips", secIp); | ||
| cmd.add("--action=" + action); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that RULE_TARGET_SEPARATOR is not being used outside this class. Is that correct? If it is indeed the case, this should be set back to private.