📄 xenddomaininfo.py
字号:
sxpr = ['domain', ['domid', self.domid], ['name', self.info['name_label']], ['vcpu_count', self.info['VCPUs_max']]] for i in range(0, self.info['VCPUs_max']): if self.domid is not None: info = xc.vcpu_getinfo(self.domid, i) sxpr.append(['vcpu', ['number', i], ['online', info['online']], ['blocked', info['blocked']], ['running', info['running']], ['cpu_time', info['cpu_time'] / 1e9], ['cpu', info['cpu']], ['cpumap', info['cpumap']]]) else: sxpr.append(['vcpu', ['number', i], ['online', 0], ['blocked', 0], ['running', 0], ['cpu_time', 0.0], ['cpu', -1], ['cpumap', self.info['cpus'][i] and \ self.info['cpus'][i] or range(64)]]) return sxpr except RuntimeError, exn: raise XendError(str(exn)) def getDomInfo(self): return dom_get(self.domid) # # internal functions ... TODO: re-categorised # def _augmentInfo(self, priv): """Augment self.info, as given to us through L{recreate}, with values taken from the store. This recovers those values known to xend but not to the hypervisor. """ augment_entries = XendConfig.LEGACY_XENSTORE_VM_PARAMS[:] if priv: augment_entries.remove('memory') augment_entries.remove('maxmem') augment_entries.remove('vcpus') augment_entries.remove('vcpu_avail') vm_config = self._readVMDetails([(k, XendConfig.LEGACY_CFG_TYPES[k]) for k in augment_entries]) # make returned lists into a dictionary vm_config = dict(zip(augment_entries, vm_config)) for arg in augment_entries: val = vm_config[arg] if val != None: if arg in XendConfig.LEGACY_CFG_TO_XENAPI_CFG: xapiarg = XendConfig.LEGACY_CFG_TO_XENAPI_CFG[arg] self.info[xapiarg] = val elif arg == "memory": self.info["static_memory_min"] = val elif arg == "maxmem": self.info["static_memory_max"] = val else: self.info[arg] = val # read CPU Affinity self.info['cpus'] = [] vcpus_info = self.getVCPUInfo() for vcpu_info in sxp.children(vcpus_info, 'vcpu'): self.info['cpus'].append(sxp.child_value(vcpu_info, 'cpumap')) # For dom0, we ignore any stored value for the vcpus fields, and # read the current value from Xen instead. This allows boot-time # settings to take precedence over any entries in the store. if priv: xeninfo = dom_get(self.domid) self.info['VCPUs_max'] = xeninfo['online_vcpus'] self.info['vcpu_avail'] = (1 << xeninfo['online_vcpus']) - 1 # read image value image_sxp = self._readVm('image') if image_sxp: self.info.update_with_image_sxp(sxp.from_string(image_sxp)) # read devices devices = [] for devclass in XendDevices.valid_devices(): devconfig = self.getDeviceController(devclass).configurations() if devconfig: devices.extend(devconfig) if not self.info['devices'] and devices is not None: for device in devices: self.info.device_add(device[0], cfg_sxp = device) self._update_consoles() def _update_consoles(self, transaction = None): if self.domid == None or self.domid == 0: return # Update VT100 port if it exists if transaction is None: self.console_port = self.readDom('console/port') else: self.console_port = self.readDomTxn(transaction, 'console/port') if self.console_port is not None: serial_consoles = self.info.console_get_all('vt100') if not serial_consoles: cfg = self.info.console_add('vt100', self.console_port) self._createDevice('console', cfg) else: console_uuid = serial_consoles[0].get('uuid') self.info.console_update(console_uuid, 'location', self.console_port) # Update VNC port if it exists and write to xenstore if transaction is None: vnc_port = self.readDom('console/vnc-port') else: vnc_port = self.readDomTxn(transaction, 'console/vnc-port') if vnc_port is not None: for dev_uuid, (dev_type, dev_info) in self.info['devices'].items(): if dev_type == 'vfb': old_location = dev_info.get('location') listen_host = dev_info.get('vnclisten', 'localhost') new_location = '%s:%s' % (listen_host, str(vnc_port)) if old_location == new_location: break dev_info['location'] = new_location self.info.device_update(dev_uuid, cfg_xenapi = dev_info) vfb_ctrl = self.getDeviceController('vfb') vfb_ctrl.reconfigureDevice(0, dev_info) break # # Function to update xenstore /vm/* # def _readVm(self, *args): return xstransact.Read(self.vmpath, *args) def _writeVm(self, *args): return xstransact.Write(self.vmpath, *args) def _removeVm(self, *args): return xstransact.Remove(self.vmpath, *args) def _gatherVm(self, *args): return xstransact.Gather(self.vmpath, *args) def _listRecursiveVm(self, *args): return xstransact.ListRecursive(self.vmpath, *args) def storeVm(self, *args): return xstransact.Store(self.vmpath, *args) def permissionsVm(self, *args): return xstransact.SetPermissions(self.vmpath, *args) def _readVmTxn(self, transaction, *args): paths = map(lambda x: self.vmpath + "/" + x, args) return transaction.read(*paths) def _writeVmTxn(self, transaction, *args): paths = map(lambda x: self.vmpath + "/" + x, args) return transaction.write(*paths) def _removeVmTxn(self, transaction, *args): paths = map(lambda x: self.vmpath + "/" + x, args) return transaction.remove(*paths) def _gatherVmTxn(self, transaction, *args): paths = map(lambda x: self.vmpath + "/" + x, args) return transaction.gather(paths) def storeVmTxn(self, transaction, *args): paths = map(lambda x: self.vmpath + "/" + x, args) return transaction.store(*paths) def permissionsVmTxn(self, transaction, *args): paths = map(lambda x: self.vmpath + "/" + x, args) return transaction.set_permissions(*paths) # # Function to update xenstore /dom/* # def readDom(self, *args): return xstransact.Read(self.dompath, *args) def gatherDom(self, *args): return xstransact.Gather(self.dompath, *args) def _writeDom(self, *args): return xstransact.Write(self.dompath, *args) def _removeDom(self, *args): return xstransact.Remove(self.dompath, *args) def storeDom(self, *args): return xstransact.Store(self.dompath, *args) def readDomTxn(self, transaction, *args): paths = map(lambda x: self.dompath + "/" + x, args) return transaction.read(*paths) def gatherDomTxn(self, transaction, *args): paths = map(lambda x: self.dompath + "/" + x, args) return transaction.gather(*paths) def _writeDomTxn(self, transaction, *args): paths = map(lambda x: self.dompath + "/" + x, args) return transaction.write(*paths) def _removeDomTxn(self, transaction, *args): paths = map(lambda x: self.dompath + "/" + x, args) return transaction.remove(*paths) def storeDomTxn(self, transaction, *args): paths = map(lambda x: self.dompath + "/" + x, args) return transaction.store(*paths) def _recreateDom(self): complete(self.dompath, lambda t: self._recreateDomFunc(t)) def _recreateDomFunc(self, t): t.remove() t.mkdir() t.set_permissions({'dom' : self.domid}) t.write('vm', self.vmpath) def _storeDomDetails(self): to_store = { 'domid': str(self.domid), 'vm': self.vmpath, 'name': self.info['name_label'], 'console/limit': str(xoptions.get_console_limit() * 1024), 'memory/target': str(self.info['memory_dynamic_max'] / 1024), } def f(n, v): if v is not None: if type(v) == bool: to_store[n] = v and "1" or "0" else: to_store[n] = str(v) # Figure out if we need to tell xenconsoled to ignore this guest's # console - device model will handle console if it is running constype = "ioemu" if 'device_model' not in self.info['platform']: constype = "xenconsoled" f('console/port', self.console_port) f('console/ring-ref', self.console_mfn) f('console/type', constype) f('store/port', self.store_port) f('store/ring-ref', self.store_mfn) if arch.type == "x86": f('control/platform-feature-multiprocessor-suspend', True) # elfnotes for n, v in self.info.get_notes().iteritems(): n = n.lower().replace('_', '-') if n == 'features': for v in v.split('|'): v = v.replace('_', '-') if v.startswith('!'): f('image/%s/%s' % (n, v[1:]), False) else: f('image/%s/%s' % (n, v), True) else: f('image/%s' % n, v) if self.info.has_key('security_label'): f('security_label', self.info['security_label']) to_store.update(self._vcpuDomDetails()) log.debug("Storing domain details: %s", scrub_password(to_store)) self._writeDom(to_store) def _vcpuDomDetails(self): def availability(n): if self.info['vcpu_avail'] & (1 << n): return 'online' else: return 'offline' result = {} for v in range(0, self.info['VCPUs_max']): result["cpu/%d/availability" % v] = availability(v) return result # # xenstore watches # def _registerWatches(self): """Register a watch on this VM's entries in the store, and the domain's control/shutdown node, so that when they are changed externally, we keep up to date. This should only be called by {@link #create}, {@link #recreate}, or {@link #restore}, once the domain's details have been written, but before the new instance is returned.""" self.vmWatch = xswatch(self.vmpath, self._storeChanged) self.shutdownWatch = xswatch(self.dompath + '/control/shutdown', self._handleShutdownWatch) def _storeChanged(self, _): log.trace("XendDomainInfo.storeChanged"); changed = False # Check whether values in the configuration have # changed in Xenstore. cfg_vm = ['name', 'on_poweroff', 'on_reboot', 'on_crash', 'rtc/timeoffset'] vm_details = self._readVMDetails([(k,XendConfig.LEGACY_CFG_TYPES[k]) for k in cfg_vm]) # convert two lists into a python dictionary vm_details = dict(zip(cfg_vm, vm_details)) if vm_details['rtc/timeoffset'] == None: vm_details['rtc/timeoffset'] = "0" for arg, val in vm_details.items(): if arg in XendConfig.LEGACY_CFG_TO_XENAPI_CFG: xapiarg = XendConfig.LEGACY_CFG_TO_XENAPI_CFG[arg] if val != None and val != self.info[xapiarg]: self.info[xapiarg] = val changed = True elif arg == "memory": if val != None and val != self.info["static_memory_min"]: self.info["static_memory_min"] = val changed = True elif arg == "maxmem": if val != None and val != self.info["static_memory_max"]:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -