/* 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; using System.Threading; namespace XenAdmin.Actions { /// /// Performs a scan of a CSLG server for storage systems. /// public class SrCslgStorageSystemScanAction : SrCslgScanAction { private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private ReadOnlyCollection _cslgSystemStorages; private string _adapterid; public SrCslgStorageSystemScanAction(IXenConnection connection, string adapterid, string target, string user, string password) : base(connection, target, user, password) { _adapterid = adapterid; } /// /// Gets the CSLG system storages. Returns null before the action has been run. /// /// The CSLG system storages. public ReadOnlyCollection CslgSystemStorages { get { return _cslgSystemStorages; } } /// /// Runs this instance. /// protected override void Run() { Dictionary dconf = GetAuthenticationDeviceConfig(); Log.DebugFormat("Attempting to find SRs on CSLG {0}.", dconf["target"]); dconf["adapterid"] = _adapterid; RunProbe(dconf); if (!string.IsNullOrEmpty(Result)) _cslgSystemStorages = new ReadOnlyCollection(ParseStorageSystemsXml(Util.GetContentsOfValueNode(Result))); } private List ParseStorageSystemsXml(String xml) { List output = new List(); XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); foreach (XmlNode storageSystemInfo in doc.GetElementsByTagName("csl__storageSystemInfo")) { string displayName = GetXmlNodeInnerText(storageSystemInfo, "displayName"); string storageSystemId = GetXmlNodeInnerText(storageSystemInfo, "storageSystemId"); List protocols = new List(); protocols.Add(new CslgParameter(null, Messages.NEWSR_CSLG_AUTO)); List provisioningOptions = new List(); provisioningOptions.Add(new CslgParameter(null, Messages.NEWSR_CSLG_NONE)); bool supportsCHAP = false; foreach (string innerText in GetXmlChildNodeInnerTexts(storageSystemInfo, "systemCapabilities/capabilities")) { if (innerText == "DEDUPLICATION") { provisioningOptions.Add(new CslgParameter(innerText, Messages.NEWSR_CSLG_DEDUPLICATION)); } if (innerText == "SUPPORTS_CHAP") { supportsCHAP = true; } } foreach (string innerText in GetXmlChildNodeInnerTexts(storageSystemInfo, "protocolSupport/capabilities")) { if (innerText == "ISCSI") { protocols.Add(new CslgParameter(innerText, Messages.NEWSR_CSLG_ISCSI)); } else if (innerText == "FC") { protocols.Add(new CslgParameter(innerText, Messages.NEWSR_CSLG_FC)); } } output.Add(new CslgSystemStorage(displayName, storageSystemId, protocols, provisioningOptions, supportsCHAP)); } return output; } } #region CslgSystemStorage class /// /// Represents a System Storage from a CSLG server. /// public class CslgSystemStorage { private readonly string _displayName; private readonly string _storageSystemId; private readonly ReadOnlyCollection _protocols; private readonly ReadOnlyCollection _provisioningOptions; private readonly bool _supportsCHAP; /// /// Initializes a new instance of the class. /// /// The display name. /// The storage system id. /// The available protocols. /// The available provisioning options. /// Indicates whether CHAP is supported. public CslgSystemStorage(string displayName, string storageSystemId, IEnumerable protocols, IEnumerable provisioningOptions, bool supportsCHAP) { Util.ThrowIfStringParameterNullOrEmpty(displayName, "displayName"); Util.ThrowIfStringParameterNullOrEmpty(storageSystemId, "storageSystemId"); Util.ThrowIfParameterNull(protocols, "protocols"); Util.ThrowIfParameterNull(protocols, "provisioningOptions"); _displayName = displayName; _storageSystemId = storageSystemId; _protocols = new ReadOnlyCollection(new List(protocols)); _provisioningOptions = new ReadOnlyCollection(new List(provisioningOptions)); _supportsCHAP = supportsCHAP; } /// /// Gets the display name. /// /// The display name. public string DisplayName { get { return _displayName; } } /// /// Gets the available protocols. /// /// The available protocols. public ReadOnlyCollection Protocols { get { return _protocols; } } /// /// Gets the storage system id. /// /// The storage system id. public string StorageSystemId { get { return _storageSystemId; } } public override string ToString() { return DisplayName; } /// /// Gets the available provisioning options. /// /// The available provisioning options. public ReadOnlyCollection ProvisioningOptions { get { return _provisioningOptions; } } /// /// Gets supports CHAP value. /// /// Indicates whether CHAP is supported. public bool SupportsCHAP { get { return _supportsCHAP; } } public override bool Equals(object obj) { var other = obj as CslgSystemStorage; return other != null && other.StorageSystemId == StorageSystemId; } public override int GetHashCode() { return StorageSystemId.GetHashCode(); } } #endregion #region CslgParameter class /// /// Represents a parameter required to configure CSLG storage repository which has a string value and string display-name for that value. /// public class CslgParameter { private readonly string _name; private readonly string _displayName; /// /// Initializes a new instance of the class. /// /// The name. /// The display name. public CslgParameter(string name, string displayName) { Util.ThrowIfStringParameterNullOrEmpty(displayName, "displayName"); _name = name; _displayName = displayName; } /// /// Gets the name. /// /// The name. public string Name { get { return _name; } } /// /// Gets the display name. /// /// The display name. public string DisplayName { get { return _displayName; } } public override string ToString() { return _displayName; } } #endregion }