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

        /// <summary>Queries the cloud provider to get a list of the virtual machine templates (in OCCI: <i>instance types</i>) defined on it.</summary>
        public override VirtualMachineTemplate[] FindVirtualMachineTemplates(bool detailed)
        {
            XmlNodeList nodes = GetResourceNodeList("/instance_type", "INSTANCE_TYPE_COLLECTION/INSTANCE_TYPE");

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

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

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

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

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

        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 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));
        }
예제 #5
0
        //---------------------------------------------------------------------------------------------------------------------

        public static OcciInstanceType FromListXml(IfyContext context, CloudProvider provider, XmlElement elem)
        {
            OcciInstanceType result = new OcciInstanceType(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);
            if (result.Name == null)
            {
                result.Name = elem.InnerXml;
            }
            return(result);
        }
예제 #6
0
        //---------------------------------------------------------------------------------------------------------------------

        public static OcciInstanceType FromItemXml(IfyContext context, CloudProvider provider, XmlElement elem)
        {
            OcciInstanceType result = new OcciInstanceType(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);
            XmlNode node;

            if ((node = elem.SelectSingleNode("CLASS")) != null)
            {
                result.Class = node.InnerXml;
            }
            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"));
            }
        }