Skip to content

Commit

Permalink
Merge pull request xcp-ng#12 from kc284/vm-copy-credentials_CA-359712
Browse files Browse the repository at this point in the history
Merge from master
  • Loading branch information
danilo-delbusso committed Dec 3, 2021
2 parents 89620bf + a0a706e commit 76b20f4
Show file tree
Hide file tree
Showing 113 changed files with 1,413 additions and 1,575 deletions.
3 changes: 3 additions & 0 deletions Branding/Branding.resx
Expand Up @@ -182,6 +182,9 @@
<data name="PRODUCT_VERSION_8_2" xml:space="preserve">
<value>8.2</value>
</data>
<data name="PRODUCT_VERSION_8_2_1" xml:space="preserve">
<value>8.2.1</value>
</data>
<data name="PRODUCT_VERSION_POST_8_2" xml:space="preserve">
<value>[BRANDING_PRODUCT_VERSION_TEXT]</value>
</data>
Expand Down
14 changes: 7 additions & 7 deletions XenAdmin/Actions/GUIActions/ExternalPluginAction.cs
Expand Up @@ -246,21 +246,21 @@ void _extAppProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
}

// Returns a set of params which relate to the object you have selected in the treeview
private List<string> RetrieveParams(IXenObject obj)
private IEnumerable<string> RetrieveParams(IXenObject obj)
{
IXenConnection connection = obj.Connection;
Host coordinator = connection != null ? Helpers.GetCoordinator(connection) : null; // get coordinator asserts connection is not null
string coordinatorAddress = EmptyParameter;
var connection = obj?.Connection;
var coordinator = connection != null ? Helpers.GetCoordinator(connection) : null; // get coordinator asserts connection is not null
var coordinatorAddress = EmptyParameter;

if (coordinator != null)
{
coordinatorAddress = Helpers.GetUrl(coordinator.Connection);
WriteTrustedCertificates(coordinator.Connection);
}

string sessionRef = connection.Session != null ? connection.Session.opaque_ref : EmptyParameter;
string objCls = obj != null ? obj.GetType().Name : EmptyParameter;
string objUuid = obj != null && connection.Session != null ? Helpers.GetUuid(obj) : EmptyParameter;
var sessionRef = connection?.Session != null ? connection.Session.opaque_ref : EmptyParameter;
var objCls = obj != null ? obj.GetType().Name : EmptyParameter;
var objUuid = connection?.Session != null ? Helpers.GetUuid(obj) : EmptyParameter;
return new List<string>(new string[] { coordinatorAddress, sessionRef, objCls, objUuid });
}

Expand Down
9 changes: 2 additions & 7 deletions XenAdmin/Actions/GUIActions/Wlb/WlbOptimizePoolAction.cs
Expand Up @@ -55,13 +55,8 @@ class WlbOptimizePoolAction : AsyncAction
public WlbOptimizePoolAction(Pool pool, Dictionary<VM, WlbOptimizationRecommendation> vmOptLst, string optId)
: base(pool.Connection, string.Format(Messages.WLB_OPTIMIZING_POOL, Helpers.GetName(pool).Ellipsise(50)))
{
if (pool == null)
throw new ArgumentNullException("pool");
if (vmOptLst == null)
throw new ArgumentNullException("vmOptLst");

this.Pool = pool;
this.vmOptList = vmOptLst;
Pool = pool;
vmOptList = vmOptLst ?? throw new ArgumentNullException("vmOptLst");
this.optId = optId;

#region RBAC Dependencies
Expand Down
5 changes: 4 additions & 1 deletion XenAdmin/Commands/ChangeControlDomainMemoryCommand.cs
Expand Up @@ -58,7 +58,10 @@ public ChangeControlDomainMemoryCommand(IMainWindow mainWindow, IEnumerable<Sele

protected override void RunCore(SelectedItemCollection selection)
{
Host host = selection[0].HostAncestor;
var host = selection[0].HostAncestor;
if (host == null)
return;

using (var dlg = new ControlDomainMemoryDialog(host))
dlg.ShowDialog(Program.MainWindow);
}
Expand Down
15 changes: 6 additions & 9 deletions XenAdmin/Commands/Controls/ResumeVMOnHostToolStripMenuItem.cs
Expand Up @@ -92,23 +92,20 @@ private bool CanRun(SelectedItem selection)

protected override bool CanRunCore(SelectedItemCollection selection)
{
if (!selection.AllItemsAre<VM>())
{
return false;
}

IXenConnection connection = null;

bool atLeastOneCanRun = false;
foreach (SelectedItem item in selection)
var atLeastOneCanRun = false;
foreach (var item in selection)
{
VM vm = (VM)item.XenObject;

if (!(item.XenObject is VM vm))
return false;

// all VMs must be on the same connection
if (connection != null && vm.Connection != connection)
{
return false;
}
connection = vm.Connection;

if (CanRun(item))
{
Expand Down
21 changes: 11 additions & 10 deletions XenAdmin/Commands/Controls/VMOperationToolStripMenuItem.cs
Expand Up @@ -33,12 +33,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using XenAdmin.Actions.Wlb;
using XenAdmin.Controls;
using XenAPI;
using XenAdmin.Core;
using XenAdmin.Actions;
using XenAdmin.Actions.Wlb;
using XenAdmin.Network;
using XenAPI;


namespace XenAdmin.Commands
Expand Down Expand Up @@ -112,7 +111,7 @@ protected override void OnDropDownOpening(EventArgs e)

// Adds the migrate wizard button, do this before the enable checks on the other items
AddAdditionalMenuItems(selection);

UpdateHostList();
}

Expand Down Expand Up @@ -163,11 +162,13 @@ private void UpdateHostList()
if (Helpers.WlbEnabled(connection))
{
var vms = selection.AsXenObjects<VM>();
if (vms == null || vms.Count == 0)
return;

var retrieveVmRecommendationsAction = new WlbRetrieveVmRecommendationsAction(connection, vms);
retrieveVmRecommendationsAction.Completed += delegate
{
if (Stopped || retrieveVmRecommendationsAction.Cancelled ||
!retrieveVmRecommendationsAction.Succeeded)
if (Stopped || retrieveVmRecommendationsAction.Cancelled || !retrieveVmRecommendationsAction.Succeeded)
return;

var recommendations = new WlbRecommendations(vms, retrieveVmRecommendationsAction.Recommendations);
Expand Down Expand Up @@ -244,7 +245,7 @@ private void EnableAppropriateHostsNoWlb()
var firstItem = DropDownItems[0] as VMOperationToolStripMenuSubItem;
if (firstItem == null)
return;

// API calls could happen in CanRun(), which take time to wait. So a Producer-Consumer-Queue with size 25 is used here to :
// 1. Make API calls for different menu items happen in parallel;
// 2. Limit the count of concurrent threads (now it's 25).
Expand All @@ -254,7 +255,7 @@ private void EnableAppropriateHostsNoWlb()
var connection = selection[0].Connection;
var session = connection.DuplicateSession();

var affinityHost = connection.Resolve(((VM) selection[0].XenObject).affinity);
var affinityHost = connection.Resolve(((VM)selection[0].XenObject).affinity);

EnqueueHostMenuItem(this, session, affinityHost, firstItem, true);

Expand All @@ -279,7 +280,7 @@ private void EnqueueHostMenuItem(VMOperationToolStripMenuItem menu, Session sess
workerQueueWithoutWlb.EnqueueItem(() =>
{
var selection = menu.Command.GetSelection();
var cmd = isHomeServer
var cmd = isHomeServer
? new VMOperationHomeServerCommand(menu.Command.MainWindowCommandInterface, selection, menu._operation, session)
: new VMOperationHostCommand(menu.Command.MainWindowCommandInterface, selection, delegate { return host; }, host.Name().EscapeAmpersands(), menu._operation, session);
Expand Down Expand Up @@ -321,7 +322,7 @@ private void EnqueueHostMenuItem(VMOperationToolStripMenuItem menu, Session sess
}
});
}

#endregion

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions XenAdmin/Commands/Controls/WlbRecommendations.cs
Expand Up @@ -54,8 +54,6 @@ internal class WlbRecommendations
/// <param name="recommendations"></param>
public WlbRecommendations(List<VM> vms, Dictionary<VM, Dictionary<XenRef<Host>, string[]>> recommendations)
{
Util.ThrowIfEnumerableParameterNullOrEmpty(vms, "vms");

_vms = new ReadOnlyCollection<VM>(vms);
_recommendations = recommendations;
_isError = recommendations == null;
Expand Down
2 changes: 1 addition & 1 deletion XenAdmin/Commands/DragDropMigrateVMCommand.cs
Expand Up @@ -140,7 +140,7 @@ protected override bool CanRunCore()

if(!LiveMigrateAllowedInVersion(targetHost, draggedVM))
{
Pool targetPool = targetHost == null ? null : Helpers.GetPool(targetHost.Connection);
Pool targetPool = Helpers.GetPool(targetHost.Connection);

if(targetPool == null)
return false;
Expand Down
6 changes: 5 additions & 1 deletion XenAdmin/Commands/EnableTlsVerificationCommand.cs
Expand Up @@ -111,7 +111,8 @@ protected override bool CanRunCore(SelectedItemCollection selection)
!pool.current_operations.Values.Contains(pool_allowed_operations.ha_enable) &&
!pool.current_operations.Values.Contains(pool_allowed_operations.ha_disable) &&
!pool.current_operations.Values.Contains(pool_allowed_operations.cluster_create) &&
!pool.current_operations.Values.Contains(pool_allowed_operations.designate_new_master);
!pool.current_operations.Values.Contains(pool_allowed_operations.designate_new_master) &&
!pool.RollingUpgrade();
}

protected override string GetCantRunReasonCore(IXenObject item)
Expand All @@ -134,6 +135,9 @@ protected override string GetCantRunReasonCore(IXenObject item)

if (pool.current_operations.Values.Contains(pool_allowed_operations.designate_new_master))
return Messages.ENABLE_TLS_VERIFICATION_NEW_COORDINATOR;

if (pool.RollingUpgrade())
return Messages.ENABLE_TLS_VERIFICATION_RPU;
}

return base.GetCantRunReasonCore(item);
Expand Down
8 changes: 4 additions & 4 deletions XenAdmin/Commands/ImPortCommand.cs
Expand Up @@ -49,14 +49,14 @@ public ImportCommand(IMainWindow mainWindow,Pool pool)
: base(mainWindow, pool)
{ }

public override string MenuText { get { return Messages.HOST_MENU_IMPORT_VM_TEXT; } }
public override string ContextMenuText{get{return Messages.HOST_MENU_IMPORT_VM_TEXT;}}
public override string MenuText => Messages.HOST_MENU_IMPORT_VM_TEXT;

public override string ContextMenuText => Messages.HOST_MENU_IMPORT_VM_TEXT;

protected override void RunCore(SelectedItemCollection selection)
{
var con = selection.GetConnectionOfFirstItem();
MainWindowCommandInterface.ShowPerConnectionWizard(con, new ImportWizard(con, selection.FirstAsXenObject, null, false));
MainWindowCommandInterface.ShowPerConnectionWizard(con, new ImportWizard(con, selection.FirstAsXenObject, null));
}
}
}
5 changes: 4 additions & 1 deletion XenAdmin/Commands/RepairSRCommand.cs
Expand Up @@ -78,7 +78,10 @@ protected override void RunCore(SelectedItemCollection selection)
dlg.ShowDialog(Parent);
}

new RepairSRDialog(srList).Show(Parent);
if (srList.Count != 0)
{
new RepairSRDialog(srList).Show(Parent);
}
}

protected override bool CanRunCore(SelectedItemCollection selection)
Expand Down
4 changes: 2 additions & 2 deletions XenAdmin/ConsoleView/VNCGraphicsClient.cs
Expand Up @@ -1497,7 +1497,7 @@ private void SetupScaling()

if (this.Size.Height >= (displayBorder ? this.DesktopSize.Height + BORDER_PADDING + BORDER_PADDING : DesktopSize.Height))
{
this.dy = (this.Size.Height - this.DesktopSize.Height) / 2;
this.dy = ((float) this.Size.Height - this.DesktopSize.Height) / 2;
}
else
{
Expand All @@ -1515,7 +1515,7 @@ private void SetupScaling()

if (this.Size.Width >= (displayBorder ? this.DesktopSize.Width + BORDER_PADDING + BORDER_PADDING : DesktopSize.Width))
{
this.dx = (this.Size.Width - this.DesktopSize.Width) / 2;
this.dx = ((float) this.Size.Width - this.DesktopSize.Width) / 2;
}
else
{
Expand Down
16 changes: 4 additions & 12 deletions XenAdmin/ConsoleView/VNCTabView.cs
Expand Up @@ -711,18 +711,10 @@ private void hideTopBarContents()
}
else if (source.power_state == vm_power_state.Paused)
{
if (source.allowed_operations.Contains(vm_operations.unpause))
{
//EnablePowerStateLabel(Messages.CONSOLE_POWER_STATE_PAUSED_UNPAUSE);
// CA-12637: Pause/UnPause is not supported in the GUI. Comment out
// the EnablePowerStateLabel because it gives the appearance that we
// support unpause via the GUI.
DisablePowerStateLabel(Messages.CONSOLE_POWER_STATE_PAUSED);
}
else
{
DisablePowerStateLabel(Messages.CONSOLE_POWER_STATE_PAUSED);
}
// CA-12637: Pause/UnPause is not supported in the GUI. Comment out
// the EnablePowerStateLabel because it gives the impression that we
// support unpause via the GUI.
DisablePowerStateLabel(Messages.CONSOLE_POWER_STATE_PAUSED);
}
else if (source.power_state == vm_power_state.Suspended)
{
Expand Down
3 changes: 3 additions & 0 deletions XenAdmin/Controls/Ballooning/HostMemoryControls.cs
Expand Up @@ -127,6 +127,9 @@ void vm_metrics_PropertyChanged(object sender, PropertyChangedEventArgs e)

private void valueControlDomain_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (host == null)
return;

using (var dlg = new ControlDomainMemoryDialog(host))
dlg.ShowDialog(Program.MainWindow);
}
Expand Down
5 changes: 2 additions & 3 deletions XenAdmin/Controls/ConsolePanel.cs
Expand Up @@ -310,10 +310,9 @@ public void StartCloseVNCTimer(VNCView vncView)

// find the <VM, VNCView> pair in vncViews and start timer on the vm
var views = vncViews.Where(kvp => kvp.Value == vncView).ToList();
foreach (var kvp in views)
if (views.Count > 0)
{
StartCloseVNCTimer(kvp.Key);
break;
StartCloseVNCTimer(views.First().Key);
}
}

Expand Down
6 changes: 1 addition & 5 deletions XenAdmin/Controls/CustomDataGraph/DataKey.cs
Expand Up @@ -300,11 +300,7 @@ public DataRange YRange
{
get
{
foreach (DataSet s in Sets.Values)
{
return s.CustomYRange;
}
return null;
return Sets.Values.Select(s => s.CustomYRange).FirstOrDefault();
}
}

Expand Down
10 changes: 3 additions & 7 deletions XenAdmin/Controls/CustomDataGraph/DataSet.cs
Expand Up @@ -482,19 +482,15 @@ private void InsertPoint(int index, DataPoint dataPoint)

public override bool Equals(object obj)
{
if(!(obj is DataSet))
return base.Equals(obj);

DataSet other = (DataSet)obj;
if (!(obj is DataSet other))
return false;

return Id == other.Id;
}

public override int GetHashCode()
{
if (string.IsNullOrEmpty(Id))
return base.GetHashCode();
return Id.GetHashCode();
return string.IsNullOrEmpty(Id) ? 0 : Id.GetHashCode();
}

internal void InsertPointCollection(List<DataPoint> list)
Expand Down
12 changes: 6 additions & 6 deletions XenAdmin/Controls/CustomGridView/GridRow.cs
Expand Up @@ -38,8 +38,8 @@ namespace XenAdmin.Controls.CustomGridView
{
public class GridRow : IComparable<GridRow>
{
public readonly Dictionary<String, GridItemBase> Items = new Dictionary<string, GridItemBase>();
public readonly List<GridRow> Rows = new List<GridRow>();
public Dictionary<string, GridItemBase> Items = new Dictionary<string, GridItemBase>();
public List<GridRow> Rows = new List<GridRow>();

public static Image ExpandedImage = Images.StaticImages.expanded_triangle;
public static Image ShrunkenImage = Images.StaticImages.contracted_triangle;
Expand Down Expand Up @@ -678,14 +678,14 @@ internal void RestoreExpandedState(List<string> expandedState)

public override bool Equals(object obj)
{
if(!(obj is GridRow))
return base.Equals(obj);
return OpaqueRef == ((GridRow)obj).OpaqueRef;
if (!(obj is GridRow row))
return false;
return OpaqueRef == row.OpaqueRef;
}

public override int GetHashCode()
{
return base.GetHashCode();
return (OpaqueRef != null ? OpaqueRef.GetHashCode() : 0);
}
}

Expand Down

0 comments on commit 76b20f4

Please sign in to comment.