/* * 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 System.Linq; using Newtonsoft.Json; namespace XenAPI { /// /// A virtual TPM device /// First published in XenServer 4.0. /// public partial class VTPM : XenObject { #region Constructors public VTPM() { } public VTPM(string uuid, XenRef VM, XenRef backend) { this.uuid = uuid; this.VM = VM; this.backend = backend; } /// /// Creates a new VTPM from a Hashtable. /// Note that the fields not contained in the Hashtable /// will be created with their default values. /// /// public VTPM(Hashtable table) : this() { UpdateFrom(table); } /// /// Creates a new VTPM from a Proxy_VTPM. /// /// public VTPM(Proxy_VTPM proxy) { UpdateFrom(proxy); } #endregion /// /// Updates each field of this instance with the value of /// the corresponding field of a given VTPM. /// public override void UpdateFrom(VTPM record) { uuid = record.uuid; VM = record.VM; backend = record.backend; } internal void UpdateFrom(Proxy_VTPM proxy) { uuid = proxy.uuid == null ? null : proxy.uuid; VM = proxy.VM == null ? null : XenRef.Create(proxy.VM); backend = proxy.backend == null ? null : XenRef.Create(proxy.backend); } /// /// Given a Hashtable with field-value pairs, it updates the fields of this VTPM /// 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("VM")) VM = Marshalling.ParseRef(table, "VM"); if (table.ContainsKey("backend")) backend = Marshalling.ParseRef(table, "backend"); } public Proxy_VTPM ToProxy() { Proxy_VTPM result_ = new Proxy_VTPM(); result_.uuid = uuid ?? ""; result_.VM = VM ?? ""; result_.backend = backend ?? ""; return result_; } public bool DeepEquals(VTPM other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Helper.AreEqual2(this._uuid, other._uuid) && Helper.AreEqual2(this._VM, other._VM) && Helper.AreEqual2(this._backend, other._backend); } public override string SaveChanges(Session session, string opaqueRef, VTPM 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 VTPM. /// First published in XenServer 4.0. /// /// The session /// The opaque_ref of the given vtpm public static VTPM get_record(Session session, string _vtpm) { if (session.JsonRpcClient != null) return session.JsonRpcClient.vtpm_get_record(session.opaque_ref, _vtpm); else return new VTPM(session.XmlRpcProxy.vtpm_get_record(session.opaque_ref, _vtpm ?? "").parse()); } /// /// Get a reference to the VTPM instance with the specified UUID. /// First published in XenServer 4.0. /// /// The session /// UUID of object to return public static XenRef get_by_uuid(Session session, string _uuid) { if (session.JsonRpcClient != null) return session.JsonRpcClient.vtpm_get_by_uuid(session.opaque_ref, _uuid); else return XenRef.Create(session.XmlRpcProxy.vtpm_get_by_uuid(session.opaque_ref, _uuid ?? "").parse()); } /// /// Create a new VTPM instance, and return its handle. /// First published in XenServer 4.0. /// /// The session /// All constructor arguments public static XenRef create(Session session, VTPM _record) { if (session.JsonRpcClient != null) return session.JsonRpcClient.vtpm_create(session.opaque_ref, _record); else return XenRef.Create(session.XmlRpcProxy.vtpm_create(session.opaque_ref, _record.ToProxy()).parse()); } /// /// Create a new VTPM instance, and return its handle. /// First published in XenServer 4.0. /// /// The session /// All constructor arguments public static XenRef async_create(Session session, VTPM _record) { if (session.JsonRpcClient != null) return session.JsonRpcClient.async_vtpm_create(session.opaque_ref, _record); else return XenRef.Create(session.XmlRpcProxy.async_vtpm_create(session.opaque_ref, _record.ToProxy()).parse()); } /// /// Destroy the specified VTPM instance. /// First published in XenServer 4.0. /// /// The session /// The opaque_ref of the given vtpm public static void destroy(Session session, string _vtpm) { if (session.JsonRpcClient != null) session.JsonRpcClient.vtpm_destroy(session.opaque_ref, _vtpm); else session.XmlRpcProxy.vtpm_destroy(session.opaque_ref, _vtpm ?? "").parse(); } /// /// Destroy the specified VTPM instance. /// First published in XenServer 4.0. /// /// The session /// The opaque_ref of the given vtpm public static XenRef async_destroy(Session session, string _vtpm) { if (session.JsonRpcClient != null) return session.JsonRpcClient.async_vtpm_destroy(session.opaque_ref, _vtpm); else return XenRef.Create(session.XmlRpcProxy.async_vtpm_destroy(session.opaque_ref, _vtpm ?? "").parse()); } /// /// Get the uuid field of the given VTPM. /// First published in XenServer 4.0. /// /// The session /// The opaque_ref of the given vtpm public static string get_uuid(Session session, string _vtpm) { if (session.JsonRpcClient != null) return session.JsonRpcClient.vtpm_get_uuid(session.opaque_ref, _vtpm); else return session.XmlRpcProxy.vtpm_get_uuid(session.opaque_ref, _vtpm ?? "").parse(); } /// /// Get the VM field of the given VTPM. /// First published in XenServer 4.0. /// /// The session /// The opaque_ref of the given vtpm public static XenRef get_VM(Session session, string _vtpm) { if (session.JsonRpcClient != null) return session.JsonRpcClient.vtpm_get_vm(session.opaque_ref, _vtpm); else return XenRef.Create(session.XmlRpcProxy.vtpm_get_vm(session.opaque_ref, _vtpm ?? "").parse()); } /// /// Get the backend field of the given VTPM. /// First published in XenServer 4.0. /// /// The session /// The opaque_ref of the given vtpm public static XenRef get_backend(Session session, string _vtpm) { if (session.JsonRpcClient != null) return session.JsonRpcClient.vtpm_get_backend(session.opaque_ref, _vtpm); else return XenRef.Create(session.XmlRpcProxy.vtpm_get_backend(session.opaque_ref, _vtpm ?? "").parse()); } /// /// Unique identifier/object reference /// public virtual string uuid { get { return _uuid; } set { if (!Helper.AreEqual(value, _uuid)) { _uuid = value; NotifyPropertyChanged("uuid"); } } } private string _uuid = ""; /// /// the virtual machine /// [JsonConverter(typeof(XenRefConverter))] public virtual XenRef VM { get { return _VM; } set { if (!Helper.AreEqual(value, _VM)) { _VM = value; NotifyPropertyChanged("VM"); } } } private XenRef _VM = new XenRef(Helper.NullOpaqueRef); /// /// the domain where the backend is located /// [JsonConverter(typeof(XenRefConverter))] public virtual XenRef backend { get { return _backend; } set { if (!Helper.AreEqual(value, _backend)) { _backend = value; NotifyPropertyChanged("backend"); } } } private XenRef _backend = new XenRef(Helper.NullOpaqueRef); } }