📄 create.py
字号:
#============================================================================# This library is free software; you can redistribute it and/or# modify it under the terms of version 2.1 of the GNU Lesser General Public# License as published by the Free Software Foundation.## This library is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU# Lesser General Public License for more details.## You should have received a copy of the GNU Lesser General Public# License along with this library; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#============================================================================# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com># Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com># Copyright (C) 2005-2006 XenSource Ltd#============================================================================"""Domain creation."""import osimport os.pathimport sysimport socketimport reimport timeimport xmlrpclibfrom xen.xend import sxpfrom xen.xend import PrettyPrint as SXPPrettyPrintfrom xen.xend import osdepimport xen.xend.XendClientfrom xen.xend.XendBootloader import bootloaderfrom xen.util import blkifimport xen.util.xsm.xsm as securityfrom xen.xm.main import serverType, SERVER_XEN_API, get_single_vmfrom xen.xm.opts import *from main import serverimport consolegopts = Opts(use="""[options] [vars]Create a domain.Domain creation parameters can be set by command-line switches, froma python configuration script or an SXP config file. See documentationfor --defconfig, --config. Configuration variables can be set usingVAR=VAL on the command line. For example vmid=3 sets vmid to 3.""")gopts.opt('help', short='h', fn=set_true, default=0, use="Print this help.")gopts.opt('help_config', fn=set_true, default=0, use="Print the available configuration variables (vars) for the " "configuration script.")gopts.opt('quiet', short='q', fn=set_true, default=0, use="Quiet.")gopts.opt('path', val='PATH', fn=set_value, default='.:/etc/xen', use="Search path for configuration scripts. " "The value of PATH is a colon-separated directory list.")gopts.opt('defconfig', short='f', val='FILE', fn=set_value, default='xmdefconfig', use="Use the given Python configuration script." "The configuration script is loaded after arguments have been " "processed. Each command-line option sets a configuration " "variable named after its long option name, and these " "variables are placed in the environment of the script before " "it is loaded. Variables for options that may be repeated have " "list values. Other variables can be set using VAR=VAL on the " "command line. " "After the script is loaded, option values that were not set " "on the command line are replaced by the values set in the script.")gopts.default('defconfig')gopts.opt('config', short='F', val='FILE', fn=set_value, default=None, use="Domain configuration to use (SXP).\n" "SXP is the underlying configuration format used by Xen.\n" "SXP configurations can be hand-written or generated from Python " "configuration scripts, using the -n (dryrun) option to print " "the configuration.")gopts.opt('dryrun', short='n', fn=set_true, default=0, use="Dry run - prints the resulting configuration in SXP but " "does not create the domain.")gopts.opt('xmldryrun', short='x', fn=set_true, default=0, use="XML dry run - prints the resulting configuration in XML but " "does not create the domain.")gopts.opt('skipdtd', short='s', fn=set_true, default=0, use="Skip DTD checking - skips checks on XML before creating. " " Experimental. Can decrease create time." )gopts.opt('paused', short='p', fn=set_true, default=0, use='Leave the domain paused after it is created.')gopts.opt('console_autoconnect', short='c', fn=set_true, default=0, use="Connect to the console after the domain is created.")gopts.var('vncpasswd', val='NAME', fn=set_value, default=None, use="Password for VNC console on HVM domain.")gopts.var('vncviewer', val='no|yes', fn=set_bool, default=None, use="Spawn a vncviewer listening for a vnc server in the domain.\n" "The address of the vncviewer is passed to the domain on the " "kernel command line using 'VNC_SERVER=<host>:<port>'. The port " "used by vnc is 5500 + DISPLAY. A display value with a free port " "is chosen if possible.\nOnly valid when vnc=1.")gopts.var('vncconsole', val='no|yes', fn=set_bool, default=None, use="Spawn a vncviewer process for the domain's graphical console.\n" "Only valid when vnc=1.")gopts.var('name', val='NAME', fn=set_value, default=None, use="Domain name. Must be unique.")gopts.var('bootloader', val='FILE', fn=set_value, default=None, use="Path to bootloader.")gopts.var('bootargs', val='NAME', fn=set_value, default=None, use="Arguments to pass to boot loader")gopts.var('bootentry', val='NAME', fn=set_value, default=None, use="DEPRECATED. Entry to boot via boot loader. Use bootargs.")gopts.var('kernel', val='FILE', fn=set_value, default=None, use="Path to kernel image.")gopts.var('ramdisk', val='FILE', fn=set_value, default='', use="Path to ramdisk.")gopts.var('features', val='FEATURES', fn=set_value, default='', use="Features to enable in guest kernel")gopts.var('builder', val='FUNCTION', fn=set_value, default='linux', use="Function to use to build the domain.")gopts.var('memory', val='MEMORY', fn=set_int, default=128, use="Domain memory in MB.")gopts.var('maxmem', val='MEMORY', fn=set_int, default=None, use="Maximum domain memory in MB.")gopts.var('shadow_memory', val='MEMORY', fn=set_int, default=0, use="Domain shadow memory in MB.")gopts.var('cpu', val='CPU', fn=set_int, default=None, use="CPU to run the VCPU0 on.")gopts.var('cpus', val='CPUS', fn=set_value, default=None, use="CPUS to run the domain on.")gopts.var('rtc_timeoffset', val='RTC_TIMEOFFSET', fn=set_value, default="0", use="Set RTC offset.")gopts.var('pae', val='PAE', fn=set_int, default=1, use="Disable or enable PAE of HVM domain.")gopts.var('timer_mode', val='TIMER_MODE', fn=set_int, default=0, use="""Timer mode (0=delay virtual time when ticks are missed; 1=virtual time is always wallclock time.""")gopts.var('acpi', val='ACPI', fn=set_int, default=1, use="Disable or enable ACPI of HVM domain.")gopts.var('apic', val='APIC', fn=set_int, default=1, use="Disable or enable APIC mode.")gopts.var('vcpus', val='VCPUS', fn=set_int, default=1, use="# of Virtual CPUS in domain.")gopts.var('vcpu_avail', val='VCPUS', fn=set_long, default=None, use="Bitmask for virtual CPUs to make available immediately.")gopts.var('vhpt', val='VHPT', fn=set_int, default=0, use="Log2 of domain VHPT size for IA64.")gopts.var('cpu_cap', val='CAP', fn=set_int, default=None, use="""Set the maximum amount of cpu. CAP is a percentage that fixes the maximum amount of cpu.""")gopts.var('cpu_weight', val='WEIGHT', fn=set_int, default=None, use="""Set the cpu time ratio to be allocated to the domain.""")gopts.var('restart', val='onreboot|always|never', fn=set_value, default=None, use="""Deprecated. Use on_poweroff, on_reboot, and on_crash instead. Whether the domain should be restarted on exit. - onreboot: restart on exit with shutdown code reboot - always: always restart on exit, ignore exit code - never: never restart on exit, ignore exit code""")gopts.var('on_poweroff', val='destroy|restart|preserve|rename-restart', fn=set_value, default=None, use="""Behaviour when a domain exits with reason 'poweroff'. - destroy: the domain is cleaned up as normal; - restart: a new domain is started in place of the old one; - preserve: no clean-up is done until the domain is manually destroyed (using xm destroy, for example); - rename-restart: the old domain is not cleaned up, but is renamed and a new domain started in its place. """)gopts.var('on_reboot', val='destroy|restart|preserve|rename-restart', fn=set_value, default=None, use="""Behaviour when a domain exits with reason 'reboot'. - destroy: the domain is cleaned up as normal; - restart: a new domain is started in place of the old one; - preserve: no clean-up is done until the domain is manually destroyed (using xm destroy, for example); - rename-restart: the old domain is not cleaned up, but is renamed and a new domain started in its place. """)gopts.var('on_crash', val='destroy|restart|preserve|rename-restart', fn=set_value, default=None, use="""Behaviour when a domain exits with reason 'crash'. - destroy: the domain is cleaned up as normal; - restart: a new domain is started in place of the old one; - preserve: no clean-up is done until the domain is manually destroyed (using xm destroy, for example); - rename-restart: the old domain is not cleaned up, but is renamed and a new domain started in its place. """)gopts.var('blkif', val='no|yes', fn=set_bool, default=0, use="Make the domain a block device backend.")gopts.var('netif', val='no|yes', fn=set_bool, default=0, use="Make the domain a network interface backend.")gopts.var('tpmif', val='no|yes', fn=append_value, default=0, use="Make the domain a TPM interface backend.")gopts.var('disk', val='phy:DEV,VDEV,MODE[,DOM]', fn=append_value, default=[], use="""Add a disk device to a domain. The physical device is DEV, which is exported to the domain as VDEV. The disk is read-only if MODE is 'r', read-write if MODE is 'w'. If DOM is specified it defines the backend driver domain to use for the disk. The option may be repeated to add more than one disk.""")gopts.var('pci', val='BUS:DEV.FUNC', fn=append_value, default=[], use="""Add a PCI device to a domain, using given params (in hex). For example 'pci=c0:02.1a'. The option may be repeated to add more than one pci device.""")gopts.var('ioports', val='FROM[-TO]', fn=append_value, default=[], use="""Add a legacy I/O range to a domain, using given params (in hex). For example 'ioports=02f8-02ff'. The option may be repeated to add more than one i/o range.""")gopts.var('irq', val='IRQ', fn=append_value, default=[], use="""Add an IRQ (interrupt line) to a domain. For example 'irq=7'. This option may be repeated to add more than one IRQ.""")gopts.var('vfb', val="type={vnc,sdl},vncunused=1,vncdisplay=N,vnclisten=ADDR,display=DISPLAY,xauthority=XAUTHORITY,vncpasswd=PASSWORD", fn=append_value, default=[], use="""Make the domain a framebuffer backend. The backend type should be either sdl or vnc. For type=vnc, connect an external vncviewer. The server will listen on ADDR (default 127.0.0.1) on port N+5900. N defaults to the domain id. If vncunused=1, the server will try to find an arbitrary unused port above 5900. vncpasswd overrides the XenD configured default password. For type=sdl, a viewer will be started automatically using the given DISPLAY and XAUTHORITY, which default to the current user's ones.""")gopts.var('vif', val="type=TYPE,mac=MAC,bridge=BRIDGE,ip=IPADDR,script=SCRIPT," + \ "backend=DOM,vifname=NAME,rate=RATE,model=MODEL,accel=ACCEL", fn=append_value, default=[], use="""Add a network interface with the given MAC address and bridge. The vif is configured by calling the given configuration script. If type is not specified, default is netfront. If mac is not specified a random MAC address is used. If not specified then the network backend chooses it's own MAC address. If bridge is not specified the first bridge found is used. If script is not specified the default script is used. If backend is not specified the default backend driver domain is used. If vifname is not specified the backend virtual interface will have name vifD.N where D is the domain id and N is the interface id. If rate is not specified the default rate is used. If model is not specified the default model is used. If accel is not specified an accelerator plugin module is not used. This option may be repeated to add more than one vif. Specifying vifs will increase the number of interfaces as needed.""")gopts.var('vtpm', val="instance=INSTANCE,backend=DOM,type=TYPE", fn=append_value, default=[], use="""Add a TPM interface. On the backend side use the given instance as virtual TPM instance. The given number is merely the preferred instance number. The hotplug script will determine which instance number will actually be assigned to the domain. The associtation between virtual machine and the TPM instance number can be found in /etc/xen/vtpm.db. Use the backend in the given domain. The type parameter can be used to select a specific driver type that the VM can use. To prevent a fully virtualized domain (HVM) from being able to access an emulated device model, you may specify 'paravirtualized' here.""")gopts.var('access_control', val="policy=POLICY,label=LABEL", fn=append_value, default=[], use="""Add a security label and the security policy reference that defines it. The local ssid reference is calculated when starting/resuming the domain. At this time, the policy is checked against the active policy as well. This way, migrating through save/restore is covered and local labels are automatically created correctly on the system where a domain is started / resumed.""")gopts.var('nics', val="NUM", fn=set_int, default=-1, use="""DEPRECATED. Use empty vif entries instead. Set the number of network interfaces. Use the vif option to define interface parameters, otherwise defaults are used. Specifying vifs will increase the number of interfaces as needed.""")gopts.var('root', val='DEVICE', fn=set_value, default='', use="""Set the root= parameter on the kernel command line. Use a device, e.g. /dev/sda1, or /dev/nfs for NFS root.""")gopts.var('extra', val="ARGS", fn=set_value, default='', use="Set extra arguments to append to the kernel command line.")gopts.var('ip', val='IPADDR', fn=set_value, default='', use="Set the kernel IP interface address.")gopts.var('gateway', val="IPADDR", fn=set_value, default='', use="Set the kernel IP gateway.")gopts.var('netmask', val="MASK", fn=set_value, default = '', use="Set the kernel IP netmask.")gopts.var('hostname', val="NAME", fn=set_value, default='', use="Set the kernel IP hostname.")gopts.var('interface', val="INTF", fn=set_value, default="eth0", use="Set the kernel IP interface name.")gopts.var('dhcp', val="off|dhcp", fn=set_value, default='off', use="Set the kernel dhcp option.")gopts.var('nfs_server', val="IPADDR",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -