Merge pull request #768 from GaborApatiNagy/CA-187681

CA-187681: Improvement for VM.IsWindows property
This commit is contained in:
Mihaela Stoica 2016-01-13 13:16:01 +00:00
commit 68caba0f65
2 changed files with 58 additions and 13 deletions

View File

@ -40,6 +40,8 @@ using XenAdmin;
using XenAdmin.Core;
using XenAdmin.Model;
using XenAdmin.Network;
using System.Net;
using System.Text.RegularExpressions;
namespace XenAPI
@ -1918,11 +1920,6 @@ namespace XenAPI
}
}
/// <summary>
/// List of distro values that we treat as Linux/Non-Windows (written by Linux Guest Agent, evaluating xe-linux-distribution)
/// </summary>
private readonly string[] linuxDistros = { "debian", "rhel", "fedora", "centos", "scientific", "oracle", "sles", "lsb", "boot2docker", "freebsd" };
/// <summary>
/// Returns true if this VM is Windows.
/// </summary>
@ -1933,16 +1930,14 @@ namespace XenAPI
{
get
{
//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 && 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;
}
if (gm != null && gm.IsVmNotWindows)
return false;
var gmFromLastBootedRecord = GuestMetricsFromLastBootedRecord;
if (gmFromLastBootedRecord != null && gmFromLastBootedRecord.IsVmNotWindows)
return false;
//generic check
return
@ -1950,6 +1945,26 @@ namespace XenAPI
}
}
private VM_guest_metrics GuestMetricsFromLastBootedRecord
{
get
{
if (!string.IsNullOrEmpty(this.last_booted_record))
{
Regex regex = new Regex("'guest_metrics' +'(OpaqueRef:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})'");
var v = regex.Match(this.last_booted_record);
if (v.Success)
{
string s = v.Groups[1].ToString();
return this.Connection.Resolve<VM_guest_metrics>(new XenRef<VM_guest_metrics>(s));
}
}
return null;
}
}
public bool WindowsUpdateCapable
{
get

View File

@ -29,10 +29,17 @@
* SUCH DAMAGE.
*/
using System.Linq;
namespace XenAPI
{
public partial class VM_guest_metrics
{
/// <summary>
/// List of distro values that we treat as Linux/Non-Windows (written by Linux Guest Agent, evaluating xe-linux-distribution)
/// </summary>
private readonly string[] linuxDistros = { "debian", "rhel", "fedora", "centos", "scientific", "oracle", "sles", "lsb", "boot2docker", "freebsd" };
//This will tell if they are install (but they may not be upto date!)
public bool PV_drivers_installed
{
@ -41,5 +48,28 @@ namespace XenAPI
return PV_drivers_version.ContainsKey("major") && PV_drivers_version.ContainsKey("minor");
}
}
/// <summary>
/// Returns true if (it is known that) this VM_guest_metrics belongs to a non-Windows VM.
/// (Returns false if the VM is Windows or unknown)
/// </summary>
/// <param name="gm"></param>
/// <returns></returns>
public bool IsVmNotWindows
{
get
{
if (this.os_version != null)
{
if (this.os_version.ContainsKey("distro") && !string.IsNullOrEmpty(this.os_version["distro"]) && linuxDistros.Contains(this.os_version["distro"].ToLowerInvariant()))
return true;
if (this.os_version.ContainsKey("uname") && this.os_version["uname"].ToLowerInvariant().Contains("netscaler"))
return true;
}
return false;
}
}
}
}