diff --git a/lib/constants.py b/lib/constants.py index 7847316d8229f630c3172f2c034ad7363e7b008b..cd6493d23c75f54c13d01bc5d3177845649f88ff 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -367,6 +367,7 @@ HV_CDROM_IMAGE_PATH = "cdrom_image_path" HV_NIC_TYPE = "nic_type" HV_DISK_TYPE = "disk_type" HV_VNC_BIND_ADDRESS = "vnc_bind_address" +HV_VNC_PASSWORD_FILE = "vnc_password_file" HV_VNC_TLS = "vnc_tls" HV_VNC_X509 = "vnc_x509_path" HV_VNC_X509_VERIFY = "vnc_x509_verify" @@ -389,6 +390,7 @@ HVS_PARAMETER_TYPES = { HV_CDROM_IMAGE_PATH: VTYPE_STRING, HV_NIC_TYPE: VTYPE_STRING, HV_DISK_TYPE: VTYPE_STRING, + HV_VNC_PASSWORD_FILE: VTYPE_STRING, HV_VNC_BIND_ADDRESS: VTYPE_STRING, HV_VNC_TLS: VTYPE_BOOL, HV_VNC_X509: VTYPE_STRING, @@ -604,6 +606,7 @@ HVC_DEFAULTS = { HV_NIC_TYPE: HT_NIC_RTL8139, HV_DISK_TYPE: HT_DISK_PARAVIRTUAL, HV_VNC_BIND_ADDRESS: '0.0.0.0', + HV_VNC_PASSWORD_FILE: VNC_PASSWORD_FILE, HV_ACPI: True, HV_PAE: True, HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader", @@ -620,6 +623,7 @@ HVC_DEFAULTS = { HV_VNC_TLS: False, HV_VNC_X509: '', HV_VNC_X509_VERIFY: False, + HV_VNC_PASSWORD_FILE: '', HV_CDROM_IMAGE_PATH: '', HV_BOOT_ORDER: HT_BO_DISK, HV_NIC_TYPE: HT_NIC_PARAVIRTUAL, diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index 27dd28f2319382cbf3984d5140b5e56dad867d77..74005f075042501fe5fbfeaf415b8584f08c148c 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -62,6 +62,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): constants.HV_VNC_TLS: hv_base.NO_CHECK, constants.HV_VNC_X509: hv_base.OPT_DIR_CHECK, constants.HV_VNC_X509_VERIFY: hv_base.NO_CHECK, + constants.HV_VNC_PASSWORD_FILE: hv_base.OPT_FILE_CHECK, constants.HV_CDROM_IMAGE_PATH: hv_base.OPT_FILE_CHECK, constants.HV_BOOT_ORDER: hv_base.ParamInSet(True, constants.HT_KVM_VALID_BO_TYPES), @@ -330,7 +331,6 @@ class KVMHypervisor(hv_base.BaseHypervisor): kvm_cmd.extend(['-usb']) kvm_cmd.extend(['-usbdevice', mouse_type]) - # FIXME: handle vnc password vnc_bind_address = hvp[constants.HV_VNC_BIND_ADDRESS] if vnc_bind_address: if utils.IsValidIP(vnc_bind_address): @@ -358,6 +358,9 @@ class KVMHypervisor(hv_base.BaseHypervisor): elif hvp[constants.HV_VNC_X509]: vnc_append = '%s,x509=%s' % (vnc_append, hvp[constants.HV_VNC_X509]) + if hvp[constants.HV_VNC_PASSWORD_FILE]: + vnc_append = '%s,password' % vnc_append + vnc_arg = '%s%s' % (vnc_arg, vnc_append) else: @@ -432,6 +435,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): """ pidfile, pid, alive = self._InstancePidAlive(instance.name) + hvp = instance.hvparams if alive: raise errors.HypervisorError("Failed to start instance %s: %s" % (instance.name, "already running")) @@ -460,6 +464,15 @@ class KVMHypervisor(hv_base.BaseHypervisor): target, port = incoming kvm_cmd.extend(['-incoming', 'tcp:%s:%s' % (target, port)]) + vnc_pwd_file = hvp[constants.HV_VNC_PASSWORD_FILE] + vnc_pwd = None + if vnc_pwd_file: + try: + vnc_pwd = utils.ReadFile(vnc_pwd_file) + except EnvironmentError, err: + raise errors.HypervisorError("Failed to open VNC password file %s: %s" + % (vnc_pwd_file, err)) + result = utils.RunCmd(kvm_cmd) if result.failed: raise errors.HypervisorError("Failed to start instance %s: %s (%s)" % @@ -470,6 +483,10 @@ class KVMHypervisor(hv_base.BaseHypervisor): raise errors.HypervisorError("Failed to start instance %s: %s" % (instance.name)) + if vnc_pwd: + change_cmd = 'change vnc password %s' % vnc_pwd + self._CallMonitorCommand(instance.name, change_cmd) + for filename in temp_files: utils.RemoveFile(filename) diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py index c82c344598b71bfea5f9204009b2b998a0aa1fab..32385a2982a1cb7dcf30570f34bdd4c176370fb4 100644 --- a/lib/hypervisor/hv_xen.py +++ b/lib/hypervisor/hv_xen.py @@ -526,6 +526,7 @@ class XenHvmHypervisor(XenHypervisor): "VNC bind address is not a valid IP address", None, None), constants.HV_KERNEL_PATH: hv_base.REQ_FILE_CHECK, constants.HV_DEVICE_MODEL: hv_base.REQ_FILE_CHECK, + constants.HV_VNC_PASSWORD_FILE: hv_base.REQ_FILE_CHECK, } @classmethod @@ -574,11 +575,12 @@ class XenHvmHypervisor(XenHypervisor): config.write("# vncdisplay = 1\n") config.write("vncunused = 1\n") + vnc_pwd_file = hvp[constants.HV_VNC_PASSWORD_FILE] try: - password = utils.ReadFile(constants.VNC_PASSWORD_FILE) + password = utils.ReadFile(vnc_pwd_file) except EnvironmentError, err: raise errors.HypervisorError("Failed to open VNC password file %s: %s" % - (constants.VNC_PASSWORD_FILE, err)) + (vnc_pwd_file, err)) config.write("vncpasswd = '%s'\n" % password.rstrip())