/* * Copyright (c) Cloud Software Group, Inc. * * 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 { /// /// VM appliance /// First published in XenServer 6.0. /// public partial class VM_appliance : XenObject { #region Constructors public VM_appliance() { } public VM_appliance(string uuid, string name_label, string name_description, List allowed_operations, Dictionary current_operations, List> VMs) { this.uuid = uuid; this.name_label = name_label; this.name_description = name_description; this.allowed_operations = allowed_operations; this.current_operations = current_operations; this.VMs = VMs; } /// /// Creates a new VM_appliance from a Hashtable. /// Note that the fields not contained in the Hashtable /// will be created with their default values. /// /// public VM_appliance(Hashtable table) : this() { UpdateFrom(table); } #endregion /// /// Updates each field of this instance with the value of /// the corresponding field of a given VM_appliance. /// public override void UpdateFrom(VM_appliance record) { uuid = record.uuid; name_label = record.name_label; name_description = record.name_description; allowed_operations = record.allowed_operations; current_operations = record.current_operations; VMs = record.VMs; } /// /// Given a Hashtable with field-value pairs, it updates the fields of this VM_appliance /// 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("name_label")) name_label = Marshalling.ParseString(table, "name_label"); if (table.ContainsKey("name_description")) name_description = Marshalling.ParseString(table, "name_description"); if (table.ContainsKey("allowed_operations")) allowed_operations = Helper.StringArrayToEnumList(Marshalling.ParseStringArray(table, "allowed_operations")); if (table.ContainsKey("current_operations")) current_operations = Maps.convert_from_proxy_string_vm_appliance_operation(Marshalling.ParseHashTable(table, "current_operations")); if (table.ContainsKey("VMs")) VMs = Marshalling.ParseSetRef(table, "VMs"); } public bool DeepEquals(VM_appliance other, bool ignoreCurrentOperations) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; if (!ignoreCurrentOperations && !Helper.AreEqual2(this.current_operations, other.current_operations)) return false; return Helper.AreEqual2(this._uuid, other._uuid) && Helper.AreEqual2(this._name_label, other._name_label) && Helper.AreEqual2(this._name_description, other._name_description) && Helper.AreEqual2(this._allowed_operations, other._allowed_operations) && Helper.AreEqual2(this._VMs, other._VMs); } public override string SaveChanges(Session session, string opaqueRef, VM_appliance server) { if (opaqueRef == null) { var reference = create(session, this); return reference == null ? null : reference.opaque_ref; } else { if (!Helper.AreEqual2(_name_label, server._name_label)) { VM_appliance.set_name_label(session, opaqueRef, _name_label); } if (!Helper.AreEqual2(_name_description, server._name_description)) { VM_appliance.set_name_description(session, opaqueRef, _name_description); } return null; } } /// /// Get a record containing the current state of the given VM_appliance. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static VM_appliance get_record(Session session, string _vm_appliance) { return session.JsonRpcClient.vm_appliance_get_record(session.opaque_ref, _vm_appliance); } /// /// Get a reference to the VM_appliance instance with the specified UUID. /// First published in XenServer 6.0. /// /// The session /// UUID of object to return public static XenRef get_by_uuid(Session session, string _uuid) { return session.JsonRpcClient.vm_appliance_get_by_uuid(session.opaque_ref, _uuid); } /// /// Create a new VM_appliance instance, and return its handle. /// First published in XenServer 6.0. /// /// The session /// All constructor arguments public static XenRef create(Session session, VM_appliance _record) { return session.JsonRpcClient.vm_appliance_create(session.opaque_ref, _record); } /// /// Create a new VM_appliance instance, and return its handle. /// First published in XenServer 6.0. /// /// The session /// All constructor arguments public static XenRef async_create(Session session, VM_appliance _record) { return session.JsonRpcClient.async_vm_appliance_create(session.opaque_ref, _record); } /// /// Destroy the specified VM_appliance instance. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static void destroy(Session session, string _vm_appliance) { session.JsonRpcClient.vm_appliance_destroy(session.opaque_ref, _vm_appliance); } /// /// Destroy the specified VM_appliance instance. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static XenRef async_destroy(Session session, string _vm_appliance) { return session.JsonRpcClient.async_vm_appliance_destroy(session.opaque_ref, _vm_appliance); } /// /// Get all the VM_appliance instances with the given label. /// First published in XenServer 6.0. /// /// The session /// label of object to return public static List> get_by_name_label(Session session, string _label) { return session.JsonRpcClient.vm_appliance_get_by_name_label(session.opaque_ref, _label); } /// /// Get the uuid field of the given VM_appliance. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static string get_uuid(Session session, string _vm_appliance) { return session.JsonRpcClient.vm_appliance_get_uuid(session.opaque_ref, _vm_appliance); } /// /// Get the name/label field of the given VM_appliance. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static string get_name_label(Session session, string _vm_appliance) { return session.JsonRpcClient.vm_appliance_get_name_label(session.opaque_ref, _vm_appliance); } /// /// Get the name/description field of the given VM_appliance. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static string get_name_description(Session session, string _vm_appliance) { return session.JsonRpcClient.vm_appliance_get_name_description(session.opaque_ref, _vm_appliance); } /// /// Get the allowed_operations field of the given VM_appliance. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static List get_allowed_operations(Session session, string _vm_appliance) { return session.JsonRpcClient.vm_appliance_get_allowed_operations(session.opaque_ref, _vm_appliance); } /// /// Get the current_operations field of the given VM_appliance. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static Dictionary get_current_operations(Session session, string _vm_appliance) { return session.JsonRpcClient.vm_appliance_get_current_operations(session.opaque_ref, _vm_appliance); } /// /// Get the VMs field of the given VM_appliance. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static List> get_VMs(Session session, string _vm_appliance) { return session.JsonRpcClient.vm_appliance_get_vms(session.opaque_ref, _vm_appliance); } /// /// Set the name/label field of the given VM_appliance. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance /// New value to set public static void set_name_label(Session session, string _vm_appliance, string _label) { session.JsonRpcClient.vm_appliance_set_name_label(session.opaque_ref, _vm_appliance, _label); } /// /// Set the name/description field of the given VM_appliance. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance /// New value to set public static void set_name_description(Session session, string _vm_appliance, string _description) { session.JsonRpcClient.vm_appliance_set_name_description(session.opaque_ref, _vm_appliance, _description); } /// /// Start all VMs in the appliance /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance /// Instantiate all VMs belonging to this appliance in paused state if set to true. public static void start(Session session, string _vm_appliance, bool _paused) { session.JsonRpcClient.vm_appliance_start(session.opaque_ref, _vm_appliance, _paused); } /// /// Start all VMs in the appliance /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance /// Instantiate all VMs belonging to this appliance in paused state if set to true. public static XenRef async_start(Session session, string _vm_appliance, bool _paused) { return session.JsonRpcClient.async_vm_appliance_start(session.opaque_ref, _vm_appliance, _paused); } /// /// Perform a clean shutdown of all the VMs in the appliance /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static void clean_shutdown(Session session, string _vm_appliance) { session.JsonRpcClient.vm_appliance_clean_shutdown(session.opaque_ref, _vm_appliance); } /// /// Perform a clean shutdown of all the VMs in the appliance /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static XenRef async_clean_shutdown(Session session, string _vm_appliance) { return session.JsonRpcClient.async_vm_appliance_clean_shutdown(session.opaque_ref, _vm_appliance); } /// /// Perform a hard shutdown of all the VMs in the appliance /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static void hard_shutdown(Session session, string _vm_appliance) { session.JsonRpcClient.vm_appliance_hard_shutdown(session.opaque_ref, _vm_appliance); } /// /// Perform a hard shutdown of all the VMs in the appliance /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static XenRef async_hard_shutdown(Session session, string _vm_appliance) { return session.JsonRpcClient.async_vm_appliance_hard_shutdown(session.opaque_ref, _vm_appliance); } /// /// For each VM in the appliance, try to shut it down cleanly. If this fails, perform a hard shutdown of the VM. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static void shutdown(Session session, string _vm_appliance) { session.JsonRpcClient.vm_appliance_shutdown(session.opaque_ref, _vm_appliance); } /// /// For each VM in the appliance, try to shut it down cleanly. If this fails, perform a hard shutdown of the VM. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance public static XenRef async_shutdown(Session session, string _vm_appliance) { return session.JsonRpcClient.async_vm_appliance_shutdown(session.opaque_ref, _vm_appliance); } /// /// Assert whether all SRs required to recover this VM appliance are available. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance /// The session to which the VM appliance is to be recovered. public static void assert_can_be_recovered(Session session, string _vm_appliance, string _session_to) { session.JsonRpcClient.vm_appliance_assert_can_be_recovered(session.opaque_ref, _vm_appliance, _session_to); } /// /// Assert whether all SRs required to recover this VM appliance are available. /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance /// The session to which the VM appliance is to be recovered. public static XenRef async_assert_can_be_recovered(Session session, string _vm_appliance, string _session_to) { return session.JsonRpcClient.async_vm_appliance_assert_can_be_recovered(session.opaque_ref, _vm_appliance, _session_to); } /// /// Get the list of SRs required by the VM appliance to recover. /// First published in XenServer 6.5. /// /// The session /// The opaque_ref of the given vm_appliance /// The session to which the list of SRs have to be recovered . public static List> get_SRs_required_for_recovery(Session session, string _vm_appliance, string _session_to) { return session.JsonRpcClient.vm_appliance_get_srs_required_for_recovery(session.opaque_ref, _vm_appliance, _session_to); } /// /// Get the list of SRs required by the VM appliance to recover. /// First published in XenServer 6.5. /// /// The session /// The opaque_ref of the given vm_appliance /// The session to which the list of SRs have to be recovered . public static XenRef async_get_SRs_required_for_recovery(Session session, string _vm_appliance, string _session_to) { return session.JsonRpcClient.async_vm_appliance_get_srs_required_for_recovery(session.opaque_ref, _vm_appliance, _session_to); } /// /// Recover the VM appliance /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance /// The session to which the VM appliance is to be recovered. /// Whether the VMs should replace newer versions of themselves. public static void recover(Session session, string _vm_appliance, string _session_to, bool _force) { session.JsonRpcClient.vm_appliance_recover(session.opaque_ref, _vm_appliance, _session_to, _force); } /// /// Recover the VM appliance /// First published in XenServer 6.0. /// /// The session /// The opaque_ref of the given vm_appliance /// The session to which the VM appliance is to be recovered. /// Whether the VMs should replace newer versions of themselves. public static XenRef async_recover(Session session, string _vm_appliance, string _session_to, bool _force) { return session.JsonRpcClient.async_vm_appliance_recover(session.opaque_ref, _vm_appliance, _session_to, _force); } /// /// Return a list of all the VM_appliances known to the system. /// First published in XenServer 6.0. /// /// The session public static List> get_all(Session session) { return session.JsonRpcClient.vm_appliance_get_all(session.opaque_ref); } /// /// Get all the VM_appliance Records at once, in a single XML RPC call /// First published in XenServer 6.0. /// /// The session public static Dictionary, VM_appliance> get_all_records(Session session) { return session.JsonRpcClient.vm_appliance_get_all_records(session.opaque_ref); } /// /// Unique identifier/object reference /// public virtual string uuid { get { return _uuid; } set { if (!Helper.AreEqual(value, _uuid)) { _uuid = value; NotifyPropertyChanged("uuid"); } } } private string _uuid = ""; /// /// a human-readable name /// public virtual string name_label { get { return _name_label; } set { if (!Helper.AreEqual(value, _name_label)) { _name_label = value; NotifyPropertyChanged("name_label"); } } } private string _name_label = ""; /// /// a notes field containing human-readable description /// public virtual string name_description { get { return _name_description; } set { if (!Helper.AreEqual(value, _name_description)) { _name_description = value; NotifyPropertyChanged("name_description"); } } } private string _name_description = ""; /// /// list of the operations allowed in this state. This list is advisory only and the server state may have changed by the time this field is read by a client. /// public virtual List allowed_operations { get { return _allowed_operations; } set { if (!Helper.AreEqual(value, _allowed_operations)) { _allowed_operations = value; NotifyPropertyChanged("allowed_operations"); } } } private List _allowed_operations = new List() {}; /// /// links each of the running tasks using this object (by reference) to a current_operation enum which describes the nature of the task. /// public virtual Dictionary current_operations { get { return _current_operations; } set { if (!Helper.AreEqual(value, _current_operations)) { _current_operations = value; NotifyPropertyChanged("current_operations"); } } } private Dictionary _current_operations = new Dictionary() {}; /// /// all VMs in this appliance /// [JsonConverter(typeof(XenRefListConverter))] public virtual List> VMs { get { return _VMs; } set { if (!Helper.AreEqual(value, _VMs)) { _VMs = value; NotifyPropertyChanged("VMs"); } } } private List> _VMs = new List>() {}; } }