private static ulong GetVmSize(VirtualSystem_Type virtualSystemType) { try { ulong num = 0; foreach (Section_Type sectionType in virtualSystemType.Items) { if (sectionType is VirtualHardwareSection_Type) { VirtualHardwareSection_Type hardwareSectionType = (VirtualHardwareSection_Type)sectionType; if (hardwareSectionType.Item != null) { foreach (RASD_Type virtualDiskItem in ((IEnumerable <RASD_Type>)hardwareSectionType.Item).ToList <RASD_Type>()) { if (virtualDiskItem.ResourceType.Value.Equals("17")) { VirtualDisk virtualDisk = new VirtualDisk(virtualDiskItem); if (virtualDisk.GetHardDiskSize() != 0UL) { num += virtualDisk.GetHardDiskSize(); } } } } } } return(num); } catch (Exception ex) { throw new VCloudException(ex.Message); } }
private static bool ValidateVHS(VirtualSystem_Type vs, ref List <string> validationErrorMessages) { bool isValid = true; VirtualHardwareSection_Type vhs = null; foreach (Section_Type section in vs.Items) { if (section is VirtualHardwareSection_Type) { vhs = (VirtualHardwareSection_Type)section; if (vhs.System != null && vhs.System.VirtualSystemIdentifier != null && vhs.System.VirtualSystemIdentifier.Value != null) { if (!Properties.Settings.Default.knownVirtualSystemTypes.Contains(vhs.System.VirtualSystemType.Value)) { var message = string.Format(Messages.VALIDATION_UNKNOWN_HARDWARE_TYPE, vhs.System.VirtualSystemType.Value); Log.Warning(message); validationErrorMessages.Add(message); isValid = false; } } } } return(isValid); }
// Find a name to use of a VM within an envelope that could have come from any hypervisor. // TODO: Consider refactoring this method because it is very similar to OVF.FindSystemName(). private string FindVMName(EnvelopeType ovfEnv, string systemid) { VirtualSystem_Type vSystem = OVF.FindVirtualSystemById(ovfEnv, systemid); // Use the given name if present and valid. // The given name is Envelope.VirtualSystem.Name specified in the OVF Specification 1.1 clause 7.2. // XenServer sets the name property. // vSphere 4.1 and Virtual Box 4.0.6 do not. if ((Tools.ValidateProperty("Name", vSystem)) && !String.IsNullOrEmpty(vSystem.Name[0].Value)) { return(vSystem.Name[0].Value); } // The VM wasn't given a name. // Build a list of choices from various properties. var choices = new List <string>(); // VirtualSystem.id is next preference because vSphere and Virtual Box typically set this property to the VM name. if (!string.IsNullOrEmpty(vSystem.id)) { choices.Add(vSystem.id); } // VirtualHardwareSection_Type.VirtualSystemIdentifier is next preference because Virtual Box will also set this property to the VM name. VirtualHardwareSection_Type[] vhsList = OVF.FindVirtualHardwareSection(ovfEnv, systemid); foreach (VirtualHardwareSection_Type vhs in vhsList) { if (vhs == null || vhs.System == null) { continue; } if (Tools.ValidateProperty("VirtualSystemIdentifier", vhs.System)) { choices.Add(vhs.System.VirtualSystemIdentifier.Value); } } // Operating system description is next preference. OperatingSystemSection_Type[] ossList = OVF.FindSections <OperatingSystemSection_Type>(vSystem.Items); foreach (OperatingSystemSection_Type oss in ossList) { if (Tools.ValidateProperty("Description", oss)) { choices.Add(oss.Description.Value); } } // Envelope name is the last preference for XenServer that can could be a path in some cases. // vSphere and Virtual Box usually don't set this property. choices.Add(Path.GetFileNameWithoutExtension(ovfEnv.Name)); // Last preference is file name. choices.Add(Path.GetFileNameWithoutExtension(m_pageImportSource.SelectedOvfPackage.PackageSourceFile)); // First choice is one that is not a GUID. foreach (var choice in choices) { if (!String.IsNullOrEmpty(choice) && !IsGUID(choice)) { return(choice); } } // Second choice is the first GUID. foreach (var choice in choices) { if (!String.IsNullOrEmpty(choice)) { return(choice); } } // Last resort is a new GUID. return(Guid.NewGuid().ToString()); }
private static bool ValidateVHS(VirtualSystem_Type vs, ref List<string> validationErrorMessages) { bool isValid = true; VirtualHardwareSection_Type vhs = null; foreach (Section_Type section in vs.Items) { if (section is VirtualHardwareSection_Type) { vhs = (VirtualHardwareSection_Type)section; if (vhs.System != null && vhs.System.VirtualSystemIdentifier != null && vhs.System.VirtualSystemIdentifier.Value != null) { if (!Properties.Settings.Default.knownVirtualSystemTypes.Contains(vhs.System.VirtualSystemType.Value)) { var message = string.Format(Messages.VALIDATION_UNKNOWN_HARDWARE_TYPE, vhs.System.VirtualSystemType.Value); log.Warn(message); validationErrorMessages.Add(message); isValid = false; } } } } return isValid; }