CP-17756: Do not use the field VM.is_control_domain to find the console for the

host as it applies to other control domains too. Use the new Host.control_domain
field instead. Minor refactoring.
This commit is contained in:
Konstantina Chremmou 2016-07-04 11:58:59 +01:00
parent 56265bbfd6
commit 04ffdbadc5
7 changed files with 39 additions and 85 deletions

View File

@ -116,7 +116,7 @@ namespace XenAdmin.ConsoleView
VM_CollectionChangedWithInvoke = Program.ProgramInvokeHandler(VM_CollectionChanged);
source.Connection.Cache.RegisterCollectionChanged<VM>(VM_CollectionChangedWithInvoke);
if (source.is_control_domain)
if (source.IsControlDomainZero)
{
Host host = source.Connection.Resolve(source.resident_on);
if (host != null)
@ -155,7 +155,7 @@ namespace XenAdmin.ConsoleView
this.vncScreen = new XSVNCScreen(source, new EventHandler(RDPorVNCResizeHandler), this, elevatedUsername, elevatedPassword);
ShowGpuWarningIfRequired();
if (source.is_control_domain || source.IsHVM && !hasRDP) //Linux HVM guests should only have one console: the console switch button vanishes altogether.
if (source.IsControlDomainZero || source.IsHVM && !hasRDP) //Linux HVM guests should only have one console: the console switch button vanishes altogether.
{
toggleConsoleButton.Visible = false;
}
@ -241,7 +241,7 @@ namespace XenAdmin.ConsoleView
private void Host_CollectionChanged(object sender, CollectionChangeEventArgs e)
{
if (source.is_control_domain)
if (source.IsControlDomainZero)
return;
Host host = e.Element as Host;
@ -277,7 +277,7 @@ namespace XenAdmin.ConsoleView
if (this.guestMetrics != null)
this.guestMetrics.PropertyChanged -= guestMetrics_PropertyChanged;
if (source.is_control_domain)
if (source.IsControlDomainZero)
{
Host host = source.Connection.Resolve<Host>(source.resident_on);
if (host != null)
@ -516,7 +516,7 @@ namespace XenAdmin.ConsoleView
UpdateOpenSSHConsoleButtonState();
}
if (source.is_control_domain && e.PropertyName == "name_label")
if (source.IsControlDomainZero && e.PropertyName == "name_label")
{
HostLabel.Text = string.Format(Messages.CONSOLE_HOST, source.AffinityServerString);
if (parentVNCView != null && parentVNCView.undockedForm != null)
@ -578,7 +578,7 @@ namespace XenAdmin.ConsoleView
private void Server_EnabledPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != "enabled" || source.is_control_domain)
if (e.PropertyName != "enabled" || source.IsControlDomainZero)
return;
Host host = sender as Host;
@ -606,7 +606,7 @@ namespace XenAdmin.ConsoleView
private void updatePowerState()
{
if (source.is_control_domain)
if (source.IsControlDomainZero)
{
Host host = source.Connection.Resolve<Host>(source.resident_on);
if (host == null)
@ -672,7 +672,7 @@ namespace XenAdmin.ConsoleView
private void hideTopBarContents()
{
VMPowerOff();
if (source.is_control_domain)
if (source.IsControlDomainZero)
{
log.DebugFormat("'{0}' console: Hide top bar contents, server is unavailable", source.Name);
DisablePowerStateLabel(Messages.CONSOLE_HOST_DEAD);
@ -1409,7 +1409,7 @@ namespace XenAdmin.ConsoleView
ContextMenuItemCollection contextMenuItems = new ContextMenuItemCollection();
if (source.is_control_domain)
if (source.IsControlDomainZero)
{
// We're looking at the host console
if (host.Connection.IsConnected)
@ -1569,7 +1569,7 @@ namespace XenAdmin.ConsoleView
if (source.IsWindows)
return false;
if (source.is_control_domain)
if (source.IsControlDomainZero)
{
Host host = source.Connection.Resolve<Host>(source.resident_on);
if (host == null)

View File

@ -129,7 +129,7 @@ namespace XenAdmin.ConsoleView
oldScaledSetting = vncTabView.scaleCheckBox.Checked;
vncTabView.showHeaderBar(!source.is_control_domain, true);
vncTabView.showHeaderBar(!source.IsControlDomainZero, !source.is_control_domain);
undockedForm.ClientSize = vncTabView.GrowToFit();
@ -188,7 +188,7 @@ namespace XenAdmin.ConsoleView
private string UndockedWindowTitle(VM source)
{
if (source.is_control_domain)
if (source.IsControlDomainZero)
{
Host host = source.Connection.Resolve(source.resident_on);
return host == null ? source.Name : string.Format(Messages.CONSOLE_HOST, host.Name);

View File

@ -726,10 +726,9 @@ namespace XenAdmin.ConsoleView
{
parentVNCTabView.DisableToggleVNCButton();
}
//Start the polling again
if (Source != null && !Source.is_control_domain)
if (Source != null && !Source.IsControlDomainZero)
{
if (!Source.IsHVM)
{
@ -740,7 +739,7 @@ namespace XenAdmin.ConsoleView
connectionPoller = new Timer(PollRDPPort, null, RETRY_SLEEP_TIME, RDP_POLL_INTERVAL);
}
}
}
}
}
private void VM_PropertyChanged(object sender, PropertyChangedEventArgs e)

View File

@ -44,8 +44,6 @@ namespace XenAdmin.Controls
{
private const int MAX_ACTIVE_VM_CONSOLES = 10;
private static string CouldNotConnect = Messages.VNC_COULD_NOT_CONNECT_CONSOLE;
private static string CouldNotFindConsole = Messages.VNC_COULD_NOT_FIND_CONSOLES;
public VNCView activeVNCView;
private Dictionary<VM, VNCView> vncViews = new Dictionary<VM, VNCView>();
@ -159,82 +157,41 @@ namespace XenAdmin.Controls
{
if (source == null)
{
log.Error("No local copy of host information when connecting to host VNC console...");
SetErrorMessage(CouldNotConnect);
log.Error("No local copy of host information when connecting to host VNC console.");
SetErrorMessage(Messages.VNC_COULD_NOT_CONNECT_CONSOLE);
return;
}
if (source.resident_VMs == null)
VM dom0 = source.ControlDomainZero;
if (dom0 == null)
{
log.Error("No dom0 on host when connecting to host VNC console.");
SetErrorMessage(CouldNotConnect);
return;
}
List<XenRef<VM>> controlVMs =
source.resident_VMs.FindAll((Predicate<XenRef<VM>>)delegate(XenRef<VM> vmRef)
{
VM vm = source.Connection.Resolve<VM>(vmRef);
if (vm == null)
{
return false;
}
else
{
return vm.is_control_domain;
}
});
if (controlVMs.Count > 0)
{
VM vm = source.Connection.Resolve<VM>(controlVMs[0]);
if (vm == null)
{
SetErrorMessage(CouldNotFindConsole);
}
else
{
this.setCurrentSource(vm);
}
SetErrorMessage(Messages.VNC_COULD_NOT_FIND_CONSOLES);
}
else
{
SetErrorMessage(CouldNotFindConsole);
}
setCurrentSource(dom0);
}
public static bool RbacDenied(VM source, out List<Role> AllowedRoles)
public static bool RbacDenied(VM source, out List<Role> allowedRoles)
{
if (source == null || source.Connection == null)
{
AllowedRoles = null;
allowedRoles = null;
return false;
}
else
var session = source.Connection.Session;
if (session != null && session.IsLocalSuperuser)
{
var session = source.Connection.Session;
if (session != null && session.IsLocalSuperuser)
{
AllowedRoles = null;
return false;
}
}
List<Role> allowedRoles = null;
if (source.is_control_domain)
allowedRoles = Role.ValidRoleList("http/connect_console/host_console", source.Connection);
else
allowedRoles = Role.ValidRoleList("http/connect_console", source.Connection);
if (source.Connection.Session.Roles.Find(delegate(Role r) { return allowedRoles.Contains(r); }) != null)
{
AllowedRoles = allowedRoles;
allowedRoles = null;
return false;
}
AllowedRoles = allowedRoles;
return true;
string roleList = source.IsControlDomainZero ? "http/connect_console/host_console" : "http/connect_console";
List<Role> validRoles = Role.ValidRoleList(roleList, source.Connection);
allowedRoles = validRoles;
return source.Connection.Session.Roles.Find(r => validRoles.Contains(r)) == null;
}
internal Image Snapshot(VM vm, string elevatedUsername, string elevatedPassword)

View File

@ -70,7 +70,7 @@ namespace XenAdmin.Controls.ConsoleTab
if (_selectedScreen == null) //screen not assigned yet
return;
string connectionName = _selectedScreen.Source.is_control_domain
string connectionName = _selectedScreen.Source.IsControlDomainZero
? _selectedScreen.Source.AffinityServerString
: _selectedScreen.Source.Name;

View File

@ -769,9 +769,7 @@ namespace XenAdmin
}
foreach (Host host in connection.Cache.Hosts)
foreach (VM vm in host.Connection.ResolveAll(host.resident_VMs))
if (vm.is_control_domain)
this.ConsolePanel.closeVNCForSource(vm);
ConsolePanel.closeVNCForSource(host.ControlDomainZero);
connection.EndConnect();

View File

@ -1463,22 +1463,22 @@ namespace XenAdmin.Core
public static string GetNameAndObject(IXenObject XenObject)
{
if (XenObject is Pool)
return string.Format(Messages.POOL_X, Helpers.GetName(XenObject));
return string.Format(Messages.POOL_X, GetName(XenObject));
if (XenObject is Host)
return string.Format(Messages.SERVER_X, Helpers.GetName(XenObject));
return string.Format(Messages.SERVER_X, GetName(XenObject));
if (XenObject is VM)
{
VM vm = (VM)XenObject;
if (vm.is_control_domain)
return string.Format(Messages.SERVER_X, Helpers.GetName(XenObject.Connection.Resolve(vm.resident_on)));
if (vm.IsControlDomainZero)
return string.Format(Messages.SERVER_X, GetName(XenObject.Connection.Resolve(vm.resident_on)));
else
return string.Format(Messages.VM_X, Helpers.GetName(XenObject));
return string.Format(Messages.VM_X, GetName(XenObject));
}
if (XenObject is SR)
return string.Format(Messages.STORAGE_REPOSITORY_X, Helpers.GetName(XenObject));
return string.Format(Messages.STORAGE_REPOSITORY_X, GetName(XenObject));
return Messages.UNKNOWN_OBJECT;
}