/* 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: * * * 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.Collections.ObjectModel; using System.Xml; using XenAdmin.Core; using XenAdmin.Network; using XenAPI; namespace XenAdmin.Actions { /// /// Represents a storage volume of a storage system on a CSLG server. /// internal class SrCslgStorageVolumeScanAction : SrCslgScanAction { private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private readonly string _storageSystemId; private readonly string _storagePoolId; private ReadOnlyCollection _cslgStorageVolumes; /// /// Initializes a new instance of the class. /// /// The connection. /// The hostname. /// The username. /// The password secret. /// The storage system id. /// The storage pool to be queried. public SrCslgStorageVolumeScanAction(IXenConnection connection, string hostname, string username, string passwordSecret, string storageSystemId, string storagePoolId) : base(connection, hostname, username, passwordSecret) { Util.ThrowIfStringParameterNullOrEmpty(storageSystemId, "storageSystemId"); Util.ThrowIfStringParameterNullOrEmpty(storagePoolId, "storagePoolId"); _storageSystemId = storageSystemId; _storagePoolId = storagePoolId; } private List ParseStorageVolumeXml(String xml) { List output = new List(); XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); foreach (XmlNode storagePoolInfo in doc.GetElementsByTagName("csl__storageVolumeInfo")) { string displayName = GetXmlNodeInnerText(storagePoolInfo, "displayName"); string sizeInMB = string.Format(Messages.VAL_MB, GetXmlNodeInnerText(storagePoolInfo, "sizeInMB")); string storageVolumeId = GetXmlNodeInnerText(storagePoolInfo, "storageVolumeId"); string storageSystemId = GetXmlNodeInnerText(storagePoolInfo, "storageSystemId"); string storagePoolId = GetXmlNodeInnerText(storagePoolInfo, "storagePoolId"); int size; int.TryParse(sizeInMB, out size); output.Add(new CslgStorageVolume(displayName, storagePoolId, storageSystemId, storageVolumeId, size)); } return output; } /// /// Gets the CSLG storage volumes. /// /// The CSLG storage volumes. public ReadOnlyCollection CslgStorageVolumes { get { return _cslgStorageVolumes; } } /// /// Runs this instance. /// protected override void Run() { Dictionary dconf = GetAuthenticationDeviceConfig(); dconf["storageSystemId"] = _storageSystemId; dconf["storagePoolId"] = _storagePoolId; Log.DebugFormat("Attempting to find volumes on pool {0}.", _storagePoolId); RunProbe(dconf); _cslgStorageVolumes = new ReadOnlyCollection(new List(ParseStorageVolumeXml(Util.GetContentsOfValueNode(Result)))); } } #region CslgStorageVolume class /// /// Represents a storage volume on a storage system on a CSLG server. /// internal class CslgStorageVolume { private readonly string _displayName; private readonly string _storagePoolId; private readonly string _storageSystemId; private readonly string _storageVolumeId; private readonly int _sizeInMB; /// /// Initializes a new instance of the class. /// /// The display name. /// The storage pool id. /// The storage system id. /// The storage volume id. /// The size in MB. public CslgStorageVolume(string displayName, string storagePoolId, string storageSystemId, string storageVolumeId, int sizeInMB) { Util.ThrowIfStringParameterNullOrEmpty(displayName, "displayName"); Util.ThrowIfStringParameterNullOrEmpty(storageSystemId, "storageSystemId"); _displayName = displayName; _storagePoolId = storagePoolId; _storageSystemId = storageSystemId; _storageVolumeId = storageVolumeId; _sizeInMB = sizeInMB; } /// /// Gets the size in MB. /// /// The size in MB. public int SizeInMB { get { return _sizeInMB; } } /// /// Gets the display name. /// /// The display name. public string DisplayName { get { return _displayName; } } /// /// Gets the storage pool ID. /// /// The storage pool ID. public string StoragePoolId { get { return _storagePoolId; } } /// /// Gets the storage system ID. /// /// The storage system ID. public string StorageSystemId { get { return _storageSystemId; } } /// /// Gets the storage volume ID. /// /// The storage volume ID. public string StorageVolumeId { get { return _storageVolumeId; } } } #endregion }