Skip to content

Commit 807dc09

Browse files
CLOUDSTACK-5561 Support of multiple public vlans on VR running in HyperV
1 parent ce0dc3b commit 807dc09

15 files changed

Lines changed: 697 additions & 75 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.agent.api;
18+
19+
import java.util.List;
20+
21+
public class GetVmConfigAnswer extends Answer {
22+
23+
String vmName;
24+
List<NicDetails> nics;
25+
26+
protected GetVmConfigAnswer() {
27+
}
28+
29+
public GetVmConfigAnswer(String vmName, List<NicDetails> nics) {
30+
this.vmName = vmName;
31+
this.nics = nics;
32+
}
33+
34+
public String getVmName() {
35+
return vmName;
36+
}
37+
38+
public List<NicDetails> getNics() {
39+
return nics;
40+
}
41+
42+
public class NicDetails {
43+
String macAddress;
44+
int vlanid;
45+
46+
public NicDetails() {
47+
}
48+
49+
public NicDetails(String macAddress, int vlanid) {
50+
this.macAddress = macAddress;
51+
this.vlanid = vlanid;
52+
}
53+
54+
public String getMacAddress() {
55+
return macAddress;
56+
}
57+
58+
public int getVlanid() {
59+
return vlanid;
60+
}
61+
62+
}
63+
64+
@Override
65+
public boolean executeInSequence() {
66+
return false;
67+
}
68+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.agent.api;
18+
19+
20+
import java.util.List;
21+
22+
import com.cloud.agent.api.to.NicTO;
23+
24+
public class GetVmConfigCommand extends Command {
25+
String vmName;
26+
List<NicTO> nics;
27+
protected GetVmConfigCommand() {
28+
}
29+
30+
public GetVmConfigCommand(String vmName) {
31+
this.vmName = vmName;
32+
}
33+
34+
public String getVmName() {
35+
return vmName;
36+
}
37+
38+
public void setNics(List<NicTO> nics){
39+
this.nics = nics;
40+
}
41+
42+
@Override
43+
public boolean executeInSequence() {
44+
return false;
45+
}
46+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.agent.api;
18+
19+
public class ModifyVmNicConfigAnswer extends Answer {
20+
String vmName;
21+
protected ModifyVmNicConfigAnswer() {
22+
}
23+
24+
public ModifyVmNicConfigAnswer(String vmName) {
25+
this.vmName = vmName;
26+
}
27+
28+
public String getVmName() {
29+
return vmName;
30+
}
31+
32+
@Override
33+
public boolean executeInSequence() {
34+
return false;
35+
}
36+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.agent.api;
18+
19+
20+
public class ModifyVmNicConfigCommand extends Command {
21+
String vmName;
22+
int vlan;
23+
String macAddress;
24+
protected ModifyVmNicConfigCommand() {
25+
}
26+
27+
public ModifyVmNicConfigCommand(String vmName, int vlan, String macAddress) {
28+
this.vmName = vmName;
29+
this.vlan = vlan;
30+
this.macAddress = macAddress;
31+
}
32+
33+
public String getVmName() {
34+
return vmName;
35+
}
36+
37+
38+
@Override
39+
public boolean executeInSequence() {
40+
return false;
41+
}
42+
}

plugins/hypervisors/hyperv/DotNet/ServerResource/AgentShell/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<value>2048</value>
9797
</setting>
9898
<setting name="private_ip_address" serializeAs="String">
99-
<value>10.102.192.150</value>
99+
<value>0.0.0.0</value>
100100
</setting>
101101
</CloudStack.Plugin.AgentShell.AgentSettings>
102102
</applicationSettings>

plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,20 @@ public class VmStatsEntry
690690
public String entityType;
691691
}
692692

693+
public class NicDetails
694+
{
695+
[JsonProperty("macAddress")]
696+
public string macaddress;
697+
[JsonProperty("vlanid")]
698+
public int vlanid;
699+
public NicDetails() { }
700+
public NicDetails(String macaddress, int vlanid)
701+
{
702+
this.macaddress = macaddress;
703+
this.vlanid = vlanid;
704+
}
705+
}
706+
693707
/// <summary>
694708
/// Fully qualified named for a number of types used in CloudStack. Used to specify the intended type for JSON serialised objects.
695709
/// </summary>
@@ -738,6 +752,10 @@ public class CloudStackTypes
738752
public const string GetVmDiskStatsCommand = "com.cloud.agent.api.GetVmDiskStatsCommand";
739753
public const string GetVmStatsAnswer = "com.cloud.agent.api.GetVmStatsAnswer";
740754
public const string GetVmStatsCommand = "com.cloud.agent.api.GetVmStatsCommand";
755+
public const string GetVmConfigCommand = "com.cloud.agent.api.GetVmConfigCommand";
756+
public const string GetVmConfigAnswer = "com.cloud.agent.api.GetVmConfigAnswer";
757+
public const string ModifyVmNicConfigCommand = "com.cloud.agent.api.ModifyVmNicConfigCommand";
758+
public const string ModifyVmNicConfigAnswer = "com.cloud.agent.api.ModifyVmNicConfigAnswer";
741759
public const string GetVncPortAnswer = "com.cloud.agent.api.GetVncPortAnswer";
742760
public const string GetVncPortCommand = "com.cloud.agent.api.GetVncPortCommand";
743761
public const string HostStatsEntry = "com.cloud.agent.api.HostStatsEntry";

plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,24 @@ private bool ValidateStoragePoolCommand(dynamic cmd, out string localPath, out S
982982
return true;
983983
}
984984

985+
// POST api/HypervResource/PlugNicCommand
986+
[HttpPost]
987+
[ActionName(CloudStackTypes.PlugNicCommand)]
988+
public JContainer PlugNicCommand([FromBody]dynamic cmd)
989+
{
990+
using (log4net.NDC.Push(Guid.NewGuid().ToString()))
991+
{
992+
logger.Info(CloudStackTypes.PlugNicCommand + cmd.ToString());
993+
object ansContent = new
994+
{
995+
result = true,
996+
details = "instead of plug, change he network settings",
997+
contextMap = contextMap
998+
};
999+
return ReturnCloudStackTypedJArray(ansContent, CloudStackTypes.PlugNicAnswer);
1000+
}
1001+
}
1002+
9851003

9861004
// POST api/HypervResource/CleanupNetworkRulesCmd
9871005
[HttpPost]
@@ -1264,6 +1282,88 @@ public JContainer PingCommand([FromBody]dynamic cmd)
12641282
}
12651283
}
12661284

1285+
// POST api/HypervResource/ModifyVmVnicVlanCommand
1286+
[HttpPost]
1287+
[ActionName(CloudStackTypes.ModifyVmNicConfigCommand)]
1288+
public JContainer ModifyVmNicConfigCommand([FromBody]dynamic cmd)
1289+
{
1290+
1291+
using (log4net.NDC.Push(Guid.NewGuid().ToString()))
1292+
{
1293+
logger.Info(CloudStackTypes.ModifyVmNicConfigCommand + cmd.ToString());
1294+
bool result = false;
1295+
String vmName = cmd.vmName;
1296+
uint vlan = (uint)cmd.vlan;
1297+
string macAddress = cmd.macAddress;
1298+
wmiCallsV2.ModifyVmVLan(vmName, vlan, macAddress);
1299+
1300+
result = true;
1301+
1302+
object ansContent = new
1303+
{
1304+
vmName = vmName,
1305+
result = result,
1306+
contextMap = contextMap
1307+
};
1308+
return ReturnCloudStackTypedJArray(ansContent, CloudStackTypes.ModifyVmNicConfigAnswer);
1309+
}
1310+
1311+
}
1312+
1313+
// POST api/HypervResource/GetVmConfigCommand
1314+
[HttpPost]
1315+
[ActionName(CloudStackTypes.GetVmConfigCommand)]
1316+
public JContainer GetVmConfigCommand([FromBody]dynamic cmd)
1317+
{
1318+
using (log4net.NDC.Push(Guid.NewGuid().ToString()))
1319+
{
1320+
logger.Info(CloudStackTypes.GetVmConfigCommand + cmd.ToString());
1321+
bool result = false;
1322+
String vmName = cmd.vmName;
1323+
ComputerSystem vm = wmiCallsV2.GetComputerSystem(vmName);
1324+
List<NicDetails> nicDetails = new List<NicDetails>();
1325+
var nicSettingsViaVm = wmiCallsV2.GetEthernetPortSettings(vm);
1326+
NicDetails nic = null;
1327+
String[] macAddress = new String[nicSettingsViaVm.Length];
1328+
int index = 0;
1329+
foreach (SyntheticEthernetPortSettingData item in nicSettingsViaVm)
1330+
{
1331+
macAddress[index++] = item.Address;
1332+
}
1333+
1334+
index = 0;
1335+
var ethernetConnections = wmiCallsV2.GetEthernetConnections(vm);
1336+
int vlanid = 1;
1337+
foreach (EthernetPortAllocationSettingData item in ethernetConnections)
1338+
{
1339+
EthernetSwitchPortVlanSettingData vlanSettings = wmiCallsV2.GetVlanSettings(item);
1340+
if (vlanSettings == null)
1341+
{
1342+
vlanid = -1;
1343+
}
1344+
else
1345+
{
1346+
vlanid = vlanSettings.AccessVlanId;
1347+
}
1348+
nic = new NicDetails(macAddress[index++], vlanid);
1349+
nicDetails.Add(nic);
1350+
}
1351+
1352+
result = true;
1353+
1354+
object ansContent = new
1355+
{
1356+
vmName = vmName,
1357+
nics = nicDetails,
1358+
result = result,
1359+
contextMap = contextMap
1360+
};
1361+
return ReturnCloudStackTypedJArray(ansContent, CloudStackTypes.GetVmConfigAnswer);
1362+
}
1363+
}
1364+
1365+
1366+
12671367
// POST api/HypervResource/GetVmStatsCommand
12681368
[HttpPost]
12691369
[ActionName(CloudStackTypes.GetVmStatsCommand)]

plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/IWmiCallsV2.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ public interface IWmiCallsV2
6666
void patchSystemVmIso(string vmName, string systemVmIso);
6767
void SetState(ComputerSystem vm, ushort requiredState);
6868
Dictionary<String, VmState> GetVmSync(String privateIpAddress);
69+
void ModifyVmVLan(string vmName, uint vlanid, string mac);
6970
}
7071
}

0 commit comments

Comments
 (0)