📄 create.py
字号:
def configure_vscsis(config_devs, vals): """Create the config for vscsis (virtual scsi devices). """ devidlist = [] config_scsi = [] if len(vals.vscsi) == 0: return 0 scsi_devices = vscsi_util.vscsi_get_scsidevices() for (p_dev, v_dev, backend) in vals.vscsi: tmp = p_dev.split(':') if len(tmp) == 4: (p_hctl, block) = vscsi_util._vscsi_hctl_block(p_dev, scsi_devices) else: (p_hctl, block) = vscsi_util._vscsi_block_scsiid_to_hctl(p_dev, scsi_devices) if p_hctl == None: raise ValueError("Cannot find device \"%s\"" % p_dev) for config in config_scsi: dev = vscsi_convert_sxp_to_dict(config) if dev['v-dev'] == v_dev: raise ValueError('The virtual device "%s" is already defined' % v_dev) v_hctl = v_dev.split(':') devid = int(v_hctl[0]) config_scsi.append(['dev', \ ['state', 'Initialising'], \ ['devid', devid], \ ['p-dev', p_hctl], \ ['p-devname', block], \ ['v-dev', v_dev] ]) if vscsi_lookup_devid(devidlist, devid) == 0: devidlist.append([devid, backend]) for devid, backend in devidlist: tmp = [] for config in config_scsi: dev = vscsi_convert_sxp_to_dict(config) if dev['devid'] == devid: tmp.append(config) tmp.insert(0, 'vscsi') if backend: tmp.append(['backend', backend]) config_devs.append(['device', tmp])def configure_ioports(config_devs, vals): """Create the config for legacy i/o ranges. """ for (io_from, io_to) in vals.ioports: config_ioports = ['ioports', ['from', io_from], ['to', io_to]] config_devs.append(['device', config_ioports])def configure_irq(config_devs, vals): """Create the config for irqs. """ for irq in vals.irq: config_irq = ['irq', ['irq', irq]] config_devs.append(['device', config_irq])def configure_vfbs(config_devs, vals): for f in vals.vfb: d = comma_sep_kv_to_dict(f) config = ['vfb'] if not d.has_key("type"): d['type'] = 'sdl' for (k,v) in d.iteritems(): if not k in [ 'vnclisten', 'vncunused', 'vncdisplay', 'display', 'videoram', 'xauthority', 'type', 'vncpasswd', 'opengl', 'keymap' ]: err("configuration option %s unknown to vfbs" % k) config.append([k,v]) if not d.has_key("keymap"): if vals.keymap: config.append(['keymap',vals.keymap]) if not d.has_key("display") and os.environ.has_key("DISPLAY"): config.append(["display", os.environ['DISPLAY']]) if not d.has_key("xauthority"): config.append(["xauthority", get_xauthority()]) config_devs.append(['device', ['vkbd']]) config_devs.append(['device', config])def configure_security(config, vals): """Create the config for ACM security labels. """ access_control = vals.access_control num = len(access_control) if num == 1: d = access_control[0] policy = d.get('policy') label = d.get('label') if policy != security.active_policy: err("Security policy (" + policy + ") incompatible with enforced policy (" + security.active_policy + ")." ) config_access_control = ['access_control', ['policy', policy], ['label', label] ] security_label = ['security', [ config_access_control ] ] config.append(security_label) elif num > 1: err("VM config error: Multiple access_control definitions!")def configure_vtpm(config_devs, vals): """Create the config for virtual TPM interfaces. """ vtpm = vals.vtpm if len(vtpm) > 0: d = vtpm[0] instance = d.get('instance') if instance == "VTPMD": instance = "0" else: if instance != None: try: if int(instance) == 0: err('VM config error: vTPM instance must not be 0.') except ValueError: err('Vm config error: could not parse instance number.') backend = d.get('backend') typ = d.get('type') config_vtpm = ['vtpm'] if instance: config_vtpm.append(['pref_instance', instance]) if backend: config_vtpm.append(['backend', backend]) if typ: config_vtpm.append(['type', type]) config_devs.append(['device', config_vtpm])def configure_vifs(config_devs, vals): """Create the config for virtual network interfaces. """ vifs = vals.vif vifs_n = len(vifs) if hasattr(vals, 'nics'): if vals.nics > 0: warn("The nics option is deprecated. Please use an empty vif " "entry instead:\n\n vif = [ '' ]\n") for _ in range(vifs_n, vals.nics): vifs.append('') vifs_n = len(vifs) elif vals.nics == 0: warn("The nics option is deprecated. Please remove it.") for c in vifs: d = comma_sep_kv_to_dict(c) config_vif = ['vif'] def f(k): if k not in ['backend', 'bridge', 'ip', 'mac', 'script', 'type', 'vifname', 'rate', 'model', 'accel', 'policy', 'label']: err('Invalid vif option: ' + k) config_vif.append([k, d[k]]) map(f, d.keys()) config_devs.append(['device', config_vif])def configure_hvm(config_image, vals): """Create the config for HVM devices. """ args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb', 'timer_mode', 'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'soundhw', 'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten', 'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor', 'acpi', 'apic', 'usb', 'usbdevice', 'keymap', 'pci', 'hpet', 'guest_os_type', 'hap', 'opengl', 'cpuid', 'cpuid_check'] for a in args: if a in vals.__dict__ and vals.__dict__[a] is not None: config_image.append([a, vals.__dict__[a]]) if vals.vncpasswd is not None: config_image.append(['vncpasswd', vals.vncpasswd])def make_config(vals): """Create the domain configuration. """ config = ['vm'] def add_conf(n): if hasattr(vals, n): v = getattr(vals, n) if v: config.append([n, v]) map(add_conf, ['name', 'memory', 'maxmem', 'shadow_memory', 'restart', 'on_poweroff', 'on_reboot', 'on_crash', 'vcpus', 'vcpu_avail', 'features', 'on_xend_start', 'on_xend_stop', 'target', 'cpuid', 'cpuid_check', 'machine_address_size']) if vals.uuid is not None: config.append(['uuid', vals.uuid]) if vals.cpu is not None: config.append(['cpu', vals.cpu]) if vals.cpus is not None: config.append(['cpus', vals.cpus]) if vals.cpu_cap is not None: config.append(['cpu_cap', vals.cpu_cap]) if vals.cpu_weight is not None: config.append(['cpu_weight', vals.cpu_weight]) if vals.blkif: config.append(['backend', ['blkif']]) if vals.netif: config.append(['backend', ['netif']]) if vals.tpmif: config.append(['backend', ['tpmif']]) if vals.localtime: config.append(['localtime', vals.localtime]) config_image = configure_image(vals) if vals.bootloader: if vals.bootloader == "pygrub": vals.bootloader = osdep.pygrub_path config.append(['bootloader', vals.bootloader]) if vals.bootargs: config.append(['bootloader_args', vals.bootargs]) else: if vals.console_autoconnect: config.append(['bootloader_args', '']) else: config.append(['bootloader_args', '-q']) config.append(['image', config_image]) config_devs = [] configure_disks(config_devs, vals) configure_pci(config_devs, vals) configure_vscsis(config_devs, vals) configure_ioports(config_devs, vals) configure_irq(config_devs, vals) configure_vifs(config_devs, vals) configure_vtpm(config_devs, vals) configure_vfbs(config_devs, vals) configure_security(config, vals) config += config_devs return configdef preprocess_disk(vals): if not vals.disk: return disk = [] for v in vals.disk: d = v.split(',') n = len(d) if n == 3: d.append(None) d.append(None) elif n == 4: d.append(None) elif n == 5: pass else: err('Invalid disk specifier: ' + v) disk.append(d) vals.disk = diskdef preprocess_cpuid(vals, attr_name): if not vals.cpuid: return cpuid = {} for cpuid_input in getattr(vals, attr_name): input_re = "(0x)?[0-9A-Fa-f]+(,(0x)?[0-9A-Fa-f]+)?" cpuid_match = re.match(r'(?P<input>%s):(?P<regs>.*)' % \ input_re, cpuid_input) if cpuid_match != None: res_cpuid = cpuid_match.groupdict() input = res_cpuid['input'] regs = res_cpuid['regs'].split(',') cpuid[input]= {} # New input for reg in regs: reg_match = re.match(r"(?P<reg>eax|ebx|ecx|edx)=(?P<val>.*)", reg) if reg_match == None: err("cpuid's syntax is (eax|ebx|ecx|edx)=value") res = reg_match.groupdict() if (res['val'][:2] != '0x' and len(res['val']) != 32): err("cpuid: We should specify all the bits " \ "of the register %s for input %s\n" % (res['reg'], input) ) cpuid[input][res['reg']] = res['val'] # new register setattr(vals, attr_name, cpuid)def preprocess_pci(vals): if not vals.pci: return pci = [] for pci_dev_str in vals.pci: pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" + \ r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" + \ r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" + \ r"(?P<func>[0-7])$", pci_dev_str) if pci_match!=None: pci_dev_info = pci_match.groupdict('0') try: pci.append( ('0x'+pci_dev_info['domain'], \ '0x'+pci_dev_info['bus'], \ '0x'+pci_dev_info['slot'], \ '0x'+pci_dev_info['func'])) except IndexError: err('Error in PCI slot syntax "%s"'%(pci_dev_str)) vals.pci = pcidef preprocess_vscsi(vals): if not vals.vscsi: return scsi = [] for scsi_str in vals.vscsi: d = scsi_str.split(',') n = len(d) if n == 2: tmp = d[1].split(':') if len(tmp) != 4: err('vscsi syntax error "%s"' % d[1]) else: d.append(None) elif n == 3: pass else: err('vscsi syntax error "%s"' % scsi_str) scsi.append(d) vals.vscsi = scsidef preprocess_ioports(vals): if not vals.ioports: return ioports = [] for v in vals.ioports: d = v.split('-') if len(d) < 1 or len(d) > 2: err('Invalid i/o port range specifier: ' + v) if len(d) == 1: d.append(d[0]) # Components are in hex: add hex specifier.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -