From 8447f52bf8a6e8509f122c1100c9b97726a74cf3 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Thu, 5 Feb 2009 13:36:43 +0000 Subject: [PATCH] KVM: allow binding vnc to a file Before we forced the VNC_BIND_ADDRESS to be an ip. Now we also accept a path, and bind the instance to it, or to a file in it if it's a directory. Reviewed-by: iustinp --- lib/hypervisor/hv_kvm.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index 0df7e422d..19d96453c 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -264,18 +264,25 @@ class KVMHypervisor(hv_base.BaseHypervisor): vnc_bind_address = instance.hvparams[constants.HV_VNC_BIND_ADDRESS] if vnc_bind_address: kvm_cmd.extend(['-usbdevice', 'tablet']) - if instance.network_port > constants.HT_HVM_VNC_BASE_PORT: - display = instance.network_port - constants.HT_HVM_VNC_BASE_PORT - if vnc_bind_address == '0.0.0.0': - vnc_arg = ':%d' % (display) + if utils.IsValidIP(vnc_bind_address): + if instance.network_port > constants.HT_HVM_VNC_BASE_PORT: + display = instance.network_port - constants.HT_HVM_VNC_BASE_PORT + if vnc_bind_address == '0.0.0.0': + vnc_arg = ':%d' % (display) + else: + vnc_arg = '%s:%d' % (constants.HV_VNC_BIND_ADDRESS, display) else: - vnc_arg = '%s:%d' % (constants.HV_VNC_BIND_ADDRESS, display) - kvm_cmd.extend(['-vnc', vnc_arg]) + logging.error("Network port is not a valid VNC display (%d < %d)." + " Not starting VNC" % + (instance.network_port, + constants.HT_HVM_VNC_BASE_PORT)) + vnc_arg = 'none' else: - logging.error("Network port is not a valid VNC display (%d < %d)." - " Not starting VNC" % - (instance.network_port, constants.HT_HVM_VNC_BASE_PORT)) - kvm_cmd.extend(['-vnc', 'none']) + if os.path.isdir(vnc_bind_address): + vnc_arg = 'unix:%s/%s.vnc' % (vnc_bind_address, instance.name) + else: + vnc_arg = 'unix:%s' % vnc_bind_address + kvm_cmd.extend(['-vnc', vnc_arg]) else: kvm_cmd.extend(['-nographic']) @@ -683,9 +690,11 @@ class KVMHypervisor(hv_base.BaseHypervisor): vnc_bind_address = hvparams[constants.HV_VNC_BIND_ADDRESS] if vnc_bind_address: if not utils.IsValidIP(vnc_bind_address): - raise errors.OpPrereqError("given VNC bind address '%s' doesn't look" - " like a valid IP address" % - vnc_bind_address) + if not os.path.isabs(vnc_bind_address): + raise errors.HypervisorError("The VNC bind address must be either" + " a valid IP address or an absolute" + " pathname. '%s' given" % + vnc_bind_address) def ValidateParameters(self, hvparams): """Check the given parameters for validity. -- GitLab