2018-01-17 09:58:15 +01:00
/ *
* Copyright ( c ) Citrix Systems , Inc .
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
*
* 1 ) Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
*
* 2 ) 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 ;
using System.Collections.Generic ;
2018-02-27 12:34:57 +01:00
using System.ComponentModel ;
using System.Globalization ;
using Newtonsoft.Json ;
using Newtonsoft.Json.Converters ;
2018-01-17 09:58:15 +01:00
namespace XenAPI
{
/// <summary>
/// network-sriov which connects logical pif and physical pif
/// First published in Unreleased.
/// </summary>
public partial class Network_sriov : XenObject < Network_sriov >
{
public Network_sriov ( )
{
}
public Network_sriov ( string uuid ,
XenRef < PIF > physical_PIF ,
XenRef < PIF > logical_PIF ,
bool requires_reboot ,
sriov_configuration_mode configuration_mode )
{
this . uuid = uuid ;
this . physical_PIF = physical_PIF ;
this . logical_PIF = logical_PIF ;
this . requires_reboot = requires_reboot ;
this . configuration_mode = configuration_mode ;
}
/// <summary>
/// Creates a new Network_sriov from a Proxy_Network_sriov.
/// </summary>
/// <param name="proxy"></param>
public Network_sriov ( Proxy_Network_sriov proxy )
{
this . UpdateFromProxy ( proxy ) ;
}
public override void UpdateFrom ( Network_sriov update )
{
uuid = update . uuid ;
physical_PIF = update . physical_PIF ;
logical_PIF = update . logical_PIF ;
requires_reboot = update . requires_reboot ;
configuration_mode = update . configuration_mode ;
}
internal void UpdateFromProxy ( Proxy_Network_sriov proxy )
{
uuid = proxy . uuid = = null ? null : ( string ) proxy . uuid ;
physical_PIF = proxy . physical_PIF = = null ? null : XenRef < PIF > . Create ( proxy . physical_PIF ) ;
logical_PIF = proxy . logical_PIF = = null ? null : XenRef < PIF > . Create ( proxy . logical_PIF ) ;
requires_reboot = ( bool ) proxy . requires_reboot ;
configuration_mode = proxy . configuration_mode = = null ? ( sriov_configuration_mode ) 0 : ( sriov_configuration_mode ) Helper . EnumParseDefault ( typeof ( sriov_configuration_mode ) , ( string ) proxy . configuration_mode ) ;
}
public Proxy_Network_sriov ToProxy ( )
{
Proxy_Network_sriov result_ = new Proxy_Network_sriov ( ) ;
result_ . uuid = uuid ? ? "" ;
result_ . physical_PIF = physical_PIF ? ? "" ;
result_ . logical_PIF = logical_PIF ? ? "" ;
result_ . requires_reboot = requires_reboot ;
result_ . configuration_mode = sriov_configuration_mode_helper . ToString ( configuration_mode ) ;
return result_ ;
}
/// <summary>
/// Creates a new Network_sriov from a Hashtable.
/// </summary>
/// <param name="table"></param>
public Network_sriov ( Hashtable table )
{
uuid = Marshalling . ParseString ( table , "uuid" ) ;
physical_PIF = Marshalling . ParseRef < PIF > ( table , "physical_PIF" ) ;
logical_PIF = Marshalling . ParseRef < PIF > ( table , "logical_PIF" ) ;
requires_reboot = Marshalling . ParseBool ( table , "requires_reboot" ) ;
configuration_mode = ( sriov_configuration_mode ) Helper . EnumParseDefault ( typeof ( sriov_configuration_mode ) , Marshalling . ParseString ( table , "configuration_mode" ) ) ;
}
public bool DeepEquals ( Network_sriov other )
{
if ( ReferenceEquals ( null , other ) )
return false ;
if ( ReferenceEquals ( this , other ) )
return true ;
return Helper . AreEqual2 ( this . _uuid , other . _uuid ) & &
Helper . AreEqual2 ( this . _physical_PIF , other . _physical_PIF ) & &
Helper . AreEqual2 ( this . _logical_PIF , other . _logical_PIF ) & &
Helper . AreEqual2 ( this . _requires_reboot , other . _requires_reboot ) & &
Helper . AreEqual2 ( this . _configuration_mode , other . _configuration_mode ) ;
}
internal static List < Network_sriov > ProxyArrayToObjectList ( Proxy_Network_sriov [ ] input )
{
var result = new List < Network_sriov > ( ) ;
foreach ( var item in input )
result . Add ( new Network_sriov ( item ) ) ;
return result ;
}
public override string SaveChanges ( Session session , string opaqueRef , Network_sriov server )
{
if ( opaqueRef = = null )
{
System . Diagnostics . Debug . Assert ( false , "Cannot create instances of this type on the server" ) ;
return "" ;
}
else
{
throw new InvalidOperationException ( "This type has no read/write properties" ) ;
}
}
/// <summary>
/// Get a record containing the current state of the given network_sriov.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_network_sriov">The opaque_ref of the given network_sriov</param>
public static Network_sriov get_record ( Session session , string _network_sriov )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . network_sriov_get_record ( session . uuid , _network_sriov ) ;
else
return new Network_sriov ( ( Proxy_Network_sriov ) session . proxy . network_sriov_get_record ( session . uuid , _network_sriov ? ? "" ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Get a reference to the network_sriov instance with the specified UUID.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_uuid">UUID of object to return</param>
public static XenRef < Network_sriov > get_by_uuid ( Session session , string _uuid )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . network_sriov_get_by_uuid ( session . uuid , _uuid ) ;
else
return XenRef < Network_sriov > . Create ( session . proxy . network_sriov_get_by_uuid ( session . uuid , _uuid ? ? "" ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Get the uuid field of the given network_sriov.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_network_sriov">The opaque_ref of the given network_sriov</param>
public static string get_uuid ( Session session , string _network_sriov )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . network_sriov_get_uuid ( session . uuid , _network_sriov ) ;
else
return ( string ) session . proxy . network_sriov_get_uuid ( session . uuid , _network_sriov ? ? "" ) . parse ( ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Get the physical_PIF field of the given network_sriov.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_network_sriov">The opaque_ref of the given network_sriov</param>
public static XenRef < PIF > get_physical_PIF ( Session session , string _network_sriov )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . network_sriov_get_physical_pif ( session . uuid , _network_sriov ) ;
else
return XenRef < PIF > . Create ( session . proxy . network_sriov_get_physical_pif ( session . uuid , _network_sriov ? ? "" ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Get the logical_PIF field of the given network_sriov.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_network_sriov">The opaque_ref of the given network_sriov</param>
public static XenRef < PIF > get_logical_PIF ( Session session , string _network_sriov )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . network_sriov_get_logical_pif ( session . uuid , _network_sriov ) ;
else
return XenRef < PIF > . Create ( session . proxy . network_sriov_get_logical_pif ( session . uuid , _network_sriov ? ? "" ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Get the requires_reboot field of the given network_sriov.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_network_sriov">The opaque_ref of the given network_sriov</param>
public static bool get_requires_reboot ( Session session , string _network_sriov )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . network_sriov_get_requires_reboot ( session . uuid , _network_sriov ) ;
else
return ( bool ) session . proxy . network_sriov_get_requires_reboot ( session . uuid , _network_sriov ? ? "" ) . parse ( ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Get the configuration_mode field of the given network_sriov.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_network_sriov">The opaque_ref of the given network_sriov</param>
public static sriov_configuration_mode get_configuration_mode ( Session session , string _network_sriov )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . network_sriov_get_configuration_mode ( session . uuid , _network_sriov ) ;
else
return ( sriov_configuration_mode ) Helper . EnumParseDefault ( typeof ( sriov_configuration_mode ) , ( string ) session . proxy . network_sriov_get_configuration_mode ( session . uuid , _network_sriov ? ? "" ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Enable SR-IOV on the specific PIF. It will create a network-sriov based on the specific PIF and automatically create a logical PIF to connect the specific network.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_pif">PIF on which to enable SR-IOV</param>
/// <param name="_network">Network to connect SR-IOV virtual functions with VM VIFs</param>
public static XenRef < Network_sriov > create ( Session session , string _pif , string _network )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . network_sriov_create ( session . uuid , _pif , _network ) ;
else
return XenRef < Network_sriov > . Create ( session . proxy . network_sriov_create ( session . uuid , _pif ? ? "" , _network ? ? "" ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Enable SR-IOV on the specific PIF. It will create a network-sriov based on the specific PIF and automatically create a logical PIF to connect the specific network.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_pif">PIF on which to enable SR-IOV</param>
/// <param name="_network">Network to connect SR-IOV virtual functions with VM VIFs</param>
public static XenRef < Task > async_create ( Session session , string _pif , string _network )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . async_network_sriov_create ( session . uuid , _pif , _network ) ;
else
return XenRef < Task > . Create ( session . proxy . async_network_sriov_create ( session . uuid , _pif ? ? "" , _network ? ? "" ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Disable SR-IOV on the specific PIF. It will destroy the network-sriov and the logical PIF accordingly.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_network_sriov">The opaque_ref of the given network_sriov</param>
public static void destroy ( Session session , string _network_sriov )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
session . JsonRpcClient . network_sriov_destroy ( session . uuid , _network_sriov ) ;
else
session . proxy . network_sriov_destroy ( session . uuid , _network_sriov ? ? "" ) . parse ( ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Disable SR-IOV on the specific PIF. It will destroy the network-sriov and the logical PIF accordingly.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_network_sriov">The opaque_ref of the given network_sriov</param>
public static XenRef < Task > async_destroy ( Session session , string _network_sriov )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . async_network_sriov_destroy ( session . uuid , _network_sriov ) ;
else
return XenRef < Task > . Create ( session . proxy . async_network_sriov_destroy ( session . uuid , _network_sriov ? ? "" ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Get the number of VF that still can be allocated from this SRIOV object
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_network_sriov">The opaque_ref of the given network_sriov</param>
public static long get_remaining_capacity ( Session session , string _network_sriov )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . network_sriov_get_remaining_capacity ( session . uuid , _network_sriov ) ;
else
return long . Parse ( ( string ) session . proxy . network_sriov_get_remaining_capacity ( session . uuid , _network_sriov ? ? "" ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Get the number of VF that still can be allocated from this SRIOV object
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_network_sriov">The opaque_ref of the given network_sriov</param>
public static XenRef < Task > async_get_remaining_capacity ( Session session , string _network_sriov )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . async_network_sriov_get_remaining_capacity ( session . uuid , _network_sriov ) ;
else
return XenRef < Task > . Create ( session . proxy . async_network_sriov_get_remaining_capacity ( session . uuid , _network_sriov ? ? "" ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Return a list of all the network_sriovs known to the system.
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
public static List < XenRef < Network_sriov > > get_all ( Session session )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . network_sriov_get_all ( session . uuid ) ;
else
return XenRef < Network_sriov > . Create ( session . proxy . network_sriov_get_all ( session . uuid ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Get all the network_sriov Records at once, in a single XML RPC call
/// First published in Unreleased.
/// </summary>
/// <param name="session">The session</param>
public static Dictionary < XenRef < Network_sriov > , Network_sriov > get_all_records ( Session session )
{
2018-02-27 12:34:57 +01:00
if ( session . JsonRpcClient ! = null )
return session . JsonRpcClient . network_sriov_get_all_records ( session . uuid ) ;
else
return XenRef < Network_sriov > . Create < Proxy_Network_sriov > ( session . proxy . network_sriov_get_all_records ( session . uuid ) . parse ( ) ) ;
2018-01-17 09:58:15 +01:00
}
/// <summary>
/// Unique identifier/object reference
/// </summary>
public virtual string uuid
{
get { return _uuid ; }
set
{
if ( ! Helper . AreEqual ( value , _uuid ) )
{
_uuid = value ;
Changed = true ;
NotifyPropertyChanged ( "uuid" ) ;
}
}
}
2018-02-27 12:34:57 +01:00
private string _uuid = "" ;
2018-01-17 09:58:15 +01:00
/// <summary>
/// The PIF that has SR-IOV enabled
/// </summary>
2018-02-27 12:34:57 +01:00
[JsonConverter(typeof(XenRefConverter<PIF>))]
2018-01-17 09:58:15 +01:00
public virtual XenRef < PIF > physical_PIF
{
get { return _physical_PIF ; }
set
{
if ( ! Helper . AreEqual ( value , _physical_PIF ) )
{
_physical_PIF = value ;
Changed = true ;
NotifyPropertyChanged ( "physical_PIF" ) ;
}
}
}
2018-02-27 12:34:57 +01:00
private XenRef < PIF > _physical_PIF = new XenRef < PIF > ( Helper . NullOpaqueRef ) ;
2018-01-17 09:58:15 +01:00
/// <summary>
/// The logical PIF to connect to the SR-IOV network after enable SR-IOV on the physical PIF
/// </summary>
2018-02-27 12:34:57 +01:00
[JsonConverter(typeof(XenRefConverter<PIF>))]
2018-01-17 09:58:15 +01:00
public virtual XenRef < PIF > logical_PIF
{
get { return _logical_PIF ; }
set
{
if ( ! Helper . AreEqual ( value , _logical_PIF ) )
{
_logical_PIF = value ;
Changed = true ;
NotifyPropertyChanged ( "logical_PIF" ) ;
}
}
}
2018-02-27 12:34:57 +01:00
private XenRef < PIF > _logical_PIF = new XenRef < PIF > ( Helper . NullOpaqueRef ) ;
2018-01-17 09:58:15 +01:00
/// <summary>
/// Indicates whether the host need to be rebooted before SR-IOV is enabled on the physical PIF
/// </summary>
public virtual bool requires_reboot
{
get { return _requires_reboot ; }
set
{
if ( ! Helper . AreEqual ( value , _requires_reboot ) )
{
_requires_reboot = value ;
Changed = true ;
NotifyPropertyChanged ( "requires_reboot" ) ;
}
}
}
2018-02-27 12:34:57 +01:00
private bool _requires_reboot = false ;
2018-01-17 09:58:15 +01:00
/// <summary>
/// The mode for configure network sriov
/// </summary>
2018-02-27 12:34:57 +01:00
[JsonConverter(typeof(sriov_configuration_modeConverter))]
2018-01-17 09:58:15 +01:00
public virtual sriov_configuration_mode configuration_mode
{
get { return _configuration_mode ; }
set
{
if ( ! Helper . AreEqual ( value , _configuration_mode ) )
{
_configuration_mode = value ;
Changed = true ;
NotifyPropertyChanged ( "configuration_mode" ) ;
}
}
}
2018-02-27 12:34:57 +01:00
private sriov_configuration_mode _configuration_mode = sriov_configuration_mode . unknown ;
2018-01-17 09:58:15 +01:00
}
}