⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.py

📁 xen虚拟机源代码安装包
💻 PY
📖 第 1 页 / 共 5 页
字号:
# (C) Copyright IBM Corp. 2005# Copyright (C) 2004 Mike Wray# Copyright (c) 2005-2006 XenSource Ltd.## Authors:#     Sean Dague <sean at dague dot net>#     Mike Wray <mike dot wray at hp dot com>## 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"""Grand unified management application for Xen."""import atexitimport cmdimport osimport pprintimport shleximport sysimport reimport getoptimport socketimport tracebackimport xmlrpclibimport timeimport datetimefrom select import selectimport xml.dom.minidomfrom xen.util.blkif import blkdev_name_to_numberfrom xen.util import vscsi_utilfrom xen.util.pci import *import warningswarnings.filterwarnings('ignore', category=FutureWarning)from xen.xend import PrettyPrintfrom xen.xend import sxpfrom xen.xend import XendClientfrom xen.xend.XendConstants import *from xen.xm.opts import OptionError, Opts, wrap, set_truefrom xen.xm import consolefrom xen.util.xmlrpcclient import ServerProxyimport xen.util.xsm.xsm as securityfrom xen.util.xsm.xsm import XSMErrorfrom xen.util.acmpolicy import ACM_LABEL_UNLABELED_DISPLAYimport XenAPIimport xen.lowlevel.xcxc = xen.lowlevel.xc.xc()import inspectfrom xen.xend import XendOptionsxoptions = XendOptions.instance()import signalsignal.signal(signal.SIGINT, signal.SIG_DFL)# getopt.gnu_getopt is better, but only exists in Python 2.3+.  Use# getopt.getopt if gnu_getopt is not available.  This will mean that options# may only be specified before positional arguments.if not hasattr(getopt, 'gnu_getopt'):    getopt.gnu_getopt = getopt.getoptXM_CONFIG_FILE_ENVVAR = 'XM_CONFIG_FILE'XM_CONFIG_FILE_DEFAULT = '/etc/xen/xm-config.xml'# Supported types of serverSERVER_LEGACY_XMLRPC = 'LegacyXMLRPC'SERVER_XEN_API = 'Xen-API'# General help messageUSAGE_HELP = "Usage: xm <subcommand> [args]\n\n" \             "Control, list, and manipulate Xen guest instances.\n"USAGE_FOOTER = '<Domain> can either be the Domain Name or Id.\n' \               'For more help on \'xm\' see the xm(1) man page.\n' \               'For more help on \'xm create\' see the xmdomain.cfg(5) '\               ' man page.\n'# Help strings are indexed by subcommand name in this way:# 'subcommand': (argstring, description)SUBCOMMAND_HELP = {    # common commands    'shell'       : ('', 'Launch an interactive shell.'),        'console'     : ('[-q|--quiet] <Domain>',                     'Attach to <Domain>\'s console.'),    'vncviewer'   : ('[--[vncviewer-]autopass] <Domain>',                     'Attach to <Domain>\'s VNC server.'),    'create'      : ('<ConfigFile> [options] [vars]',                     'Create a domain based on <ConfigFile>.'),    'destroy'     : ('<Domain>',                     'Terminate a domain immediately.'),    'help'        : ('', 'Display this message.'),    'list'        : ('[options] [Domain, ...]',                     'List information about all/some domains.'),    'mem-max'     : ('<Domain> <Mem>',                     'Set the maximum amount reservation for a domain.'),    'mem-set'     : ('<Domain> <Mem>',                     'Set the current memory usage for a domain.'),    'migrate'     : ('<Domain> <Host>',                     'Migrate a domain to another machine.'),    'pause'       : ('<Domain>', 'Pause execution of a domain.'),    'reboot'      : ('<Domain> [-wa]', 'Reboot a domain.'),    'reset'       : ('<Domain>', 'Reset a domain.'),    'restore'     : ('<CheckpointFile> [-p]',                     'Restore a domain from a saved state.'),    'save'        : ('[-c] <Domain> <CheckpointFile>',                     'Save a domain state to restore later.'),    'shutdown'    : ('<Domain> [-waRH]', 'Shutdown a domain.'),    'top'         : ('', 'Monitor a host and the domains in real time.'),    'unpause'     : ('<Domain>', 'Unpause a paused domain.'),    'uptime'      : ('[-s] [Domain, ...]',                     'Print uptime for all/some domains.'),    # Life cycle xm commands    'new'         : ('<ConfigFile> [options] [vars]',                     'Adds a domain to Xend domain management'),    'delete'      : ('<DomainName>',                     'Remove a domain from Xend domain management.'),    'start'       : ('<DomainName>', 'Start a Xend managed domain'),    'resume'      : ('<DomainName>', 'Resume a Xend managed domain'),    'suspend'     : ('<DomainName>', 'Suspend a Xend managed domain'),    # less used commands    'dmesg'       : ('[-c|--clear]',                     'Read and/or clear Xend\'s message buffer.'),    'domid'       : ('<DomainName>', 'Convert a domain name to domain id.'),    'domname'     : ('<DomId>', 'Convert a domain id to domain name.'),    'dump-core'   : ('[-L|--live] [-C|--crash] [-R|--reset] <Domain> [Filename]',                     'Dump core for a specific domain.'),    'info'        : ('[-c|--config]', 'Get information about Xen host.'),    'log'         : ('', 'Print Xend log'),    'rename'      : ('<Domain> <NewDomainName>', 'Rename a domain.'),    'sched-sedf'  : ('<Domain> [options]', 'Get/set EDF parameters.'),    'sched-credit': ('[-d <Domain> [-w[=WEIGHT]|-c[=CAP]]]',                     'Get/set credit scheduler parameters.'),    'sysrq'       : ('<Domain> <letter>', 'Send a sysrq to a domain.'),    'debug-keys'  : ('<Keys>', 'Send debug keys to Xen.'),    'trigger'     : ('<Domain> <nmi|reset|init|s3resume> [<VCPU>]',                     'Send a trigger to a domain.'),    'vcpu-list'   : ('[Domain, ...]',                     'List the VCPUs for all/some domains.'),    'vcpu-pin'    : ('<Domain> <VCPU|all> <CPUs|all>',                     'Set which CPUs a VCPU can use.'),    'vcpu-set'    : ('<Domain> <vCPUs>',                     'Set the number of active VCPUs for allowed for the'                     ' domain.'),    # device commands    'block-attach'  :  ('<Domain> <BackDev> <FrontDev> <Mode> [BackDomain]',                        'Create a new virtual block device.'),    'block-configure': ('<Domain> <BackDev> <FrontDev> <Mode> [BackDomain]',                        'Change block device configuration'),    'block-detach'  :  ('<Domain> <DevId> [-f|--force]',                        'Destroy a domain\'s virtual block device.'),    'block-list'    :  ('<Domain> [--long]',                        'List virtual block devices for a domain.'),    'network-attach':  ('<Domain> [type=<type>] [mac=<mac>] [bridge=<bridge>] '                        '[ip=<ip>] [script=<script>] [backend=<BackDomain>] '                        '[vifname=<name>] [rate=<rate>] [model=<model>]'                        '[accel=<accel>]',                        'Create a new virtual network device.'),    'network-detach':  ('<Domain> <DevId> [-f|--force]',                        'Destroy a domain\'s virtual network device.'),    'network-list'  :  ('<Domain> [--long]',                        'List virtual network interfaces for a domain.'),    'vnet-create'   :  ('<ConfigFile>','Create a vnet from ConfigFile.'),    'vnet-delete'   :  ('<VnetId>', 'Delete a Vnet.'),    'vnet-list'     :  ('[-l|--long]', 'List Vnets.'),    'vtpm-list'     :  ('<Domain> [--long]', 'List virtual TPM devices.'),    'pci-attach'    :  ('<Domain> <domain:bus:slot.func> [virtual slot]',                        'Insert a new pass-through pci device.'),    'pci-detach'    :  ('<Domain> <domain:bus:slot.func>',                        'Remove a domain\'s pass-through pci device.'),    'pci-list'      :  ('<Domain>',                        'List pass-through pci devices for a domain.'),    'pci-list-assignable-devices' : ('', 'List all the assignable pci devices'),    'scsi-attach'  :  ('<Domain> <PhysDevice> <VirtDevice> [BackDomain]',                        'Attach a new SCSI device.'),    'scsi-detach'  :  ('<Domain> <VirtDevice>',                        'Detach a specified SCSI device.'),    'scsi-list'    :  ('<Domain> [--long]',                        'List all SCSI devices currently attached.'),    # security    'addlabel'      :  ('<label> {dom <ConfigFile>|res <resource>|mgt <managed domain>}\n'                        '                   [<policy>]',                        'Add security label to domain.'),    'rmlabel'       :  ('{dom <ConfigFile>|res <Resource>|mgt<managed domain>}',                        'Remove a security label from domain.'),    'getlabel'      :  ('{dom <ConfigFile>|res <Resource>|mgt <managed domain>}',                        'Show security label for domain or resource.'),    'dry-run'       :  ('<ConfigFile>',                        'Test if a domain can access its resources.'),    'resources'     :  ('', 'Show info for each labeled resource.'),    'dumppolicy'    :  ('', 'Print hypervisor ACM state information.'),    'setpolicy'     :  ('<policytype> <policyfile> [options]',                        'Set the policy of the system.'),    'resetpolicy'   :  ('',                        'Set the policy of the system to the default policy.'),    'getpolicy'     :  ('[options]', 'Get the policy of the system.'),    'labels'        :  ('[policy] [type=dom|res|any]',                        'List <type> labels for (active) policy.'),    'serve'         :  ('', 'Proxy Xend XMLRPC over stdio.'),}SUBCOMMAND_OPTIONS = {    'sched-sedf': (       ('-p [MS]', '--period[=MS]', 'Relative deadline(ms)'),       ('-s [MS]', '--slice[=MS]' ,        'Worst-case execution time(ms). (slice < period)'),       ('-l [MS]', '--latency[=MS]',        'Scaled period (ms) when domain performs heavy I/O'),       ('-e [FLAG]', '--extra[=FLAG]',        'Flag (0 or 1) controls if domain can run in extra time.'),       ('-w [FLOAT]', '--weight[=FLOAT]',        'CPU Period/slice (do not set with --period/--slice)'),    ),    'sched-credit': (       ('-d DOMAIN', '--domain=DOMAIN', 'Domain to modify'),       ('-w WEIGHT', '--weight=WEIGHT', 'Weight (int)'),       ('-c CAP',    '--cap=CAP',       'Cap (int)'),    ),    'list': (       ('-l', '--long',         'Output all VM details in SXP'),       ('', '--label',          'Include security labels'),       ('', '--state=<state>',  'Select only VMs with the specified state'),    ),    'console': (       ('-q', '--quiet', 'Do not print an error message if the domain does not exist'),    ),    'vncviewer': (       ('', '--autopass', 'Pass VNC password to viewer via stdin and -autopass'),       ('', '--vncviewer-autopass', '(consistency alias for --autopass)'),    ),    'dmesg': (       ('-c', '--clear', 'Clear dmesg buffer as well as printing it'),    ),    'vnet-list': (       ('-l', '--long', 'List Vnets as SXP'),    ),    'network-list': (       ('-l', '--long', 'List resources as SXP'),    ),    'dump-core': (       ('-L', '--live', 'Dump core without pausing the domain'),       ('-C', '--crash', 'Crash domain after dumping core'),       ('-R', '--reset', 'Reset domain after dumping core'),    ),    'start': (       ('-p', '--paused', 'Do not unpause domain after starting it'),       ('-c', '--console_autoconnect', 'Connect to the console after the domain is created'),       ('', '--vncviewer', 'Connect to display via VNC after the domain is created'),       ('', '--vncviewer-autopass', 'Pass VNC password to viewer via stdin and -autopass'),    ),    'resume': (       ('-p', '--paused', 'Do not unpause domain after resuming it'),    ),    'save': (       ('-c', '--checkpoint', 'Leave domain running after creating snapshot'),    ),    'restore': (       ('-p', '--paused', 'Do not unpause domain after restoring it'),    ),    'info': (       ('-c', '--config', 'List Xend configuration parameters'),    ),}common_commands = [    "console",    "vncviewer",    "create",    "new",    "delete",    "destroy",    "dump-core",    "help",    "list",    "mem-set",    "migrate",    "pause",    "reboot",    "reset",    "restore",    "resume",    "save",    "shell",    "shutdown",    "start",    "suspend",    "top",    "unpause",    "uptime",    "vcpu-set",    ]domain_commands = [    "console",    "vncviewer",    "create",    "new",    "delete",    "destroy",    "domid",    "domname",    "dump-core",    "list",    "mem-max",    "mem-set",    "migrate",    "pause",    "reboot",    "rename",    "reset",    "restore",    "resume",    "save",    "shutdown",    "start",    "suspend",    "sysrq",    "trigger",    "top",    "unpause",    "uptime",    "vcpu-list",    "vcpu-pin",    "vcpu-set",    ]host_commands = [    "debug-keys",    "dmesg",    "info",    "log",    "serve",    ]scheduler_commands = [    "sched-credit",    "sched-sedf",    ]device_commands = [    "block-attach",    "block-detach",    "block-list",    "block-configure",    "network-attach",    "network-detach",    "network-list",    "vtpm-list",    "pci-attach",    "pci-detach",    "pci-list",    "pci-list-assignable-devices",    "scsi-attach",    "scsi-detach",    "scsi-list",    ]vnet_commands = [    "vnet-list",    "vnet-create",    "vnet-delete",    ]acm_commands = [    "labels",    "addlabel",    "rmlabel",    "getlabel",    "dry-run",    "resources",    "dumppolicy",    "setpolicy",    "resetpolicy",    "getpolicy",    ]all_commands = (domain_commands + host_commands + scheduler_commands +                device_commands + vnet_commands + acm_commands +                ['shell', 'event-monitor'])### Configuration File Parsing##xmConfigFile = os.getenv(XM_CONFIG_FILE_ENVVAR, XM_CONFIG_FILE_DEFAULT)config = Noneif os.path.isfile(xmConfigFile):    try:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -