[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] tools: cpupools: Rename cpu-pool commands in xm to cpupool-*
# HG changeset patch # User Juergen Gross <juergen.gross@xxxxxxxxxxxxxx> # Date 1287682518 -3600 # Node ID 87e8339826f7170f3edcff3e65b27457e5d6664b # Parent ee0e2acc0d99e7a97f57ef055a6296bf33904247 tools: cpupools: Rename cpu-pool commands in xm to cpupool-* The xm commands pool-* are renamed to cpupool-* The old pool-* commands are defined as aliases. Signed-off-by: juergen.gross@xxxxxxxxxxxxxx Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> --- tools/python/xen/xm/pool-create.py | 51 ------- tools/python/xen/xm/pool-new.py | 50 ------- tools/python/xen/xm/pool.py | 236 ---------------------------------- tools/python/xen/xm/cpupool-create.py | 51 +++++++ tools/python/xen/xm/cpupool-new.py | 50 +++++++ tools/python/xen/xm/cpupool.py | 236 ++++++++++++++++++++++++++++++++++ tools/python/xen/xm/main.py | 143 ++++++++++---------- 7 files changed, 413 insertions(+), 404 deletions(-) diff -r ee0e2acc0d99 -r 87e8339826f7 tools/python/xen/xm/cpupool-create.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xm/cpupool-create.py Thu Oct 21 18:35:18 2010 +0100 @@ -0,0 +1,51 @@ +#============================================================================ +# 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) 2009 Fujitsu Technology Solutions +#============================================================================ + +""" Create a new unmanaged cpupool. +""" + +import sys +from xen.xm.main import serverType, SERVER_XEN_API, server +from xen.xm.cpupool import parseCommandLine, err, help as help_options +from xen.util.sxputils import sxp2map + +def help(): + return help_options() + + +def main(argv): + try: + (opts, config) = parseCommandLine(argv) + except StandardError, ex: + err(str(ex)) + + if not opts: + return + + if serverType == SERVER_XEN_API: + record = sxp2map(config) + if type(record.get('proposed_CPUs', [])) != list: + record['proposed_CPUs'] = [record['proposed_CPUs']] + ref = server.xenapi.cpu_pool.create(record) + if ref: + server.xenapi.cpu_pool.activate(ref) + else: + server.xend.cpu_pool.create(config) + +if __name__ == '__main__': + main(sys.argv) + diff -r ee0e2acc0d99 -r 87e8339826f7 tools/python/xen/xm/cpupool-new.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xm/cpupool-new.py Thu Oct 21 18:35:18 2010 +0100 @@ -0,0 +1,50 @@ +#============================================================================ +# 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) 2009 Fujitsu Technology Solutions +#============================================================================ + +""" Create a new managed cpupool. +""" + +import sys +from xen.xm.main import serverType, SERVER_XEN_API, server +from xen.xm.cpupool import parseCommandLine, err, help as help_options +from xen.util.sxputils import sxp2map + + +def help(): + return help_options() + + +def main(argv): + try: + (opts, config) = parseCommandLine(argv) + except StandardError, ex: + err(str(ex)) + + if not opts: + return + + if serverType == SERVER_XEN_API: + record = sxp2map(config) + if type(record.get('proposed_CPUs', [])) != list: + record['proposed_CPUs'] = [record['proposed_CPUs']] + server.xenapi.cpu_pool.create(record) + else: + server.xend.cpu_pool.new(config) + +if __name__ == '__main__': + main(sys.argv) + diff -r ee0e2acc0d99 -r 87e8339826f7 tools/python/xen/xm/cpupool.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xm/cpupool.py Thu Oct 21 18:35:18 2010 +0100 @@ -0,0 +1,236 @@ +#============================================================================ +# 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) 2009 Fujitsu Technology Solutions +#============================================================================ + +""" Common function of cmds cpupool-new / cpupool-create. +""" + +import sys +import types +import os + +from xen.xend import PrettyPrint +from xen.xend import sxp + +from xen.xm.opts import Opts, set_value, set_true, append_value, OptionError + +GOPTS = Opts(use="""[options] [vars] + +Create a cpupool. + +Pool creation parameters can be set by command-line switches, from +a python configuration script or an SXP config file. See documentation +for --defconfig, --config. Configuration variables can be set using +VAR=VAL on the command line. For example name=Pool-1 sets name to Pool-1. + +""") + +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('path', val='PATH', + fn=set_value, default='.:/etc/xen/cpupool', + 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="CPU pool 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 CPU pool.") + +GOPTS.var('name', val='NAME', fn=set_value, default=None, + use="CPU pool name.") + +GOPTS.var('sched', val='SCHED', fn=set_value, default='credit', + use="Scheduler to use for the CPU pool.") + +GOPTS.var('cpus', val='CPUS', fn=set_value, default=1, + use="CPUS to assign to the CPU pool.") + +GOPTS.var('other_config', val='OTHER_CONFIG', fn=append_value, default=[], + use="Additional info for CPU pool") + + +def sxp2map(sxp_val): + record = {} + for x in sxp_val: + if isinstance(x, (types.ListType, types.TupleType)) \ + and len(x) > 1: + if isinstance(x[1], (types.ListType, types.TupleType)): + record[x[0]] = sxp2map(x[1]) + else: + record[x[0]] = x[1] + return record + +def err(msg): + print >> sys.stderr, "Error: %s" % msg + sys.exit(-1) + +def make_cpus_config(cfg_cpus): + """ Taken from XendConfig. """ + # Convert 'cpus' to list of list of ints + + cpus_list = [] + # Convert the following string to list of ints. + # The string supports a list of ranges (0-3), + # seperated by commas, and negation (^1). + # Precedence is settled by order of the string: + # "0-3,^1" -> [0,2,3] + # "0-3,^1,1" -> [0,1,2,3] + def cnv(s): + l = [] + for c in s.split(','): + if c.find('-') != -1: + (x, y) = c.split('-') + for i in range(int(x), int(y)+1): + l.append(int(i)) + else: + # remove this element from the list + if len(c) > 0: + if c[0] == '^': + l = [x for x in l if x != int(c[1:])] + else: + l.append(int(c)) + return l + + if type(cfg_cpus) == list: + if len(cfg_cpus) > 0 and type(cfg_cpus[0]) == list: + # If sxp_cfg was created from config.sxp, + # the form of 'cpus' is list of list of string. + # Convert 'cpus' to list of list of ints. + # Conversion examples: + # [['1']] -> [[1]] + # [['0','2'],['1','3']] -> [[0,2],[1,3]] + try: + for c1 in cfg_cpus: + cpus = [] + for c2 in c1: + cpus.append(int(c2)) + cpus_list.append(cpus) + except ValueError, e: + raise err('cpus = %s: %s' % (cfg_cpus, e)) + else: + # Conversion examples: + # ["1"] -> [[1]] + # ["0,2","1,3"] -> [[0,2],[1,3]] + # ["0-3,^1","1-4,^2"] -> [[0,2,3],[1,3,4]] + try: + for c in cfg_cpus: + cpus = cnv(c) + cpus_list.append(cpus) + except ValueError, e: + raise err('cpus = %s: %s' % (cfg_cpus, e)) + else: + # Conversion examples: + # cpus=1: + # "1" -> [[1]] + # "0-3,^1" -> [[0,2,3]] + # cpus=2: + # "1" -> [[1],[1]] + # "0-3,^1" -> [[0,2,3],[0,2,3]] + try: + cpus_list = cnv(cfg_cpus) + except ValueError, e: + err('cpus = %s: %s' % (cfg_cpus, e)) + return cpus_list + +def make_config(vals): + config = ['pool'] + config += [['name_label', vals.name]] + config += [['sched_policy', vals.sched]] + if type(vals.cpus) == int: + config += [['ncpu', vals.cpus], ['proposed_CPUs' , []]] + elif type(vals.cpus) == str and len(vals.cpus) > 1 and vals.cpus[0] == '#': + try: + config += [['ncpu', int(vals.cpus[1:])], ['proposed_CPUs' , []]] + except ValueError, ex: + err('Wrong illegal of parameter "cpus"') + else: + prop_cpus = make_cpus_config(vals.cpus) + config += [['ncpu', len(prop_cpus)], + ['proposed_CPUs'] + prop_cpus] + other_config = [] + for entry in vals.other_config: + if '=' in entry: + (var, val) = entry.strip().split('=', 1) + other_config.append([var, val]) + config += [['other_config'] + other_config] + return config + +def parseCommandLine(argv): + GOPTS.reset() + args = GOPTS.parse(argv) + + if GOPTS.vals.help or GOPTS.vals.help_config: + if GOPTS.vals.help_config: + print GOPTS.val_usage() + return (None, None) + + # Process remaining args as config variables. + for arg in args: + if '=' in arg: + (var, val) = arg.strip().split('=', 1) + GOPTS.setvar(var.strip(), val.strip()) + if GOPTS.vals.config: + try: + config = sxp.parse(file(GOPTS.vals.config))[0] + except IOError, ex: + raise OptionError("Cannot read file %s: %s" % (config, ex[1])) + else: + GOPTS.load_defconfig() + if not GOPTS.getopt('name') and GOPTS.getopt('defconfig'): + GOPTS.setopt('name', os.path.basename( + GOPTS.getopt('defconfig'))) + config = make_config(GOPTS.vals) + + if GOPTS.vals.dryrun: + PrettyPrint.prettyprint(config) + return (None, None) + + return (GOPTS, config) + +def help(): + return str(GOPTS) + diff -r ee0e2acc0d99 -r 87e8339826f7 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Thu Oct 21 18:32:56 2010 +0100 +++ b/tools/python/xen/xm/main.py Thu Oct 21 18:35:18 2010 +0100 @@ -242,20 +242,20 @@ SUBCOMMAND_HELP = { 'tmem-shared-auth' : ('[<Domain>|-a|--all] [--uuid=<uuid>] [--auth=<0|1>]', 'De/authenticate shared tmem pool.'), # - # pool commands + # cpupool commands # - 'pool-create' : ('<ConfigFile> [vars]', + 'cpupool-create' : ('<ConfigFile> [vars]', 'Create a CPU pool based an ConfigFile.'), - 'pool-new' : ('<ConfigFile> [vars]', + 'cpupool-new' : ('<ConfigFile> [vars]', 'Adds a CPU pool to Xend CPU pool management'), - 'pool-start' : ('<CPU Pool>', 'Starts a Xend CPU pool'), - 'pool-list' : ('[<CPU Pool>] [-l|--long] [-c|--cpus]', 'List CPU pools on host'), - 'pool-destroy' : ('<CPU Pool>', 'Deactivates a CPU pool'), - 'pool-delete' : ('<CPU Pool>', + 'cpupool-start' : ('<CPU Pool>', 'Starts a Xend CPU pool'), + 'cpupool-list' : ('[<CPU Pool>] [-l|--long] [-c|--cpus]', 'List CPU pools on host'), + 'cpupool-destroy' : ('<CPU Pool>', 'Deactivates a CPU pool'), + 'cpupool-delete' : ('<CPU Pool>', 'Removes a CPU pool from Xend management'), - 'pool-cpu-add' : ('<CPU Pool> <CPU nr>', 'Adds a CPU to a CPU pool'), - 'pool-cpu-remove': ('<CPU Pool> <CPU nr>', 'Removes a CPU from a CPU pool'), - 'pool-migrate' : ('<Domain> <CPU Pool>', + 'cpupool-cpu-add' : ('<CPU Pool> <CPU nr>', 'Adds a CPU to a CPU pool'), + 'cpupool-cpu-remove': ('<CPU Pool> <CPU nr>', 'Removes a CPU from a CPU pool'), + 'cpupool-migrate' : ('<Domain> <CPU Pool>', 'Moves a domain into a CPU pool'), # security @@ -370,7 +370,7 @@ SUBCOMMAND_OPTIONS = { ('-u', '--uuid', 'Specify uuid (abcdef01-2345-6789-01234567890abcdef).'), ('-A', '--auth', '0=auth,1=deauth'), ), - 'pool-list': ( + 'cpupool-list': ( ('-l', '--long', 'Output all CPU pool details in SXP format'), ('-c', '--cpus', 'Output list of CPUs used by a pool'), ), @@ -521,21 +521,21 @@ tmem_commands = [ "tmem-shared-auth", ] -pool_commands = [ - "pool-create", - "pool-new", - "pool-start", - "pool-list", - "pool-destroy", - "pool-delete", - "pool-cpu-add", - "pool-cpu-remove", - "pool-migrate", +cpupool_commands = [ + "cpupool-create", + "cpupool-new", + "cpupool-start", + "cpupool-list", + "cpupool-destroy", + "cpupool-delete", + "cpupool-cpu-add", + "cpupool-cpu-remove", + "cpupool-migrate", ] all_commands = (domain_commands + host_commands + scheduler_commands + device_commands + vnet_commands + security_commands + - acm_commands + flask_commands + tmem_commands + pool_commands + + acm_commands + flask_commands + tmem_commands + cpupool_commands + ['shell', 'event-monitor']) @@ -3625,7 +3625,7 @@ def xm_tmem_shared_auth(args): else: return server.xend.node.tmem_shared_auth(domid,uuid_str,auth) -def get_pool_ref(name): +def get_cpupool_ref(name): refs = server.xenapi.cpu_pool.get_by_name_label(name) if len(refs) > 0: return refs[0] @@ -3633,15 +3633,15 @@ def get_pool_ref(name): err('unknown pool name') sys.exit(1) -def xm_pool_start(args): - arg_check(args, "pool-start", 1) - if serverType == SERVER_XEN_API: - ref = get_pool_ref(args[0]) +def xm_cpupool_start(args): + arg_check(args, "cpupool-start", 1) + if serverType == SERVER_XEN_API: + ref = get_cpupool_ref(args[0]) server.xenapi.cpu_pool.activate(ref) else: server.xend.cpu_pool.start(args[0]) -def brief_pool_list(sxprs): +def brief_cpupool_list(sxprs): format_str = "%-16s %3s %8s %s %s" for sxpr in sxprs: if sxpr == sxprs[0]: @@ -3665,7 +3665,7 @@ def brief_pool_list(sxprs): active = 'n' print format_str % (name, cpu_count, sched_policy, active, vm_count) -def brief_pool_list_cpus(sxprs): +def brief_cpupool_list_cpus(sxprs): format_str = "%-16s %s" for sxpr in sxprs: if sxpr == sxprs[0]: @@ -3685,16 +3685,16 @@ def brief_pool_list_cpus(sxprs): cpus = "-" print format_str % (name, cpus) -def xm_pool_list(args): - arg_check(args, "pool-list", 0, 2) +def xm_cpupool_list(args): + arg_check(args, "cpupool-list", 0, 2) try: (options, params) = getopt.gnu_getopt(args, 'lc', ['long','cpus']) except getopt.GetoptError, opterr: err(opterr) - usage('pool-list') + usage('cpupool-list') if len(params) > 1: - err("Only one pool name for selection allowed") - usage('pool-list') + err("Only one cpupool name for selection allowed") + usage('cpupool-list') use_long = False show_cpus = False @@ -3730,30 +3730,30 @@ def xm_pool_list(args): for sxpr in sxprs: PrettyPrint.prettyprint(sxpr) elif show_cpus: - brief_pool_list_cpus(sxprs) - else: - brief_pool_list(sxprs) - -def xm_pool_destroy(args): - arg_check(args, "pool-destroy", 1) - if serverType == SERVER_XEN_API: - ref = get_pool_ref(args[0]) + brief_cpupool_list_cpus(sxprs) + else: + brief_cpupool_list(sxprs) + +def xm_cpupool_destroy(args): + arg_check(args, "cpupool-destroy", 1) + if serverType == SERVER_XEN_API: + ref = get_cpupool_ref(args[0]) server.xenapi.cpu_pool.deactivate(ref) else: server.xend.cpu_pool.destroy(args[0]) -def xm_pool_delete(args): - arg_check(args, "pool-delete", 1) - if serverType == SERVER_XEN_API: - ref = get_pool_ref(args[0]) +def xm_cpupool_delete(args): + arg_check(args, "cpupool-delete", 1) + if serverType == SERVER_XEN_API: + ref = get_cpupool_ref(args[0]) server.xenapi.cpu_pool.destroy(ref) else: server.xend.cpu_pool.delete(args[0]) -def xm_pool_cpu_add(args): - arg_check(args, "pool-cpu-add", 2) - if serverType == SERVER_XEN_API: - ref = get_pool_ref(args[0]) +def xm_cpupool_cpu_add(args): + arg_check(args, "cpupool-cpu-add", 2) + if serverType == SERVER_XEN_API: + ref = get_cpupool_ref(args[0]) cpu_ref_list = server.xenapi.host_cpu.get_all_records() cpu_ref = [ c_rec['uuid'] for c_rec in cpu_ref_list.values() if c_rec['number'] == args[1] ] @@ -3764,10 +3764,10 @@ def xm_pool_cpu_add(args): else: server.xend.cpu_pool.cpu_add(args[0], args[1]) -def xm_pool_cpu_remove(args): - arg_check(args, "pool-cpu-remove", 2) - if serverType == SERVER_XEN_API: - ref = get_pool_ref(args[0]) +def xm_cpupool_cpu_remove(args): + arg_check(args, "cpupool-cpu-remove", 2) + if serverType == SERVER_XEN_API: + ref = get_cpupool_ref(args[0]) cpu_ref_list = server.xenapi.host_cpu.get_all_records() cpu_ref = [ c_rec['uuid'] for c_rec in cpu_ref_list.values() if c_rec['number'] == args[1] ] @@ -3778,12 +3778,12 @@ def xm_pool_cpu_remove(args): else: server.xend.cpu_pool.cpu_remove(args[0], args[1]) -def xm_pool_migrate(args): - arg_check(args, "pool-migrate", 2) +def xm_cpupool_migrate(args): + arg_check(args, "cpupool-migrate", 2) domname = args[0] poolname = args[1] if serverType == SERVER_XEN_API: - pool_ref = get_pool_ref(poolname) + pool_ref = get_cpupool_ref(poolname) server.xenapi.VM.cpu_pool_migrate(get_single_vm(domname), pool_ref) else: server.xend.cpu_pool.migrate(domname, poolname) @@ -3874,14 +3874,14 @@ commands = { "usb-list-assignable-devices": xm_usb_list_assignable_devices, "usb-hc-create": xm_usb_hc_create, "usb-hc-destroy": xm_usb_hc_destroy, - # pool - "pool-start": xm_pool_start, - "pool-list": xm_pool_list, - "pool-destroy": xm_pool_destroy, - "pool-delete": xm_pool_delete, - "pool-cpu-add": xm_pool_cpu_add, - "pool-cpu-remove": xm_pool_cpu_remove, - "pool-migrate": xm_pool_migrate, + # cpupool + "cpupool-start": xm_cpupool_start, + "cpupool-list": xm_cpupool_list, + "cpupool-destroy": xm_cpupool_destroy, + "cpupool-delete": xm_cpupool_delete, + "cpupool-cpu-add": xm_cpupool_cpu_add, + "cpupool-cpu-remove": xm_cpupool_cpu_remove, + "cpupool-migrate": xm_cpupool_migrate, # tmem "tmem-thaw": xm_tmem_thaw, "tmem-freeze": xm_tmem_freeze, @@ -3915,8 +3915,8 @@ IMPORTED_COMMANDS = [ 'resetpolicy', 'getenforce', 'setenforce', - 'pool-create', - 'pool-new', + 'cpupool-create', + 'cpupool-new', ] for c in IMPORTED_COMMANDS: @@ -3924,6 +3924,15 @@ for c in IMPORTED_COMMANDS: aliases = { "balloon": "mem-set", + "pool-create": "cpupool-create", + "pool-new": "cpupool-new", + "pool-start": "cpupool-start", + "pool-list": "cpupool-list", + "pool-destroy": "cpupool-destroy", + "pool-delete": "cpupool-delete", + "pool-cpu-add": "cpupool-cpu-add", + "pool-cpu-remove": "cpupool-cpu-remove", + "pool-migrate": "cpupool-migrate", "set-vcpus": "vcpu-set", "vif-list": "network-list", "vbd-create": "block-attach", diff -r ee0e2acc0d99 -r 87e8339826f7 tools/python/xen/xm/pool-create.py --- a/tools/python/xen/xm/pool-create.py Thu Oct 21 18:32:56 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -#============================================================================ -# 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) 2009 Fujitsu Technology Solutions -#============================================================================ - -""" Create a new unmanaged pool. -""" - -import sys -from xen.xm.main import serverType, SERVER_XEN_API, server -from xen.xm.pool import parseCommandLine, err, help as help_options -from xen.util.sxputils import sxp2map - -def help(): - return help_options() - - -def main(argv): - try: - (opts, config) = parseCommandLine(argv) - except StandardError, ex: - err(str(ex)) - - if not opts: - return - - if serverType == SERVER_XEN_API: - record = sxp2map(config) - if type(record.get('proposed_CPUs', [])) != list: - record['proposed_CPUs'] = [record['proposed_CPUs']] - ref = server.xenapi.cpu_pool.create(record) - if ref: - server.xenapi.cpu_pool.activate(ref) - else: - server.xend.cpu_pool.create(config) - -if __name__ == '__main__': - main(sys.argv) - diff -r ee0e2acc0d99 -r 87e8339826f7 tools/python/xen/xm/pool-new.py --- a/tools/python/xen/xm/pool-new.py Thu Oct 21 18:32:56 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -#============================================================================ -# 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) 2009 Fujitsu Technology Solutions -#============================================================================ - -""" Create a new managed pool. -""" - -import sys -from xen.xm.main import serverType, SERVER_XEN_API, server -from xen.xm.pool import parseCommandLine, err, help as help_options -from xen.util.sxputils import sxp2map - - -def help(): - return help_options() - - -def main(argv): - try: - (opts, config) = parseCommandLine(argv) - except StandardError, ex: - err(str(ex)) - - if not opts: - return - - if serverType == SERVER_XEN_API: - record = sxp2map(config) - if type(record.get('proposed_CPUs', [])) != list: - record['proposed_CPUs'] = [record['proposed_CPUs']] - server.xenapi.cpu_pool.create(record) - else: - server.xend.cpu_pool.new(config) - -if __name__ == '__main__': - main(sys.argv) - diff -r ee0e2acc0d99 -r 87e8339826f7 tools/python/xen/xm/pool.py --- a/tools/python/xen/xm/pool.py Thu Oct 21 18:32:56 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,236 +0,0 @@ -#============================================================================ -# 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) 2009 Fujitsu Technology Solutions -#============================================================================ - -""" Common function of cmds pool-new / pool-create. -""" - -import sys -import types -import os - -from xen.xend import PrettyPrint -from xen.xend import sxp - -from xen.xm.opts import Opts, set_value, set_true, append_value, OptionError - -GOPTS = Opts(use="""[options] [vars] - -Create a pool. - -Pool creation parameters can be set by command-line switches, from -a python configuration script or an SXP config file. See documentation -for --defconfig, --config. Configuration variables can be set using -VAR=VAL on the command line. For example name=Pool-1 sets name to Pool-1. - -""") - -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('path', val='PATH', - fn=set_value, default='.:/etc/xen/pool', - 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="CPU pool 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 CPU pool.") - -GOPTS.var('name', val='NAME', fn=set_value, default=None, - use="CPU pool name.") - -GOPTS.var('sched', val='SCHED', fn=set_value, default='credit', - use="Scheduler to use for the CPU pool.") - -GOPTS.var('cpus', val='CPUS', fn=set_value, default=1, - use="CPUS to assign to the CPU pool.") - -GOPTS.var('other_config', val='OTHER_CONFIG', fn=append_value, default=[], - use="Additional info for CPU pool") - - -def sxp2map(sxp_val): - record = {} - for x in sxp_val: - if isinstance(x, (types.ListType, types.TupleType)) \ - and len(x) > 1: - if isinstance(x[1], (types.ListType, types.TupleType)): - record[x[0]] = sxp2map(x[1]) - else: - record[x[0]] = x[1] - return record - -def err(msg): - print >> sys.stderr, "Error: %s" % msg - sys.exit(-1) - -def make_cpus_config(cfg_cpus): - """ Taken from XendConfig. """ - # Convert 'cpus' to list of list of ints - - cpus_list = [] - # Convert the following string to list of ints. - # The string supports a list of ranges (0-3), - # seperated by commas, and negation (^1). - # Precedence is settled by order of the string: - # "0-3,^1" -> [0,2,3] - # "0-3,^1,1" -> [0,1,2,3] - def cnv(s): - l = [] - for c in s.split(','): - if c.find('-') != -1: - (x, y) = c.split('-') - for i in range(int(x), int(y)+1): - l.append(int(i)) - else: - # remove this element from the list - if len(c) > 0: - if c[0] == '^': - l = [x for x in l if x != int(c[1:])] - else: - l.append(int(c)) - return l - - if type(cfg_cpus) == list: - if len(cfg_cpus) > 0 and type(cfg_cpus[0]) == list: - # If sxp_cfg was created from config.sxp, - # the form of 'cpus' is list of list of string. - # Convert 'cpus' to list of list of ints. - # Conversion examples: - # [['1']] -> [[1]] - # [['0','2'],['1','3']] -> [[0,2],[1,3]] - try: - for c1 in cfg_cpus: - cpus = [] - for c2 in c1: - cpus.append(int(c2)) - cpus_list.append(cpus) - except ValueError, e: - raise err('cpus = %s: %s' % (cfg_cpus, e)) - else: - # Conversion examples: - # ["1"] -> [[1]] - # ["0,2","1,3"] -> [[0,2],[1,3]] - # ["0-3,^1","1-4,^2"] -> [[0,2,3],[1,3,4]] - try: - for c in cfg_cpus: - cpus = cnv(c) - cpus_list.append(cpus) - except ValueError, e: - raise err('cpus = %s: %s' % (cfg_cpus, e)) - else: - # Conversion examples: - # cpus=1: - # "1" -> [[1]] - # "0-3,^1" -> [[0,2,3]] - # cpus=2: - # "1" -> [[1],[1]] - # "0-3,^1" -> [[0,2,3],[0,2,3]] - try: - cpus_list = cnv(cfg_cpus) - except ValueError, e: - err('cpus = %s: %s' % (cfg_cpus, e)) - return cpus_list - -def make_config(vals): - config = ['pool'] - config += [['name_label', vals.name]] - config += [['sched_policy', vals.sched]] - if type(vals.cpus) == int: - config += [['ncpu', vals.cpus], ['proposed_CPUs' , []]] - elif type(vals.cpus) == str and len(vals.cpus) > 1 and vals.cpus[0] == '#': - try: - config += [['ncpu', int(vals.cpus[1:])], ['proposed_CPUs' , []]] - except ValueError, ex: - err('Wrong illegal of parameter "cpus"') - else: - prop_cpus = make_cpus_config(vals.cpus) - config += [['ncpu', len(prop_cpus)], - ['proposed_CPUs'] + prop_cpus] - other_config = [] - for entry in vals.other_config: - if '=' in entry: - (var, val) = entry.strip().split('=', 1) - other_config.append([var, val]) - config += [['other_config'] + other_config] - return config - -def parseCommandLine(argv): - GOPTS.reset() - args = GOPTS.parse(argv) - - if GOPTS.vals.help or GOPTS.vals.help_config: - if GOPTS.vals.help_config: - print GOPTS.val_usage() - return (None, None) - - # Process remaining args as config variables. - for arg in args: - if '=' in arg: - (var, val) = arg.strip().split('=', 1) - GOPTS.setvar(var.strip(), val.strip()) - if GOPTS.vals.config: - try: - config = sxp.parse(file(GOPTS.vals.config))[0] - except IOError, ex: - raise OptionError("Cannot read file %s: %s" % (config, ex[1])) - else: - GOPTS.load_defconfig() - if not GOPTS.getopt('name') and GOPTS.getopt('defconfig'): - GOPTS.setopt('name', os.path.basename( - GOPTS.getopt('defconfig'))) - config = make_config(GOPTS.vals) - - if GOPTS.vals.dryrun: - PrettyPrint.prettyprint(config) - return (None, None) - - return (GOPTS, config) - -def help(): - return str(GOPTS) - _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |