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

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

            result.Provider = provider;
            result.Load(elem);
            return(result);
        }
        //---------------------------------------------------------------------------------------------------------------------

        public override CloudAppliance CreateInstance(string name, VirtualMachineTemplate template, VirtualDisk[] disks, VirtualNetwork network)
        {
            CloudAppliance appliance = OcciCloudAppliance.FromResources(context, template as OcciInstanceType, disks as OcciStorage[], network as OcciNetwork);

            appliance.Name = name;
            appliance.Create();
            return(appliance);
        }
        //---------------------------------------------------------------------------------------------------------------------

        public static OcciCloudAppliance FromResources(IfyContext context, OcciInstanceType instanceType, OcciStorage[] storages, OcciNetwork network)
        {
            OcciCloudAppliance result = new OcciCloudAppliance(context);

            result.Provider     = instanceType.Provider;
            result.InstanceType = instanceType;
            result.Storages     = storages;
            result.Network      = network;
            return(result);
        }
        //---------------------------------------------------------------------------------------------------------------------

        public static OcciCloudAppliance FromListXml(IfyContext context, CloudProvider provider, XmlElement elem)
        {
            OcciCloudAppliance result = new OcciCloudAppliance(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 CloudAppliance FromOneXmlTemplate(IfyContext context, string sbXmlTemplate)
        {
            OcciCloudAppliance result = new OcciCloudAppliance(context);

            // One of the parameter is a base64 xml template from opennebula
            XmlDocument sbXmlDoc = new XmlDocument();

            sbXmlDoc.LoadXml(sbXmlTemplate);

            result.Name     = sbXmlDoc.SelectSingleNode("/VM/NAME").InnerText;
            result.RemoteId = sbXmlDoc.SelectSingleNode("/VM/ID").InnerText;
            XmlNode itnode = sbXmlDoc.SelectSingleNode("/VM/TEMPLATE/INSTANCE_TYPE");

            if (itnode != null)
            {
                result.InstanceType = new OcciInstanceType(context, itnode.InnerText);
            }
            result.Network           = new OcciNetwork(context);
            result.Network.IpAddress = sbXmlDoc.SelectSingleNode("/VM/TEMPLATE/NIC/IP").InnerText;
            result.State             = MachineState.Active;
            result.StatusText        = "UNKNOWN";
            return(result);
        }
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Froms the OCCI interface.
        /// </summary>
        /// <returns>
        /// The OCCI interface.
        /// </returns>
        /// <param name='context'>
        /// Context.
        /// </param>
        /// <param name='provider'>
        /// Provider.
        /// </param>
        public static OcciCloudAppliance FromOCCIInterface(IfyContext context, CloudProvider provider, string remoteId)
        {
            OcciCloudAppliance result = new OcciCloudAppliance(context);

            result.Provider = provider;
            result.RemoteId = remoteId;

            HttpWebRequest  httpRequest = context.GetSslRequest(String.Format("{0}/compute/{1}", provider.AccessPoint, remoteId), "GET", null);
            HttpWebResponse response    = null;

            try {
                // Get response stream.
                response = (HttpWebResponse)httpRequest.GetResponse();
                XmlDocument doc = new XmlDocument();
                doc.Load(response.GetResponseStream());
                result.Load(doc.DocumentElement);

                response.Close();
            } catch (WebException we) {
                throw new WebException("Error during request to " + httpRequest.RequestUri, we, we.Status, response);
            }

            return(result);
        }