From d8a5a8169cbbf3d2d2b104fd21ef06316df73855 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Sat, 24 Mar 2018 09:34:06 -0500 Subject: [PATCH] Mark the nic spray fixed once the nic has been re-added. They should still add a test to make sure the IP has been put back, etc. Also fixed an issue with duplicate nic names. --- EduNetworkBuilder/DeviceConfig.cs | 8 ++++++-- EduNetworkBuilder/Network.cs | 11 ++++++++++- EduNetworkBuilder/NetworkDevice.cs | 28 +++++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 6 deletions(-) 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