KVM: Allow changing VM video card via agent.properties. This change in

LibvirtVMDef can also be leveraged to add the option to service offering
or template hardware selection (as nic and disk types do).
This commit is contained in:
Marcus Sorensen 2014-07-18 16:40:09 -06:00
parent 1bb3ea8b7a
commit 849049a2f0
2 changed files with 32 additions and 0 deletions

View File

@ -230,6 +230,7 @@ import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef.guestNetType;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.SerialDef;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.TermPolicy;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.VirtioSerialDef;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.VideoDef;
import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk;
import com.cloud.hypervisor.kvm.storage.KVMStoragePool;
import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager;
@ -450,6 +451,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
protected String _guestCpuMode;
protected String _guestCpuModel;
protected boolean _noKvmClock;
protected String _videoHw;
protected int _videoRam;
private final Map <String, String> _pifs = new HashMap<String, String>();
private final Map<String, VmStats> _vmStats = new ConcurrentHashMap<String, VmStats>();
@ -800,6 +803,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
_noMemBalloon = true;
}
_videoHw = (String) params.get("vm.video.hardware");
value = (String) params.get("vm.video.ram");
_videoRam = NumbersUtil.parseInt(value, 0);
value = (String)params.get("host.reserved.mem.mb");
_dom0MinMem = NumbersUtil.parseInt(value, 0) * 1024 * 1024;
@ -3747,6 +3754,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
devices.addDevice(vserial);
}
VideoDef videoCard = new VideoDef(_videoHw, _videoRam);
devices.addDevice(videoCard);
ConsoleDef console = new ConsoleDef("pty", null, null, (short)0);
devices.addDevice(console);

View File

@ -1060,6 +1060,28 @@ public class LibvirtVMDef {
}
}
public static class VideoDef {
private String _videoModel;
private int _videoRam;
public VideoDef(String videoModel, int videoRam) {
_videoModel = videoModel;
_videoRam = videoRam;
}
@Override
public String toString() {
StringBuilder videoBuilder = new StringBuilder();
if (_videoModel != null && !_videoModel.isEmpty() && _videoRam != 0){
videoBuilder.append("<video>\n");
videoBuilder.append("<model type='" + _videoModel + "' vram='" + _videoRam + "'/>\n");
videoBuilder.append("</video>\n");
return videoBuilder.toString();
}
return "";
}
}
public static class VirtioSerialDef {
private final String _name;
private String _path;