def signalDeviceModel(self, cmd, ret, par=None): if self.device_model is None: return # Signal the device model to for action if cmd is '' or ret is '': raise VmError( 'need valid command and result when signal device model') count = 0 while True: orig_state = xstransact.Read( "/local/domain/0/device-model/%i/state" % self.vm.getDomid()) # This can occur right after start-up if orig_state != None: break log.debug('signalDeviceModel: orig_state is None, retrying') time.sleep(0.1) count += 1 if count < 100: continue raise VmError('Device model isn\'t ready for commands') if par is not None: xstransact.Store( "/local/domain/0/device-model/%i" % self.vm.getDomid(), ('parameter', par)) xstransact.Store( "/local/domain/0/device-model/%i" % self.vm.getDomid(), ('command', cmd)) # Wait for confirmation. Could do this with a watch but we'd # still end up spinning here waiting for the watch to fire. state = '' count = 0 while state != ret: state = xstransact.Read("/local/domain/0/device-model/%i/state" % self.vm.getDomid()) time.sleep(0.1) count += 1 if count > 100: raise VmError('Timed out waiting for device model action') #resotre orig state xstransact.Store( "/local/domain/0/device-model/%i" % self.vm.getDomid(), ('state', orig_state)) log.info("signalDeviceModel:restore dm state to %s", orig_state)
def stress_write(): xstransact.Write(PATH, 'key', '1') while True: val = xstransact.Gather(PATH, ('key', int)) xstransact.Store(PATH, ('key', val + 1)) random_sleep()
def resumeDeviceModel(self): if self.device_model is None: return # Signal the device model to resume activity after pausing to save. xstransact.Store( "/local/domain/0/device-model/%i" % self.vm.getDomid(), ('command', 'continue'))
def configure(self, vmConfig): ImageHandler.configure(self, vmConfig) self.loader = vmConfig['platform'].get('loader') info = xc.xeninfo() if 'hvm' not in info['xen_caps']: raise HVMRequired() xen_platform_pci = int(vmConfig['platform'].get('xen_platform_pci', 1)) rtc_timeoffset = vmConfig['platform'].get('rtc_timeoffset') if not self.display: self.display = '' store_dmargs = [ x for x in self.dmargs if x not in ['-sdl', '-disable-opengl'] ] try: midx = store_dmargs.index('-monitor') store_dmargs[midx + 1] = 'pty' except ValueError: pass self.vm.storeVm(("image/dmargs", " ".join(store_dmargs)), ("image/device-model", self.device_model), ("image/display", self.display)) self.vm.permissionsVm("image/dmargs", { 'dom': self.vm.getDomid(), 'read': True }) if xen_platform_pci == 0: disable_pf = 1 log.info("No need to create platform device.[domid:%d]", self.vm.getDomid()) else: disable_pf = 0 log.info("Need to create platform device.[domid:%d]", self.vm.getDomid()) xstransact.Store( "/local/domain/0/device-model/%i" % self.vm.getDomid(), ('disable_pf', disable_pf)) self.vm.storeVm(("rtc/timeoffset", rtc_timeoffset)) self.vm.permissionsVm("rtc/timeoffset", { 'dom': self.vm.getDomid(), 'read': True }) self.apic = int(vmConfig['platform'].get('apic', 0)) self.acpi = int(vmConfig['platform'].get('acpi', 0)) self.guest_os_type = vmConfig['platform'].get('guest_os_type') self.memory_sharing = int(vmConfig['memory_sharing']) try: xc.dom_set_memshr(self.vm.getDomid(), self.memory_sharing) except: pass
def saveDeviceModel(self): if self.device_model is None: return # Signal the device model to pause itself and save its state xstransact.Store( "/local/domain/0/device-model/%i" % self.vm.getDomid(), ('command', 'save')) # Wait for confirmation. Could do this with a watch but we'd # still end up spinning here waiting for the watch to fire. state = '' count = 0 while state != 'paused': state = xstransact.Read("/local/domain/0/device-model/%i/state" % self.vm.getDomid()) time.sleep(0.1) count += 1 if count > 100: raise VmError('Timed out waiting for device model to save')
def parseDeviceModelArgs(self, vmConfig): ret = ["-domain-name", str(self.vm.info['name_label'])] xen_extended_power_mgmt = int(vmConfig['platform'].get( 'xen_extended_power_mgmt', 0)) if xen_extended_power_mgmt != 0: xstransact.Store( "/local/domain/0/device-model/%i" % self.vm.getDomid(), ('xen_extended_power_mgmt', xen_extended_power_mgmt)) # Find RFB console device, and if it exists, make QEMU enable # the VNC console. if int(vmConfig['platform'].get('nographic', 0)) != 0: # skip vnc init if nographic is set ret.append('-nographic') return ret vram = str(vmConfig['platform'].get('videoram', 4)) ret.append('-videoram') ret.append(vram) vnc_config = {} has_vnc = int(vmConfig['platform'].get('vnc', 0)) != 0 has_sdl = int(vmConfig['platform'].get('sdl', 0)) != 0 opengl = 1 keymap = vmConfig['platform'].get("keymap") for dev_uuid in vmConfig['console_refs']: dev_type, dev_info = vmConfig['devices'][dev_uuid] if dev_type == 'vfb': if 'keymap' in dev_info: keymap = dev_info.get('keymap', {}) if 'monitor' in dev_info: ret.append("-serial") ret.append(dev_info.get('monitor', {})) ret.append("-monitor") ret.append("null") if 'serial' in dev_info: ret.append("-serial") ret.append(dev_info.get('serial', {})) if int(dev_info.get('vnc', 0)) != 0: has_vnc = True if int(dev_info.get('sdl', 0)) != 0: has_sdl = True if has_sdl: self.display = dev_info.get('display', self.display) self.xauthority = dev_info.get('xauthority', self.xauthority) opengl = int(dev_info.get('opengl', opengl)) if has_vnc: vnc_config = dev_info.get('other_config', {}) break if keymap: ret.append("-k") ret.append(keymap) if has_vnc: if not vnc_config: for key in ('vncunused', 'vnclisten', 'vncdisplay', 'vncpasswd'): if key in vmConfig['platform']: vnc_config[key] = vmConfig['platform'][key] if vnc_config.has_key("vncpasswd"): passwd = vnc_config["vncpasswd"] else: passwd = XendOptions.instance().get_vncpasswd_default() vncopts = "" if passwd: self.vm.storeVm("vncpasswd", passwd) self.vm.permissionsVm("vncpasswd", { 'dom': self.vm.getDomid(), 'read': True }) vncopts = vncopts + ",password" log.debug("Stored a VNC password for vfb access") else: log.debug("No VNC passwd configured for vfb access") if XendOptions.instance().get_vnc_tls(): vncx509certdir = XendOptions.instance().get_vnc_x509_cert_dir() vncx509verify = XendOptions.instance().get_vnc_x509_verify() if not os.path.exists(vncx509certdir): raise VmError( "VNC x509 certificate dir %s does not exist" % vncx509certdir) if vncx509verify: vncopts = vncopts + ",tls,x509verify=%s" % vncx509certdir else: vncopts = vncopts + ",tls,x509=%s" % vncx509certdir vnclisten = vnc_config.get( 'vnclisten', XendOptions.instance().get_vnclisten_address()) vncdisplay = int(vnc_config.get('vncdisplay', 0)) ret.append('-vnc') ret.append("%s:%s%s" % (vnclisten, vncdisplay, vncopts)) if int(vnc_config.get('vncunused', 1)) != 0: ret.append('-vncunused') if has_sdl: ret.append('-sdl') if int(vmConfig['platform'].get('opengl', opengl)) != 1: ret.append('-disable-opengl') if not has_sdl and not has_vnc: ret.append('-nographic') if vmConfig['platform'].get('parallel'): ret = ret + ["-parallel", vmConfig['platform'].get('parallel')] if int(vmConfig['platform'].get('monitor', 0)) != 0: if vmConfig['platform'].get('monitor_path'): ret = ret + [ '-monitor', vmConfig['platform'].get('monitor_path') ] else: ret = ret + ['-monitor', 'vc'] return ret