2023-01-24 15:29:31 +01:00
/ * Copyright ( c ) Cloud Software Group , Inc .
2013-06-24 13:41:48 +02:00
*
* Redistribution and use in source and binary forms ,
* with or without modification , are permitted provided
* that the following conditions are met :
*
* * Redistributions of source code must retain the above
* copyright notice , this list of conditions and the
* following disclaimer .
* * Redistributions in binary form must reproduce the above
* copyright notice , this list of conditions and the
* following disclaimer in the documentation and / or other
* materials provided with the distribution .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES ,
* INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL ,
* SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING ,
* BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS
* INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY ,
* WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING
* NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE .
* /
using System ;
using System.Collections.Generic ;
using System.Linq ;
using XenAdmin.CustomFields ;
using XenAdmin.Model ;
using XenAPI ;
using XenAdmin.Core ;
using System.Collections ;
using XenAdmin.Network ;
2017-11-17 00:30:51 +01:00
using XenCenterLib ;
2013-06-24 13:41:48 +02:00
namespace XenAdmin.XenSearch
{
//
// We need to access delegate, i18n and icons via enums
// to allow for serialisation
//
// The order of this enum determines the order of types in the
// tree in Folder View (CA-28418). But on the search-for
// menu, see SearchFor.PopulateSearchForComboButton().
[Flags]
public enum ObjectTypes
{
None = 0 ,
Pool = 1 < < 0 ,
Server = 1 < < 1 ,
DisconnectedServer = 1 < < 2 ,
VM = 1 < < 3 ,
Snapshot = 1 < < 4 ,
UserTemplate = 1 < < 5 ,
DefaultTemplate = 1 < < 6 ,
RemoteSR = 1 < < 7 ,
LocalSR = 1 < < 8 ,
VDI = 1 < < 9 ,
Network = 1 < < 10 ,
Folder = 1 < < 11 ,
2015-02-05 17:22:00 +01:00
AllIncFolders = ( 1 < < 12 ) - 1 ,
2013-06-24 13:41:48 +02:00
AllExcFolders = AllIncFolders & ~ ObjectTypes . Folder ,
Appliance = 1 < < 13 ,
2015-02-04 10:48:32 +01:00
DockerContainer = 1 < < 14 ,
2013-06-24 13:41:48 +02:00
}
public enum PropertyNames
{
2019-08-31 15:40:08 +02:00
/// <summary>The type of the selected object, e.g. VM, Network</summary>
2013-06-24 13:41:48 +02:00
type ,
2019-08-31 15:40:08 +02:00
/// <summary>The label of the selected object</summary>
2013-06-24 13:41:48 +02:00
label ,
2019-08-31 15:40:08 +02:00
/// <summary>The UUID of the selected object, or the full pathname of a folder</summary>
2013-06-24 13:41:48 +02:00
uuid ,
2019-08-31 15:40:08 +02:00
/// <summary>The description of the selected object</summary>
2013-06-24 13:41:48 +02:00
description ,
2019-08-31 15:40:08 +02:00
/// <summary>Comma-separated list of the tags of the selected object</summary>
2013-06-24 13:41:48 +02:00
tags ,
2019-08-31 15:40:08 +02:00
/// <summary>The host name</summary>
2013-06-24 13:41:48 +02:00
host ,
2019-08-31 15:40:08 +02:00
/// <summary>The pool name</summary>
2013-06-24 13:41:48 +02:00
pool ,
2019-08-31 15:40:08 +02:00
/// <summary>Comma-separated list of the names of the networks attached to the object</summary>
2013-06-24 13:41:48 +02:00
networks ,
2019-08-31 15:40:08 +02:00
/// <summary>Comma-separated list of the names of the storage attached to the object</summary>
2013-06-24 13:41:48 +02:00
storage ,
2019-08-31 15:40:08 +02:00
/// <summary>Comma-separated list of the types of the storage attached to the object</summary>
2013-06-24 13:41:48 +02:00
disks ,
2019-08-31 15:40:08 +02:00
/// <summary>The host memory, in bytes</summary>
2013-06-24 13:41:48 +02:00
memory ,
2019-08-31 15:40:08 +02:00
/// <summary>The name of the operating system that a VM is running</summary>
2013-06-24 13:41:48 +02:00
os_name ,
2019-08-31 15:40:08 +02:00
/// <summary>The VM power state, e.g. Halted, Running</summary>
2013-06-24 13:41:48 +02:00
power_state ,
2019-08-31 15:40:08 +02:00
/// <summary>The state of the pure virtualization drivers installed on a VM</summary>
2015-09-14 17:21:44 +02:00
virtualisation_status ,
2019-08-31 15:40:08 +02:00
/// <summary>Date and time that the VM was started</summary>
2013-06-24 13:41:48 +02:00
start_time ,
2019-08-31 15:40:08 +02:00
/// <summary>The HA restart priority of the VM</summary>
2013-06-24 13:41:48 +02:00
ha_restart_priority ,
2019-08-31 15:40:08 +02:00
/// <summary>The size in bytes of the attached disks</summary>
2013-06-24 13:41:48 +02:00
size ,
2019-08-31 15:40:08 +02:00
/// <summary>Comma-separated list of IP addresses associated with the selected object</summary>
2013-06-24 13:41:48 +02:00
ip_address ,
2019-08-31 15:40:08 +02:00
/// <summary>Uptime of the object, in a form such as '2 days, 1 hour, 26 minutes'</summary>
2013-06-24 13:41:48 +02:00
uptime ,
2019-08-31 15:40:08 +02:00
/// <summary>true if HA is enabled, false otherwise</summary>
2013-06-24 13:41:48 +02:00
ha_enabled ,
2021-08-31 12:31:16 +02:00
/// <summary>true if at least one of the supporters has different XenServer version from the coordinator, false otherwise</summary>
2013-12-13 18:35:40 +01:00
isNotFullyUpgraded ,
2019-08-31 15:40:08 +02:00
/// <summary>A logical set of VMs</summary>
2013-06-24 13:41:48 +02:00
appliance ,
2019-08-31 15:40:08 +02:00
/// <summary>Applicable to storage, true if storage is shared, false otherwise</summary>
2013-06-24 13:41:48 +02:00
shared ,
2019-08-31 15:40:08 +02:00
/// <summary>Comma-separated list of VM names</summary>
2013-06-24 13:41:48 +02:00
vm ,
2019-08-31 15:40:08 +02:00
/// <summary>List of Docker host-VM names.</summary>
2015-02-04 10:48:32 +01:00
dockervm ,
2019-08-31 15:40:08 +02:00
/// <summary>Whether a VM is using read caching</summary>
2015-03-09 16:23:42 +01:00
read_caching_enabled ,
2019-08-31 15:40:08 +02:00
/// <summary>The immediate parent folder of the selected object</summary>
2013-06-24 13:41:48 +02:00
folder ,
2019-08-31 15:40:08 +02:00
/// <summary>Comma-separated list of all the ancestor folders of the selected object</summary>
2013-06-24 13:41:48 +02:00
folders ,
2019-08-31 15:40:08 +02:00
/// <summary>INTERNAL. Used for populating the query panel.</summary>
2013-06-24 13:41:48 +02:00
memoryText ,
2019-08-31 15:40:08 +02:00
/// <summary>INTERNAL Used for populating the query panel.</summary>
2013-06-24 13:41:48 +02:00
memoryValue ,
2019-08-31 15:40:08 +02:00
/// <summary>INTERNAL Used for populating the query panel.</summary>
2013-06-24 13:41:48 +02:00
memoryRank ,
2019-08-31 15:40:08 +02:00
/// <summary>INTERNAL Used for populating the query panel.</summary>
2013-06-24 13:41:48 +02:00
cpuText ,
2019-08-31 15:40:08 +02:00
/// <summary>INTERNAL Used for populating the query panel.</summary>
2013-06-24 13:41:48 +02:00
cpuValue ,
2019-08-31 15:40:08 +02:00
/// <summary>INTERNAL Used for populating the query panel.</summary>
2013-06-24 13:41:48 +02:00
diskText ,
2019-08-31 15:40:08 +02:00
/// <summary>INTERNAL Used for populating the query panel.</summary>
2013-06-24 13:41:48 +02:00
networkText ,
2019-08-31 15:40:08 +02:00
/// <summary>INTERNAL Used for populating the query panel.</summary>
2013-06-24 13:41:48 +02:00
haText ,
2019-08-31 15:40:08 +02:00
/// <summary>Comma-separated list of host names. Hidden property used for plug-ins.</summary>
2013-06-24 13:41:48 +02:00
connection_hostname ,
2019-08-31 15:40:08 +02:00
/// <summary>Applicable to storage, the storage type. Hidden property used for plug-ins.</summary>
2013-06-24 13:41:48 +02:00
sr_type ,
2019-08-31 15:40:08 +02:00
/// <summary>Applicable to pools, a String representation of the license. Hidden property used for plug-ins.</summary>
2013-06-24 13:41:48 +02:00
license ,
2019-08-31 15:40:08 +02:00
/// <summary>Whether the object has any custom fields defined. Hidden property used for plug-ins.</summary>
2013-06-24 13:41:48 +02:00
has_custom_fields ,
2019-08-31 15:40:08 +02:00
/// <summary>Whether the VM is in any vApp</summary>
2015-12-17 12:05:22 +01:00
in_any_appliance ,
2019-08-31 15:40:08 +02:00
/// <summary>Windows Update capability</summary>
2015-12-17 12:05:22 +01:00
vendor_device_state ,
2013-06-24 13:41:48 +02:00
}
public enum ColumnNames
{
name ,
cpu ,
memory ,
disks ,
network ,
ha ,
ip ,
uptime ,
}
public class PropertyAccessors
{
private static Dictionary < PropertyNames , Type > property_types = new Dictionary < PropertyNames , Type > ( ) ;
2020-07-02 17:19:41 +02:00
private static Dictionary < PropertyNames , Func < IXenObject , IComparable > > properties = new Dictionary < PropertyNames , Func < IXenObject , IComparable > > ( ) ;
2013-06-24 13:41:48 +02:00
public static readonly Dictionary < String , vm_power_state > VM_power_state_i18n = new Dictionary < string , vm_power_state > ( ) ;
public static readonly Dictionary < String , VM . VirtualisationStatus > VirtualisationStatus_i18n = new Dictionary < string , VM . VirtualisationStatus > ( ) ;
public static readonly Dictionary < String , ObjectTypes > ObjectTypes_i18n = new Dictionary < string , ObjectTypes > ( ) ;
public static readonly Dictionary < String , VM . HA_Restart_Priority > HARestartPriority_i18n = new Dictionary < string , VM . HA_Restart_Priority > ( ) ;
public static readonly Dictionary < String , SR . SRTypes > SRType_i18n = new Dictionary < string , SR . SRTypes > ( ) ;
public static readonly Dictionary < PropertyNames , String > PropertyNames_i18n = new Dictionary < PropertyNames , string > ( ) ;
2015-05-27 18:40:51 +02:00
public static readonly Dictionary < PropertyNames , String > PropertyNames_i18n_false = new Dictionary < PropertyNames , string > ( ) ;
2013-06-24 13:41:48 +02:00
public static readonly Dictionary < vm_power_state , Icons > VM_power_state_images = new Dictionary < vm_power_state , Icons > ( ) ;
public static readonly Dictionary < ObjectTypes , Icons > ObjectTypes_images = new Dictionary < ObjectTypes , Icons > ( ) ;
private static Dictionary < ColumnNames , PropertyNames > column_sort_by = new Dictionary < ColumnNames , PropertyNames > ( ) ;
static PropertyAccessors ( )
{
foreach ( vm_power_state p in Enum . GetValues ( typeof ( vm_power_state ) ) )
2019-01-25 01:03:17 +01:00
VM_power_state_i18n [ FriendlyNameManager . GetFriendlyName ( string . Format ( "Label-VM.power_state-{0}" , p . ToString ( ) ) ) ] = p ;
2013-06-24 13:41:48 +02:00
foreach ( SR . SRTypes type in Enum . GetValues ( typeof ( SR . SRTypes ) ) )
2021-02-24 00:50:07 +01:00
SRType_i18n [ SR . GetFriendlyTypeName ( type ) ] = type ;
2013-06-24 13:41:48 +02:00
2020-07-03 17:23:52 +02:00
VirtualisationStatus_i18n [ Messages . VIRTUALIZATION_STATE_VM_NOT_OPTIMIZED ] = VM . VirtualisationStatus . NOT_INSTALLED ;
2013-06-24 13:41:48 +02:00
VirtualisationStatus_i18n [ Messages . OUT_OF_DATE ] = VM . VirtualisationStatus . PV_DRIVERS_OUT_OF_DATE ;
VirtualisationStatus_i18n [ Messages . UNKNOWN ] = VM . VirtualisationStatus . UNKNOWN ;
2015-09-29 16:39:17 +02:00
VirtualisationStatus_i18n [ Messages . VIRTUALIZATION_STATE_VM_IO_OPTIMIZED_ONLY ] = VM . VirtualisationStatus . IO_DRIVERS_INSTALLED ;
2020-07-03 14:17:23 +02:00
VirtualisationStatus_i18n [ Messages . VIRTUALIZATION_STATE_VM_MANAGEMENT_AGENT_INSTALLED_ONLY ] = VM . VirtualisationStatus . MANAGEMENT_INSTALLED ;
2015-09-29 16:39:17 +02:00
VirtualisationStatus_i18n [ Messages . VIRTUALIZATION_STATE_VM_OPTIMIZED ] = VM . VirtualisationStatus . IO_DRIVERS_INSTALLED | VM . VirtualisationStatus . MANAGEMENT_INSTALLED ;
2015-09-14 17:21:44 +02:00
2013-06-24 13:41:48 +02:00
ObjectTypes_i18n [ Messages . VMS ] = ObjectTypes . VM ;
2021-03-16 02:50:45 +01:00
ObjectTypes_i18n [ string . Format ( Messages . XENSERVER_TEMPLATES , BrandManager . ProductBrand ) ] = ObjectTypes . DefaultTemplate ;
2013-06-24 13:41:48 +02:00
ObjectTypes_i18n [ Messages . CUSTOM_TEMPLATES ] = ObjectTypes . UserTemplate ;
ObjectTypes_i18n [ Messages . POOLS ] = ObjectTypes . Pool ;
ObjectTypes_i18n [ Messages . SERVERS ] = ObjectTypes . Server ;
ObjectTypes_i18n [ Messages . DISCONNECTED_SERVERS ] = ObjectTypes . DisconnectedServer ;
ObjectTypes_i18n [ Messages . LOCAL_SRS ] = ObjectTypes . LocalSR ;
ObjectTypes_i18n [ Messages . REMOTE_SRS ] = ObjectTypes . RemoteSR ;
ObjectTypes_i18n [ Messages . NETWORKS ] = ObjectTypes . Network ;
ObjectTypes_i18n [ Messages . SNAPSHOTS ] = ObjectTypes . Snapshot ;
ObjectTypes_i18n [ Messages . VIRTUAL_DISKS ] = ObjectTypes . VDI ;
ObjectTypes_i18n [ Messages . FOLDERS ] = ObjectTypes . Folder ;
ObjectTypes_i18n [ Messages . VM_APPLIANCE ] = ObjectTypes . Appliance ;
foreach ( VM . HA_Restart_Priority p in VM . GetAvailableRestartPriorities ( null ) ) //CA-57600 - From Boston onwards, the HA restart priorities list contains Restart instead of AlwaysRestartHighPriority and AlwaysRestart
{
HARestartPriority_i18n [ Helpers . RestartPriorityI18n ( p ) ] = p ;
}
// This one is used for grouping and filtering i18n
PropertyNames_i18n [ PropertyNames . description ] = Messages . DESCRIPTION ;
PropertyNames_i18n [ PropertyNames . host ] = Messages . SERVER ;
PropertyNames_i18n [ PropertyNames . label ] = Messages . NAME ;
2015-10-07 18:19:44 +02:00
PropertyNames_i18n [ PropertyNames . uuid ] = Messages . UUID ;
2013-06-24 13:41:48 +02:00
PropertyNames_i18n [ PropertyNames . networks ] = Messages . NETWORK ;
PropertyNames_i18n [ PropertyNames . os_name ] = Messages . OPERATING_SYSTEM ;
PropertyNames_i18n [ PropertyNames . pool ] = Messages . POOL ;
PropertyNames_i18n [ PropertyNames . power_state ] = Messages . POWER_STATE ;
PropertyNames_i18n [ PropertyNames . start_time ] = Messages . START_TIME ;
PropertyNames_i18n [ PropertyNames . storage ] = Messages . SR ;
PropertyNames_i18n [ PropertyNames . disks ] = Messages . VIRTUAL_DISK ;
PropertyNames_i18n [ PropertyNames . type ] = Messages . TYPE ;
2015-09-14 17:21:44 +02:00
PropertyNames_i18n [ PropertyNames . virtualisation_status ] = Messages . TOOLS_STATUS ;
2013-06-24 13:41:48 +02:00
PropertyNames_i18n [ PropertyNames . ha_restart_priority ] = Messages . HA_RESTART_PRIORITY ;
PropertyNames_i18n [ PropertyNames . appliance ] = Messages . VM_APPLIANCE ;
PropertyNames_i18n [ PropertyNames . tags ] = Messages . TAGS ;
PropertyNames_i18n [ PropertyNames . shared ] = Messages . SHARED ;
PropertyNames_i18n [ PropertyNames . ha_enabled ] = Messages . HA ;
2013-12-13 18:35:40 +01:00
PropertyNames_i18n [ PropertyNames . isNotFullyUpgraded ] = Messages . POOL_VERSIONS_LINK_TEXT_SHORT ;
2013-06-24 13:41:48 +02:00
PropertyNames_i18n [ PropertyNames . ip_address ] = Messages . ADDRESS ;
PropertyNames_i18n [ PropertyNames . vm ] = Messages . VM ;
2015-02-04 10:48:32 +01:00
PropertyNames_i18n [ PropertyNames . dockervm ] = "Docker VM" ;
2015-03-09 16:23:42 +01:00
PropertyNames_i18n [ PropertyNames . read_caching_enabled ] = Messages . VM_READ_CACHING_ENABLED_SEARCH ;
2015-05-27 18:40:51 +02:00
PropertyNames_i18n_false [ PropertyNames . read_caching_enabled ] = Messages . VM_READ_CACHING_DISABLED_SEARCH ;
2013-06-24 13:41:48 +02:00
PropertyNames_i18n [ PropertyNames . memory ] = Messages . MEMORY ;
PropertyNames_i18n [ PropertyNames . sr_type ] = Messages . STORAGE_TYPE ;
PropertyNames_i18n [ PropertyNames . folder ] = Messages . PARENT_FOLDER ;
PropertyNames_i18n [ PropertyNames . folders ] = Messages . ANCESTOR_FOLDERS ;
PropertyNames_i18n [ PropertyNames . has_custom_fields ] = Messages . HAS_CUSTOM_FIELDS ;
PropertyNames_i18n [ PropertyNames . in_any_appliance ] = Messages . IN_ANY_APPLIANCE ;
2015-12-17 12:05:22 +01:00
PropertyNames_i18n [ PropertyNames . vendor_device_state ] = Messages . WINDOWS_UPDATE_CAPABLE ;
PropertyNames_i18n_false [ PropertyNames . vendor_device_state ] = Messages . WINDOWS_UPDATE_CAPABLE_NOT ;
2013-06-24 13:41:48 +02:00
VM_power_state_images [ vm_power_state . Halted ] = Icons . PowerStateHalted ;
VM_power_state_images [ vm_power_state . Paused ] = Icons . PowerStateSuspended ;
VM_power_state_images [ vm_power_state . Running ] = Icons . PowerStateRunning ;
VM_power_state_images [ vm_power_state . Suspended ] = Icons . PowerStateSuspended ;
VM_power_state_images [ vm_power_state . unknown ] = Icons . PowerStateUnknown ;
ObjectTypes_images [ ObjectTypes . DefaultTemplate ] = Icons . Template ;
ObjectTypes_images [ ObjectTypes . UserTemplate ] = Icons . TemplateUser ;
ObjectTypes_images [ ObjectTypes . Pool ] = Icons . Pool ;
ObjectTypes_images [ ObjectTypes . Server ] = Icons . Host ;
ObjectTypes_images [ ObjectTypes . DisconnectedServer ] = Icons . HostDisconnected ;
ObjectTypes_images [ ObjectTypes . LocalSR ] = Icons . Storage ;
ObjectTypes_images [ ObjectTypes . RemoteSR ] = Icons . Storage ;
ObjectTypes_images [ ObjectTypes . LocalSR | ObjectTypes . RemoteSR ] = Icons . Storage ;
ObjectTypes_images [ ObjectTypes . VM ] = Icons . VM ;
ObjectTypes_images [ ObjectTypes . Network ] = Icons . Network ;
ObjectTypes_images [ ObjectTypes . Snapshot ] = Icons . Snapshot ;
ObjectTypes_images [ ObjectTypes . VDI ] = Icons . VDI ;
ObjectTypes_images [ ObjectTypes . Folder ] = Icons . Folder ;
2013-07-01 17:59:42 +02:00
ObjectTypes_images [ ObjectTypes . Appliance ] = Icons . VmAppliance ;
2013-06-24 13:41:48 +02:00
property_types . Add ( PropertyNames . pool , typeof ( Pool ) ) ;
property_types . Add ( PropertyNames . host , typeof ( Host ) ) ;
property_types . Add ( PropertyNames . os_name , typeof ( string ) ) ;
property_types . Add ( PropertyNames . power_state , typeof ( vm_power_state ) ) ;
2015-09-14 17:21:44 +02:00
property_types . Add ( PropertyNames . virtualisation_status , typeof ( VM . VirtualisationStatus ) ) ;
2013-06-24 13:41:48 +02:00
property_types . Add ( PropertyNames . type , typeof ( ObjectTypes ) ) ;
property_types . Add ( PropertyNames . networks , typeof ( XenAPI . Network ) ) ;
property_types . Add ( PropertyNames . storage , typeof ( SR ) ) ;
property_types . Add ( PropertyNames . ha_restart_priority , typeof ( VM . HA_Restart_Priority ) ) ;
2015-03-09 16:23:42 +01:00
property_types . Add ( PropertyNames . read_caching_enabled , typeof ( bool ) ) ;
2013-06-24 13:41:48 +02:00
property_types . Add ( PropertyNames . appliance , typeof ( VM_appliance ) ) ;
property_types . Add ( PropertyNames . tags , typeof ( string ) ) ;
property_types . Add ( PropertyNames . has_custom_fields , typeof ( bool ) ) ;
property_types . Add ( PropertyNames . ip_address , typeof ( ComparableAddress ) ) ;
property_types . Add ( PropertyNames . vm , typeof ( VM ) ) ;
property_types . Add ( PropertyNames . sr_type , typeof ( SR . SRTypes ) ) ;
property_types . Add ( PropertyNames . folder , typeof ( Folder ) ) ;
property_types . Add ( PropertyNames . folders , typeof ( Folder ) ) ;
property_types . Add ( PropertyNames . in_any_appliance , typeof ( bool ) ) ;
property_types . Add ( PropertyNames . disks , typeof ( VDI ) ) ;
2022-09-01 11:56:25 +02:00
properties [ PropertyNames . os_name ] = o = > o is VM vm & & vm . IsRealVm ( ) ? vm . GetOSName ( ) : null ;
properties [ PropertyNames . power_state ] = o = > o is VM vm & & vm . IsRealVm ( ) ? ( IComparable ) vm . power_state : null ;
properties [ PropertyNames . vendor_device_state ] = o = > o is VM vm & & vm . IsRealVm ( ) ? ( bool? ) vm . WindowsUpdateCapable ( ) : null ;
properties [ PropertyNames . virtualisation_status ] = o = > o is VM vm & & vm . IsRealVm ( ) ? ( IComparable ) vm . GetVirtualisationStatus ( out _ ) : null ;
properties [ PropertyNames . start_time ] = o = > o is VM vm & & vm . IsRealVm ( ) ? ( DateTime ? ) vm . GetStartTime ( ) : null ;
properties [ PropertyNames . read_caching_enabled ] = o = > o is VM vm & & vm . IsRealVm ( ) ? ( bool? ) vm . ReadCachingEnabled ( ) : null ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
properties [ PropertyNames . label ] = Helpers . GetName ;
properties [ PropertyNames . pool ] = o = > o = = null ? null : Helpers . GetPool ( o . Connection ) ;
2013-06-24 13:41:48 +02:00
properties [ PropertyNames . host ] = HostProperty ;
properties [ PropertyNames . vm ] = VMProperty ;
2020-07-02 17:19:41 +02:00
properties [ PropertyNames . dockervm ] = o = > o is DockerContainer dc ? new ComparableList < VM > { dc . Parent } : new ComparableList < VM > ( ) ;
2013-06-24 13:41:48 +02:00
properties [ PropertyNames . networks ] = NetworksProperty ;
properties [ PropertyNames . storage ] = StorageProperty ;
properties [ PropertyNames . disks ] = DisksProperty ;
properties [ PropertyNames . has_custom_fields ] = delegate ( IXenObject o )
{
// this needs to be tidied up so that CustomFields calls don't require the event thread.
bool ret = false ;
InvokeHelper . Invoke ( delegate { ret = CustomFieldsManager . HasCustomFields ( o ) ; } ) ;
return ret ;
} ;
2020-07-02 17:19:41 +02:00
properties [ PropertyNames . memory ] = o = >
2013-06-24 13:41:48 +02:00
{
2022-09-01 11:56:25 +02:00
if ( o is VM vm & & vm . IsRealVm ( ) & & vm . Connection ! = null )
2020-07-02 17:19:41 +02:00
{
var metrics = vm . Connection . Resolve ( vm . metrics ) ;
if ( metrics ! = null )
return metrics . memory_actual ;
}
return null ;
2013-06-24 13:41:48 +02:00
} ;
properties [ PropertyNames . ha_restart_priority ] = delegate ( IXenObject o )
2020-07-02 17:19:41 +02:00
{
2022-09-01 11:56:25 +02:00
if ( o is VM vm & & vm . IsRealVm ( ) )
2013-06-24 13:41:48 +02:00
{
2020-07-02 17:19:41 +02:00
Pool pool = Helpers . GetPool ( vm . Connection ) ;
if ( pool ! = null & & pool . ha_enabled )
return vm . HaPriorityIsRestart ( ) ? VM . HA_Restart_Priority . Restart : vm . HARestartPriority ( ) ;
// CA-57600 - From Boston onwards, the HA_restart_priority enum contains Restart instead of
// AlwaysRestartHighPriority and AlwaysRestart. When searching in a pre-Boston pool for VMs
// with HA_restart_priority.Restart, the search will return VMs with HA_restart_priority
// AlwaysRestartHighPriority or AlwaysRestart
}
return null ;
} ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
properties [ PropertyNames . appliance ] = delegate ( IXenObject o )
{
if ( o is VM_appliance app )
return app ;
2013-06-24 13:41:48 +02:00
2022-09-01 11:56:25 +02:00
if ( o is VM vm & & vm . IsRealVm ( ) & & vm . Connection ! = null )
2020-07-02 17:19:41 +02:00
return vm . Connection . Resolve ( vm . appliance ) ;
return null ;
} ;
2013-06-24 13:41:48 +02:00
properties [ PropertyNames . in_any_appliance ] = delegate ( IXenObject o )
{
if ( o is VM_appliance )
2020-07-02 17:19:41 +02:00
return true ;
2022-09-01 11:56:25 +02:00
if ( o is VM vm & & vm . IsRealVm ( ) & & vm . Connection ! = null )
2020-07-02 17:19:41 +02:00
return vm . Connection . Resolve ( vm . appliance ) ! = null ;
return null ;
2015-03-09 16:23:42 +01:00
} ;
2013-06-24 13:41:48 +02:00
properties [ PropertyNames . connection_hostname ] = ConnectionHostnameProperty ;
properties [ PropertyNames . cpuText ] = CPUTextProperty ;
properties [ PropertyNames . cpuValue ] = CPUValueProperty ;
properties [ PropertyNames . description ] = DescriptionProperty ;
properties [ PropertyNames . diskText ] = DiskTextProperty ;
properties [ PropertyNames . folder ] = Folders . GetFolder ;
properties [ PropertyNames . folders ] = Folders . GetAncestorFolders ;
properties [ PropertyNames . haText ] = HATextProperty ;
2020-07-02 17:19:41 +02:00
properties [ PropertyNames . ha_enabled ] = o = > o is Pool pool ? ( IComparable ) pool . ha_enabled : null ;
properties [ PropertyNames . isNotFullyUpgraded ] = o = > o is Pool pool ? ( IComparable ) ! pool . IsPoolFullyUpgraded ( ) : null ;
2013-06-24 13:41:48 +02:00
properties [ PropertyNames . ip_address ] = IPAddressProperty ;
properties [ PropertyNames . license ] = LicenseProperty ;
properties [ PropertyNames . memoryText ] = MemoryTextProperty ;
properties [ PropertyNames . memoryValue ] = MemoryValueProperty ;
properties [ PropertyNames . memoryRank ] = MemoryRankProperty ;
properties [ PropertyNames . networkText ] = NetworkTextProperty ;
properties [ PropertyNames . shared ] = SharedProperty ;
2020-07-02 17:19:41 +02:00
properties [ PropertyNames . size ] = o = > o is VDI vdi ? ( IComparable ) vdi . virtual_size : null ;
properties [ PropertyNames . sr_type ] = o = > o is SR sr ? ( IComparable ) sr . GetSRType ( false ) : null ;
2013-06-24 13:41:48 +02:00
properties [ PropertyNames . tags ] = Tags . GetTagList ;
properties [ PropertyNames . type ] = TypeProperty ;
properties [ PropertyNames . uptime ] = UptimeProperty ;
properties [ PropertyNames . uuid ] = UUIDProperty ;
column_sort_by [ ColumnNames . name ] = PropertyNames . label ;
column_sort_by [ ColumnNames . cpu ] = PropertyNames . cpuValue ;
column_sort_by [ ColumnNames . memory ] = PropertyNames . memoryValue ;
column_sort_by [ ColumnNames . disks ] = PropertyNames . diskText ;
column_sort_by [ ColumnNames . network ] = PropertyNames . networkText ;
column_sort_by [ ColumnNames . ha ] = PropertyNames . haText ;
column_sort_by [ ColumnNames . ip ] = PropertyNames . ip_address ;
column_sort_by [ ColumnNames . uptime ] = PropertyNames . uptime ;
}
private static IComparable DescriptionProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
if ( o is VM vm & & vm . DescriptionType ( ) = = VM . VmDescriptionType . None )
2013-06-24 13:41:48 +02:00
{
//return string.Empty instead of null, or it prints hyphens and looks ugly
return string . Empty ;
}
2017-09-03 04:33:29 +02:00
return o . Description ( ) ;
2013-06-24 13:41:48 +02:00
}
private static IComparable UptimeProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
2022-09-01 11:56:25 +02:00
return vm . IsRealVm ( ) ? vm . RunningTime ( ) : null ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is Host host )
2017-09-03 04:33:29 +02:00
return host . Uptime ( ) ;
2013-06-24 13:41:48 +02:00
return null ;
}
private static IComparable CPUTextProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
2022-09-01 11:56:25 +02:00
return vm . IsRealVm ( ) & & vm . power_state = = vm_power_state . Running
2020-07-02 17:19:41 +02:00
? PropertyAccessorHelper . vmCpuUsageString ( vm )
: null ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is Host host )
return host . Connection ! = null & & host . Connection . IsConnected
? PropertyAccessorHelper . hostCpuUsageString ( host )
: null ;
2013-06-24 13:41:48 +02:00
return null ;
}
private static IComparable CPUValueProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
2022-09-01 11:56:25 +02:00
return vm . IsRealVm ( ) & & vm . power_state = = vm_power_state . Running
2020-07-02 17:19:41 +02:00
? ( IComparable ) PropertyAccessorHelper . vmCpuUsageRank ( vm )
: null ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is Host host )
return host . Connection ! = null & & host . Connection . IsConnected
? ( IComparable ) PropertyAccessorHelper . hostCpuUsageRank ( host )
: null ;
2013-06-24 13:41:48 +02:00
return null ;
}
private static IComparable MemoryTextProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
{
2022-09-01 11:56:25 +02:00
return vm . IsRealVm ( ) & &
2020-07-02 17:19:41 +02:00
vm . power_state = = vm_power_state . Running & &
vm . GetVirtualisationStatus ( out _ ) . HasFlag ( VM . VirtualisationStatus . MANAGEMENT_INSTALLED )
? PropertyAccessorHelper . vmMemoryUsageString ( vm )
: null ;
}
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is Host host )
return host . Connection ! = null & & host . Connection . IsConnected
? PropertyAccessorHelper . hostMemoryUsageString ( host )
: null ;
if ( o is VDI vdi )
return PropertyAccessorHelper . vdiMemoryUsageString ( vdi ) ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
return null ;
2013-06-24 13:41:48 +02:00
}
private static IComparable MemoryRankProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
{
2022-09-01 11:56:25 +02:00
return vm . IsRealVm ( ) & &
2020-07-02 17:19:41 +02:00
vm . power_state = = vm_power_state . Running & &
vm . GetVirtualisationStatus ( out _ ) . HasFlag ( VM . VirtualisationStatus . MANAGEMENT_INSTALLED )
? ( IComparable ) PropertyAccessorHelper . vmMemoryUsageRank ( vm )
: null ;
}
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is Host host )
return host . Connection ! = null & & host . Connection . IsConnected
? ( IComparable ) PropertyAccessorHelper . hostMemoryUsageRank ( host )
: null ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is VDI vdi )
return vdi . virtual_size = = 0 ? 0 : ( int ) ( vdi . physical_utilisation * 100 / vdi . virtual_size ) ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
return null ;
2013-06-24 13:41:48 +02:00
}
private static IComparable MemoryValueProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
2013-06-24 13:41:48 +02:00
{
2022-09-01 11:56:25 +02:00
return vm . IsRealVm ( ) & &
2020-07-02 17:19:41 +02:00
vm . power_state = = vm_power_state . Running & &
vm . GetVirtualisationStatus ( out _ ) . HasFlag ( VM . VirtualisationStatus . MANAGEMENT_INSTALLED )
? ( IComparable ) PropertyAccessorHelper . vmMemoryUsageValue ( vm )
: null ;
}
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is Host host )
return host . Connection ! = null & & host . Connection . IsConnected
? ( IComparable ) PropertyAccessorHelper . hostMemoryUsageValue ( host )
: null ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is VDI vdi )
return vdi . virtual_size = = 0 ? 0.0 : vdi . physical_utilisation ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
return null ;
2013-06-24 13:41:48 +02:00
}
private static IComparable NetworkTextProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
2013-06-24 13:41:48 +02:00
{
2022-09-01 11:56:25 +02:00
return vm . IsRealVm ( ) & &
2022-02-16 21:49:03 +01:00
vm . power_state = = vm_power_state . Running & &
2020-07-02 17:19:41 +02:00
vm . GetVirtualisationStatus ( out _ ) . HasFlag ( VM . VirtualisationStatus . IO_DRIVERS_INSTALLED )
? PropertyAccessorHelper . vmNetworkUsageString ( vm )
: null ;
2013-06-24 13:41:48 +02:00
}
2020-07-02 17:19:41 +02:00
if ( o is Host host )
return host . Connection ! = null & & host . Connection . IsConnected
? PropertyAccessorHelper . hostNetworkUsageString ( host )
: null ;
2013-06-24 13:41:48 +02:00
return null ;
}
private static IComparable DiskTextProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
return o is VM vm & &
2022-09-01 11:56:25 +02:00
vm . IsRealVm ( ) & &
2020-07-02 17:19:41 +02:00
vm . power_state = = vm_power_state . Running & &
vm . GetVirtualisationStatus ( out _ ) . HasFlag ( VM . VirtualisationStatus . IO_DRIVERS_INSTALLED )
? PropertyAccessorHelper . vmDiskUsageString ( vm )
: null ;
2013-06-24 13:41:48 +02:00
}
private static IComparable HATextProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
return PropertyAccessorHelper . GetVMHAStatus ( vm ) ;
if ( o is Pool pool )
return PropertyAccessorHelper . GetPoolHAStatus ( pool ) ;
if ( o is SR sr )
return PropertyAccessorHelper . GetSRHAStatus ( sr ) ;
return null ;
2013-06-24 13:41:48 +02:00
}
private static IComparable UUIDProperty ( IXenObject o )
{
if ( o = = null )
return null ;
// A folder has no UUID, so we return the pathname in that case
if ( o is Folder )
return o . opaque_ref ;
return Helpers . GetUuid ( o ) ;
}
private static IComparable ConnectionHostnameProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
IXenConnection xc = o ? . Connection ;
2013-06-24 13:41:48 +02:00
if ( xc ! = null & & xc . IsConnected )
return xc . Hostname ;
return null ;
}
private static IComparable LicenseProperty ( IXenObject o )
{
Pool pool = Helpers . GetPool ( o . Connection ) ;
if ( pool = = null )
return null ;
2021-08-31 12:31:16 +02:00
Host coordinator = Helpers . GetCoordinator ( pool . Connection ) ;
if ( coordinator = = null )
2013-06-24 13:41:48 +02:00
return null ;
2021-08-31 12:31:16 +02:00
return Helpers . GetFriendlyLicenseName ( coordinator ) ;
2013-06-24 13:41:48 +02:00
}
private static IComparable SharedProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
if ( o is SR sr )
2013-06-24 13:41:48 +02:00
return sr . shared ;
2020-07-02 17:19:41 +02:00
if ( o is VDI vdi & & vdi . Connection ! = null )
2013-06-24 13:41:48 +02:00
{
int vms = 0 ;
foreach ( VBD vbd in vdi . Connection . ResolveAll ( vdi . VBDs ) )
{
VM vm = vbd . Connection . Resolve ( vbd . VM ) ;
if ( vm ! = null )
{
if ( + + vms > = 2 )
return true ;
}
}
return false ;
}
return null ;
}
private static IComparable TypeProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
2013-06-24 13:41:48 +02:00
{
if ( vm . is_a_snapshot )
2016-06-30 13:11:01 +02:00
return ObjectTypes . Snapshot ;
2020-07-02 17:19:41 +02:00
if ( vm . is_a_template )
2017-09-03 04:33:29 +02:00
return vm . DefaultTemplate ( ) ? ObjectTypes . DefaultTemplate : ObjectTypes . UserTemplate ;
2020-07-02 17:19:41 +02:00
if ( vm . is_control_domain )
2013-06-24 13:41:48 +02:00
return null ;
2020-07-02 17:19:41 +02:00
return ObjectTypes . VM ;
2013-06-24 13:41:48 +02:00
}
2020-07-02 17:19:41 +02:00
if ( o is VM_appliance )
2016-06-30 13:11:01 +02:00
return ObjectTypes . Appliance ;
2020-07-02 17:19:41 +02:00
if ( o is Host )
return o . Connection ! = null & & o . Connection . IsConnected ? ObjectTypes . Server : ObjectTypes . DisconnectedServer ;
if ( o is Pool )
2016-06-30 13:11:01 +02:00
return ObjectTypes . Pool ;
2020-07-02 17:19:41 +02:00
if ( o is SR sr )
2017-09-03 04:33:29 +02:00
return sr . IsLocalSR ( ) ? ObjectTypes . LocalSR : ObjectTypes . RemoteSR ;
2020-07-02 17:19:41 +02:00
if ( o is XenAPI . Network )
2016-06-30 13:11:01 +02:00
return ObjectTypes . Network ;
2020-07-02 17:19:41 +02:00
if ( o is VDI )
2016-06-30 13:11:01 +02:00
return ObjectTypes . VDI ;
2020-07-02 17:19:41 +02:00
if ( o is Folder )
2016-06-30 13:11:01 +02:00
return ObjectTypes . Folder ;
2020-07-02 17:19:41 +02:00
if ( o is DockerContainer )
2016-06-30 13:11:01 +02:00
return ObjectTypes . DockerContainer ;
2013-06-24 13:41:48 +02:00
return null ;
}
private static ComparableList < XenAPI . Network > NetworksProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
var networks = new ComparableList < XenAPI . Network > ( ) ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
2013-06-24 13:41:48 +02:00
{
2022-09-01 11:56:25 +02:00
if ( vm . IsRealVm ( ) & & vm . Connection ! = null )
2020-07-02 17:19:41 +02:00
foreach ( VIF vif in vm . Connection . ResolveAll ( vm . VIFs ) )
{
XenAPI . Network network = vm . Connection . Resolve ( vif . network ) ;
if ( network = = null )
continue ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
networks . Add ( network ) ;
}
2013-06-24 13:41:48 +02:00
}
2020-07-02 17:19:41 +02:00
else if ( o is XenAPI . Network network )
2013-06-24 13:41:48 +02:00
{
2020-07-02 17:19:41 +02:00
networks . Add ( network ) ;
2013-06-24 13:41:48 +02:00
}
return networks ;
}
private static ComparableList < VM > VMProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
var vms = new ComparableList < VM > ( ) ;
if ( o . Connection = = null )
return vms ;
2013-06-24 13:41:48 +02:00
if ( o is Pool )
{
vms . AddRange ( o . Connection . Cache . VMs ) ;
}
2020-07-02 17:19:41 +02:00
else if ( o is Host host )
2013-06-24 13:41:48 +02:00
{
vms . AddRange ( host . Connection . ResolveAll ( host . resident_VMs ) ) ;
}
2020-07-02 17:19:41 +02:00
else if ( o is SR sr )
2013-06-24 13:41:48 +02:00
{
foreach ( VDI vdi in sr . Connection . ResolveAll ( sr . VDIs ) )
foreach ( VBD vbd in vdi . Connection . ResolveAll ( vdi . VBDs ) )
{
VM vm = vbd . Connection . Resolve ( vbd . VM ) ;
if ( vm = = null )
continue ;
vms . Add ( vm ) ;
}
}
2020-07-02 17:19:41 +02:00
else if ( o is XenAPI . Network network )
2013-06-24 13:41:48 +02:00
{
foreach ( VIF vif in network . Connection . ResolveAll ( network . VIFs ) )
{
VM vm = vif . Connection . Resolve ( vif . VM ) ;
if ( vm = = null )
continue ;
vms . Add ( vm ) ;
}
}
2020-07-02 17:19:41 +02:00
else if ( o is VDI vdi )
2013-06-24 13:41:48 +02:00
{
foreach ( VBD vbd in vdi . Connection . ResolveAll ( vdi . VBDs ) )
{
VM vm = vbd . Connection . Resolve ( vbd . VM ) ;
if ( vm = = null )
continue ;
vms . Add ( vm ) ;
}
}
2020-07-02 17:19:41 +02:00
else if ( o is VM vm )
2013-06-24 13:41:48 +02:00
{
if ( vm . is_a_snapshot )
{
VM from = vm . Connection . Resolve ( vm . snapshot_of ) ;
if ( from ! = null ) // Can be null if VM has been deleted: CA-29249
vms . Add ( from ) ;
}
else
vms . Add ( vm ) ;
}
2020-07-02 17:19:41 +02:00
else if ( o is DockerContainer container )
2015-02-04 10:48:32 +01:00
{
2020-07-02 17:19:41 +02:00
vms . Add ( container . Parent ) ;
2015-02-04 10:48:32 +01:00
}
2022-09-01 11:56:25 +02:00
vms . RemoveAll ( vm = > ! vm . IsRealVm ( ) ) ;
2015-02-04 10:48:32 +01:00
return vms ;
}
2013-06-24 13:41:48 +02:00
private static ComparableList < Host > HostProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
var hosts = new ComparableList < Host > ( ) ;
if ( o . Connection = = null )
return hosts ;
2013-06-24 13:41:48 +02:00
// If we're not in a pool then just group everything under the same host
Pool pool = Helpers . GetPool ( o . Connection ) ;
2020-07-02 17:19:41 +02:00
2013-06-24 13:41:48 +02:00
if ( pool = = null )
{
2020-07-02 17:19:41 +02:00
hosts . AddRange ( o . Connection . Cache . Hosts ) ;
2013-06-24 13:41:48 +02:00
}
2020-07-02 17:19:41 +02:00
else if ( o is VM vm )
2013-06-24 13:41:48 +02:00
{
2020-07-02 17:19:41 +02:00
Host host = vm . Home ( ) ;
2013-06-24 13:41:48 +02:00
if ( host ! = null )
hosts . Add ( host ) ;
}
2020-07-02 17:19:41 +02:00
else if ( o is SR sr )
2013-06-24 13:41:48 +02:00
{
2020-07-02 17:19:41 +02:00
Host host = sr . Home ( ) ;
2013-06-24 13:41:48 +02:00
if ( host ! = null )
hosts . Add ( host ) ;
}
2020-07-02 17:19:41 +02:00
else if ( o is XenAPI . Network network )
2013-06-24 13:41:48 +02:00
{
if ( network . PIFs . Count = = 0 )
hosts . AddRange ( network . Connection . Cache . Hosts ) ;
}
2020-07-02 17:19:41 +02:00
else if ( o is Host host )
2013-06-24 13:41:48 +02:00
{
2020-07-02 17:19:41 +02:00
hosts . Add ( host ) ;
2013-06-24 13:41:48 +02:00
}
2020-07-02 17:19:41 +02:00
else if ( o is VDI vdi )
2013-06-24 13:41:48 +02:00
{
2020-07-02 17:19:41 +02:00
SR theSr = vdi . Connection . Resolve ( vdi . SR ) ;
if ( theSr ! = null )
hosts . Add ( theSr . Home ( ) ) ;
2013-06-24 13:41:48 +02:00
}
2020-07-02 17:19:41 +02:00
else if ( o is DockerContainer container )
2015-02-05 16:46:47 +01:00
{
2020-07-02 17:19:41 +02:00
VM parent = container . Parent ;
Host homeHost = parent . Home ( ) ;
if ( homeHost ! = null )
hosts . Add ( homeHost ) ;
2015-02-05 16:46:47 +01:00
}
2013-06-24 13:41:48 +02:00
return hosts ;
}
private static ComparableList < SR > StorageProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
var srs = new ComparableList < SR > ( ) ;
if ( o . Connection = = null )
return srs ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
2013-06-24 13:41:48 +02:00
{
2022-09-01 11:56:25 +02:00
if ( vm . IsRealVm ( ) )
2020-07-02 17:19:41 +02:00
foreach ( VBD vbd in vm . Connection . ResolveAll ( vm . VBDs ) )
{
VDI vdi = vbd . Connection . Resolve ( vbd . VDI ) ;
if ( vdi = = null )
continue ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
SR sr = vdi . Connection . Resolve ( vdi . SR ) ;
if ( sr ! = null & & ! srs . Contains ( sr ) )
srs . Add ( sr ) ;
}
2013-06-24 13:41:48 +02:00
}
2020-07-02 17:19:41 +02:00
else if ( o is SR sr )
2013-06-24 13:41:48 +02:00
{
2020-07-02 17:19:41 +02:00
srs . Add ( sr ) ;
2013-06-24 13:41:48 +02:00
}
2020-07-02 17:19:41 +02:00
else if ( o is VDI vdi )
2013-06-24 13:41:48 +02:00
{
2020-07-02 17:19:41 +02:00
SR theSr = vdi . Connection . Resolve ( vdi . SR ) ;
if ( theSr = = null )
2013-06-24 13:41:48 +02:00
return null ;
2020-07-02 17:19:41 +02:00
srs . Add ( theSr ) ;
2013-06-24 13:41:48 +02:00
}
return srs ;
}
private static ComparableList < VDI > DisksProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
var vdis = new ComparableList < VDI > ( ) ;
if ( o . Connection = = null )
return vdis ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is VDI theVdi )
2013-06-24 13:41:48 +02:00
{
2020-07-02 17:19:41 +02:00
vdis . Add ( theVdi ) ;
2013-06-24 13:41:48 +02:00
}
2020-07-02 17:19:41 +02:00
else if ( o is VM vm )
2013-06-24 13:41:48 +02:00
{
2022-09-01 11:56:25 +02:00
if ( vm . IsRealVm ( ) )
2020-07-02 17:19:41 +02:00
foreach ( VBD vbd in vm . Connection . ResolveAll ( vm . VBDs ) )
{
VDI vdi = vbd . Connection . Resolve ( vbd . VDI ) ;
if ( vdi ! = null & & ! vdis . Contains ( vdi ) )
vdis . Add ( vdi ) ;
}
2013-06-24 13:41:48 +02:00
}
return vdis ;
}
private static ComparableList < ComparableAddress > IPAddressProperty ( IXenObject o )
{
2020-07-02 17:19:41 +02:00
var addresses = new ComparableList < ComparableAddress > ( ) ;
if ( o . Connection = = null )
return addresses ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( o is VM vm )
2013-06-24 13:41:48 +02:00
{
2022-09-01 11:56:25 +02:00
if ( ! vm . IsRealVm ( ) )
2020-07-02 17:19:41 +02:00
return addresses ;
2013-06-24 13:41:48 +02:00
VM_guest_metrics metrics = vm . Connection . Resolve ( vm . guest_metrics ) ;
if ( metrics = = null )
return null ;
List < VIF > vifs = vm . Connection . ResolveAll ( vm . VIFs ) ;
foreach ( VIF vif in vifs )
{
2018-11-29 10:47:39 +01:00
foreach ( var value in Helpers . FindIpAddresses ( metrics . networks , vif . device ) )
2013-06-24 13:41:48 +02:00
{
2020-07-02 17:19:41 +02:00
if ( ComparableAddress . TryParse ( value , false , true , out var ipAddress ) )
addresses . Add ( ipAddress ) ;
2013-06-24 13:41:48 +02:00
}
}
2020-07-02 17:19:41 +02:00
addresses = new ComparableList < ComparableAddress > ( addresses . Distinct ( ) ) ;
2013-06-24 13:41:48 +02:00
}
2020-07-02 17:19:41 +02:00
else if ( o is Host host )
2013-06-24 13:41:48 +02:00
{
foreach ( PIF pif in host . Connection . ResolveAll ( host . PIFs ) )
{
2020-07-02 17:19:41 +02:00
if ( ComparableAddress . TryParse ( pif . IP , false , true , out var ipAddress ) )
addresses . Add ( ipAddress ) ;
2013-06-24 13:41:48 +02:00
}
}
2020-07-02 17:19:41 +02:00
else if ( o is SR sr )
2013-06-24 13:41:48 +02:00
{
2017-09-03 04:33:29 +02:00
string target = sr . Target ( ) ;
2013-06-24 13:41:48 +02:00
if ( ! string . IsNullOrEmpty ( target ) )
{
2020-07-02 17:19:41 +02:00
if ( ComparableAddress . TryParse ( target , false , true , out var ipAddress ) )
2013-06-24 13:41:48 +02:00
addresses . Add ( ipAddress ) ;
}
}
2020-07-02 17:19:41 +02:00
return addresses . Count = = 0 ? null : addresses ; // CA-28300
2013-06-24 13:41:48 +02:00
}
2020-07-02 17:19:41 +02:00
public static Func < IXenObject , IComparable > Get ( PropertyNames p )
2013-06-24 13:41:48 +02:00
{
return properties [ p ] ;
}
public static Type GetType ( PropertyNames p )
{
return property_types [ p ] ;
}
public static IDictionary Geti18nFor ( PropertyNames p )
{
switch ( p )
{
case PropertyNames . type :
return ObjectTypes_i18n ;
2015-09-14 17:21:44 +02:00
case PropertyNames . virtualisation_status :
2013-06-24 13:41:48 +02:00
return VirtualisationStatus_i18n ;
case PropertyNames . power_state :
return VM_power_state_i18n ;
case PropertyNames . ha_restart_priority :
return HARestartPriority_i18n ;
case PropertyNames . sr_type :
return SRType_i18n ;
default :
return null ;
}
}
2020-07-02 17:19:41 +02:00
public static object GetImagesFor ( PropertyNames p )
2013-06-24 13:41:48 +02:00
{
switch ( p )
{
case PropertyNames . type :
2020-07-02 17:19:41 +02:00
return ( Func < ObjectTypes , Icons > ) ( type = > ObjectTypes_images [ type ] ) ;
2013-06-24 13:41:48 +02:00
case PropertyNames . power_state :
2020-07-02 17:19:41 +02:00
return ( Func < vm_power_state , Icons > ) ( state = > VM_power_state_images [ state ] ) ;
2013-06-24 13:41:48 +02:00
case PropertyNames . networks :
2020-07-02 17:19:41 +02:00
return ( Func < XenAPI . Network , Icons > ) ( _ = > Icons . Network ) ;
2013-06-24 13:41:48 +02:00
case PropertyNames . appliance :
2020-07-02 17:19:41 +02:00
return ( Func < VM_appliance , Icons > ) ( o = > Icons . VmAppliance ) ;
2013-06-24 13:41:48 +02:00
case PropertyNames . os_name :
2020-07-02 17:19:41 +02:00
return ( Func < string , Icons > ) ( osName = >
{
string os = osName . ToLowerInvariant ( ) ;
if ( os . Contains ( "debian" ) )
return Icons . Debian ;
if ( os . Contains ( "gooroom" ) )
return Icons . Gooroom ;
2021-08-23 08:54:57 +02:00
if ( os . Contains ( "rocky" ) )
return Icons . Rocky ;
2020-07-02 17:19:41 +02:00
if ( os . Contains ( "linx" ) )
return Icons . Linx ;
if ( os . Contains ( "red" ) )
return Icons . RHEL ;
if ( os . Contains ( "cent" ) )
return Icons . CentOS ;
if ( os . Contains ( "oracle" ) )
return Icons . Oracle ;
if ( os . Contains ( "suse" ) )
return Icons . SUSE ;
if ( os . Contains ( "ubuntu" ) )
return Icons . Ubuntu ;
if ( os . Contains ( "scientific" ) )
return Icons . SciLinux ;
if ( os . Contains ( "yinhe" ) )
return Icons . YinheKylin ;
if ( os . Contains ( "kylin" ) )
return Icons . NeoKylin ;
if ( os . Contains ( "asianux" ) )
return Icons . Asianux ;
if ( os . Contains ( "turbo" ) )
return Icons . Turbo ;
if ( os . Contains ( "windows" ) )
return Icons . Windows ;
if ( os . Contains ( "coreos" ) )
return Icons . CoreOS ;
return Icons . XenCenter ;
} ) ;
2013-06-24 13:41:48 +02:00
2015-09-14 17:21:44 +02:00
case PropertyNames . virtualisation_status :
2020-07-02 17:19:41 +02:00
return ( Func < VM . VirtualisationStatus , Icons > ) ( status = >
{
if ( status . HasFlag ( VM . VirtualisationStatus . IO_DRIVERS_INSTALLED | VM . VirtualisationStatus . MANAGEMENT_INSTALLED ) )
return Icons . ToolInstalled ;
2013-06-24 13:41:48 +02:00
2020-07-02 17:19:41 +02:00
if ( status . HasFlag ( VM . VirtualisationStatus . PV_DRIVERS_OUT_OF_DATE ) )
return Icons . ToolsOutOfDate ;
2015-09-18 16:48:59 +02:00
2020-07-02 17:19:41 +02:00
return Icons . ToolsNotInstalled ;
} ) ;
2013-06-24 13:41:48 +02:00
case PropertyNames . sr_type :
2020-07-02 17:19:41 +02:00
return ( Func < SR . SRTypes , Icons > ) ( _ = > Icons . Storage ) ;
2013-06-24 13:41:48 +02:00
case PropertyNames . tags :
2020-07-02 17:19:41 +02:00
return ( Func < string , Icons > ) ( _ = > Icons . Tag ) ;
2013-06-24 13:41:48 +02:00
case PropertyNames . ha_restart_priority :
2020-07-02 17:19:41 +02:00
return ( Func < VM . HA_Restart_Priority , Icons > ) ( _ = > Icons . HA ) ;
2013-06-24 13:41:48 +02:00
2015-03-09 16:23:42 +01:00
case PropertyNames . read_caching_enabled :
2020-07-02 17:19:41 +02:00
return ( Func < bool , Icons > ) ( _ = > Icons . VDI ) ;
2015-03-09 16:23:42 +01:00
2013-06-24 13:41:48 +02:00
default :
return null ;
}
}
public static PropertyNames GetSortPropertyName ( ColumnNames c )
{
return column_sort_by [ c ] ;
}
}
public class PropertyWrapper
{
2020-07-02 17:19:41 +02:00
private readonly Func < IXenObject , IComparable > property ;
2013-06-24 13:41:48 +02:00
private readonly IXenObject o ;
public PropertyWrapper ( PropertyNames property , IXenObject o )
{
this . property = PropertyAccessors . Get ( property ) ;
this . o = o ;
}
public override String ToString ( )
{
Object obj = property ( o ) ;
return obj ! = null ? obj . ToString ( ) : Messages . HYPHEN ;
}
}
}