📄 create.py
字号:
fn=set_value, default=None, use="Set the address of the NFS server for NFS root.")gopts.var('nfs_root', val="PATH", fn=set_value, default=None, use="Set the path of the root NFS directory.")gopts.var('device_model', val='FILE', fn=set_value, default='', use="Path to device model program.")gopts.var('fda', val='FILE', fn=set_value, default='', use="Path to fda")gopts.var('fdb', val='FILE', fn=set_value, default='', use="Path to fdb")gopts.var('serial', val='FILE', fn=set_value, default='', use="Path to serial or pty or vc")gopts.var('monitor', val='no|yes', fn=set_bool, default=0, use="""Should the device model use monitor?""")gopts.var('localtime', val='no|yes', fn=set_bool, default=0, use="Is RTC set to localtime?")gopts.var('keymap', val='FILE', fn=set_value, default='', use="Set keyboard layout used")gopts.var('usb', val='no|yes', fn=set_bool, default=0, use="Emulate USB devices?")gopts.var('usbdevice', val='NAME', fn=set_value, default='', use="Name of USB device to add?")gopts.var('guest_os_type', val='NAME', fn=set_value, default='default', use="Guest OS type running in HVM")gopts.var('stdvga', val='no|yes', fn=set_bool, default=0, use="Use std vga or cirrhus logic graphics")gopts.var('isa', val='no|yes', fn=set_bool, default=0, use="Simulate an ISA only system?")gopts.var('boot', val="a|b|c|d", fn=set_value, default='c', use="Default boot device")gopts.var('nographic', val='no|yes', fn=set_bool, default=0, use="Should device models use graphics?")gopts.var('soundhw', val='audiodev', fn=set_value, default='', use="Should device models enable audio device?")gopts.var('vnc', val='', fn=set_value, default=None, use="""Should the device model use VNC?""")gopts.var('vncdisplay', val='', fn=set_value, default=None, use="""VNC display to use""")gopts.var('vnclisten', val='', fn=set_value, default=None, use="""Address for VNC server to listen on.""")gopts.var('vncunused', val='', fn=set_bool, default=1, use="""Try to find an unused port for the VNC server. Only valid when vnc=1.""")gopts.var('sdl', val='', fn=set_value, default=None, use="""Should the device model use SDL?""")gopts.var('display', val='DISPLAY', fn=set_value, default=None, use="X11 display to use")gopts.var('xauthority', val='XAUTHORITY', fn=set_value, default=None, use="X11 Authority to use")gopts.var('uuid', val='', fn=set_value, default=None, use="""xenstore UUID (universally unique identifier) to use. One will be randomly generated if this option is not set, just like MAC addresses for virtual network interfaces. This must be a unique value across the entire cluster.""")gopts.var('on_xend_start', val='ignore|start', fn=set_value, default='ignore', use='Action to perform when xend starts')gopts.var('on_xend_stop', val='ignore|shutdown|suspend', fn=set_value, default="ignore", use="""Behaviour when Xend stops: - ignore: Domain continues to run; - shutdown: Domain is shutdown; - suspend: Domain is suspended; """)def err(msg): """Print an error to stderr and exit. """ print >>sys.stderr, "Error:", msg sys.exit(1)def warn(msg): """Print a warning to stdout. """ print >>sys.stderr, "Warning:", msgdef strip(pre, s): """Strip prefix 'pre' if present. """ if s.startswith(pre): return s[len(pre):] else: return sdef configure_image(vals): """Create the image config. """ if not vals.builder: return None config_image = [ vals.builder ] if vals.kernel: config_image.append([ 'kernel', os.path.abspath(vals.kernel) ]) if vals.ramdisk: config_image.append([ 'ramdisk', os.path.abspath(vals.ramdisk) ]) if vals.cmdline_ip: cmdline_ip = strip('ip=', vals.cmdline_ip) config_image.append(['ip', cmdline_ip]) if vals.root: cmdline_root = strip('root=', vals.root) config_image.append(['root', cmdline_root]) if vals.extra: config_image.append(['args', vals.extra]) if vals.builder == 'hvm': configure_hvm(config_image, vals) if vals.vhpt != 0: config_image.append(['vhpt', vals.vhpt]) return config_image def configure_disks(config_devs, vals): """Create the config for disks (virtual block devices). """ for (uname, dev, mode, backend, protocol) in vals.disk: if uname.startswith('tap:'): cls = 'tap' else: cls = 'vbd' config_vbd = [cls, ['uname', uname], ['dev', dev ], ['mode', mode ] ] if backend: config_vbd.append(['backend', backend]) if protocol: config_vbd.append(['protocol', protocol]) config_devs.append(['device', config_vbd])def configure_pci(config_devs, vals): """Create the config for pci devices. """ config_pci = [] for (domain, bus, slot, func) in vals.pci: config_pci.append(['dev', ['domain', domain], ['bus', bus], \ ['slot', slot], ['func', func]]) if len(config_pci)>0: config_pci.insert(0, 'pci') config_devs.append(['device', config_pci])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', 'xauthority', 'type', 'vncpasswd' ]: 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', 'guest_os_type'] 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']) 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_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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -