//---------------------------------------------------------------------------------------------------------------------

        public static void FromItemXml(OcciStorage storage, CloudProvider provider, XmlElement elem)
        {
            storage.RemoteId = (elem.HasAttribute("href") ? elem.Attributes["href"].Value : null);
            if (storage.RemoteId != null)
            {
                storage.RemoteId = Regex.Replace(storage.RemoteId, "^.*/", String.Empty);
            }
            foreach (XmlNode node in elem)
            {
                XmlElement subElem = node as XmlElement;
                if (subElem == null)
                {
                    continue;
                }
                switch (subElem.Name)
                {
                case "NAME":
                    storage.Name = subElem.InnerXml;
                    break;

                case "TYPE":
                    storage.Type = subElem.InnerXml;
                    break;

                case "CLASS":
                    storage.Class = subElem.InnerXml;
                    break;
                }
            }
        }
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Queries the cloud provider to get a list of the virtual disks (in OCCI: <i>storages</i>) defined on it.</summary>
        public override VirtualDisk[] FindVirtualDisks(bool detailed)
        {
            XmlNodeList nodes = GetResourceNodeList("/storage", "STORAGE_COLLECTION/STORAGE");

            if (nodes == null)
            {
                return(null);
            }

            List <OcciStorage> list = new List <OcciStorage>();

            foreach (XmlNode node in nodes)
            {
                XmlElement elem = node as XmlElement;
                if (elem == null)
                {
                    continue;
                }
                OcciStorage item = new OcciStorage(context);
                if (detailed)
                {
                    if (elem.HasAttribute("href"))
                    {
                        elem = GetResourceNode(String.Format("/storage/{0}", Regex.Replace(node.Attributes["href"].Value, "^.*/", String.Empty)));
                        OcciStorage.FromItemXml(item, this, elem);
                    }
                }
                else
                {
                    item = OcciStorage.FromListXml(context, this, elem);
                }
                list.Add(item);
            }
            return(list.ToArray());
        }
        //---------------------------------------------------------------------------------------------------------------------

        public static OcciStorage FromRemoteId(IfyContext context, CloudProvider provider, string remoteId)
        {
            OcciStorage result = new OcciStorage(context);

            result.Provider = provider;
            result.RemoteId = remoteId;
            return(result);
        }
        //---------------------------------------------------------------------------------------------------------------------

        public override CloudAppliance CreateInstance(string name, string templateName, string networkName)
        {
            OcciInstanceType template = OcciInstanceType.FromRemoteId(context, this, templateName);

            OcciStorage[] disks = new OcciStorage[0];//this.GetDisks();//\todo GetDisks
            //for (int i = 0; i < diskNames.Length; i++) disks[i] = OcciStorage.FromRemoteId(context, this, diskNames[i]);
            OcciNetwork network = OcciNetwork.FromRemoteId(context, this, networkName);

            return(CreateInstance(name, template, disks, network));
        }
        //---------------------------------------------------------------------------------------------------------------------

        public static OcciStorage FromListXml(IfyContext context, CloudProvider provider, XmlElement elem)
        {
            OcciStorage result = new OcciStorage(context);

            result.Provider = provider;
            result.RemoteId = (elem.HasAttribute("href") ? elem.Attributes["href"].Value : null);
            if (result.RemoteId != null)
            {
                result.RemoteId = Regex.Replace(result.RemoteId, "^.*/", String.Empty);
            }
            result.Name = (elem.HasAttribute("name") ? elem.Attributes["name"].Value : null);
            return(result);
        }
        //---------------------------------------------------------------------------------------------------------------------

        public static OcciStorage FromComputeXml(IfyContext context, CloudAppliance appliance, XmlElement elem)
        {
            OcciStorage result = new OcciStorage(context);

            result.Appliance = appliance;
            result.Id        = int.Parse(elem.Attributes ["id"].Value);
            foreach (XmlNode node in elem)
            {
                XmlElement subElem = node as XmlElement;
                if (subElem == null)
                {
                    continue;
                }
                switch (subElem.Name)
                {
                case "STORAGE":
                    if (subElem.HasAttribute("href"))
                    {
                        result.RemoteId = Regex.Replace(subElem.Attributes ["href"].Value, "^.*/", String.Empty);
                    }
                    if (subElem.HasAttribute("name"))
                    {
                        result.Name = subElem.Attributes ["name"].Value;
                    }
                    break;

                case "TYPE":
                    result.Type = subElem.InnerXml;
                    break;

                case "TARGET":
                    result.Target = subElem.InnerXml;
                    break;

                case "SAVE_AS":
                    if (subElem.HasAttribute("href"))
                    {
                        result.SavedAs = Regex.Replace(subElem.Attributes ["href"].Value, "^.*/", String.Empty);
                    }
                    break;
                }
            }



            return(result);
        }
        //---------------------------------------------------------------------------------------------------------------------

        protected void Load(XmlElement elem)
        {
            RemoteId = (elem.HasAttribute("href") ? elem.Attributes["href"].Value : null);
            if (RemoteId != null)
            {
                RemoteId = Regex.Replace(RemoteId, "^.*/", String.Empty);
            }
            Name = (elem.HasAttribute("name") ? elem.Attributes["name"].Value : null);
            List <OcciStorage> storageList = new List <OcciStorage>();

            foreach (XmlNode node in elem)
            {
                XmlElement subElem = node as XmlElement;
                if (subElem == null)
                {
                    continue;
                }
                switch (subElem.Name)
                {
                case "USER":
                    if (subElem.HasAttribute("name"))
                    {
                        Owner = subElem.Attributes["name"].Value;
                    }
                    break;

                case "NAME":
                    Name = subElem.InnerXml;
                    break;

                case "INSTANCE_TYPE":
                    InstanceType = OcciInstanceType.FromListXml(context, Provider, subElem);
                    break;

                case "STATE":
                    StatusText = subElem.InnerXml;
                    State      = GetStateFromString(StatusText);
                    break;

                case "DISK":
                    storageList.Add(OcciStorage.FromComputeXml(context, this, subElem));
                    break;

                case "NIC":
                    Network = OcciNetwork.FromComputeXml(context, this, subElem);
                    break;

                case "CONTEXT":
                    foreach (XmlNode node2 in subElem)
                    {
                        XmlElement subElem2 = node2 as XmlElement;
                        if (subElem2 == null)
                        {
                            continue;
                        }
                        switch (subElem2.Name)
                        {
                        case "CIOP_USERNAME":
                            Username = subElem2.InnerText;
                            break;
                        }
                    }
                    break;
                }
            }

            switch (StatusText)
            {
            case "ACTIVE":
                // If the IP Address is not yet ready, the system is probably booting.
                if (Network != null && VirtualNetwork.IpAddress == null)
                {
                    StatusText = "PREPARING";
                }
                break;
            }

            Storages = storageList.ToArray();

            int diskErrorCount = 0;

            for (int i = 0; i < Storages.Length; i++)
            {
                OcciStorage storage = Storages[i];
                try {
                    if (storage.RemoteId != String.Empty)
                    {
                        XmlElement elem2 = (Provider as OcciCloudProvider).GetResourceNode(String.Format("/storage/{0}", storage.RemoteId));
                        OcciStorage.FromItemXml(storage, Provider, elem2);
                    }
                    if (storage.SavedAs != null)
                    {
                        context.AddDebug(3, "Found Disk " + storage.Id + " to be saved as " + storage.SavedAs);
                        XmlElement elem2 = (Provider as OcciCloudProvider).GetResourceNode(String.Format("/storage/{0}", storage.SavedAs));
                        storage.SavedAs = elem2["NAME"].InnerXml;
                    }
                } catch (Exception e) {
                    context.AddWarning(e.Message);
                    diskErrorCount++;
                }
            }

            if (diskErrorCount != 0)
            {
                context.AddWarning(String.Format("No information available for {0}", diskErrorCount == 1 ? "one storage" : diskErrorCount + " storages"));
            }
        }