private void TransformXvaOvf_VM(EnvelopeType env, string vsId, string lang, XenStruct vmstruct) { int PVvalue = 0; foreach (XenMember n in vmstruct.xenmember) { // // Currently these are the only values we care about. // if (n.xenname.ToLower().Equals("uuid")) { UpdateVirtualSystemSettingData(env, vsId, "VirtualSystemIdentifier", (string)n.xenvalue); } if (n.xenname.ToLower().Equals("name_label")) { if (n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { UpdateVirtualSystemName(env, vsId, lang, (string)n.xenvalue); UpdateVirtualSystemSettingData(env, vsId, "ElementName", (string)n.xenvalue); UpdateVirtualSystemSettingData(env, vsId, "Caption", _ovfrm.GetString("CONVERT_APP_NAME")); } } else if (n.xenname.ToLower().Equals("memory_static_max")) { if (n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { UInt64 memory = Convert.ToUInt64(n.xenvalue) / MB; SetMemory(env, vsId, memory, "MB"); } } else if (n.xenname.ToLower().Equals("vcpus_max")) { if (n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { UInt64 cpus = Convert.ToUInt64(n.xenvalue); SetCPUs(env, vsId, cpus); } } else if ( n.xenname.ToLower().Equals("pv_bootloader") || n.xenname.ToLower().Equals("pv_kernel") || n.xenname.ToLower().Equals("pv_ramdisk") || n.xenname.ToLower().Equals("pv_args") || n.xenname.ToLower().Equals("pv_bootloader_args") || n.xenname.ToLower().Equals("pv_legacy_args") || n.xenname.ToLower().Equals("hvm_boot_policy") || n.xenname.ToLower().Equals("hvm_shadow_multiplier") ) { if (n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { if (n.xenname.ToLower().StartsWith("pv")) { PVvalue++; } if (n.xenname.ToLower().StartsWith("hvm_boot")) { PVvalue--; } AddOtherSystemSettingData(env, vsId, lang, n.xenname, (string)n.xenvalue, _ovfrm.GetString("XENSERVER_SPECIFIC_DESCRIPTION")); } } else if (n.xenname.ToLower().Equals("hvm_boot_params")) { if (n.xenvalue != null && n.xenvalue is XenStruct && ((XenStruct)n.xenvalue).xenmember != null) { string bootorder = "dc"; foreach (XenMember xm in ((XenStruct)n.xenvalue).xenmember) { PVvalue--; if (xm.xenname.ToLower().Equals("order")) { if (xm.xenvalue != null && xm.xenvalue is string && ((string)xm.xenvalue).Length > 0) { bootorder = (string)xm.xenvalue; } } } AddOtherSystemSettingData(env, vsId, lang, n.xenname, bootorder, _ovfrm.GetString("XENSERVER_SPECIFIC_DESCRIPTION")); } } else if (n.xenname.ToLower().Equals("platform")) { if (n.xenvalue != null && n.xenvalue is XenStruct && ((XenStruct)n.xenvalue).xenmember != null) { StringBuilder p = new StringBuilder(); foreach (XenMember xm in ((XenStruct)n.xenvalue).xenmember) { if (xm.xenvalue != null && xm.xenvalue is string && ((string)xm.xenvalue).Length > 0) { p.AppendFormat("{0}={1}; ", xm.xenname, (string)xm.xenvalue); } } AddOtherSystemSettingData(env, vsId, lang, n.xenname, p.ToString().Trim(), _ovfrm.GetString("XENSERVER_PLATFORM_DESCRIPTION")); } } else if (n.xenname.ToLower().Equals("other_config")) { // Ignored, why you say? Because I haven't found one that is 'required' to reproduce the vm, yet. } else if (n.xenname.ToLower().Equals("domarch")) { // Can't depend on a value here but we need to set it to work correctly. if (n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { string svalue = (string)n.xenvalue; if (svalue.Equals("hvm")) { PVvalue = -10; } } if (PVvalue < 0) { UpdateVirtualSystemSettingData(env, vsId, "VirtualSystemType", "hvm-3.0-unknown"); } else { UpdateVirtualSystemSettingData(env, vsId, "VirtualSystemType", "xen-3.0-unknown"); } } } log.DebugFormat("OVF.TransformXvaOvf_VM completed {0}", vsId); }
private void TransformXvaOvf_VIF(EnvelopeType env, string vsId, string lang, XenStruct vmstruct) { string vifuuid = null; string mac = null; foreach (XenMember n in vmstruct.xenmember) { // // Currently these are the only values we care about. // if (n.xenname.ToLower().Equals("uuid") && n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { vifuuid = (string)n.xenvalue; if (vifuuid.ToLower().Contains("null")) { vifuuid = null; } } else if (n.xenname.ToLower().Equals("network") && n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { string netref = ((string)n.xenvalue); if (!netref.ToLower().Contains("null")) { if (!mappings.ContainsKey(netref)) { mappings.Add(netref, vifuuid); } } } else if (n.xenname.ToLower().Equals("mac") && n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { mac = ((string)n.xenvalue); } } AddNetwork(env, vsId, lang, vifuuid, null, mac); log.DebugFormat("OVF.TransformXvaOvf_VIF completed {0}", vsId); }
private void TransformXvaOvf_VDI(EnvelopeType env, string vsId, string lang, string refId, DiskInfo di, XenStruct vmstruct) { string instanceId = null; if (mappings.ContainsKey(refId)) { instanceId = string.Format(@"Xen:{0}/{1}", vsId, mappings[refId]); } else { instanceId = string.Format(@"Xen:{0}/{1}", vsId, Guid.NewGuid().ToString()); } string description = null; string vhdfilename = di.VhdFileName; ulong filesize = 0; ulong capacity = 0; ulong freespace = 0; foreach (XenMember n in vmstruct.xenmember) { if (n.xenname.ToLower().Equals("virtual_size")) { capacity = Convert.ToUInt64(n.xenvalue); } else if (n.xenname.ToLower().Equals("physical_utilisation")) { filesize = Convert.ToUInt64(n.xenvalue); } } freespace = capacity - filesize; UpdateDisk(env, vsId, instanceId, description, vhdfilename, filesize, capacity, freespace); log.DebugFormat("OVF.TransformXvaOvf_VDI completed {0}", vsId); }
private void TransformXvaOvf_VBD(EnvelopeType env, string vsId, string lang, XenStruct vmstruct) { string diskId = null; string vhdfilename = ""; bool bootable = false; string caption = null; string description = null; ulong filesize = 0; ulong capacity = 0; string vdiuuid = null; bool isDisk = false; StringBuilder connection = new StringBuilder(); foreach (XenMember n in vmstruct.xenmember) { // // Currently these are the only values we care about. // if (n.xenname.ToLower().Equals("uuid") && n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { vdiuuid = (string)n.xenvalue; if (!vdiuuid.ToLower().Contains("null")) { diskId = string.Format(@"Xen:{0}/{1}", vsId, vdiuuid); } else { vdiuuid = null; } } else if (n.xenname.ToLower().Equals("vdi") && n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { string vdiref = ((string)n.xenvalue); if (!vdiref.ToLower().Contains("null")) { if (!mappings.ContainsKey(vdiref)) { mappings.Add(vdiref, vdiuuid); } } } else if (n.xenname.ToLower().Equals("userdevice") && n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { connection.AppendFormat("device={0},", ((string)n.xenvalue)); } else if (n.xenname.ToLower().Equals("bootable") && n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { connection.AppendFormat("bootable={0},", ((string)n.xenvalue)); bootable = Convert.ToBoolean(((string)n.xenvalue)); } else if (n.xenname.ToLower().Equals("mode") && n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { connection.AppendFormat("mode={0},", ((string)n.xenvalue)); } else if (n.xenname.ToLower().Equals("type") && n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { switch (((string)n.xenvalue).ToUpper()) { case "CD": { isDisk = false; caption = _ovfrm.GetString("RASD_16_CAPTION"); description = _ovfrm.GetString("RASD_16_DESCRIPTION"); break; } case "DISK": { caption = _ovfrm.GetString("RASD_19_CAPTION"); description = _ovfrm.GetString("RASD_19_DESCRIPTION"); isDisk = true; break; } } } } if (vdiuuid != null) connection.AppendFormat("vdi={0}", vdiuuid); if (isDisk) { AddDisk(env, vsId, diskId, lang, vhdfilename, bootable, caption, description, filesize, capacity); UpdateResourceAllocationSettingData(env, vsId, diskId, "Connection", connection.ToString()); } else { AddCDROM(env, vsId, diskId, caption, description); } log.DebugFormat("OVF.TransformXvaOvf_VBD completed {0}", vsId); }
private void TransformXvaOvf_SR(EnvelopeType env, string vsId, string lang, XenStruct vmstruct) { // // Currently this is data for the Environment not necessarily part of the VM // even if the VM is in this SR it may not exist in the target server therefore // it is not required in the OVF. // log.DebugFormat("OVF.TransformXvaOvf_SR completed {0}", vsId); }
private void TransformXvaOvf_Network(EnvelopeType env, string vsId, string lang, string refId, XenStruct vmstruct) { string networkName = null; foreach (XenMember n in vmstruct.xenmember) { // // Currently these are the only values we care about. // if (n.xenname.ToLower().Equals("name_label") && n.xenvalue != null && n.xenvalue is string && ((string)n.xenvalue).Length > 0) { networkName = ((string)n.xenvalue); break; } } foreach (Section_Type section in env.Sections) { if (section is NetworkSection_Type) { NetworkSection_Type ns = (NetworkSection_Type)section; foreach (NetworkSection_TypeNetwork net in ns.Network) { if (net.Description != null && net.Description.msgid != null && net.Description.msgid.Equals(mappings[refId])) { net.Description.Value = networkName; break; } } break; } } log.DebugFormat("OVF.TransformXvaOvf_Network completed {0}", vsId); }