CA-289189: Add sole PIF name changing action

Signed-off-by: Ji Jiang <ji.jiang@citrix.com>
This commit is contained in:
Ji Jiang 2018-08-21 12:29:03 +01:00 committed by Konstantina Chremmou
parent c35a8f739d
commit 4896b89bb6
5 changed files with 104 additions and 8 deletions

View File

@ -438,6 +438,7 @@ namespace XenAdmin.Dialogs
private void AcceptBtn_Click(object sender, EventArgs e) private void AcceptBtn_Click(object sender, EventArgs e)
{ {
List<PIF> newPIFs = new List<PIF>(); List<PIF> newPIFs = new List<PIF>();
List<PIF> newNamePIFs = new List<PIF>();
List<PIF> downPIFs = new List<PIF>(); List<PIF> downPIFs = new List<PIF>();
foreach (PIF pif in AllPIFs) foreach (PIF pif in AllPIFs)
@ -450,7 +451,7 @@ namespace XenAdmin.Dialogs
{ {
try try
{ {
CollateChanges(page, page.Tag as PIF, newPIFs); CollateChanges(page, page.Tag as PIF, newPIFs, newNamePIFs);
} }
catch (Failure) catch (Failure)
{ {
@ -490,11 +491,18 @@ namespace XenAdmin.Dialogs
// Any PIFs that are in downPIFs but also in newPIFs need to be removed from the former. // Any PIFs that are in downPIFs but also in newPIFs need to be removed from the former.
// downPIFs should contain all those that we no longer want to keep up. // downPIFs should contain all those that we no longer want to keep up.
downPIFs.RemoveAll(delegate(PIF p) { return PIFContains(newPIFs, p); }); downPIFs.RemoveAll(p => PIFContains(newPIFs, p));
// Remove any PIFs that haven't changed -- there's nothing to do for these ones. They are in this // Remove any PIFs that haven't changed -- there's nothing to do for these ones. They are in this
// list originally so that they can be used as a filter against downPIFs. // list originally so that they can be used as a filter against downPIFs.
newPIFs.RemoveAll(delegate(PIF p) { return !p.Changed; }); newPIFs.RemoveAll(p => !p.Changed);
newNamePIFs.RemoveAll(p => !p.Changed);
if (newNamePIFs.Count > 0)
{
new SetSecondaryManagementPurposeAction(connection, Pool, newNamePIFs).RunAsync();
}
if (newPIFs.Count > 0 || downPIFs.Count > 0) if (newPIFs.Count > 0 || downPIFs.Count > 0)
{ {
@ -564,7 +572,8 @@ namespace XenAdmin.Dialogs
/// <param name="page"></param> /// <param name="page"></param>
/// <param name="oldPIF"></param> /// <param name="oldPIF"></param>
/// <param name="newPIFs"></param> /// <param name="newPIFs"></param>
private void CollateChanges(NetworkingPropertiesPage page, PIF oldPIF, List<PIF> newPIFs) /// <param name="newNamePIFs"></param>
private void CollateChanges(NetworkingPropertiesPage page, PIF oldPIF, List<PIF> newPIFs, List<PIF> newNamePIFs)
{ {
bool changed = false; bool changed = false;
@ -597,6 +606,8 @@ namespace XenAdmin.Dialogs
PIF newPIF = (PIF)oldPIF.Clone(); PIF newPIF = (PIF)oldPIF.Clone();
newPIF.Changed = changed; newPIF.Changed = changed;
PIF newNamePIF = (PIF)oldPIF.Clone();
newNamePIF.Changed = false;
if (page.DHCPIPRadioButton.Checked) if (page.DHCPIPRadioButton.Checked)
{ {
@ -619,15 +630,18 @@ namespace XenAdmin.Dialogs
newPIF.DNS = string.Join(",", dns.ToArray()); newPIF.DNS = string.Join(",", dns.ToArray());
} }
newPIF.management = page.type != NetworkingPropertiesPage.Type.SECONDARY;
if (page.type == NetworkingPropertiesPage.Type.SECONDARY) if (page.type == NetworkingPropertiesPage.Type.SECONDARY)
{ {
newPIF.SetManagementPurspose(page.PurposeTextBox.Text); if (newPIF.Changed)
newPIF.management = false; newPIF.SetManagementPurspose(page.PurposeTextBox.Text);
else
newNamePIF.SetManagementPurspose(page.PurposeTextBox.Text);
} }
else
newPIF.management = true;
newPIFs.Add(newPIF); newPIFs.Add(newPIF);
newNamePIFs.Add(newNamePIF);
} }
private PIF FindPIFForThisHost(List<XenRef<PIF>> pifs) private PIF FindPIFForThisHost(List<XenRef<PIF>> pifs)

View File

@ -0,0 +1,57 @@
using System.Collections.Generic;
using XenAdmin.Network;
using XenAPI;
namespace XenAdmin.Actions
{
public class SetSecondaryManagementPurposeAction : AsyncAction
{
private Pool pool;
private List<PIF> pifs;
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public SetSecondaryManagementPurposeAction(IXenConnection connection, Pool pool, List<PIF> pifs)
: base(connection, Messages.ACTION_SET_SECONDARY_MANAGEMENT_PURPOSE_TITLE)
{
this.pool = pool;
this.pifs = pifs;
#region RBAC Dependencies
ApiMethodsToRoleCheck.Add("pif.set_other_config");
#endregion
}
protected override void Run()
{
foreach (PIF pif in pifs)
{
XenAPI.Network network = Connection.Resolve(pif.network);
if (network == null)
{
log.Warn("Network has gone away");
return;
}
List<PIF> allPifs = Connection.ResolveAll(network.PIFs);
List<PIF> toReconfigure = pool != null ? allPifs : allPifs.FindAll(
p => p.host.opaque_ref == pif.host.opaque_ref);
if (toReconfigure.Count == 0)
return;
foreach (PIF p in toReconfigure)
{
p.Locked = true;
try
{
pif.SaveChanges(Session, p.opaque_ref, p);
}
finally
{
p.Locked = false;
}
}
}
Description = Messages.ACTION_SET_SECONDARY_MANAGEMENT_PURPOSE_DONE;
}
}
}

View File

@ -2022,6 +2022,24 @@ namespace XenAdmin {
} }
} }
/// <summary>
/// Looks up a localized string similar to Renamed server network interface.
/// </summary>
public static string ACTION_SET_SECONDARY_MANAGEMENT_PURPOSE_DONE {
get {
return ResourceManager.GetString("ACTION_SET_SECONDARY_MANAGEMENT_PURPOSE_DONE", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Renaming server network interface.
/// </summary>
public static string ACTION_SET_SECONDARY_MANAGEMENT_PURPOSE_TITLE {
get {
return ResourceManager.GetString("ACTION_SET_SECONDARY_MANAGEMENT_PURPOSE_TITLE", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Saving VM Configuration. /// Looks up a localized string similar to Saving VM Configuration.
/// </summary> /// </summary>

View File

@ -771,6 +771,12 @@
<data name="ACTION_SCANNING_SR_FROM" xml:space="preserve"> <data name="ACTION_SCANNING_SR_FROM" xml:space="preserve">
<value>Performing SR scan from '{0}'</value> <value>Performing SR scan from '{0}'</value>
</data> </data>
<data name="ACTION_SET_SECONDARY_MANAGEMENT_PURPOSE_TITLE" xml:space="preserve">
<value>Renaming server network interface</value>
</data>
<data name="ACTION_SET_SECONDARY_MANAGEMENT_PURPOSE_DONE" xml:space="preserve">
<value>Renamed server network interface</value>
</data>
<data name="ACTION_SET_VM_OTHER_CONFIG_TITLE" xml:space="preserve"> <data name="ACTION_SET_VM_OTHER_CONFIG_TITLE" xml:space="preserve">
<value>Saving VM Configuration</value> <value>Saving VM Configuration</value>
</data> </data>

View File

@ -101,6 +101,7 @@
<Compile Include="Actions\MultipleAction.cs" /> <Compile Include="Actions\MultipleAction.cs" />
<Compile Include="Actions\MultipleActionLauncher.cs" /> <Compile Include="Actions\MultipleActionLauncher.cs" />
<Compile Include="Actions\Network\CreateSriovAction.cs" /> <Compile Include="Actions\Network\CreateSriovAction.cs" />
<Compile Include="Actions\Network\SetSecondaryManagementPurposeAction.cs" />
<Compile Include="Actions\ParallelAction.cs" /> <Compile Include="Actions\ParallelAction.cs" />
<Compile Include="Actions\Pool\AddHostToPoolAction.cs" /> <Compile Include="Actions\Pool\AddHostToPoolAction.cs" />
<Compile Include="Actions\Pool\CreatePoolAction.cs" /> <Compile Include="Actions\Pool\CreatePoolAction.cs" />