From 03308f0f405bf03a53b5bd63f63f6cc5a7d8d6ea Mon Sep 17 00:00:00 2001 From: Gabor Apati-Nagy Date: Tue, 8 Dec 2015 14:57:24 +0000 Subject: [PATCH] CP-14874: Enable XC SSH support for (more) Linux VMs VM.IsWindows flag is getting clever As this property is used on the General tab and on the SSH Console, HVM Linux VMs with the viridian flag turned on will no longer be treated as Windows VMs (as long as they have the Linux Guest Agent running) Signed-off-by: Gabor Apati-Nagy --- XenModel/XenAPI-Extensions/VM.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/XenModel/XenAPI-Extensions/VM.cs b/XenModel/XenAPI-Extensions/VM.cs index 7f01ec1b9..45a743672 100644 --- a/XenModel/XenAPI-Extensions/VM.cs +++ b/XenModel/XenAPI-Extensions/VM.cs @@ -1889,25 +1889,32 @@ namespace XenAPI } } + /// + /// List of distro values that we treat as Linux/Non-Windows (written by Linux Guest Agent, evaluating xe-linux-distribution) + /// + private readonly string[] linuxDistros = { "debian", "rhel", "fedora", "centos", "scientific", "oracle", "sles", "lsb", "boot2docker", "freebsd" }; + /// /// Returns true if this VM is Windows. /// /// - /// This really should be just a flag from XAPI, but we do not have such. - /// /// To get an acceptable result, this getter is trying to detect some specific cases before falling back to the viridian flag - /// that may not be correct at all times. + /// that may not be correct at all times. (Linux distro can be detected if the guest agent is running on a Linux VM.) public bool IsWindows { get { - //try to detect special cases when we are sure - having guest_metrics can help + //try to detect special cases when the decision is easy - the presence of guest_metrics helps var gm = Connection.Resolve(this.guest_metrics); - if (gm != null) - if (gm.os_version.ContainsKey("distro") && gm.os_version["distro"].ToLowerInvariant().Contains("freebsd") - || gm.os_version.ContainsKey("uname") && gm.os_version["uname"].ToLowerInvariant().Contains("netscaler")) + if (gm != null && gm.os_version != null) + { + if (gm.os_version.ContainsKey("distro") && !string.IsNullOrEmpty(gm.os_version["distro"]) && linuxDistros.Contains(gm.os_version["distro"].ToLowerInvariant())) return false; + if (gm.os_version.ContainsKey("uname") && gm.os_version["uname"].ToLowerInvariant().Contains("netscaler")) + return false; + } + //generic check return this.IsHVM && BoolKey(this.platform, "viridian");