2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2020-08-27 18:35:53 +02:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
2020-10-12 12:47:17 +02:00
|
|
|
|
using DiscUtils;
|
|
|
|
|
using DiscUtils.Vhd;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenOvf;
|
|
|
|
|
using XenOvf.Definitions;
|
|
|
|
|
using XenOvf.Utilities;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
2013-09-25 11:28:38 +02:00
|
|
|
|
|
2020-09-01 04:21:41 +02:00
|
|
|
|
namespace XenAdmin.Actions.OvfActions
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-01 04:21:41 +02:00
|
|
|
|
public partial class ExportApplianceAction
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-09-25 11:28:38 +02:00
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
private EnvelopeType Export(string targetDir, VM vm, Action<float> updatePercentage)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-03 01:36:40 +02:00
|
|
|
|
if (vm.power_state != vm_power_state.Halted && vm.power_state != vm_power_state.Suspended)
|
|
|
|
|
{
|
|
|
|
|
log.Error($"Cannot export VM {vm.Name()} ({vm.opaque_ref}); it is neither halted nor suspended.");
|
|
|
|
|
throw new Exception(string.Format(Messages.ERROR_VM_NOT_HALTED, vm.Name()));
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
log.Info($"Exporting metadata for {vm.name_label}...");
|
|
|
|
|
|
|
|
|
|
#region CREATE ENVELOPE / ADD VIRTUAL SYSTEM
|
|
|
|
|
EnvelopeType ovfEnv = OVF.CreateEnvelope(m_applianceFileName);
|
|
|
|
|
string vsId = OVF.AddVirtualSystem(ovfEnv, vm.name_label);
|
|
|
|
|
string vhsId = OVF.AddVirtualHardwareSection(ovfEnv, vsId);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region TRY TO ID OS
|
|
|
|
|
|
|
|
|
|
VM_guest_metrics vmgm = Connection.Resolve(vm.guest_metrics);
|
|
|
|
|
|
|
|
|
|
if (vmgm?.os_version != null && vmgm.os_version.TryGetValue("name", out string osName))
|
|
|
|
|
{
|
|
|
|
|
ushort osId = ValueMaps.OperatingSystem(osName);
|
|
|
|
|
if (osId == 0xFFFF)
|
|
|
|
|
osId = 1; // change to OTHER since search failed.
|
|
|
|
|
|
|
|
|
|
string version = OVF.GetContentMessage("SECTION_OPERATINGSYSTEM_INFO");
|
|
|
|
|
|
|
|
|
|
if (vmgm.os_version.TryGetValue("major", out string major) &&
|
|
|
|
|
vmgm.os_version.TryGetValue("minor", out string minor))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-03 01:36:40 +02:00
|
|
|
|
version = string.Format(OVF.GetContentMessage("SECTION_OPERATINGSYSTEM_VERSION"), major, minor);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
string[] osNameParts = osName.Split('|');
|
|
|
|
|
if (osNameParts.Length > 0)
|
|
|
|
|
OVF.UpdateOperatingSystemSection(ovfEnv, vsId, osNameParts[0], version, osId);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
#endregion
|
2020-08-31 03:09:03 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
#region ADD VirtualSystemType identification
|
|
|
|
|
var pv = vm.IsHVM() ? "hvm" : "xen";
|
|
|
|
|
var arch = string.IsNullOrEmpty(vm.domarch) ? "unknown" : vm.domarch;
|
|
|
|
|
var vmType = string.Format("{0}-3.0-{1}", pv, arch);
|
2020-08-31 03:09:03 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
OVF.AddVirtualSystemSettingData(ovfEnv, vsId, vhsId, vm.name_label, OVF.GetContentMessage("VSSD_CAPTION"), vm.name_description, Guid.NewGuid().ToString(), vmType);
|
|
|
|
|
#endregion
|
2020-08-31 03:09:03 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
#region ADD CPUS
|
|
|
|
|
OVF.SetCPUs(ovfEnv, vsId, (ulong)vm.VCPUs_max);
|
|
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
#region ADD MEMORY
|
|
|
|
|
OVF.SetMemory(ovfEnv, vsId, (ulong)(vm.memory_dynamic_max / Util.BINARY_MEGA), "MB");
|
|
|
|
|
#endregion
|
2020-08-31 03:09:03 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
#region ADD NETWORKS
|
2020-08-31 03:09:03 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
foreach (XenRef<VIF> vifRef in vm.VIFs)
|
|
|
|
|
{
|
|
|
|
|
VIF vif = Connection.Resolve(vifRef);
|
|
|
|
|
if (vif == null)
|
|
|
|
|
continue;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
XenAPI.Network net = Connection.Resolve(vif.network);
|
|
|
|
|
if (net == null)
|
|
|
|
|
continue;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
OVF.AddNetwork(ovfEnv, vsId, net.uuid, net.name_label, net.name_description, vif.MAC);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
#endregion
|
2020-08-31 03:09:03 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
#region SET STARTUP OPTIONS
|
|
|
|
|
OVF.AddStartupSection(ovfEnv, true, vsId, vm.order, vm.start_delay, vm.shutdown_delay);
|
|
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
#region EXPORT DISKS
|
|
|
|
|
|
|
|
|
|
int diskIndex = 0;
|
|
|
|
|
var vbdRefs = vm.VBDs;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
for (int i = 0; i < vbdRefs.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
int curVbd = i;
|
|
|
|
|
XenRef<VBD> vbdRef = vbdRefs[i];
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
VBD vbd = Connection.Resolve(vbdRef);
|
|
|
|
|
if (vbd == null)
|
|
|
|
|
continue;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
if (vbd.type == vbd_type.CD)
|
|
|
|
|
{
|
|
|
|
|
string rasdid = OVF.AddCDROM(ovfEnv, vsId, vbd.uuid, OVF.GetContentMessage("RASD_16_CAPTION"), OVF.GetContentMessage("RASD_16_DESCRIPTION"));
|
|
|
|
|
OVF.SetTargetDeviceInRASD(ovfEnv, vsId, rasdid, vbd.userdevice);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
VDI vdi = Connection.Resolve(vbd.VDI);
|
|
|
|
|
if (vdi == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
try
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-03 01:36:40 +02:00
|
|
|
|
var diskFilename = $"{vdi.uuid}.vhd";
|
|
|
|
|
var diskPath = Path.Combine(targetDir, diskFilename);
|
2013-09-25 12:10:28 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
if (File.Exists(diskPath))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-03 01:36:40 +02:00
|
|
|
|
var oldFileName = diskFilename;
|
|
|
|
|
diskFilename = $"{vdi.uuid}_{Thread.CurrentThread.ManagedThreadId}.vhd";
|
|
|
|
|
diskPath = Path.Combine(targetDir, diskFilename);
|
|
|
|
|
log.InfoFormat("VHD Name collision, renamed {0} to {1}", oldFileName, diskFilename);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-09-03 01:36:40 +02:00
|
|
|
|
|
|
|
|
|
string diskName = vdi.name_label;
|
|
|
|
|
if (string.IsNullOrEmpty(diskName))
|
|
|
|
|
diskName = $"{OVF.GetContentMessage("RASD_19_CAPTION")} {diskIndex}";
|
|
|
|
|
|
|
|
|
|
if (!MetaDataOnly)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-03 01:36:40 +02:00
|
|
|
|
log.Info($"Exporting disk {diskName} to {diskFilename} for {vm.name_label}...");
|
|
|
|
|
|
|
|
|
|
var taskRef = Task.create(Connection.Session, "export_raw_vdi_task",
|
|
|
|
|
$"Exporting VDI {vdi.uuid} to {diskFilename}");
|
|
|
|
|
|
|
|
|
|
HTTP_actions.get_export_raw_vdi(b =>
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-03 01:36:40 +02:00
|
|
|
|
Description = string.Format(Messages.EXPORTING_VDI, diskName, diskFilename,
|
2020-11-25 16:36:17 +01:00
|
|
|
|
Util.DiskSizeString(b, 2, "F2"), Util.DiskSizeString(vdi.virtual_size));
|
2020-09-03 01:36:40 +02:00
|
|
|
|
updatePercentage((curVbd + (float)b / vdi.virtual_size) / vbdRefs.Count);
|
|
|
|
|
},
|
|
|
|
|
() => Cancelling, XenAdminConfigManager.Provider.GetProxyTimeout(true),
|
|
|
|
|
Connection.Hostname, XenAdminConfigManager.Provider.GetProxyFromSettings(Connection),
|
|
|
|
|
diskPath, taskRef, Connection.Session.opaque_ref, vdi.uuid, "vhd");
|
|
|
|
|
|
|
|
|
|
if (m_shouldVerify)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-03 01:36:40 +02:00
|
|
|
|
Description = string.Format(Messages.EXPORTING_VDI_VERIFICATION, diskFilename);
|
|
|
|
|
|
2020-10-12 12:47:17 +02:00
|
|
|
|
using (var stream = new FileStream(diskPath, FileMode.Open, FileAccess.Read))
|
|
|
|
|
using (var sw = new StringWriter())
|
|
|
|
|
{
|
|
|
|
|
var vhdChecker = new FileChecker(stream);
|
|
|
|
|
var result = vhdChecker.Check(sw, ReportLevels.All);
|
|
|
|
|
log.InfoFormat("Verifying disk {0}:\n{1}", diskFilename, sw.ToString().Replace("\0", ""));
|
|
|
|
|
if (!result)
|
2020-11-25 14:31:44 +01:00
|
|
|
|
throw new Exception(string.Format(Messages.EXPORTING_VDI_VERIFICATION_FAILURE, diskFilename));
|
2020-10-12 12:47:17 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
string diskId = Guid.NewGuid().ToString();
|
2018-08-21 08:46:42 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
OVF.AddDisk(ovfEnv, vsId, diskId, diskFilename, vbd.bootable, diskName,
|
|
|
|
|
vdi.name_description, (ulong)vdi.physical_utilisation, (ulong)vdi.virtual_size);
|
|
|
|
|
OVF.SetTargetDeviceInRASD(ovfEnv, vsId, diskId, vbd.userdevice);
|
2013-11-14 13:29:30 +01:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
diskIndex++;
|
2016-10-27 17:03:16 +02:00
|
|
|
|
}
|
2020-09-03 01:36:40 +02:00
|
|
|
|
catch (HTTP.CancelledException)
|
2018-03-16 00:14:11 +01:00
|
|
|
|
{
|
2020-09-03 01:36:40 +02:00
|
|
|
|
throw new CancelledException();
|
2018-03-16 00:14:11 +01:00
|
|
|
|
}
|
2020-09-03 01:36:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ADD XEN SPECIFICS
|
|
|
|
|
|
|
|
|
|
var _params = vm.HVM_boot_params;
|
|
|
|
|
if (_params != null && _params.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "HVM_boot_params", string.Join(";", _params.Select(kvp => string.Format("{0}={1}", kvp.Key, kvp.Value))), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_6"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(vm.HVM_boot_policy))
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "HVM_boot_policy", vm.HVM_boot_policy, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_2"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (vm.HVM_shadow_multiplier != 1.0)
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "HVM_shadow_multiplier", Convert.ToString(vm.HVM_shadow_multiplier), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var platform = vm.platform;
|
|
|
|
|
if (platform != null && platform.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "platform", string.Join(";", platform.Select(kvp => string.Format("{0}={1}", kvp.Key, kvp.Value))), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_3"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var nvram = vm.NVRAM;
|
|
|
|
|
if (nvram != null && nvram.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "NVRAM", string.Join(";", nvram.Select(kvp => string.Format("{0}={1}", kvp.Key, kvp.Value))), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_7"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(vm.PV_args))
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_args", vm.PV_args, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(vm.PV_bootloader))
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_bootloader", vm.PV_bootloader, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(vm.PV_bootloader_args))
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_bootloader_args", vm.PV_bootloader_args, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(vm.PV_kernel))
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_kernel", vm.PV_kernel, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(vm.PV_legacy_args))
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_legacy_args", vm.PV_legacy_args, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(vm.PV_ramdisk))
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_ramdisk", vm.PV_ramdisk, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (vm.hardware_platform_version >= 0)
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "hardware_platform_version", vm.hardware_platform_version.ToString(), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(vm.recommendations))
|
|
|
|
|
{
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "recommendations", vm.recommendations.ToString(), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (vm.has_vendor_device)
|
|
|
|
|
{
|
|
|
|
|
//serialise it with a different name to avoid it being deserialised automatically and getting the wrong type
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "VM_has_vendor_device", vm.has_vendor_device.ToString(), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (XenRef<VGPU> gpuRef in vm.VGPUs)
|
|
|
|
|
{
|
|
|
|
|
VGPU vgpu = Connection.Resolve(gpuRef);
|
|
|
|
|
|
|
|
|
|
if (vgpu != null)
|
2013-11-14 13:29:30 +01:00
|
|
|
|
{
|
2020-09-03 01:36:40 +02:00
|
|
|
|
var vgpuGroup = Connection.Resolve(vgpu.GPU_group);
|
|
|
|
|
var vgpuType = Connection.Resolve(vgpu.type);
|
2013-11-14 13:29:30 +01:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
sb.AppendFormat("GPU_types={{{0}}};",
|
|
|
|
|
vgpuGroup?.GPU_types == null || vgpuGroup.GPU_types.Length < 1
|
|
|
|
|
? ""
|
|
|
|
|
: string.Join(";", vgpuGroup.GPU_types));
|
|
|
|
|
sb.AppendFormat("VGPU_type_vendor_name={0};", vgpuType?.vendor_name ?? "");
|
|
|
|
|
sb.AppendFormat("VGPU_type_model_name={0};", vgpuType?.model_name ?? "");
|
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "vgpu", sb.ToString(), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_4"), true);
|
2013-11-14 13:29:30 +01:00
|
|
|
|
}
|
2020-09-03 01:36:40 +02:00
|
|
|
|
}
|
2017-03-03 19:21:29 +01:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
string pvsSiteUuid = string.Empty;
|
|
|
|
|
var allProxies = Connection.Cache.PVS_proxies;
|
2017-03-03 19:21:29 +01:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
foreach (var p in allProxies.Where(p => p != null && p.VIF != null))
|
|
|
|
|
{
|
|
|
|
|
var vif = Connection.Resolve(p.VIF);
|
|
|
|
|
if (vif != null)
|
2017-03-03 19:21:29 +01:00
|
|
|
|
{
|
2020-09-03 01:36:40 +02:00
|
|
|
|
var vmFromVif = Connection.Resolve(vif.VM);
|
|
|
|
|
if (vmFromVif != null && vmFromVif.uuid == vm.uuid)
|
2017-03-03 19:21:29 +01:00
|
|
|
|
{
|
2020-09-03 01:36:40 +02:00
|
|
|
|
var pvsSite = Connection.Resolve(p.site);
|
|
|
|
|
if (pvsSite != null)
|
|
|
|
|
pvsSiteUuid = pvsSite.uuid;
|
2017-03-06 17:03:13 +01:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
break;
|
2017-03-03 19:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-03 01:36:40 +02:00
|
|
|
|
}
|
2017-03-03 19:21:29 +01:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(pvsSiteUuid))
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
sb.AppendFormat("PVS_SITE={{{0}}};", string.Format("uuid={0}", pvsSiteUuid));
|
2017-03-03 19:21:29 +01:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
OVF.AddOtherSystemSettingData(ovfEnv, vsId, "pvssite", sb.ToString(), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_5"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-03 01:36:40 +02:00
|
|
|
|
OVF.FinalizeEnvelope(ovfEnv);
|
|
|
|
|
return ovfEnv;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|