/*
* 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;
using System.ComponentModel;
using System.Globalization;
using Newtonsoft.Json;
namespace XenAPI
{
///
/// Describes the storage that is available to a PVS site for caching purposes
/// First published in XenServer 7.1.
///
public partial class PVS_cache_storage : XenObject
{
#region Constructors
public PVS_cache_storage()
{
}
public PVS_cache_storage(string uuid,
XenRef host,
XenRef SR,
XenRef site,
long size,
XenRef VDI)
{
this.uuid = uuid;
this.host = host;
this.SR = SR;
this.site = site;
this.size = size;
this.VDI = VDI;
}
///
/// Creates a new PVS_cache_storage from a Hashtable.
/// Note that the fields not contained in the Hashtable
/// will be created with their default values.
///
///
public PVS_cache_storage(Hashtable table)
: this()
{
UpdateFrom(table);
}
///
/// Creates a new PVS_cache_storage from a Proxy_PVS_cache_storage.
///
///
public PVS_cache_storage(Proxy_PVS_cache_storage proxy)
{
UpdateFrom(proxy);
}
#endregion
///
/// Updates each field of this instance with the value of
/// the corresponding field of a given PVS_cache_storage.
///
public override void UpdateFrom(PVS_cache_storage update)
{
uuid = update.uuid;
host = update.host;
SR = update.SR;
site = update.site;
size = update.size;
VDI = update.VDI;
}
internal void UpdateFrom(Proxy_PVS_cache_storage proxy)
{
uuid = proxy.uuid == null ? null : proxy.uuid;
host = proxy.host == null ? null : XenRef.Create(proxy.host);
SR = proxy.SR == null ? null : XenRef.Create(proxy.SR);
site = proxy.site == null ? null : XenRef.Create(proxy.site);
size = proxy.size == null ? 0 : long.Parse(proxy.size);
VDI = proxy.VDI == null ? null : XenRef.Create(proxy.VDI);
}
public Proxy_PVS_cache_storage ToProxy()
{
Proxy_PVS_cache_storage result_ = new Proxy_PVS_cache_storage();
result_.uuid = uuid ?? "";
result_.host = host ?? "";
result_.SR = SR ?? "";
result_.site = site ?? "";
result_.size = size.ToString();
result_.VDI = VDI ?? "";
return result_;
}
///
/// Given a Hashtable with field-value pairs, it updates the fields of this PVS_cache_storage
/// with the values listed in the Hashtable. Note that only the fields contained
/// in the Hashtable will be updated and the rest will remain the same.
///
///
public void UpdateFrom(Hashtable table)
{
if (table.ContainsKey("uuid"))
uuid = Marshalling.ParseString(table, "uuid");
if (table.ContainsKey("host"))
host = Marshalling.ParseRef(table, "host");
if (table.ContainsKey("SR"))
SR = Marshalling.ParseRef(table, "SR");
if (table.ContainsKey("site"))
site = Marshalling.ParseRef(table, "site");
if (table.ContainsKey("size"))
size = Marshalling.ParseLong(table, "size");
if (table.ContainsKey("VDI"))
VDI = Marshalling.ParseRef(table, "VDI");
}
public bool DeepEquals(PVS_cache_storage other)
{
if (ReferenceEquals(null, other))
return false;
if (ReferenceEquals(this, other))
return true;
return Helper.AreEqual2(this._uuid, other._uuid) &&
Helper.AreEqual2(this._host, other._host) &&
Helper.AreEqual2(this._SR, other._SR) &&
Helper.AreEqual2(this._site, other._site) &&
Helper.AreEqual2(this._size, other._size) &&
Helper.AreEqual2(this._VDI, other._VDI);
}
internal static List ProxyArrayToObjectList(Proxy_PVS_cache_storage[] input)
{
var result = new List();
foreach (var item in input)
result.Add(new PVS_cache_storage(item));
return result;
}
public override string SaveChanges(Session session, string opaqueRef, PVS_cache_storage server)
{
if (opaqueRef == null)
{
var reference = create(session, this);
return reference == null ? null : reference.opaque_ref;
}
else
{
throw new InvalidOperationException("This type has no read/write properties");
}
}
///
/// Get a record containing the current state of the given PVS_cache_storage.
/// First published in XenServer 7.1.
///
/// The session
/// The opaque_ref of the given pvs_cache_storage
public static PVS_cache_storage get_record(Session session, string _pvs_cache_storage)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.pvs_cache_storage_get_record(session.opaque_ref, _pvs_cache_storage);
else
return new PVS_cache_storage(session.proxy.pvs_cache_storage_get_record(session.opaque_ref, _pvs_cache_storage ?? "").parse());
}
///
/// Get a reference to the PVS_cache_storage instance with the specified UUID.
/// First published in XenServer 7.1.
///
/// The session
/// UUID of object to return
public static XenRef get_by_uuid(Session session, string _uuid)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.pvs_cache_storage_get_by_uuid(session.opaque_ref, _uuid);
else
return XenRef.Create(session.proxy.pvs_cache_storage_get_by_uuid(session.opaque_ref, _uuid ?? "").parse());
}
///
/// Create a new PVS_cache_storage instance, and return its handle.
/// First published in XenServer 7.1.
///
/// The session
/// All constructor arguments
public static XenRef create(Session session, PVS_cache_storage _record)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.pvs_cache_storage_create(session.opaque_ref, _record);
else
return XenRef.Create(session.proxy.pvs_cache_storage_create(session.opaque_ref, _record.ToProxy()).parse());
}
///
/// Create a new PVS_cache_storage instance, and return its handle.
/// First published in XenServer 7.1.
///
/// The session
/// All constructor arguments
public static XenRef async_create(Session session, PVS_cache_storage _record)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.async_pvs_cache_storage_create(session.opaque_ref, _record);
else
return XenRef.Create(session.proxy.async_pvs_cache_storage_create(session.opaque_ref, _record.ToProxy()).parse());
}
///
/// Destroy the specified PVS_cache_storage instance.
/// First published in XenServer 7.1.
///
/// The session
/// The opaque_ref of the given pvs_cache_storage
public static void destroy(Session session, string _pvs_cache_storage)
{
if (session.JsonRpcClient != null)
session.JsonRpcClient.pvs_cache_storage_destroy(session.opaque_ref, _pvs_cache_storage);
else
session.proxy.pvs_cache_storage_destroy(session.opaque_ref, _pvs_cache_storage ?? "").parse();
}
///
/// Destroy the specified PVS_cache_storage instance.
/// First published in XenServer 7.1.
///
/// The session
/// The opaque_ref of the given pvs_cache_storage
public static XenRef async_destroy(Session session, string _pvs_cache_storage)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.async_pvs_cache_storage_destroy(session.opaque_ref, _pvs_cache_storage);
else
return XenRef.Create(session.proxy.async_pvs_cache_storage_destroy(session.opaque_ref, _pvs_cache_storage ?? "").parse());
}
///
/// Get the uuid field of the given PVS_cache_storage.
/// First published in XenServer 7.1.
///
/// The session
/// The opaque_ref of the given pvs_cache_storage
public static string get_uuid(Session session, string _pvs_cache_storage)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.pvs_cache_storage_get_uuid(session.opaque_ref, _pvs_cache_storage);
else
return session.proxy.pvs_cache_storage_get_uuid(session.opaque_ref, _pvs_cache_storage ?? "").parse();
}
///
/// Get the host field of the given PVS_cache_storage.
/// First published in XenServer 7.1.
///
/// The session
/// The opaque_ref of the given pvs_cache_storage
public static XenRef get_host(Session session, string _pvs_cache_storage)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.pvs_cache_storage_get_host(session.opaque_ref, _pvs_cache_storage);
else
return XenRef.Create(session.proxy.pvs_cache_storage_get_host(session.opaque_ref, _pvs_cache_storage ?? "").parse());
}
///
/// Get the SR field of the given PVS_cache_storage.
/// First published in XenServer 7.1.
///
/// The session
/// The opaque_ref of the given pvs_cache_storage
public static XenRef get_SR(Session session, string _pvs_cache_storage)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.pvs_cache_storage_get_sr(session.opaque_ref, _pvs_cache_storage);
else
return XenRef.Create(session.proxy.pvs_cache_storage_get_sr(session.opaque_ref, _pvs_cache_storage ?? "").parse());
}
///
/// Get the site field of the given PVS_cache_storage.
/// First published in XenServer 7.1.
///
/// The session
/// The opaque_ref of the given pvs_cache_storage
public static XenRef get_site(Session session, string _pvs_cache_storage)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.pvs_cache_storage_get_site(session.opaque_ref, _pvs_cache_storage);
else
return XenRef.Create(session.proxy.pvs_cache_storage_get_site(session.opaque_ref, _pvs_cache_storage ?? "").parse());
}
///
/// Get the size field of the given PVS_cache_storage.
/// First published in XenServer 7.1.
///
/// The session
/// The opaque_ref of the given pvs_cache_storage
public static long get_size(Session session, string _pvs_cache_storage)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.pvs_cache_storage_get_size(session.opaque_ref, _pvs_cache_storage);
else
return long.Parse(session.proxy.pvs_cache_storage_get_size(session.opaque_ref, _pvs_cache_storage ?? "").parse());
}
///
/// Get the VDI field of the given PVS_cache_storage.
/// First published in XenServer 7.1.
///
/// The session
/// The opaque_ref of the given pvs_cache_storage
public static XenRef get_VDI(Session session, string _pvs_cache_storage)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.pvs_cache_storage_get_vdi(session.opaque_ref, _pvs_cache_storage);
else
return XenRef.Create(session.proxy.pvs_cache_storage_get_vdi(session.opaque_ref, _pvs_cache_storage ?? "").parse());
}
///
/// Return a list of all the PVS_cache_storages known to the system.
/// First published in XenServer 7.1.
///
/// The session
public static List> get_all(Session session)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.pvs_cache_storage_get_all(session.opaque_ref);
else
return XenRef.Create(session.proxy.pvs_cache_storage_get_all(session.opaque_ref).parse());
}
///
/// Get all the PVS_cache_storage Records at once, in a single XML RPC call
/// First published in XenServer 7.1.
///
/// The session
public static Dictionary, PVS_cache_storage> get_all_records(Session session)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.pvs_cache_storage_get_all_records(session.opaque_ref);
else
return XenRef.Create(session.proxy.pvs_cache_storage_get_all_records(session.opaque_ref).parse());
}
///
/// Unique identifier/object reference
///
public virtual string uuid
{
get { return _uuid; }
set
{
if (!Helper.AreEqual(value, _uuid))
{
_uuid = value;
Changed = true;
NotifyPropertyChanged("uuid");
}
}
}
private string _uuid = "";
///
/// The host on which this object defines PVS cache storage
///
[JsonConverter(typeof(XenRefConverter))]
public virtual XenRef host
{
get { return _host; }
set
{
if (!Helper.AreEqual(value, _host))
{
_host = value;
Changed = true;
NotifyPropertyChanged("host");
}
}
}
private XenRef _host = new XenRef("OpaqueRef:NULL");
///
/// SR providing storage for the PVS cache
///
[JsonConverter(typeof(XenRefConverter))]
public virtual XenRef SR
{
get { return _SR; }
set
{
if (!Helper.AreEqual(value, _SR))
{
_SR = value;
Changed = true;
NotifyPropertyChanged("SR");
}
}
}
private XenRef _SR = new XenRef("OpaqueRef:NULL");
///
/// The PVS_site for which this object defines the storage
///
[JsonConverter(typeof(XenRefConverter))]
public virtual XenRef site
{
get { return _site; }
set
{
if (!Helper.AreEqual(value, _site))
{
_site = value;
Changed = true;
NotifyPropertyChanged("site");
}
}
}
private XenRef _site = new XenRef("OpaqueRef:NULL");
///
/// The size of the cache VDI (in bytes)
///
public virtual long size
{
get { return _size; }
set
{
if (!Helper.AreEqual(value, _size))
{
_size = value;
Changed = true;
NotifyPropertyChanged("size");
}
}
}
private long _size = 21474836480;
///
/// The VDI used for caching
///
[JsonConverter(typeof(XenRefConverter))]
public virtual XenRef VDI
{
get { return _VDI; }
set
{
if (!Helper.AreEqual(value, _VDI))
{
_VDI = value;
Changed = true;
NotifyPropertyChanged("VDI");
}
}
}
private XenRef _VDI = new XenRef("OpaqueRef:NULL");
}
}