Skip to content

Commit 314a491

Browse files
committed
bug 8094: forword port NetworkRulesSystemVmComman from 2.1.x to 2.2, to fix security group is lost after migration
status 8094: resovled fixed Conflicts: agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
1 parent 1bcbd98 commit 314a491

4 files changed

Lines changed: 117 additions & 3 deletions

File tree

‎agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
import com.cloud.agent.api.ModifySshKeysCommand;
109109
import com.cloud.agent.api.ModifyStoragePoolAnswer;
110110
import com.cloud.agent.api.ModifyStoragePoolCommand;
111+
import com.cloud.agent.api.NetworkRulesSystemVmCommand;
111112
import com.cloud.agent.api.NetworkUsageAnswer;
112113
import com.cloud.agent.api.NetworkUsageCommand;
113114
import com.cloud.agent.api.PingCommand;
@@ -168,6 +169,7 @@
168169
import com.cloud.hypervisor.Hypervisor.HypervisorType;
169170
import com.cloud.network.Networks.BroadcastDomainType;
170171
import com.cloud.network.Networks.RouterPrivateIpStrategy;
172+
import com.cloud.network.Networks.IsolationType;
171173
import com.cloud.network.Networks.TrafficType;
172174
import com.cloud.resource.ServerResource;
173175
import com.cloud.resource.ServerResourceBase;
@@ -865,6 +867,8 @@ public Answer executeRequest(Command cmd) {
865867
return execute((CheckSshCommand) cmd);
866868
} else if (cmd instanceof NetworkUsageCommand) {
867869
return execute((NetworkUsageCommand) cmd);
870+
} else if (cmd instanceof NetworkRulesSystemVmCommand) {
871+
return execute((NetworkRulesSystemVmCommand)cmd);
868872
} else {
869873
s_logger.warn("Unsupported command ");
870874
return Answer.createUnsupportedCommandAnswer(cmd);
@@ -1724,6 +1728,7 @@ private Answer execute(CheckVirtualMachineCommand cmd) {
17241728
_vms.put(cmd.getVmName(), State.Running);
17251729
}
17261730
}
1731+
17271732
return new CheckVirtualMachineAnswer(cmd, state, vncPort);
17281733
} catch (LibvirtException e) {
17291734
return new CheckVirtualMachineAnswer(cmd, e.getMessage());
@@ -2224,7 +2229,12 @@ protected synchronized StartAnswer execute(StartCommand cmd) {
22242229
if (vmSpec.getType() != VirtualMachine.Type.User) {
22252230
default_network_rules_for_systemvm(vmName);
22262231
} else {
2227-
default_network_rules(vmName, vmSpec.getNics()[0].getIp(), vmSpec.getId(), vmSpec.getNics()[0].getMac());
2232+
NicTO[] nics = vmSpec.getNics();
2233+
for (NicTO nic : nics) {
2234+
if (nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) {
2235+
default_network_rules(vmName, vmSpec.getNics()[0].getIp(), vmSpec.getId(), vmSpec.getNics()[0].getMac());
2236+
}
2237+
}
22282238
}
22292239

22302240
// Attach each data volume to the VM, if there is a deferred attached disk
@@ -3593,4 +3603,13 @@ private StoragePool getStoragePool(Connect conn, String uuid) throws LibvirtExce
35933603
}
35943604
return storage;
35953605
}
3606+
3607+
private Answer execute(NetworkRulesSystemVmCommand cmd) {
3608+
boolean success = false;
3609+
if (cmd.getType() != VirtualMachine.Type.User) {
3610+
success = default_network_rules_for_systemvm(cmd.getVmName());
3611+
}
3612+
3613+
return new Answer(cmd, success, "");
3614+
}
35963615
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.cloud.agent.api;
2+
3+
import com.cloud.vm.VirtualMachine;
4+
5+
public class NetworkRulesSystemVmCommand extends Command {
6+
/**
7+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
8+
*
9+
* This software is licensed under the GNU General Public License v3 or later.
10+
*
11+
* It is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation, either version 3 of the License, or any later version.
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
private String vmName;
25+
private long vmId;
26+
private String pubIp;
27+
private String mac;
28+
private VirtualMachine.Type type;
29+
30+
protected NetworkRulesSystemVmCommand() {
31+
32+
}
33+
34+
public NetworkRulesSystemVmCommand(String vmName, VirtualMachine.Type type) {
35+
this.vmName = vmName;
36+
}
37+
38+
public NetworkRulesSystemVmCommand(String vmName, long vmId, String publicIP, String mac, VirtualMachine.Type type) {
39+
this.vmName = vmName;
40+
this.vmId = vmId;
41+
this.pubIp = publicIP;
42+
this.mac = mac;
43+
this.type = type;
44+
}
45+
46+
public String getVmName() {
47+
return vmName;
48+
}
49+
50+
public long getVmId() {
51+
return vmId;
52+
}
53+
54+
public String getIp() {
55+
return pubIp;
56+
}
57+
58+
public String getMac() {
59+
return mac;
60+
}
61+
62+
public VirtualMachine.Type getType() {
63+
return type;
64+
}
65+
@Override
66+
public boolean executeInSequence() {
67+
return false;
68+
}
69+
}

‎core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import com.cloud.agent.api.ModifySshKeysCommand;
9393
import com.cloud.agent.api.ModifyStoragePoolAnswer;
9494
import com.cloud.agent.api.ModifyStoragePoolCommand;
95+
import com.cloud.agent.api.NetworkRulesSystemVmCommand;
9596
import com.cloud.agent.api.PingCommand;
9697
import com.cloud.agent.api.PingRoutingCommand;
9798
import com.cloud.agent.api.PingRoutingWithNwGroupsCommand;
@@ -441,6 +442,8 @@ public Answer executeRequest(Command cmd) {
441442
return execute((OvsDeleteFlowCommand)cmd);
442443
} else if (cmd instanceof CleanupNetworkRulesCmd){
443444
return execute((CleanupNetworkRulesCmd)cmd);
445+
} else if (cmd instanceof NetworkRulesSystemVmCommand) {
446+
return execute((NetworkRulesSystemVmCommand)cmd);
444447
} else {
445448
return Answer.createUnsupportedCommandAnswer(cmd);
446449
}
@@ -5664,4 +5667,17 @@ protected class XenServerHost {
56645667
protected String getGuestOsType(String stdType, boolean bootFromCD) {
56655668
return stdType;
56665669
}
5670+
5671+
private Answer execute(NetworkRulesSystemVmCommand cmd) {
5672+
boolean success = true;
5673+
Connection conn = getConnection();
5674+
if (cmd.getType() != VirtualMachine.Type.User) {
5675+
String result = callHostPlugin(conn, "vmops", "default_network_rules_systemvm", "vmName", cmd.getVmName());
5676+
if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
5677+
success = false;
5678+
}
5679+
}
5680+
5681+
return new Answer(cmd, success, "");
5682+
}
56675683
}

‎server/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.cloud.agent.api.Command;
4040
import com.cloud.agent.api.MigrateAnswer;
4141
import com.cloud.agent.api.MigrateCommand;
42+
import com.cloud.agent.api.NetworkRulesSystemVmCommand;
4243
import com.cloud.agent.api.PrepareForMigrationAnswer;
4344
import com.cloud.agent.api.PrepareForMigrationCommand;
4445
import com.cloud.agent.api.StartAnswer;
@@ -91,6 +92,7 @@
9192
import com.cloud.user.User;
9293
import com.cloud.user.dao.AccountDao;
9394
import com.cloud.user.dao.UserDao;
95+
import com.cloud.uservm.UserVm;
9496
import com.cloud.utils.Journal;
9597
import com.cloud.utils.NumbersUtil;
9698
import com.cloud.utils.Pair;
@@ -997,9 +999,17 @@ public <T extends VMInstanceVO> T migrate(T vm, long srcHostId, DeployDestinatio
997999
if (!ma.getResult()) {
9981000
return null;
9991001
}
1000-
1002+
Commands cmds = new Commands(OnError.Revert);
10011003
CheckVirtualMachineCommand cvm = new CheckVirtualMachineCommand(vm.getInstanceName());
1002-
CheckVirtualMachineAnswer answer = (CheckVirtualMachineAnswer)_agentMgr.send(dstHostId, cvm);
1004+
cmds.addCommand(cvm);
1005+
1006+
if (vm.getType() != VirtualMachine.Type.User) {
1007+
NetworkRulesSystemVmCommand nrc = new NetworkRulesSystemVmCommand(vm.getInstanceName(), vm.getType());
1008+
cmds.addCommand(nrc);
1009+
}
1010+
1011+
_agentMgr.send(dstHostId, cmds);
1012+
CheckVirtualMachineAnswer answer = cmds.getAnswer(CheckVirtualMachineAnswer.class);
10031013
if (!answer.getResult()) {
10041014
s_logger.debug("Unable to complete migration for " + vm.toString());
10051015
stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);

0 commit comments

Comments
 (0)