Skip to content

Commit f9cf2c2

Browse files
CLOUDSTACK-6518 [Hyper-V] Efficient way of finding the empty nic in VR/VpcVR to configure VPC entities
1 parent 6cbb9a5 commit f9cf2c2

7 files changed

Lines changed: 364 additions & 87 deletions

File tree

core/src/com/cloud/agent/api/GetVmConfigAnswer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ public List<NicDetails> getNics() {
4242
public class NicDetails {
4343
String macAddress;
4444
int vlanid;
45+
boolean state;
4546

4647
public NicDetails() {
4748
}
4849

49-
public NicDetails(String macAddress, int vlanid) {
50+
public NicDetails(String macAddress, int vlanid, boolean state) {
5051
this.macAddress = macAddress;
5152
this.vlanid = vlanid;
53+
this.state = state;
5254
}
5355

5456
public String getMacAddress() {
@@ -59,6 +61,9 @@ public int getVlanid() {
5961
return vlanid;
6062
}
6163

64+
public boolean getState() {
65+
return state;
66+
}
6267
}
6368

6469
@Override

core/src/com/cloud/agent/api/ModifyVmNicConfigCommand.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public class ModifyVmNicConfigCommand extends Command {
2222
int vlan;
2323
String macAddress;
2424
int index;
25+
boolean enable;
26+
String switchLableName;
27+
2528
protected ModifyVmNicConfigCommand() {
2629
}
2730

@@ -37,10 +40,24 @@ public ModifyVmNicConfigCommand(String vmName, int vlan, int position) {
3740
this.index = position;
3841
}
3942

43+
public ModifyVmNicConfigCommand(String vmName, int vlan, int position, boolean enable) {
44+
this.vmName = vmName;
45+
this.vlan = vlan;
46+
this.index = position;
47+
this.enable = enable;
48+
}
49+
4050
public String getVmName() {
4151
return vmName;
4252
}
4353

54+
public String getSwitchLableName() {
55+
return switchLableName;
56+
}
57+
58+
public void setSwitchLableName(String switchlableName) {
59+
this.switchLableName = switchlableName;
60+
}
4461

4562
@Override
4663
public boolean executeInSequence() {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,22 @@ public class NicDetails
717717
public string macaddress;
718718
[JsonProperty("vlanid")]
719719
public int vlanid;
720+
[JsonProperty("state")]
721+
public bool state;
720722
public NicDetails() { }
721-
public NicDetails(String macaddress, int vlanid)
723+
public NicDetails(String macaddress, int vlanid, int enabledState)
722724
{
723725
this.macaddress = macaddress;
724726
this.vlanid = vlanid;
727+
if (enabledState == 2)
728+
{
729+
this.state = true;
730+
}
731+
else
732+
{
733+
this.state = false;
734+
}
735+
725736
}
726737
}
727738

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

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,11 +1077,10 @@ public JContainer PlugNicCommand([FromBody]dynamic cmd)
10771077
using (log4net.NDC.Push(Guid.NewGuid().ToString()))
10781078
{
10791079
logger.Info(CloudStackTypes.PlugNicCommand + Utils.CleanString(cmd.ToString()));
1080-
10811080
object ansContent = new
10821081
{
10831082
result = true,
1084-
details = "instead of plug, change he network settings",
1083+
details = "Hot Nic plug not supported, change any empty virtual network adapter network settings",
10851084
contextMap = contextMap
10861085
};
10871086
return ReturnCloudStackTypedJArray(ansContent, CloudStackTypes.PlugNicAnswer);
@@ -1394,18 +1393,21 @@ public JContainer ModifyVmNicConfigCommand([FromBody]dynamic cmd)
13941393
logger.Info(CloudStackTypes.ModifyVmNicConfigCommand + Utils.CleanString(cmd.ToString()));
13951394
bool result = false;
13961395
String vmName = cmd.vmName;
1397-
uint vlan = (uint)cmd.vlan;
1396+
String vlan = cmd.vlan;
13981397
string macAddress = cmd.macAddress;
1399-
uint pos = cmd.index;
1398+
uint pos = cmd.index;
1399+
bool enable = cmd.enable;
1400+
string switchLableName = cmd.switchLableName;
14001401
if (macAddress != null)
14011402
{
1402-
wmiCallsV2.ModifyVmVLan(vmName, vlan, macAddress);
1403-
}
1404-
else if (pos > 1)
1405-
{
1406-
wmiCallsV2.ModifyVmVLan(vmName, vlan, pos);
1403+
wmiCallsV2.ModifyVmVLan(vmName, vlan, macAddress);
1404+
result = true;
14071405
}
1406+
else if (pos >= 1)
1407+
{
1408+
wmiCallsV2.ModifyVmVLan(vmName, vlan, pos, enable, switchLableName);
14081409
result = true;
1410+
}
14091411

14101412
object ansContent = new
14111413
{
@@ -1432,31 +1434,37 @@ public JContainer GetVmConfigCommand([FromBody]dynamic cmd)
14321434
List<NicDetails> nicDetails = new List<NicDetails>();
14331435
var nicSettingsViaVm = wmiCallsV2.GetEthernetPortSettings(vm);
14341436
NicDetails nic = null;
1435-
String[] macAddress = new String[nicSettingsViaVm.Length];
1436-
int index = 0;
1437-
foreach (SyntheticEthernetPortSettingData item in nicSettingsViaVm)
1438-
{
1439-
macAddress[index++] = item.Address;
1440-
}
1441-
1437+
int index = 0;
1438+
int[] nicStates = new int[8];
1439+
int[] nicVlan = new int[8];
1440+
int vlanid = 1;
1441+
1442+
var ethernetConnections = wmiCallsV2.GetEthernetConnections(vm);
1443+
foreach (EthernetPortAllocationSettingData item in ethernetConnections)
1444+
{
1445+
EthernetSwitchPortVlanSettingData vlanSettings = wmiCallsV2.GetVlanSettings(item);
1446+
if (vlanSettings == null)
1447+
{
1448+
vlanid = -1;
1449+
}
1450+
else
1451+
{
1452+
vlanid = vlanSettings.AccessVlanId;
1453+
}
1454+
nicStates[index] = (Int32)(item.EnabledState);
1455+
nicVlan[index] = vlanid;
1456+
index++;
1457+
}
1458+
14421459
index = 0;
1443-
var ethernetConnections = wmiCallsV2.GetEthernetConnections(vm);
1444-
int vlanid = 1;
1445-
foreach (EthernetPortAllocationSettingData item in ethernetConnections)
1460+
foreach (SyntheticEthernetPortSettingData item in nicSettingsViaVm)
14461461
{
1447-
EthernetSwitchPortVlanSettingData vlanSettings = wmiCallsV2.GetVlanSettings(item);
1448-
if (vlanSettings == null)
1449-
{
1450-
vlanid = -1;
1451-
}
1452-
else
1453-
{
1454-
vlanid = vlanSettings.AccessVlanId;
1455-
}
1456-
nic = new NicDetails(macAddress[index++], vlanid);
1462+
nic = new NicDetails(item.Address, nicVlan[index], nicStates[index]);
1463+
index++;
14571464
nicDetails.Add(nic);
14581465
}
14591466

1467+
14601468
result = true;
14611469

14621470
object ansContent = new

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public interface IWmiCallsV2
7070
void SetState(ComputerSystem vm, ushort requiredState);
7171
Dictionary<String, VmState> GetVmSync(String privateIpAddress);
7272
string GetVmNote(System.Management.ManagementPath sysPath);
73-
void ModifyVmVLan(string vmName, uint vlanid, string mac);
74-
void ModifyVmVLan(string vmName, uint vlanid, uint pos);
73+
void ModifyVmVLan(string vmName, String vlanid, string mac);
74+
void ModifyVmVLan(string vmName, String vlanid, uint pos, bool enable, string switchLabelName);
75+
void DisableVmNics();
76+
void DisableNicVlan(String mac, String vmName);
7577
}
7678
}

0 commit comments

Comments
 (0)