diff --git a/EduNetworkBuilder/DeviceConfig.cs b/EduNetworkBuilder/DeviceConfig.cs index 6b70d36..ab55842 100644 --- a/EduNetworkBuilder/DeviceConfig.cs +++ b/EduNetworkBuilder/DeviceConfig.cs @@ -289,6 +289,8 @@ namespace EduNetworkBuilder private void btnNicPlus_Click(object sender, EventArgs e) { List WhatToAdd = new List(); + Network tnet = NB.GetNetwork(); + NetworkCard tnic = null; //generate a new nic and add it to the device if (ClonedItem.GetType().ToString() == "EduNetworkBuilder.NetworkDevice") { @@ -314,7 +316,7 @@ namespace EduNetworkBuilder } if (WhatToAdd.Count == 1) { - ndCLonedItem.AddNic(WhatToAdd[0]); + tnic = ndCLonedItem.AddNic(WhatToAdd[0]); } if(WhatToAdd.Count > 1) { @@ -352,9 +354,11 @@ namespace EduNetworkBuilder QuestionForm.ShowDialog(); if(cbQuestions.SelectedIndex >=0) { - ndCLonedItem.AddNic(WhatToAdd[cbQuestions.SelectedIndex]); + tnic = ndCLonedItem.AddNic(WhatToAdd[cbQuestions.SelectedIndex]); } } + if(tnet != null) + tnet.RegisterNICAdded(ndCLonedItem.hostname, tnic.NicName()); } UpdateForm(); } diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index c9e10c0..df07663 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -2003,7 +2003,16 @@ namespace EduNetworkBuilder } } } - + public void RegisterNICAdded(string source, string nicname) + { + foreach (NetTest one in NetTests) + { + if (one.sHost == source && one.TheTest == NetTestType.DeviceNICSprays && one.dHost == nicname) + { + one.SetDone(); + } + } + } public void RegisterUPSAdded(string source) { foreach (NetTest one in NetTests) diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index 837e09f..47b82f6 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -184,13 +184,35 @@ namespace EduNetworkBuilder } return count; } - public void AddNic(NicType TheType = NicType.eth) + public int FirstEmptySlot(NicType TheType) + { + int count = 0; + while (true) + { + bool found = false; + string tname = TheType.ToString() + count.ToString(); + foreach (NetworkCard nic in NICs) + { + if(nic.NicName() == tname) + { + found = true; + break; + } + } + if (!found) + return count; + count++; + } + } + + public NetworkCard AddNic(NicType TheType = NicType.eth) { NetworkCard tnic; - int count = CountNics(TheType); + int count = FirstEmptySlot(TheType); tnic = new NetworkCard(count, GetUniqueIdentifier, hostname, TheType); NICs.Add(tnic); ApplyRulesToDevice(); + return tnic; } private void ApplyRulesToDevice() { @@ -984,7 +1006,7 @@ namespace EduNetworkBuilder Network theNet = NB.GetNetwork(); if(!theNet.ItemIsLocked(hostname,NICs[index].NicName(),NetTestType.LockNic)) { - if (theNet != null) theNet.RemoveLinksToNic(NICs[index].myID); + if (theNet != null) theNet.RemoveLinksToNic(NICs[index].myID); NICs.RemoveAt(index); } else