protected override void Run() { // Remove any existing VGPUs before adding new ones foreach (VGPU vgpu in vm.Connection.ResolveAll(vm.VGPUs)) { VGPU.destroy(Session, vgpu.opaque_ref); } if (gpu_group == null) // The VM doesn't want a VGPU { return; } // Add the new VGPU string device = "0"; // fixed at the moment, see PR-1060 Dictionary <string, string> other_config = new Dictionary <string, string>(); if (Helpers.FeatureForbidden(vm, Host.RestrictVgpu) || vgpuType == null) { VGPU.async_create(Session, vm.opaque_ref, gpu_group.opaque_ref, device, other_config); } else { VGPU.async_create(Session, vm.opaque_ref, gpu_group.opaque_ref, device, other_config, vgpuType.opaque_ref); } }
protected override void Run() { var vgpuSetToRemove = new HashSet <VGPU>(vm.Connection.ResolveAll(vm.VGPUs)); // Existing vGPUs must have opaque_ref var vgpuSetToUnchanged = new HashSet <VGPU>(vGpus.FindAll(x => x.opaque_ref != null)); vgpuSetToRemove.ExceptWith(vgpuSetToUnchanged); foreach (VGPU vgpu in vgpuSetToRemove) { VGPU.destroy(Session, vgpu.opaque_ref); } // New added vGPUs haven't opaque_ref foreach (var vGpu in vGpus.FindAll(x => x.opaque_ref == null)) { AddGpu(vm.Connection.Resolve(vGpu.GPU_group), vm.Connection.Resolve(vGpu.type), vGpu.device ?? "0"); } }