//--------------------------------------------------------------------------------------------------------------------- /// <summary>Queries the cloud provider to get a list of the virtual networks (in OCCI: <i>networks</i>) defined on it.</summary> public override VirtualNetwork[] FindVirtualNetworks(bool detailed) { XmlNodeList nodes = GetResourceNodeList("/network", "NETWORK_COLLECTION/NETWORK"); if (nodes == null) { return(null); } List <OcciNetwork> list = new List <OcciNetwork>(); foreach (XmlNode node in nodes) { XmlElement elem = node as XmlElement; if (elem == null) { continue; } OcciNetwork item = null; if (detailed) { if (elem.HasAttribute("href")) { elem = GetResourceNode(String.Format("/network/{0}", Regex.Replace(node.Attributes["href"].Value, "^.*/", String.Empty))); item = OcciNetwork.FromItemXml(context, this, elem); } } else { item = OcciNetwork.FromListXml(context, this, elem); } list.Add(item); } return(list.ToArray()); }
//--------------------------------------------------------------------------------------------------------------------- public static OcciNetwork FromRemoteId(IfyContext context, CloudProvider provider, string remoteId) { OcciNetwork result = new OcciNetwork(context); result.Name = provider.GetNetwork(remoteId).Name; 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 OcciNetwork FromListXml(IfyContext context, CloudProvider provider, XmlElement elem) { OcciNetwork result = new OcciNetwork(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); }
//--------------------------------------------------------------------------------------------------------------------- /// <summary>Queries the cloud provider to get a list of the virtual networks (in OCCI: <i>networks</i>) defined on it.</summary> public override VirtualNetwork GetNetwork(string remoteId) { XmlElement elem = GetResourceNode(String.Format("/network/{0}", remoteId)); if (elem == null) { return(null); } OcciNetwork result = null; result = OcciNetwork.FromItemXml(context, this, elem); return(result); }
//--------------------------------------------------------------------------------------------------------------------- public static OcciNetwork FromItemXml(IfyContext context, CloudProvider provider, XmlElement elem) { OcciNetwork result = new OcciNetwork(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); } XmlNode subElem = elem.SelectSingleNode("NAME"); result.Name = (subElem == null ? result.RemoteId : subElem.InnerXml); return(result); }
//--------------------------------------------------------------------------------------------------------------------- public static OcciNetwork FromComputeXml(IfyContext context, CloudAppliance appliance, XmlElement elem) { OcciNetwork result = new OcciNetwork(context); result.Appliance = appliance; foreach (XmlNode node in elem) { XmlElement subElem = node as XmlElement; if (subElem == null) { continue; } switch (subElem.Name) { case "NETWORK": if (subElem.HasAttribute("href")) { result.RemoteId = subElem.Attributes["href"].Value; } if (subElem.HasAttribute("name")) { result.Name = subElem.Attributes["name"].Value; } break; case "IP": result.IpAddress = subElem.InnerXml; break; case "MAC": result.MacAddress = subElem.InnerXml; 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")); } }
//--------------------------------------------------------------------------------------------------------------------- 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); }