ia64/xen-unstable

changeset 1061:9ccd60698e09

bitkeeper revision 1.700 (401d7e17TsVIdmq0QNgdFLXJHFN1kg)

transfer new domain tools and readmes from the 1.2 tree
author iap10@labyrinth.cl.cam.ac.uk
date Sun Feb 01 22:30:47 2004 +0000 (2004-02-01)
parents a4c34e4a7c07
children ff3df62df71e
files .rootkeys README README.CD tools/Makefile tools/examples/Makefile tools/examples/README tools/examples/defaults tools/examples/democd tools/examples/xc_dom_control.py tools/examples/xc_dom_create.py tools/examples/xc_vd_tool.py tools/misc/Makefile tools/misc/xen_dmesg.py tools/misc/xen_nat_enable tools/xc/py/Makefile tools/xc/py/XenoUtil.py
line diff
     1.1 --- a/.rootkeys	Sat Jan 31 19:45:13 2004 +0000
     1.2 +++ b/.rootkeys	Sun Feb 01 22:30:47 2004 +0000
     1.3 @@ -40,8 +40,12 @@ 3f776bd1Hy9rn69ntXBhPReUFw9IEA tools/Mak
     1.4  3e6377b24eQqYMsDi9XrFkIgTzZ47A tools/balloon/Makefile
     1.5  3e6377d6eiFjF1hHIS6JEIOFk62xSA tools/balloon/README
     1.6  3e6377dbGcgnisKw16DPCaND7oGO3Q tools/balloon/balloon.c
     1.7 +401d7e160vaxMBAUSLSicuZ7AQjJ3w tools/examples/Makefile
     1.8 +401d7e16UgeqroJQTIhwkrDVkoWgZQ tools/examples/README
     1.9  40083bb4_j61quzxosgZ19LUgLlgYw tools/examples/add_vbd_to_dom.py
    1.10  3fbe2f12OPAkzIUtumU3wRAihnhocQ tools/examples/createlinuxdom.py
    1.11 +401d7e16GS8YesM1zateRbaOoI6YLQ tools/examples/defaults
    1.12 +401d7e16NoWaBGC1RXbBcqAOr5Uaag tools/examples/democd
    1.13  3fbe2f12dZbmXLlgQdMgkmnSUj23AQ tools/examples/destroydom.py
    1.14  40083bb4lxCIf5HRu6fwWUyHCYOHKA tools/examples/list_vbds.py
    1.15  3fbe2f12ltvweb13kBSsxqzZDAq4sg tools/examples/listdoms.py
    1.16 @@ -59,6 +63,9 @@ 400c774eVfeVCkLn34s-Lh4-6jBXWw tools/exa
    1.17  40083bb4NhDpKiYTrebI3ZjX__oI_w tools/examples/vd_refresh.py
    1.18  400c774eXs8hWKK70ZYzi1ScKiSjPQ tools/examples/vd_to_file.py
    1.19  400c33001-uDKTfHBchTKUwuMFcqTA tools/examples/vd_undelete.py
    1.20 +401d7e16NpnVrFSsR7lKKKfTwCYvWA tools/examples/xc_dom_control.py
    1.21 +401d7e16RJj-lbtsVEjua6HYAIiKiA tools/examples/xc_dom_create.py
    1.22 +401d7e16X4iojyKopo_j63AyzYZd2A tools/examples/xc_vd_tool.py
    1.23  3f776bd2Xd-dUcPKlPN2vG89VGtfvQ tools/misc/Makefile
    1.24  3f6dc136ZKOjd8PIqLbFBl_v-rnkGg tools/misc/miniterm/Makefile
    1.25  3f6dc140C8tAeBfroAF24VrmCS4v_w tools/misc/miniterm/README
    1.26 @@ -68,6 +75,7 @@ 3f5ef5a2ir1kVAthS14Dc5QIRCEFWg tools/mis
    1.27  3f5ef5a2dTZP0nnsFoeq2jRf3mWDDg tools/misc/xen-clone.README
    1.28  3f1668d4-FUY6Enc7MB3GcwUtfJ5HA tools/misc/xen-mkdevnodes
    1.29  3f870808zS6T6iFhqYPGelroZlVfGQ tools/misc/xen_cpuperf.c
    1.30 +401d7e16hWEsgEnMwbPM9sKyInomWw tools/misc/xen_dmesg.py
    1.31  3f8bcf29ulZIC9rC4wM70H_q4s6VPg tools/misc/xen_log.c
    1.32  3f13d81eQ9Vz-h-6RDGFkNR9CRP95g tools/misc/xen_nat_enable
    1.33  3f13d81e6Z6806ihYYUw8GVKNkYnuw tools/misc/xen_nat_enable.README
     2.1 --- a/README	Sat Jan 31 19:45:13 2004 +0000
     2.2 +++ b/README	Sun Feb 01 22:30:47 2004 +0000
     2.3 @@ -1,23 +1,23 @@
     2.4  #############################
     2.5 - __  __            _   ___  
     2.6 - \ \/ /___ _ __   / | / _ \ 
     2.7 -  \  // _ \ '_ \  | || | | |
     2.8 -  /  \  __/ | | | | || |_| |
     2.9 - /_/\_\___|_| |_| |_(_)___/ 
    2.10 -                                                   
    2.11 + __  __            _   ____  
    2.12 + \ \/ /___ _ __   / | |___ \ 
    2.13 +  \  // _ \ '_ \  | |   __) |
    2.14 +  /  \  __/ | | | | |_ / __/ 
    2.15 + /_/\_\___|_| |_| |_(_)_____|
    2.16 +                                              
    2.17  #############################
    2.18  
    2.19  University of Cambridge Computer Laboratory
    2.20 -31 Aug 2003
    2.21 +30 Jan 2004
    2.22  
    2.23  http://www.cl.cam.ac.uk/netos/xen
    2.24  
    2.25  About the Xen Virtual Machine Monitor
    2.26  =====================================
    2.27  
    2.28 -"Xen" is a Virtual Machine Monitor (VMM) developed by the Systems
    2.29 -Research Group of the University of Cambridge Computer Laboratory, as
    2.30 -part of the UK-EPSRC funded XenoServers project.
    2.31 +"Xen" is a Virtual Machine Monitor (VMM) originally developed by the
    2.32 +Systems Research Group of the University of Cambridge Computer
    2.33 +Laboratory, as part of the UK-EPSRC funded XenoServers project. 
    2.34  
    2.35  The XenoServers project aims to provide a "public infrastructure for
    2.36  global distributed computing", and Xen plays a key part in that,
    2.37 @@ -54,7 +54,7 @@ tricky to handle. A good description of 
    2.38  and performance is contained in our October 2003 SOSP paper, available
    2.39  at http://www.cl.cam.ac.uk/netos/papers/2003-xensosp.pdf
    2.40  
    2.41 -We have been working on porting 3 different operating systems to run
    2.42 +We have worked on porting 3 different operating systems to run
    2.43  on Xen: Linux 2.4, Windows XP, and NetBSD.
    2.44  
    2.45  The Linux 2.4 port (currently Linux 2.4.22) works very well -- we
    2.46 @@ -65,10 +65,10 @@ tried.  We refer to our version of Linux
    2.47  virtual CPU architecture that we call xeno-x86 (abbreviated to just
    2.48  "xeno").
    2.49  
    2.50 -Unfortunately, the NetBSD port has stalled due to lack of man
    2.51 -power. We believe most of the hard stuff has already been done, and
    2.52 -are hoping to get the ball rolling again soon. In hindsight, a FreeBSD
    2.53 -4 port might have been more useful to the community. Any volunteers? :-)
    2.54 +NetBSD has been ported to Xen by Christian Limpach, and will hopefully
    2.55 +soon become part of the standard release. Work on a FreeBSD port has
    2.56 +been started by Kip Macy, and we hope to see this complete for the 1.3
    2.57 +release.
    2.58  
    2.59  The Windows XP port is nearly finished. It's running user space
    2.60  applications and is generally in pretty good shape thanks to some hard
    2.61 @@ -134,26 +134,32 @@ recommended since they require extra pac
    2.62  Building Xen and XenoLinux
    2.63  ==========================
    2.64  
    2.65 -The public master BK repository for the 1.0 release lives at: 
    2.66 -bk://xen.bkbits.net/xeno-1.0.bk
    2.67 +The public master BK repository for the 1.2 release lives at: 
    2.68 +bk://xen.bkbits.net/xeno-1.2.bk
    2.69  
    2.70  To fetch a local copy, install the BitKeeper tools, then run: 
    2.71 -'bk clone bk://xen.bkbits.net/xeno-1.0.bk'
    2.72 +'bk clone bk://xen.bkbits.net/xeno-1.2.bk'
    2.73  
    2.74  To see how to build Xen, Xenolinux, and all the control tools, inspect
    2.75 -the tools/misc/xen-clone script in the BK repository. This script can
    2.76 -be used to clone the repostitory and perform a full build.
    2.77 +the tools/misc/xen-clone script in the BK repository (also available
    2.78 +via http://www.cl.cam.ac.uk/netos/xen/readmes/xen-clone). This script
    2.79 +can be used to clone the repository and perform a full build.
    2.80  
    2.81  The build procedure for xenolinux is slightly complicated as its done
    2.82  by running the 'mkbuildtree' script over a pristine Linux tree to turn
    2.83  it into a xenolinux tree by adding the 'xeno' architecture.
    2.84  
    2.85 -There's also a pre-built source tree on the project downloads page.
    2.86 +There's also a recent pre-built source tree on the project downloads
    2.87 +page: http://www.cl.cam.ac.uk/netos/xen/downloads/xeno-1.2.tar.gz
    2.88  
    2.89  
    2.90  Using the domain control tools
    2.91  ==============================
    2.92  
    2.93 -See example Python scripts in tools/examples/
    2.94 +README.CD contains some example invocations.
    2.95 +
    2.96 +See example Python scripts in tools/examples/ and the associated README.
    2.97  
    2.98 -Further documentation is in docs/ (e.g., docs/Xeno-HOWTO).
    2.99 +Further documentation is in docs/ (e.g., docs/Xeno-HOWTO), and also in
   2.100 +
   2.101 +
     3.1 --- a/README.CD	Sat Jan 31 19:45:13 2004 +0000
     3.2 +++ b/README.CD	Sun Feb 01 22:30:47 2004 +0000
     3.3 @@ -1,15 +1,15 @@
     3.4  #############################
     3.5 - __  __            _   ___  
     3.6 - \ \/ /___ _ __   / | / _ \ 
     3.7 -  \  // _ \ '_ \  | || | | |
     3.8 -  /  \  __/ | | | | || |_| |
     3.9 - /_/\_\___|_| |_| |_(_)___/ 
    3.10 -                                                   
    3.11 + __  __            _   ____  
    3.12 + \ \/ /___ _ __   / | |___ \ 
    3.13 +  \  // _ \ '_ \  | |   __) |
    3.14 +  /  \  __/ | | | | |_ / __/ 
    3.15 + /_/\_\___|_| |_| |_(_)_____|
    3.16 +                                              
    3.17  #############################
    3.18  
    3.19 - XenDemoCD 1.0 
    3.20 + XenDemoCD 1.2
    3.21   University of Cambridge Computer Laboratory
    3.22 - 29 Sep 2003
    3.23 + 24 Jan 2004
    3.24  
    3.25   http://www.cl.cam.ac.uk/netos/xen
    3.26  
    3.27 @@ -36,7 +36,7 @@ hardware:
    3.28  
    3.29  CPU:  Pentium Pro/II/III/IV/Xeon, Athlon (i.e. P6 or newer) SMP supported
    3.30  IDE:  Intel PIIX chipset, others will be PIO only (slow)
    3.31 -SCSI: Adaptec / Dell PERC Raid (aacraid), megaraid, Adaptec aic7xxx
    3.32 +SCSI: Adaptec / Dell PERC Raid (aacraid), fusion MPT, megaraid, Adaptec aic7xxx
    3.33  Net:  Recommended: Intel e1000, Broadcom BCM57xx (tg3), 3c905 (3c59x)
    3.34        Working, but require extra copies : pcnet32, Intel e100, tulip
    3.35  
    3.36 @@ -47,9 +47,9 @@ To try out the Demo, boot from CD (you m
    3.37  configuration to do this), then select one of the four boot options 
    3.38  from the Grub menu:
    3.39  
    3.40 - Xen / linux-2.4.22 
    3.41 - Xen / linux-2.4.22 using cmdline IP configuration
    3.42 - Xen / linux-2.4.22 in "safe mode"
    3.43 + Xen / linux-2.4.24
    3.44 + Xen / linux-2.4.24 using cmdline IP configuration
    3.45 + Xen / linux-2.4.24 in "safe mode"
    3.46   linux-2.4.22
    3.47  
    3.48  The last option is a plain linux kernel that runs on the bare machine,
    3.49 @@ -91,13 +91,13 @@ via ssh::
    3.50  Once logged in, it should look just like any regular linux box. All
    3.51  the usual tools and commands should work as per usual.  However,
    3.52  because of the poor random access performance of CD drives, the
    3.53 -machine will feel rather slugish, and you may run out of memory if you
    3.54 +machine will feel very slugish, and you may run out of memory if you
    3.55  make significant modifications to the ramfs filesystem -- for the full
    3.56  experience, install a Xen and XenoLinux image on you hard drive :-)
    3.57  
    3.58  You can configure networking, either with 'dhclient' or manually via
    3.59  'ifconfig' and 'route', remembering to edit /etc/resolv.conf if you
    3.60 -want DNS.
    3.61 +want DNS to work.
    3.62  
    3.63  You can start an X server with 'startx'. It defaults to a conservative
    3.64  1024x768, but you can edit the script for higher resoloutions.  The CD
    3.65 @@ -115,100 +115,189 @@ work with Xen, and you'll only be able t
    3.66  server. We're working on a fix for this for the next release.
    3.67  
    3.68  If you want to browse the Xen / XenoLinux source, it's all located
    3.69 -under /usr/local/src, complete with BitKeeper repository. We've also
    3.70 -included source code and configuration information for the various
    3.71 -benchmarks we used in the SOSP paper.
    3.72 +under /usr/local/src/xeno-1.2, complete with BitKeeper
    3.73 +repository. We've also included source code and configuration
    3.74 +information for the various benchmarks we used in the SOSP paper.
    3.75  
    3.76  
    3.77  Starting other domains
    3.78  ======================
    3.79  
    3.80 -Xen's privileged control interfaces can be accessed using a handy C
    3.81 -library (libxc.so) or an even easier-to-use Python wrapper module
    3.82 -(Xc). Example script templates are provided in tools/examples/.
    3.83 +Xen's privileged control interfaces can be accessed using a C library
    3.84 +(libxc.so) or an easier-to-use Python wrapper module (Xc). Example
    3.85 +script templates are provided in tools/examples/.
    3.86  
    3.87  Abyway, the first thing to do is to set up a window in which you will
    3.88  receive console output from other domains. Console output will arrive
    3.89 -as UDP packets destined for 169.254.1.0, so its necessary to setup an
    3.90 -alias on eth0. The easiest way to do this is to run:
    3.91 +as UDP packets destined for 169.254.1.0. The DemoCD's startup scripts
    3.92 +automatically bring up 169.254.1.0 as an alias called eth0:xen (see
    3.93 +/etc/sysconfig/network-scripts/ifcfg-eth0 )
    3.94 +
    3.95 +If you're not intending to configure the new domain with an IP address
    3.96 +on your LAN, then you'll probably want to use NAT. The
    3.97 +'xen_nat_enable' installs a few useful iptables rules into domain0 to
    3.98 +enable NAT. [ NB: The intention is that in future Xen will do NAT
    3.99 +itsel (actually RSIP), but this is part of a larger work package that
   3.100 +isn't ready to release.]
   3.101 +
   3.102 +Next, run the xen UDP console displayer:
   3.103 +
   3.104 +  xen_read_console
   3.105 +
   3.106 +[This is currently output only, but infuture we will have
   3.107 +bidirectional domain console]
   3.108 +
   3.109 +Xen has a management interface that can be manipulated from domain0 to
   3.110 +create new domains, control their CPU, network and memory resource
   3.111 +allocations, allocate IP addresses, grant access to disk partitions,
   3.112 +and suspend/resume domains to files, etc.  The management interface is
   3.113 +implemented as a set of library functions (implemented in C) for which
   3.114 +there are Python language bindings. 
   3.115  
   3.116 -  xen_nat_enable
   3.117 +We have developed a simple set of example python tools for
   3.118 +manipulating the interface, with the intention that more sophisticated
   3.119 +high-level management tools will be developed in due course. Within
   3.120 +the source repository the tools live in tools/examples/ but are
   3.121 +installed in /usr/local/bin/ on the CD.
   3.122 +
   3.123 +Starting a new domain is achieved using xc_dom_create.py which
   3.124 +allocates resources to a new domain, populates it with a kernel image
   3.125 +(and optionally a ramdisk) and then starts it.
   3.126 +
   3.127 +It parses a configuration file written in the Python language, the
   3.128 +default location of which is "/etc/xc/defaults", but this may be
   3.129 +overridden with the "-f" option. For the Demo CD, the defaults file
   3.130 +will cause domains to be created with ram-based root file systems, and
   3.131 +mount their /usr partition from the CD, just like domain0. (If you are
   3.132 +writing your own config file, the "example" script may be a better
   3.133 +starting point)
   3.134 +
   3.135 +Variables can be initialised and passed into configuration files. Some
   3.136 +of these may be compulsory, others optional.
   3.137 +
   3.138 +The 'defaults' file on the CD requires the 'ip' variable to be set to
   3.139 +tell Xen what IP address(es) should be routed to this domain.  Xen
   3.140 +will route packets to the domain if they bear one of these addresses
   3.141 +as a destination address, and will also ensure that packets sent from
   3.142 +the domain contain one of the addresses as a source address (to
   3.143 +prevent spoofing).  If multiple IP addresses are to be assigned to a
   3.144 +domain they can be listed in a comma separated list (with no
   3.145 +whitespace).
   3.146 +
   3.147 +The 'mem' variable can be used to change the default memory allocation
   3.148 +of 64MB. For example to start a domain with two IP addresses and
   3.149 +72MB:
   3.150 +
   3.151 +  xc_dom_create.py -Dip=128.23.45.34,169.254.1.1 -Dmem=72
   3.152  
   3.153 -This also inserts a few NAT rules into "domain0", in case you'll be
   3.154 -starting other domains without their own IP addresses. Alternatively,
   3.155 -just do "ifconfig eth0:0 169.254.1.0 up". NB: The intention is that in
   3.156 -future Xen will do NAT itsel (actually RSIP), but this is part of a
   3.157 -larger work package that isn't stable enough to release.
   3.158 +[multiple variables may also be set with a single '-D' flag by
   3.159 +separating them with ':'. Also, it's possible to use DNS hostnames
   3.160 +rather than IP addresses.]
   3.161 +
   3.162 +When invoked with the '-n' option xc_dom_create.py will do a dry run
   3.163 +and just print out what resources and configuration the domain will
   3.164 +have e.g.:
   3.165 +
   3.166 +  [root@xendemo]# xc_dom_create.py -D ip=commando-1.xeno,169.254.2.3 -Dmem=100
   3.167 +  Parsing config file 'defaults'
   3.168 +
   3.169 +  VM image           : "/boot/xenolinux.gz"
   3.170 +  VM ramdisk         : "/boot/initrd.gz"
   3.171 +  VM memory (MB)     : "100"
   3.172 +  VM IP address(es)  : "128.232.38.51:169.254.2.3"
   3.173 +  VM block device(s) : "phy:cdrom,hdd,r"
   3.174 +  VM cmdline         : "ip=128.232.38.51:169.254.1.0:128.232.32.1:255.255.240.0::eth0:off root=/dev/ram0 rw init=/linuxrc 4 LOCALIP=169.254.2.3"
   3.175 +
   3.176 +If you invoke xc_dom_create.py without the '-n' option you should see
   3.177 +the domain booting on your xen_read_console window.
   3.178 +
   3.179 +The 169.254.x.x network is special in that it is the 'link local'
   3.180 +subnet, and is isolated from the external network and hence can only
   3.181 +be used for communication between virtual machines. By convention, we
   3.182 +usually give each domain a link local address. The startup scripts on
   3.183 +the CD have been modified to accept a LINKLOCAL= parameter on the
   3.184 +kernel command line and initialise an IP alias accordingly (see
   3.185 +/etc/sysinit/network-scripts/ifcfg-eth0).
   3.186  
   3.187 -Next, run a the xen UDP console displayer:
   3.188 +Linux only allows one IP address to be specified on the kernel command
   3.189 +line, so if you specify multiple IP addresses you'll need to configure
   3.190 +the new Linux VM with the other addresses manually (using ifconfig)
   3.191 +having logged in.
   3.192 +
   3.193 +If you inspect the 'defaults' config script you'll see that the new
   3.194 +domain was started with a '4' on the kernel command line to tell
   3.195 +'init' to go to runlevel 4 rather than the default of 3 used by
   3.196 +domain0. This is done simply to suppress a bunch of harmless error
   3.197 +messages that would otherwise occur when the new (unprivileged) domain
   3.198 +tried to access physical hardware resources to try setting the
   3.199 +hwclock, system font, run gpm etc.
   3.200 +
   3.201 +[root@commando-0 examples]# ./xc_dom_create.py -?
   3.202 +Usage: ./xc_dom_create.py <args>
   3.203  
   3.204 -  xen_read_console &
   3.205 +This tool is used to create and start new domains. It reads defaults
   3.206 +from a file written in Python, having allowed variables to be set and
   3.207 +passed into the file. Further command line arguments allow the
   3.208 +defaults to be overridden. The defaults for each parameter are listed
   3.209 +in [] brackets. Arguments are as follows:
   3.210 +
   3.211 +Arguments to control the parsing of the defaults file:
   3.212 + -f config_file   -- Use the specified defaults script. 
   3.213 +                     Default: ['/etc/xc/defaults']
   3.214 + -D foo=bar       -- Set variable foo=bar before parsing config
   3.215 +                     E.g. '-D vmid=3:ip=1.2.3.4'
   3.216 + -h               -- Print extended help message, including all arguments
   3.217 + -n               -- Dry run only, don't actually create domain
   3.218 +
   3.219 +The config file /etc/xc/defaults requires the following vars to be defined:
   3.220 + ip               -- List of IP addr(s) for Xen to route to domain 
   3.221 +                     e.g. -Dip='1.2.3.4,5.6.7.8'
   3.222 +The following variables may be optionally defined:
   3.223 + mem              -- Adjust initial memory allocation (default 64MB)
   3.224 + netmask          -- Override gateway for kernel ip= command line
   3.225 + gateway          -- Override network for kernel ip= command line
   3.226  
   3.227  
   3.228 -As mentioned above, a template Python script is provided:
   3.229 -tools/examples/craetelinuxdom.py. This can be modified to set up a
   3.230 -virtual Ethernet interface, access to local discs, and various other
   3.231 -parameters.
   3.232 -
   3.233 -When you execute your modified screipt, you should see the domain
   3.234 -booting on your xen_read_console window.
   3.235 -
   3.236 -The new domain may be started with a '4' on the kernel command line to
   3.237 -tell 'init' to go to runlevel 4 rather than the default of 3. This is
   3.238 -done simply to suppress a bunch of harmless error messages that would
   3.239 -otherwise occur when the new (unprivileged) domain tried to access
   3.240 -physical hardware resources to try setting the hwclock, system font,
   3.241 -run gpm etc.
   3.242 -
   3.243 -After it's booted, you should be able to ssh into your new domain. If
   3.244 -you went for a NATed address, from domain 0 you should be able to ssh
   3.245 -into '169.254.1.X' where X is the domain number.  If you ran the
   3.246 -xen_enable_nat script, a bunch of port redirects have been installed
   3.247 -to enable you to ssh in to other domains remotely.  To access the new
   3.248 -virtual machine remotely, use:
   3.249 +After it's booted, you should be able to ssh into your new domain from
   3.250 +domain0 using the link local 19.254.x.x address you assigned. If you
   3.251 +assigned a further IP address you should be able to ssh in using that
   3.252 +address too. If you ran the xen_enable_nat script, a bunch of port
   3.253 +redirects have been installed to enable you to ssh in to other domains
   3.254 +remotely even if you didn't assign an externally routeable address.
   3.255 +To access the new virtual machine remotely, use:
   3.256  
   3.257   ssh -p2201 root@IP.address.Of.Domain0  # use 2202 for domain 2 etc.
   3.258  
   3.259 -If you configured the new domain with its own IP address, you should
   3.260 -be able to ssh into it directly.
   3.261 -
   3.262 -Script 'tools/examples/listdoms.py' demonstrates how to generate a
   3.263 -list of all extant domains. Prettier printing is an exercise for the
   3.264 -reader!
   3.265 +You can manipulate running domains using the xc_dom_control.py tool.
   3.266 +Invoking it without arguments prints some usage information.
   3.267  
   3.268 -createlinuxdom.py can be used to set the new kernel's command line,
   3.269 -and hence determine what it uses as a root file system, etc. Although
   3.270 -the default is to boot in the same manner that domain0 did (using the
   3.271 -RAM-based file system for root and the CD for /usr) it's possible to
   3.272 -configure any of the following possibilities, for example:
   3.273 +To see what domains are running, run 'xc_dom_control list'.  Using the
   3.274 +tool you can change scheduling parameters, pause a domain, send it a
   3.275 +shutdown request, or blow it away with the 'destroy' command. You can
   3.276 +even suspend it to disk (but you probably won't have enough memory to
   3.277 +do the latter if you're running off the demo CD).
   3.278  
   3.279 - * initrd=/boot/initrd init=/linuxrc
   3.280 -     boot using an initial ram disk, executing /linuxrc (as per this CD)     
   3.281 -
   3.282 - * root=/dev/hda3 ro
   3.283 -     boot using a standard hard disk partition as root
   3.284 -     !!! remember to grant access in createlinuxdom.py.
   3.285 +Usage: xc_dom_control [command] <params>
   3.286  
   3.287 - * root=/dev/xvda1 ro
   3.288 -     boot using a pre-configured 'virtual block device' that will be
   3.289 -     attached to a virtual disk that previously has had a file system
   3.290 -     installed on it.
   3.291 -
   3.292 - * root=/dev/nfs nfsroot=/path/on/server ip=<blah_including server_IP>
   3.293 -     Boot using an NFS mounted root file system. This could be from a
   3.294 -     remote NFS server, or from an NFS server running in another
   3.295 -     domain. The latter is rather a useful option.
   3.296 -
   3.297 -A typical setup might be to allocate a standard disk partition for
   3.298 -each domain and populate it with files. To save space, having a shared
   3.299 -read-only usr partition might make sense.
   3.300 -
   3.301 -Block devices should only be shared between domains in a read-only
   3.302 -fashion otherwise the linux kernels will obviously get very confused
   3.303 -as the file system structure may change underneath them (having the
   3.304 -same partition mounted rw twice is a sure fire way to cause
   3.305 -irreparable damage)!  If you want read-write sharing, export the
   3.306 -directory to other domains via NFS from domain0.
   3.307 +  stop      [dom]        -- pause a domain
   3.308 +  start     [dom]        -- un-pause a domain
   3.309 +  shutdown  [dom]        -- request a domain to shutdown
   3.310 +  destroy   [dom]        -- immediately terminate a domain
   3.311 +  pincpu    [dom] [cpu]  -- pin a domain to the specified CPU
   3.312 +  save      [dom] [file] -- suspend a domain's memory to file
   3.313 +  restore   [file]       -- resume a domain from a file
   3.314 +  list                   -- print info about all domains
   3.315 +  listvbds               -- print info about all virtual block devs
   3.316 +  cpu_bvtset [dom] [mcuadv] [warp] [warpl] [warpu]
   3.317 +                         -- set scheduling parameters for domain
   3.318 +  cpu_bvtslice [slice]   -- default scheduler slice
   3.319 +  vif_stats [dom] [vif]  -- get stats for a given network vif
   3.320 +  vif_addip [dom] [vif] [ip]  -- add an IP address to a given vif
   3.321 +  vif_setsched [dom] [vif] [bytes] [usecs] -- rate limit vif bandwidth
   3.322 +  vif_getsched [dom] [vif] -- print vif's scheduling parameters
   3.323 +  vbd_add [dom] [uname] [dev] [mode] -- make disk/partition uname available to 
   3.324 +                            domain as dev e.g. 'vbd_add phy:sda3 hda1 rw'
   3.325 +  vbd_remove [dom] [dev] -- remove disk or partition attached as 'dev' 
   3.326  
   3.327  
   3.328  Troubleshooting Problems
   3.329 @@ -324,18 +413,85 @@ unsupported, use ifname=dummy
   3.330  The second line specifies which xenolinux image to use, and the
   3.331  standard linux command line arguments to pass to the kernel. In this
   3.332  case, we're configuring the root partition and stating that it should
   3.333 -be mounted read-only (normal practice). 
   3.334 +initially be mounted read-only (normal practice).
   3.335  
   3.336  If we were booting with an initial ram disk (initrd), then this would
   3.337  require a second "module" line.
   3.338  
   3.339 +Installing the Xen tools and source
   3.340 +===================================
   3.341 +
   3.342 +The tools and source live in the /usr/local/src/xen-1.2 directory on
   3.343 +the CD (and may also be downloaded from the project downloads
   3.344 +page). You'll need to copy them to some mutable storage before using
   3.345 +them.
   3.346 +
   3.347 +If you have the BitKeeper BK tools installed you can check the
   3.348 +repository is up to date by cd'ing into the xeno-1.2.bk directory and
   3.349 +typing 'bk pull' (assuming you have an Internet connection). 
   3.350 +
   3.351 +You can rebuild Xen and the tools by typing 'make'. You can install
   3.352 +them to the standard directories with 'make install', or into the
   3.353 +../install subtree with 'make dist'.
   3.354 +
   3.355 +/usr/local/bin/xc_*   	the domain control tools
   3.356 +/lib/libxc.so		the xc library
   3.357 +/usr/lib/python2.2/site-packages/XenoUtil.py	python util library
   3.358 +/usr/lib/python2.2/site-packages/Xc.c		python xc bindings
   3.359 +
   3.360 +If you're using the virtual disk control tools (xc_vd_tool) you'll
   3.361 +need the SQLite library and python binding pysqlite.  There's a tar
   3.362 +ball containing the necessary binaries on the project downloads page.
   3.363 +
   3.364 +
   3.365 +Modifying xc_mycreatelinuxdom1.py
   3.366 +=================================
   3.367 +
   3.368 +xc_mycreatelinuxdom1.py.py can be used to set the new kernel's command line,
   3.369 +and hence determine what it uses as a root file system, etc. Although
   3.370 +the default is to boot in the same manner that domain0 did (using the
   3.371 +RAM-based file system for root and the CD for /usr) it's possible to
   3.372 +configure any of the following possibilities, for example:
   3.373 +
   3.374 + * initrd=/boot/initrd init=/linuxrc
   3.375 +     boot using an initial ram disk, executing /linuxrc (as per this CD)     
   3.376 +
   3.377 + * root=/dev/hda3 ro
   3.378 +     boot using a standard hard disk partition as root
   3.379 +     !!! remember to grant access in createlinuxdom.py.
   3.380 +
   3.381 + * root=/dev/xvda1 ro
   3.382 +     boot using a pre-configured 'virtual block device' that will be
   3.383 +     attached to a virtual disk that previously has had a file system
   3.384 +     installed on it.
   3.385 +
   3.386 + * root=/dev/nfs nfsroot=/path/on/server ip=<blah_including server_IP>
   3.387 +     Boot using an NFS mounted root file system. This could be from a
   3.388 +     remote NFS server, or from an NFS server running in another
   3.389 +     domain. The latter is rather a useful option.
   3.390 +
   3.391 +A typical setup might be to allocate a standard disk partition for
   3.392 +each domain and populate it with files. To save space, having a shared
   3.393 +read-only usr partition might make sense.
   3.394 +
   3.395 +Block devices should only be shared between domains in a read-only
   3.396 +fashion otherwise the linux kernels will obviously get very confused
   3.397 +as the file system structure may change underneath them (having the
   3.398 +same partition mounted rw twice is a sure fire way to cause
   3.399 +irreparable damage)!  If you want read-write sharing, export the
   3.400 +directory to other domains via NFS from domain0.
   3.401 +
   3.402 +
   3.403 +
   3.404  
   3.405  Installing the file systems from the CD
   3.406  =======================================
   3.407  
   3.408 -If you haven't an existing Linux installation onto which you can just
   3.409 -drop down the Xen and XenoLinux images, then the file systems on the
   3.410 -CD provide a quick way of doing an install.
   3.411 +If you haven't got an existing Linux installation onto which you can
   3.412 +just drop down the Xen and XenoLinux images, then the file systems on
   3.413 +the CD provide a quick way of doing an install. However, you're
   3.414 +probably better off in the long run doing a proper Redhat, Fedora,
   3.415 +Debian etc install rather than just doing the hack described below:
   3.416  
   3.417  Choose one or two partitions, depending on whether you want a separate
   3.418  /usr or not. Make file systems on it/them e.g.: 
     4.1 --- a/tools/Makefile	Sat Jan 31 19:45:13 2004 +0000
     4.2 +++ b/tools/Makefile	Sun Feb 01 22:30:47 2004 +0000
     4.3 @@ -21,19 +21,23 @@ all:
     4.4  	$(MAKE) -C balloon
     4.5  	$(MAKE) -C xc
     4.6  	$(MAKE) -C misc
     4.7 +	$(MAKE) -C examples
     4.8  
     4.9  install: all
    4.10  	$(MAKE) -C balloon install
    4.11  	$(MAKE) -C xc install
    4.12  	$(MAKE) -C misc install
    4.13 +	$(MAKE) -C examples install
    4.14  
    4.15  dist: all
    4.16  	$(MAKE) -C balloon dist
    4.17  	$(MAKE) -C xc dist
    4.18  	$(MAKE) -C misc dist
    4.19 +	$(MAKE) -C examples dist
    4.20  
    4.21  clean:
    4.22  	$(MAKE) -C balloon clean
    4.23  	$(MAKE) -C xc clean
    4.24  	$(MAKE) -C misc clean
    4.25 +	$(MAKE) -C examples clean
    4.26  
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/examples/Makefile	Sun Feb 01 22:30:47 2004 +0000
     5.3 @@ -0,0 +1,34 @@
     5.4 +
     5.5 +CC        = gcc
     5.6 +CFLAGS    = -Wall -O3 
     5.7 +EXTRA_INC = -I../../xen/include -I../../xenolinux-sparse/include -I../xc/lib
     5.8 +
     5.9 +HDRS     = $(wildcard *.h)
    5.10 +SRCS     = $(wildcard *.c)
    5.11 +OBJS     = $(patsubst %.c,%.o,$(SRCS))
    5.12 +
    5.13 +INSTALL  = $(wildcard *.py)
    5.14 +ETC	 = defaults democd
    5.15 +
    5.16 +all: 
    5.17 +
    5.18 +install: all
    5.19 +	mkdir -p /usr/bin
    5.20 +	cp -a $(INSTALL) /usr/bin
    5.21 +	#chmod 755 $(INSTALL)
    5.22 +	mkdir -p /etc/xc
    5.23 +	for i in $(ETC) ; do [ ! -e /etc/xc/$$i ] && echo Install $$i && cp $$i /etc/xc/ ; done || true 
    5.24 +
    5.25 +dist: all
    5.26 +	mkdir -p ../../../install/bin
    5.27 +	mkdir -p ../../../install/etc
    5.28 +	cp -a $(INSTALL) ../../../install/bin
    5.29 +	cp -a $(ETC) ../../../install/etc
    5.30 +	#chmod 755 $(INSTALL)
    5.31 +
    5.32 +clean:
    5.33 +
    5.34 +
    5.35 +%: %.c $(HDRS) Makefile
    5.36 +	$(CC) $(CFLAGS) $(EXTRA_INC) -o $@ $<
    5.37 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/examples/README	Sun Feb 01 22:30:47 2004 +0000
     6.3 @@ -0,0 +1,109 @@
     6.4 +Xen Control Tools - Example Scripts
     6.5 +===================================
     6.6 +
     6.7 +This directory contains a set of example scripts for common Xen operations.
     6.8 +For many operations you will either be able to use these scripts directly, or
     6.9 +incorporate code from them into your own scripts.
    6.10 +
    6.11 +The Xc and XenoUtil Python modules provide an API for accessing all this
    6.12 +functionality - and more - from your own Python programs.  These libraries may
    6.13 +contain features for which there aren't yet example scripts written for...
    6.14 +
    6.15 +If you write a useful script and would like to share it, please do
    6.16 +send it (preferably with a little summary to go in this file) to
    6.17 +<xen-devel@lists.sourceforge.net> so we can add it to this directory.
    6.18 +
    6.19 +xc_dom_control.py
    6.20 + - general tool for controling running domains
    6.21 +  Usage: xc_dom_control.py [command] <params>
    6.22 +  stop      [dom]        -- pause a domain
    6.23 +  start     [dom]        -- un-pause a domain
    6.24 +  shutdown  [dom]        -- request a domain to shutdown
    6.25 +  destroy   [dom]        -- immediately terminate a domain
    6.26 +  pincpu    [dom] [cpu]  -- pin a domain to the specified CPU
    6.27 +  save      [dom] [file] -- suspend a domain's memory to file
    6.28 +  restore   [file]       -- resume a domain from a file
    6.29 +  list                   -- print info about all domains
    6.30 +  listvbds               -- print info about all virtual block devs
    6.31 +  cpu_bvtset [dom] [mcuadv] [warp] [warpl] [warpu]
    6.32 +                         -- set scheduling parameters for domain
    6.33 +  cpu_bvtslice [slice]   -- default scheduler slice
    6.34 +  vif_stats [dom] [vif]  -- get stats for a given network vif
    6.35 +  vif_addip [dom] [vif] [ip]  -- add an IP address to a given vif
    6.36 +  vif_setsched [dom] [vif] [bytes] [usecs] -- rate limit vif bandwidth
    6.37 +  vif_getsched [dom] [vif] -- print vif's scheduling parameters
    6.38 +  vbd_add [dom] [uname] [dev] [mode] -- make disk/partition uname available to 
    6.39 +                            domain as dev e.g. 'vbd_add phy:sda3 hda1 rw'
    6.40 +  vbd_remove [dom] [dev] -- remove disk or partition attached as 'dev' 
    6.41 +
    6.42 +
    6.43 +xc_dom_create.py
    6.44 + - This tool is used to create and start new domains. It reads defaults
    6.45 +from a file written in Python, having allowed variables to be set and
    6.46 +passed into the file. Further command line arguments allow the
    6.47 +defaults to be overridden. The defaults for each parameter are listed
    6.48 +in [] brackets. Arguments are as follows:
    6.49 +
    6.50 +Arguments to control the parsing of the defaults file:
    6.51 + -f config_file   -- Use the specified defaults script. 
    6.52 +                     Default: ['/etc/xc/defaults']
    6.53 + -D foo=bar       -- Set variable foo=bar before parsing config
    6.54 +                     E.g. '-D vmid=3:ip=1.2.3.4'
    6.55 + -h               -- Print extended help message, including all arguments
    6.56 + -n               -- Dry run only, don't actually create domain
    6.57 +
    6.58 +
    6.59 +The config file 'defaults' requires the following variable to be defined:
    6.60 + vmid             -- Numeric identifier for the new domain, used to calculate
    6.61 +                     the VM's IP address and root partition. E.g. -Dvmid=1
    6.62 +
    6.63 +
    6.64 +Arguments to override current config read from 'defaults':
    6.65 + -k image         -- Path to kernel image ['']
    6.66 + -r ramdisk       -- Path to ramdisk (or empty) ['']
    6.67 + -b builder_fn    -- Function to use to build domain ['']
    6.68 + -m mem_size      -- Initial memory allocation in MB [0MB]
    6.69 + -N domain_name   -- Set textual name of domain ['']
    6.70 + -a auto_restart  -- Restart domain on exit, yes/no ['0']
    6.71 + -e vbd_expert    -- Saftey catch to avoid some disk accidents ['0'] 
    6.72 + -d udisk,dev,rw  -- Add disk, partition, or virtual disk to domain. E.g. to 
    6.73 +                     make partion sda4 available to the domain as hda1 with 
    6.74 +                     read-write access: '-b phy:sda4,hda1,rw' To add 
    6.75 +                     multiple disks use multiple -d flags or seperate with ':'
    6.76 +                     Default: ['']
    6.77 + -i vfr_ipaddr    -- Add IP address to the list which Xen will route to
    6.78 +                     the domain. Use multiple times to add more IP addrs.
    6.79 +                     Default: ['']
    6.80 +
    6.81 +Args to override the kernel command line, which is concatenated from these:
    6.82 + -I cmdline_ip    -- Override 'ip=ipaddr:nfsserv:gateway:netmask::eth0:off'
    6.83 +                     Default: ['']
    6.84 + -R cmdline_root  -- Override root device parameters.
    6.85 +                     Default: ['']
    6.86 + -E cmdline_extra -- Override extra kernel args and rc script env vars.
    6.87 +                     Default: ['']
    6.88 +
    6.89 +
    6.90 +
    6.91 +xc_vd_tool
    6.92 + - tool for manipulating virtual disks
    6.93 +   Usage: xc_vd_tool command <params>
    6.94 +
    6.95 +   initalise [dev] [[ext_size]]  - init. a physcial partition to store vd's
    6.96 +   create [size] [[expiry]]      - allocate a vd of specified size (and expiry)
    6.97 +   delete [vdid]                 - delete a vd
    6.98 +   import [filename] [[expiry]]  - create a vd and populate w/ image from file
    6.99 +   export [vdid] [filename]      - copy vd's contents to a file
   6.100 +   setexpiry [vdid] [[expiry]]   - update the expiry time for a vd
   6.101 +   list                          - list all the unexpired virtual disks  
   6.102 +   undelete [vdid] [[expiry]]    - attempts to recover an expired vd
   6.103 +   freespace                     - print out the amount of space in free pool
   6.104 +
   6.105 +   notes:
   6.106 +   vdid      - the virtual disk's identity string
   6.107 +   size      - measured in MB
   6.108 +   expiry    - is the expiry time of the virtual disk in seconds from now
   6.109 +               (0 = don't expire) 
   6.110 +   device    - physical partition to 'format' to hold vd's. e.g. hda4
   6.111 +   ext_size  - extent size (default 64MB)
   6.112 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/examples/defaults	Sun Feb 01 22:30:47 2004 +0000
     7.3 @@ -0,0 +1,89 @@
     7.4 +
     7.5 +##### Edit this python file to reflect the configuration of your system
     7.6 +
     7.7 +##### This example script expects a variable called 'vmid' to be set.
     7.8 +
     7.9 +def config_usage ():
    7.10 +    print >>sys.stderr,"""
    7.11 +The config file '%s' requires the following variable to be defined:
    7.12 + vmid             -- Numeric identifier for the new domain, used to calculate
    7.13 +                     the VM's IP address and root partition. E.g. -Dvmid=1
    7.14 +""" % config_file
    7.15 +
    7.16 +
    7.17 +try:
    7.18 +    vmid=int(vmid) # convert to integer
    7.19 +except:
    7.20 +    print >>sys.stderr,"%s: This script expects 'vmid' to be set using -D vmid=X" % config_file
    7.21 +    assert()
    7.22 +
    7.23 +if vmid == 0:
    7.24 +    print >>sys.stderr,"%s: 'vmid' must be greater than 0" % config_file
    7.25 +    assert()
    7.26 +
    7.27 +
    7.28 +# STEP 1. Specify kernel image file and otional ramdisk. Can be gzip'ed.
    7.29 +image = "../../../install/boot/xenolinux.gz"
    7.30 +ramdisk = ""
    7.31 +#ramdisk = "/boot/initrd.gz"
    7.32 +builder_fn='xc.linux_build' # this is a linux domain
    7.33 +
    7.34 +# STEP 2. The initial memory allocation (in megabytes) for the new domain.
    7.35 +mem_size = 64
    7.36 +
    7.37 +
    7.38 +# STEP 3. A handy name for your new domain.
    7.39 +domain_name = "This is VM %d" % vmid
    7.40 +
    7.41 +
    7.42 +# STEP 4. Specify IP address(es), for the new domain.  You need to
    7.43 +# configure IP addrs within the domain just as you do normally.  This
    7.44 +# is just to let Xen know about them so it can route packets
    7.45 +# appropriately.
    7.46 +
    7.47 +#vfr_ipaddr = ["111.222.333.444","222.333.444.555"]
    7.48 +vfr_ipaddr  = [XenoUtil.add_offset_to_ip(XenoUtil.get_current_ipaddr(),vmid),
    7.49 +	       XenoUtil.add_offset_to_ip('169.254.1.0',vmid),]
    7.50 +
    7.51 +
    7.52 +# STEP 5a. Identify any physcial partitions or virtual disks you want the
    7.53 +# domain to have access to, and what you want them accessible as
    7.54 +# e.g. vbd_list = [ ('phy:sda1','sda1', 'w'),
    7.55 +#	 ('phy:sda%d' % (3+vmid), 'hda2', 'r'), 
    7.56 +#	 ('vd:as73gd784dh','hda1','w'),
    7.57 +#	 ('phy:cdrom','hdd','r')
    7.58 +
    7.59 +vbd_list = [ ('phy:sda%d'%(7+vmid),'sda1','w' ), 
    7.60 +	     ('phy:sda6','sda6','r') ]
    7.61 +
    7.62 +
    7.63 +
    7.64 +# STEP 5b. Set the VBD expertise level.  Most people should leave this
    7.65 +# on 0, at least to begin with - this script can detect most dangerous
    7.66 +# disk sharing between domains and with this set to zero it will only
    7.67 +# allow read only sharing.
    7.68 +
    7.69 +vbd_expert = 0
    7.70 +
    7.71 +
    7.72 +# STEP 6. Build the command line for the new domain. Edit as req'd.
    7.73 +# You only need the ip= line if you're NFS booting or the root file system
    7.74 +# doesn't set it later e.g. in ifcfg-eth0 or via DHCP
    7.75 +# You can use 'extrabit' to set the runlevel and custom environment
    7.76 +# variables used by custom rc scripts (e.g. VMID=, usr= )
    7.77 +
    7.78 +netmask = XenoUtil.get_current_ipmask()
    7.79 +gateway = XenoUtil.get_current_ipgw()
    7.80 +nfsserv = '169.254.1.0'  
    7.81 +
    7.82 +cmdline_ip = "ip="+vfr_ipaddr[0]+":"+nfsserv+":"+gateway+":"+netmask+"::eth0:off"
    7.83 +cmdline_root = "root=/dev/sda1 ro"
    7.84 +#cmdline_root = "root=/dev/nfs nfsroot=/full/path/to/root/directory"
    7.85 +cmdline_extra = "4 VMID=%d usr=/dev/sda6" % vmid
    7.86 +
    7.87 +
    7.88 +# STEP 7. Set according to whether you want the script to watch the domain 
    7.89 +# and auto-restart it should it die or exit.
    7.90 +
    7.91 +auto_restart = False
    7.92 +#auto_restart = True
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/examples/democd	Sun Feb 01 22:30:47 2004 +0000
     8.3 @@ -0,0 +1,126 @@
     8.4 +
     8.5 +##### Edit this python file to reflect the configuration of your system
     8.6 +
     8.7 +##### This example script requires variable 'ip' to be set, and optionally
     8.8 +##### netmask and gatewaty for the kernel command line
     8.9 +
    8.10 +def config_usage ():
    8.11 +    print >>sys.stderr, """
    8.12 +The config file %s requires the following vars to be defined:
    8.13 + ip               -- List of IP addr(s) for Xen to route to domain 
    8.14 +                     e.g. -Dip='1.2.3.4,5.6.7.8'
    8.15 +The following variables may be optionally defined:
    8.16 + mem              -- Adjust initial memory allocation (default 64MB)
    8.17 + netmask          -- Override gateway for kernel ip= command line
    8.18 + gateway          -- Override network for kernel ip= command line
    8.19 +""" % config_file
    8.20 +
    8.21 +try:
    8.22 +    ip
    8.23 +except:
    8.24 +    print "Set variable 'ip' using -Dip='1.2.3.4,5.6.7.8'"
    8.25 +    assert()
    8.26 +
    8.27 +# STEP 1. Specify kernel image file and otional ramdisk. Can be gzip'ed.
    8.28 +image   = "/boot/xenolinux.gz"
    8.29 +ramdisk = "/boot/initrd.gz"
    8.30 +builder_fn='xc.linux_build' # this is a linux domain
    8.31 +
    8.32 +# STEP 2. The initial memory allocation (in megabytes) for the new domain.
    8.33 +try:
    8.34 +    mem_size = int(mem)
    8.35 +except NameError:
    8.36 +    mem_size = 64
    8.37 +
    8.38 +
    8.39 +# STEP 3. A handy name for your new domain.
    8.40 +domain_name = "Demo CD VM %s" % ip
    8.41 +
    8.42 +
    8.43 +# STEP 4. Specify IP address(es), for the new domain.  You need to
    8.44 +# configure IP addrs within the domain just as you do normally.  This
    8.45 +# is just to let Xen know about them so it can route packets
    8.46 +# appropriately.
    8.47 +
    8.48 +#vfr_ipaddr = ["111.222.333.444","222.333.444.555"]
    8.49 +#vfr_ipaddr  = [XenoUtil.add_offset_to_ip(XenoUtil.get_current_ipaddr(),vmid)]
    8.50 +vfr_ipaddr  = map(socket.gethostbyname,string.split(ip,','))
    8.51 +
    8.52 +
    8.53 +# STEP 5a. Identify any physcial partitions or virtual disks you want the
    8.54 +# domain to have access to, and what you want them accessible as
    8.55 +# e.g. vbd_list = [ ('phy:sda1','sda1', 'w'),
    8.56 +#	 ('phy:sda%d' % (3+vmid), 'hda2', 'r'), 
    8.57 +#	 ('vd:as73gd784dh','hda1','w'),
    8.58 +#	 ('phy:cdrom','hdd','r')
    8.59 +
    8.60 +vbd_list = [ ('phy:cdrom','hdd','r' ) ]
    8.61 +
    8.62 +
    8.63 +
    8.64 +# STEP 5b. Set the VBD expertise level.  Most people should leave this
    8.65 +# on 0, at least to begin with - this script can detect most dangerous
    8.66 +# disk sharing between domains and with this set to zero it will only
    8.67 +# allow read only sharing.
    8.68 +
    8.69 +vbd_expert = 0
    8.70 +
    8.71 +
    8.72 +# STEP 6. Build the command line for the new domain. Edit as req'd.
    8.73 +# You only need the ip= line if you're NFS booting or the root file system
    8.74 +# doesn't set it later e.g. in ifcfg-eth0 or via DHCP
    8.75 +# You can use 'extrabit' to set the runlevel and custom environment
    8.76 +# variables used by custom rc scripts (e.g. VMID=, usr= )
    8.77 +
    8.78 +try: 
    8.79 +    netmask = socket.gethostbyname( netmask )
    8.80 +except NameError:
    8.81 +    netmask = XenoUtil.get_current_ipmask()
    8.82 +
    8.83 +try: 
    8.84 +    gateway = socket.gethostbyname( gateway )
    8.85 +except NameError:
    8.86 +    gateway = XenoUtil.get_current_ipgw()
    8.87 +
    8.88 +localip=''
    8.89 +for i in vfr_ipaddr:
    8.90 +    if XenoUtil.check_subnet(i,'169.254.0.0','255.255.0.0'): localip=i
    8.91 +
    8.92 +# Try to guess the machine's LAN settings
    8.93 +
    8.94 +lanip=''
    8.95 +if netmask and gateway:
    8.96 +    for i in vfr_ipaddr:
    8.97 +	if XenoUtil.check_subnet(i,gateway,netmask): 
    8.98 +	    lanip=i
    8.99 +	    break
   8.100 +
   8.101 +# Have a fall back plan...
   8.102 +
   8.103 +if not netmask:
   8.104 +    netmask = '255.255.0.0' 
   8.105 +
   8.106 +if not gateway:
   8.107 +    gateway = '169.254.1.0' 
   8.108 +
   8.109 +if not lanip:
   8.110 +    lanip = vfr_ipaddr[0]
   8.111 +
   8.112 +
   8.113 +# Calculate the components with which we will build the command line
   8.114 +
   8.115 +nfsserv = '169.254.1.0'  
   8.116 +
   8.117 +cmdline_ip="ip="+lanip+":"+nfsserv+":"+gateway+":"+netmask+"::eth0:off"
   8.118 +cmdline_root  = "root=/dev/ram0 rw init=/linuxrc"
   8.119 +
   8.120 +if localip:
   8.121 +    cmdline_extra = "4 LOCALIP=%s" % localip
   8.122 +else:
   8.123 +    cmdline_extra = "4"
   8.124 +
   8.125 +# STEP 7. Set according to whether you want the script to watch the domain 
   8.126 +# and auto-restart it should it die or exit.
   8.127 +
   8.128 +auto_restart = False
   8.129 +#auto_restart = True
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/examples/xc_dom_control.py	Sun Feb 01 22:30:47 2004 +0000
     9.3 @@ -0,0 +1,219 @@
     9.4 +#!/usr/bin/env python
     9.5 +
     9.6 +# usage: xc_dom_control [command] <params>
     9.7 +#
     9.8 +# this script isn't very smart, but it'll do for now.
     9.9 +#
    9.10 +
    9.11 +def usage ():
    9.12 +    print >>sys.stderr, """
    9.13 +Usage: %s [command] <params>
    9.14 +
    9.15 +  stop      [dom]        -- pause a domain
    9.16 +  start     [dom]        -- un-pause a domain
    9.17 +  shutdown  [dom]        -- request a domain to shutdown
    9.18 +  destroy   [dom]        -- immediately terminate a domain
    9.19 +  pincpu    [dom] [cpu]  -- pin a domain to the specified CPU
    9.20 +  save      [dom] [file] -- suspend a domain's memory to file
    9.21 +  restore   [file]       -- resume a domain from a file
    9.22 +  list                   -- print info about all domains
    9.23 +  listvbds               -- print info about all virtual block devs
    9.24 +  cpu_bvtset [dom] [mcuadv] [warp] [warpl] [warpu]
    9.25 +                         -- set scheduling parameters for domain
    9.26 +  cpu_bvtslice [slice]   -- default scheduler slice
    9.27 +  vif_stats [dom] [vif]  -- get stats for a given network vif
    9.28 +  vif_addip [dom] [vif] [ip]  -- add an IP address to a given vif
    9.29 +  vif_setsched [dom] [vif] [bytes] [usecs] -- rate limit vif bandwidth
    9.30 +  vif_getsched [dom] [vif] -- print vif's scheduling parameters
    9.31 +  vbd_add [dom] [uname] [dev] [mode] -- make disk/partition uname available to 
    9.32 +                            domain as dev e.g. 'vbd_add phy:sda3 hda1 rw'
    9.33 +  vbd_remove [dom] [dev] -- remove disk or partition attached as 'dev' 
    9.34 +""" % sys.argv[0]
    9.35 +
    9.36 +import Xc, sys, re, string
    9.37 +
    9.38 +if len(sys.argv) < 2:
    9.39 +    usage()
    9.40 +    sys.exit(-1)
    9.41 +
    9.42 +cmd = sys.argv[1]
    9.43 +
    9.44 +
    9.45 +xc = Xc.new()
    9.46 +rc = ''
    9.47 +
    9.48 +if len( sys.argv ) > 2 and re.match('\d+$', sys.argv[2]):
    9.49 +    dom = string.atoi(sys.argv[2])
    9.50 +
    9.51 +if cmd == 'stop':
    9.52 +    rc = xc.domain_stop( dom=dom )
    9.53 +
    9.54 +elif cmd == 'start':
    9.55 +    rc = xc.domain_start( dom=dom )    
    9.56 +
    9.57 +elif cmd == 'shutdown':
    9.58 +    rc = xc.domain_destroy( dom=dom, force=0 )    
    9.59 +
    9.60 +elif cmd == 'destroy':
    9.61 +    rc = xc.domain_destroy( dom=dom, force=1 )    
    9.62 +
    9.63 +elif cmd == 'pincpu':
    9.64 +
    9.65 +    if len(sys.argv) < 4:
    9.66 +        usage()
    9.67 +        sys.exit(-1)
    9.68 +
    9.69 +    cpu = int(sys.argv[3])
    9.70 +    orig_state = xc.domain_getinfo(first_dom=dom, max_doms=1)[0]['stopped']
    9.71 +
    9.72 +    while xc.domain_getinfo(first_dom=dom, max_doms=1)[0]['stopped'] != 1:
    9.73 +	xc.domain_stop( dom=dom )
    9.74 +	time.sleep(0.1)
    9.75 +
    9.76 +    rc = xc.domain_pincpu( dom, cpu )
    9.77 +
    9.78 +    if orig_state == 0:
    9.79 +	xc.domain_start( dom=dom )
    9.80 +
    9.81 +elif cmd == 'list':
    9.82 +    for i in xc.domain_getinfo(): print i
    9.83 +
    9.84 +elif cmd == 'listvbds':
    9.85 +    for i in xc.vbd_probe(): print i
    9.86 +
    9.87 +elif cmd == 'save':
    9.88 +    if len(sys.argv) < 4:
    9.89 +        usage()
    9.90 +        sys.exit(-1)
    9.91 +
    9.92 +    file = sys.argv[3]
    9.93 +        
    9.94 +    rc = xc.linux_save( dom=dom, state_file=file, progress=1)
    9.95 +
    9.96 +elif cmd == 'restore':
    9.97 +    if len(sys.argv) < 3:
    9.98 +        usage()
    9.99 +        sys.exit(-1)
   9.100 +        
   9.101 +    file = sys.argv[2]
   9.102 +    rc = xc.linux_restore( state_file=file, progress=1 )
   9.103 +
   9.104 +elif cmd == 'cpu_bvtslice':
   9.105 +    if len(sys.argv) < 3:
   9.106 +        usage()
   9.107 +        sys.exit(-1)
   9.108 +
   9.109 +    slice = dom # first int argument is in "dom" (!)
   9.110 +
   9.111 +    rc = xc.bvtsched_global_set(ctx_allow=slice)
   9.112 +
   9.113 +elif cmd == 'cpu_bvtset':
   9.114 +    if len(sys.argv) < 7:
   9.115 +        usage()
   9.116 +        sys.exit(-1)
   9.117 +
   9.118 +    mcuadv = int(sys.argv[3])
   9.119 +    warp   = int(sys.argv[4])
   9.120 +    warpl  = int(sys.argv[5])
   9.121 +    warpu  = int(sys.argv[6])
   9.122 +
   9.123 +    rc = xc.bvtsched_domain_set(dom=dom, mcuadv=mcuadv, warp=warp,
   9.124 +                                warpl=warpl, warpu=warpu)
   9.125 +elif cmd == 'vif_stats':
   9.126 +    if len(sys.argv) < 4:
   9.127 +        usage()
   9.128 +        sys.exit(-1)
   9.129 +
   9.130 +    vif = int(sys.argv[3])
   9.131 +
   9.132 +    print xc.vif_stats_get(dom=dom, vif=vif)
   9.133 +
   9.134 +elif cmd == 'vif_addip':
   9.135 +    if len(sys.argv) < 5:
   9.136 +        usage()
   9.137 +        sys.exit(-1)
   9.138 +
   9.139 +    vif = int(sys.argv[3])
   9.140 +    ip  = sys.argv[4]
   9.141 +
   9.142 +    # XXX This function should be moved to Xc once we sort out the VFR
   9.143 +    import XenoUtil
   9.144 +    XenoUtil.setup_vfr_rules_for_vif( dom, vif, ip )
   9.145 +
   9.146 +elif cmd == 'vif_setsched':
   9.147 +    if len(sys.argv) < 6:
   9.148 +        usage()
   9.149 +        sys.exit(-1)
   9.150 +
   9.151 +    vif = int(sys.argv[3])
   9.152 +    credit_bytes = int(sys.argv[4])
   9.153 +    credit_usecs = int(sys.argv[5])
   9.154 +
   9.155 +    rc = xc.xc_vif_scheduler_set(dom=dom, vif=vif, 
   9.156 +				 credit_bytes=credit_bytes, 
   9.157 +				 credit_usecs=credit_usecs)
   9.158 +
   9.159 +elif cmd == 'vif_getsched':
   9.160 +    if len(sys.argv) < 4:
   9.161 +        usage()
   9.162 +        sys.exit(-1)
   9.163 +
   9.164 +    vif = int(sys.argv[3])
   9.165 +
   9.166 +    print xc.vif_scheduler_get(dom=dom, vif=vif)
   9.167 +
   9.168 +
   9.169 +elif cmd == 'vbd_add':
   9.170 +
   9.171 +    XenoUtil.VBD_EXPERT_LEVEL = 0 # sets the allowed level of potentially unsafe mappings
   9.172 +
   9.173 +    if len(sys.argv) < 6:
   9.174 +	usage()
   9.175 +	sys.exit(1)
   9.176 +
   9.177 +    uname = sys.argv[3]
   9.178 +    dev = sys.argv[4]
   9.179 +    mode = sys.argv[5]
   9.180 +
   9.181 +    writeable = 0
   9.182 +    if mode == 'rw' or mode == 'w':
   9.183 +	writeable = 1;
   9.184 +
   9.185 +    segments = XenoUtil.lookup_disk_uname(uname)
   9.186 +
   9.187 +    if XenoUtil.vd_extents_validate(segments,writeable) < 0:
   9.188 +	print "That mapping is too unsafe for the current VBD expertise level"
   9.189 +	sys.exit(1)
   9.190 +
   9.191 +    virt_dev = XenoUtil.blkdev_name_to_number(dev)
   9.192 +
   9.193 +    xc.vbd_create(dom,virt_dev,writeable)
   9.194 +
   9.195 +    if xc.vbd_setextents( dom, virt_dev, segments ):
   9.196 +	print "Error populating VBD vbd=%d\n" % virt_dev
   9.197 +	sys.exit(1)
   9.198 +
   9.199 +    print "Added disk/partition %s to domain %d as device %s (%x)" % (uname, dom, dev, virt_dev)
   9.200 +
   9.201 +elif cmd == 'vbd_remove':
   9.202 +
   9.203 +    if len(sys.argv) < 4:
   9.204 +	usage()
   9.205 +	sys.exit(1)
   9.206 +
   9.207 +    dev = sys.argv[3]
   9.208 +    virt_dev = XenoUtil.blkdev_name_to_number(dev)
   9.209 +
   9.210 +    if not xc.vbd_destroy(dom,virt_dev):
   9.211 +	print "Removed disk/partition attached as device %s (%x) in domain %d" % (dev, virt_dev, dom)
   9.212 +    else:
   9.213 +	print "Failed"
   9.214 +	sys.exit(1)
   9.215 +
   9.216 +
   9.217 +else:
   9.218 +    usage()
   9.219 +    sys.exit(-1)
   9.220 +
   9.221 +if rc != '':
   9.222 +    print "return code %d" % rc
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/examples/xc_dom_create.py	Sun Feb 01 22:30:47 2004 +0000
    10.3 @@ -0,0 +1,296 @@
    10.4 +#!/usr/bin/env python
    10.5 +
    10.6 +import Xc, XenoUtil, string, sys, os, time, socket, getopt
    10.7 +
    10.8 +config_dir  = '/etc/xc/'
    10.9 +config_file = xc_config_file = config_dir + 'defaults'
   10.10 +
   10.11 +def main_usage ():
   10.12 +    print >>sys.stderr,"""
   10.13 +Usage: %s <args>
   10.14 +
   10.15 +This tool is used to create and start new domains. It reads defaults
   10.16 +from a file written in Python, having allowed variables to be set and
   10.17 +passed into the file. Further command line arguments allow the
   10.18 +defaults to be overridden. The defaults for each parameter are listed
   10.19 +in [] brackets. Arguments are as follows:
   10.20 +
   10.21 +Arguments to control the parsing of the defaults file:
   10.22 + -f config_file   -- Use the specified defaults script. 
   10.23 +                     Default: ['%s']
   10.24 + -D foo=bar       -- Set variable foo=bar before parsing config
   10.25 +                     E.g. '-D vmid=3:ip=1.2.3.4'
   10.26 + -h               -- Print extended help message, including all arguments
   10.27 + -n               -- Dry run only, don't actually create domain
   10.28 +""" % (sys.argv[0], xc_config_file)
   10.29 +
   10.30 +def extra_usage ():
   10.31 +    print >>sys.stderr,"""
   10.32 +Arguments to override current config read from '%s':
   10.33 + -k image         -- Path to kernel image ['%s']
   10.34 + -r ramdisk       -- Path to ramdisk (or empty) ['%s']
   10.35 + -b builder_fn    -- Function to use to build domain ['%s']
   10.36 + -m mem_size      -- Initial memory allocation in MB [%dMB]
   10.37 + -N domain_name   -- Set textual name of domain ['%s']
   10.38 + -a auto_restart  -- Restart domain on exit, yes/no ['%d']
   10.39 + -e vbd_expert    -- Saftey catch to avoid some disk accidents ['%d'] 
   10.40 + -d udisk,dev,rw  -- Add disk, partition, or virtual disk to domain. E.g. to 
   10.41 +                     make partion sda4 available to the domain as hda1 with 
   10.42 +                     read-write access: '-b phy:sda4,hda1,rw' To add 
   10.43 +                     multiple disks use multiple -d flags or seperate with ':'
   10.44 +                     Default: ['%s']
   10.45 + -i vfr_ipaddr    -- Add IP address to the list which Xen will route to
   10.46 +                     the domain. Use multiple times to add more IP addrs.
   10.47 +		     Default: ['%s']
   10.48 +
   10.49 +Args to override the kernel command line, which is concatenated from these:
   10.50 + -I cmdline_ip    -- Override 'ip=ipaddr:nfsserv:gateway:netmask::eth0:off'
   10.51 +                     Default: ['%s']
   10.52 + -R cmdline_root  -- Override root device parameters.
   10.53 +                     Default: ['%s']
   10.54 + -E cmdline_extra -- Override extra kernel args and rc script env vars.
   10.55 +                     Default: ['%s']
   10.56 +
   10.57 +""" % (config_file,
   10.58 +       image, ramdisk, builder_fn, mem_size, domain_name, auto_restart,
   10.59 +       vbd_expert, 
   10.60 +       printvbds( vbd_list ), 
   10.61 +       reduce ( (lambda a,b: a+':'+b), vfr_ipaddr,'' )[1:],
   10.62 +       cmdline_ip, cmdline_root, cmdline_extra)
   10.63 +
   10.64 +def config_usage (): pass
   10.65 +
   10.66 +def answer ( s ):
   10.67 +    s = string.lower(s)
   10.68 +    if s == 'yes' or s == 'true' or s == '1': return 1
   10.69 +    return 0
   10.70 +
   10.71 +def printvbds ( v ):
   10.72 +    s=''
   10.73 +    for (a,b,c) in v:
   10.74 +	s = s + ':%s,%s,%s' % (a,b,c)
   10.75 +    return s[1:]
   10.76 +
   10.77 +
   10.78 +bail=False; dryrun=False; extrahelp=False
   10.79 +image=''; ramdisk=''; builder_fn=''; 
   10.80 +mem_size=0; domain_name=''; vfr_ipaddr=[]; 
   10.81 +vbd_expert=0; auto_restart=0;
   10.82 +vbd_list = []; cmdline_ip = ''; cmdline_root=''; cmdline_extra=''
   10.83 +
   10.84 +##### Determine location of defautls file
   10.85 +#####
   10.86 +
   10.87 +try:
   10.88 +    opts, args = getopt.getopt(sys.argv[1:], "h?nf:D:k:r:b:m:N:a:e:d:i:I:R:E:" )
   10.89 +
   10.90 +    for opt in opts:
   10.91 +	if opt[0] == '-f': config_file= opt[1]
   10.92 +	if opt[0] == '-h' or opt[0] == '-?' : bail=True; extrahelp=True
   10.93 +	if opt[0] == '-n': dryrun=True
   10.94 +	if opt[0] == '-D': 
   10.95 +	    for o in string.split( opt[1], ':' ):
   10.96 +		(l,r) = string.split( o, '=' )
   10.97 +		exec "%s='%s'" % (l,r)
   10.98 +
   10.99 +
  10.100 +except getopt.GetoptError:
  10.101 +    bail=True
  10.102 +
  10.103 +
  10.104 +try:
  10.105 +    os.stat( config_file )
  10.106 +except:
  10.107 +    try:
  10.108 +	d = config_dir + config_file
  10.109 +	os.stat( d )
  10.110 +	config_file = d
  10.111 +    except:
  10.112 +	print >> sys.stderr, "Unable to open config file '%s'" % config_file
  10.113 +	bail = True
  10.114 +
  10.115 +
  10.116 +##### Parse the config file
  10.117 +#####
  10.118 +
  10.119 +print "Parsing config file '%s'" % config_file
  10.120 +
  10.121 +try:
  10.122 +    execfile ( config_file )
  10.123 +except (AssertionError,IOError):
  10.124 +    print >>sys.stderr,"Exiting %s" % sys.argv[0]
  10.125 +    bail = True
  10.126 +
  10.127 +##### Print out config if necessary 
  10.128 +##### 
  10.129 +
  10.130 +if bail:
  10.131 +    main_usage()
  10.132 +    config_usage()
  10.133 +    if extrahelp: extra_usage()
  10.134 +    sys.exit(1)
  10.135 +
  10.136 +##### Parse any command line overrides 
  10.137 +##### 
  10.138 +
  10.139 +x_vbd_list = []
  10.140 +x_vfr_ipaddr  = []
  10.141 +
  10.142 +for opt in opts:
  10.143 +    if opt[0] == '-k': image = opt[1]
  10.144 +    if opt[0] == '-r': ramdisk = opt[1]
  10.145 +    if opt[0] == '-b': builder_fn = opt[1]  #XXXX
  10.146 +    if opt[0] == '-m': mem_size = int(opt[1])
  10.147 +    if opt[0] == '-N': domain_name = opt[1]
  10.148 +    if opt[0] == '-a': auto_restart = answer(opt[1])
  10.149 +    if opt[0] == '-e': vbd_expert = answer(opt[1])
  10.150 +    if opt[0] == '-I': cmdline_ip = opt[1]
  10.151 +    if opt[0] == '-R': cmdline_root = opt[1]
  10.152 +    if opt[0] == '-E': cmdline_extra = opt[1]
  10.153 +    if opt[0] == '-i': x_vfr_ipaddr.append(opt[1])
  10.154 +    if opt[0] == '-d':
  10.155 +	try:
  10.156 +	    vv = string.split(opt[1],':')	    
  10.157 +	    for v in vv:
  10.158 +		(udisk,dev,mode) = string.split(v,',')
  10.159 +		x_vbd_list.append( (udisk,dev,mode) )
  10.160 +	except:
  10.161 +	    print >>sys.stderr, "Invalid block device specification : %s" % opt[1]
  10.162 +	    sys.exit(1)
  10.163 +
  10.164 +if x_vbd_list: vbd_list = x_vbd_list
  10.165 +if x_vfr_ipaddr: vfr_ipaddr = x_vfr_ipaddr
  10.166 +
  10.167 +cmdline = cmdline_ip +' '+ cmdline_root +' '+ cmdline_extra
  10.168 +
  10.169 +##### Print some debug info just incase things don't work out...
  10.170 +##### 
  10.171 +
  10.172 +print
  10.173 +print 'VM image           : "%s"' % image
  10.174 +print 'VM ramdisk         : "%s"' % ramdisk
  10.175 +print 'VM memory (MB)     : "%d"' % mem_size
  10.176 +print 'VM IP address(es)  : "%s"' % reduce((lambda a,b: a+':'+b),vfr_ipaddr,'' )[1:]
  10.177 +print 'VM block device(s) : "%s"' % printvbds( vbd_list )
  10.178 +print 'VM cmdline         : "%s"' % cmdline
  10.179 +print
  10.180 +
  10.181 +if dryrun:
  10.182 +    sys.exit(1)
  10.183 +
  10.184 +##### Code beyond this point is actually used to manage the mechanics of
  10.185 +##### starting (and watching if necessary) guest virtual machines.
  10.186 +
  10.187 +# Obtain an instance of the Xen control interface
  10.188 +xc = Xc.new()
  10.189 +
  10.190 +# This function creates, builds and starts a domain, using the values
  10.191 +# in the global variables, set above.  It is used in the subsequent
  10.192 +# code for starting the new domain and rebooting it if appropriate.
  10.193 +def make_domain():
  10.194 +    """Create, build and start a domain.
  10.195 +    Returns: [int] the ID of the new domain.
  10.196 +    """
  10.197 +
  10.198 +    # set up access to the global variables declared above
  10.199 +    global image, ramdisk, mem_size, domain_name, vfr_ipaddr, netmask
  10.200 +    global vbd_list, cmdline, xc, vbd_expert
  10.201 +    	
  10.202 +    if not os.path.isfile( image ):
  10.203 +        print "Image file '" + image + "' does not exist"
  10.204 +        sys.exit()
  10.205 +
  10.206 +    if ramdisk and not os.path.isfile( ramdisk ):
  10.207 +        print "Ramdisk file '" + ramdisk + "' does not exist"
  10.208 +        sys.exit()
  10.209 +
  10.210 +    id = xc.domain_create( mem_kb=mem_size*1024, name=domain_name )
  10.211 +    if id <= 0:
  10.212 +        print "Error creating domain"
  10.213 +        sys.exit()
  10.214 +
  10.215 +    ret = xc.linux_build( dom=id, image=image, ramdisk=ramdisk, 
  10.216 +			  cmdline=cmdline )
  10.217 +    if ret < 0:
  10.218 +        print "Error building Linux guest OS: "
  10.219 +        print "Return code from linux_build = " + str(ret)
  10.220 +        xc.domain_destroy ( dom=id )
  10.221 +        sys.exit()
  10.222 +
  10.223 +    # setup the virtual block devices
  10.224 +
  10.225 +    # set the expertise level appropriately
  10.226 +    XenoUtil.VBD_EXPERT_MODE = vbd_expert
  10.227 +    
  10.228 +    for ( uname, virt_name, rw ) in vbd_list:
  10.229 +	virt_dev = XenoUtil.blkdev_name_to_number( virt_name )
  10.230 +
  10.231 +	segments = XenoUtil.lookup_disk_uname( uname )
  10.232 +	if not segments:
  10.233 +	    print "Error looking up %s\n" % uname
  10.234 +	    xc.domain_destroy ( dom=id )
  10.235 +	    sys.exit()
  10.236 +
  10.237 +        # check that setting up this VBD won't violate the sharing
  10.238 +        # allowed by the current VBD expertise level
  10.239 +        if XenoUtil.vd_extents_validate(segments, rw=='w' or rw=='rw') < 0:
  10.240 +            xc.domain_destroy( dom = id )
  10.241 +            sys.exit()
  10.242 +            
  10.243 +	if xc.vbd_create( dom=id, vbd=virt_dev, writeable= rw=='w' or rw=='rw' ):
  10.244 +	    print "Error creating VBD vbd=%d writeable=%d\n" % (virt_dev,rw)
  10.245 +	    xc.domain_destroy ( dom=id )
  10.246 +	    sys.exit()
  10.247 +	
  10.248 +        if xc.vbd_setextents( dom=id,
  10.249 +                              vbd=virt_dev,
  10.250 +                              extents=segments):
  10.251 +            print "Error populating VBD vbd=%d\n" % virt_dev
  10.252 +            xc.domain_destroy ( dom=id )
  10.253 +            sys.exit()
  10.254 +
  10.255 +    # setup virtual firewall rules for all aliases
  10.256 +    for ip in vfr_ipaddr:
  10.257 +	XenoUtil.setup_vfr_rules_for_vif( id, 0, ip )
  10.258 +
  10.259 +    if xc.domain_start( dom=id ) < 0:
  10.260 +        print "Error starting domain"
  10.261 +        xc.domain_destroy ( dom=id )
  10.262 +        sys.exit()
  10.263 +
  10.264 +    return id
  10.265 +# end of make_domain()
  10.266 +
  10.267 +
  10.268 +
  10.269 +# The starting / monitoring of the domain actually happens here...
  10.270 +
  10.271 +# start the domain and record its ID number
  10.272 +current_id = make_domain()
  10.273 +print "VM started in domain %d" % current_id
  10.274 +
  10.275 +# if the auto_restart flag is set then keep polling to see if the domain is
  10.276 +# alive - restart if it is not by calling make_domain() again (it's necessary
  10.277 +# to update the id variable, since the new domain may have a new ID)
  10.278 +
  10.279 +if auto_restart:
  10.280 +    # turn ourselves into a background daemon
  10.281 +    try:
  10.282 +	pid = os.fork()
  10.283 +	if pid > 0:
  10.284 +	    sys.exit(0)
  10.285 +	os.setsid()
  10.286 +	pid = os.fork()
  10.287 +	if pid > 0:
  10.288 +	    print >> sys.stderr, 'Auto-restart daemon PID = %d' % pid
  10.289 +	    sys.exit(0)
  10.290 +    except:
  10.291 +	print >> sys.stderr, 'Problem starting daemon'
  10.292 +	sys.exit(1)
  10.293 +
  10.294 +    while auto_restart:
  10.295 +	time.sleep(1)
  10.296 +	if not xc.domain_getinfo(current_id):
  10.297 +	    print "Domain %d has terminated, restarting VM in new domain" % current_id
  10.298 +	    current_id = make_domain()
  10.299 +	    print "VM started in domain %d" % current_id
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tools/examples/xc_vd_tool.py	Sun Feb 01 22:30:47 2004 +0000
    11.3 @@ -0,0 +1,155 @@
    11.4 +#!/usr/bin/env python
    11.5 +
    11.6 +import XenoUtil, sys, re, string
    11.7 +
    11.8 +def usage():
    11.9 +
   11.10 +    print >>sys.stderr,"""
   11.11 +Usage: %s command <params>
   11.12 +
   11.13 +  initialise [dev] [[ext_size]] - init. a physcial partition to store vd's
   11.14 +  create [size] [[expiry]]      - allocate a vd of specified size (and expiry)
   11.15 +  enlarge [vdid] [extra_size]   - enlarge a specified vd by some amount
   11.16 +  delete [vdid]                 - delete a vd
   11.17 +  import [filename] [[expiry]]  - create a vd and populate w/ image from file
   11.18 +  export [vdid] [filename]      - copy vd's contents to a file
   11.19 +  setexpiry [vdid] [[expiry]]   - update the expiry time for a vd
   11.20 +  list                          - list all the unexpired virtual disks  
   11.21 +  undelete [vdid] [[expiry]]    - attempts to recover an expired vd
   11.22 +  freespace                     - print out the amount of space in free pool
   11.23 +
   11.24 +notes:
   11.25 +  vdid      - the virtual disk's identity string
   11.26 +  size      - measured in MB
   11.27 +  expiry    - is the expiry time of the virtual disk in seconds from now
   11.28 +               (0 = don't expire) 
   11.29 +  device    - physical partition to 'format' to hold vd's. e.g. hda4
   11.30 +  ext_size  - extent size (default 64MB)
   11.31 +""" % sys.argv[0]  
   11.32 +
   11.33 +if len(sys.argv) < 2: 
   11.34 +    usage()
   11.35 +    sys.exit(-1)
   11.36 +
   11.37 +rc=''
   11.38 +src=''
   11.39 +expiry_time = 0
   11.40 +cmd = sys.argv[1]
   11.41 +
   11.42 +if cmd == 'initialise':
   11.43 +
   11.44 +    dev = sys.argv[2]
   11.45 +
   11.46 +    if len(sys.argv) > 3:
   11.47 +	extent_size = int(sys.argv[3])
   11.48 +    else:
   11.49 +	print """No extent size specified - using default size of 64MB"""
   11.50 +	extent_size = 64
   11.51 +
   11.52 +    print "Formatting for virtual disks"
   11.53 +    print "Device: " + dev
   11.54 +    print "Extent size: " + str(extent_size) + "MB"
   11.55 +
   11.56 +    rc = XenoUtil.vd_format(dev, extent_size)
   11.57 +
   11.58 +elif cmd == 'create':
   11.59 + 
   11.60 +    size = int(sys.argv[2])
   11.61 +    
   11.62 +    if len(sys.argv) > 3:
   11.63 +	expiry_time = int(sys.argv[3])
   11.64 +
   11.65 +    print "Creating a virtual disk"
   11.66 +    print "Size: %d" % size
   11.67 +    print "Expiry time (seconds from now): %d" % expiry_time
   11.68 +
   11.69 +    src = XenoUtil.vd_create(size, expiry_time)
   11.70 +
   11.71 +elif cmd == 'enlarge':
   11.72 +
   11.73 +    id = sys.argv[2]
   11.74 +
   11.75 +    extra_size = int(sys.argv[3])
   11.76 +
   11.77 +    rc = XenoUtil.vd_enlarge(id, extra_size)
   11.78 +
   11.79 +elif cmd == 'delete':
   11.80 +
   11.81 +    id = sys.argv[2]
   11.82 +
   11.83 +    print "Deleting a virtual disk with ID: " + id
   11.84 +
   11.85 +    rc = XenoUtil.vd_delete(id)
   11.86 +
   11.87 +elif cmd == 'import':
   11.88 +
   11.89 +    file = sys.argv[2]
   11.90 +    
   11.91 +    if len(sys.argv) > 3:
   11.92 +	expiry_time = int(sys.argv[3])
   11.93 +
   11.94 +    print "Allocate new virtual disk and populate from file : %s" % file
   11.95 +
   11.96 +    print XenoUtil.vd_read_from_file(file, expiry_time)
   11.97 +
   11.98 +elif cmd == 'export':
   11.99 +
  11.100 +    id = sys.argv[2]
  11.101 +    file = sys.argv[3]
  11.102 +
  11.103 +    print "Dump contents of virtual disk to file : %s" % file
  11.104 +
  11.105 +    rc = XenoUtil.vd_cp_to_file(id, file )
  11.106 +
  11.107 +elif cmd == 'setexpiry':
  11.108 +
  11.109 +    id = sys.argv[2]
  11.110 +
  11.111 +    if len(sys.argv) > 3:
  11.112 +	expiry_time = int(sys.argv[3])
  11.113 +
  11.114 +    print "Refreshing a virtual disk"
  11.115 +    print "Id: " + id
  11.116 +    print "Expiry time (seconds from now [or 0]): " + expiry_time
  11.117 +
  11.118 +    rc = XenoUtil.vd_refresh(id, expiry_time)
  11.119 +
  11.120 +elif cmd == 'list':
  11.121 +
  11.122 +    for vbd in XenoUtil.vd_list():
  11.123 +        print """ID: %s
  11.124 +Expires: %s
  11.125 +Expiry time: %s
  11.126 +Size (MB): %d
  11.127 +""" % (vbd['vdisk_id'], vbd['expires'],
  11.128 +       str(vbd['expiry_time']), vbd['size'] / 2048)
  11.129 +
  11.130 +elif cmd == 'freespace':
  11.131 +
  11.132 +    print XenoUtil.vd_freespace()
  11.133 +
  11.134 +elif cmd == 'undelete':
  11.135 +
  11.136 +    id = sys.argv[2]
  11.137 +
  11.138 +    if len(sys.argv) > 3:
  11.139 +	expiry_time = int(sys.argv[3])
  11.140 +   
  11.141 +    if XenoUtil.vd_undelete(id, expiry_time):
  11.142 +	print "Undelete operation failed for virtual disk: " + id
  11.143 +    else:
  11.144 +	print "Undelete operation succeeded for virtual disk: " + id
  11.145 +
  11.146 +else:
  11.147 +    usage()
  11.148 +    sys.exit(-1)
  11.149 +
  11.150 +
  11.151 +if src != '':  
  11.152 +    print "Returned virtual disk id is : %s" % src
  11.153 +
  11.154 +if rc != '':
  11.155 +    print "return code %d" % rc
  11.156 +
  11.157 +
  11.158 +
    12.1 --- a/tools/misc/Makefile	Sat Jan 31 19:45:13 2004 +0000
    12.2 +++ b/tools/misc/Makefile	Sun Feb 01 22:30:47 2004 +0000
    12.3 @@ -7,7 +7,7 @@ HDRS     = $(wildcard *.h)
    12.4  SRCS     = $(wildcard *.c)
    12.5  OBJS     = $(patsubst %.c,%.o,$(SRCS))
    12.6  
    12.7 -TARGETS  = xen_read_console xen_refresh_dev xen_cpuperf
    12.8 +TARGETS  = xen_read_console xen_cpuperf
    12.9  
   12.10  INSTALL  = $(TARGETS) xen-mkdevnodes xen_nat_enable xen-clone 
   12.11  
   12.12 @@ -16,7 +16,7 @@ all: $(TARGETS)
   12.13  
   12.14  install: all
   12.15  	mkdir -p /usr/bin
   12.16 -	cp $(INSTALL) /usr/bin
   12.17 +	cp -a $(INSTALL) /usr/bin
   12.18  	chmod 755 /usr/bin/xen-mkdevnodes
   12.19  	chmod 755 /usr/bin/xen_nat_enable
   12.20  	chmod 755 /usr/bin/xen-clone
   12.21 @@ -24,7 +24,7 @@ install: all
   12.22  
   12.23  dist: all
   12.24  	mkdir -p ../../../install/bin
   12.25 -	cp $(INSTALL) ../../../install/bin
   12.26 +	cp -a $(INSTALL) ../../../install/bin
   12.27  	chmod 755 ../../../install/bin/xen-mkdevnodes
   12.28  	chmod 755 ../../../install/bin/xen_nat_enable
   12.29  	chmod 755 ../../../install/bin/xen-clone
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/tools/misc/xen_dmesg.py	Sun Feb 01 22:30:47 2004 +0000
    13.3 @@ -0,0 +1,26 @@
    13.4 +#!/usr/bin/env python
    13.5 +
    13.6 +"""Reads out the contents of the console ring
    13.7 +
    13.8 +Usage: readconsolering.py [-c]
    13.9 +The -c option causes the contents to be cleared.
   13.10 +"""
   13.11 +
   13.12 +import sys, Xc # import the Xc Xen Control module
   13.13 +
   13.14 +xc = Xc.new() # get a new instance of the control interface
   13.15 +
   13.16 +clear_buffer = False
   13.17 +
   13.18 +if sys.argv[1:] != []:
   13.19 +    if sys.argv[1] == "-c":
   13.20 +        clear_buffer = True
   13.21 +    else:
   13.22 +        print >> sys.stderr, "Usage: " + sys.argv[0] + """ [-c]
   13.23 +       Reads the contents of the console buffer.
   13.24 +       (specifying -c will also clear current contents)"""
   13.25 +
   13.26 +# Get the console ring's contents as a string and print it out.
   13.27 +# If argument to readconsolering is true then the buffer is cleared as well as
   13.28 +# fetching the (pre-clearing) contents.
   13.29 +print xc.readconsolering(clear_buffer)
    14.1 --- a/tools/misc/xen_nat_enable	Sat Jan 31 19:45:13 2004 +0000
    14.2 +++ b/tools/misc/xen_nat_enable	Sun Feb 01 22:30:47 2004 +0000
    14.3 @@ -7,7 +7,7 @@ run_iptables() {
    14.4  }
    14.5  
    14.6  ifconfig eth0 up
    14.7 -ifconfig eth0:0 169.254.1.0 up
    14.8 +ifconfig eth0:xen 169.254.1.0 up
    14.9  
   14.10  run_iptables -t filter -F
   14.11  run_iptables -t nat -F
    15.1 --- a/tools/xc/py/Makefile	Sat Jan 31 19:45:13 2004 +0000
    15.2 +++ b/tools/xc/py/Makefile	Sun Feb 01 22:30:47 2004 +0000
    15.3 @@ -10,6 +10,7 @@ dist: all
    15.4  	for i in `find . -name 'Xc.so'` ; do                           \
    15.5  		cp $$i ../../../../install/lib/python/`basename $$i` ; \
    15.6  	done
    15.7 -
    15.8 +	python -c 'import py_compile, sys; py_compile.compile("XenoUtil.py")'
    15.9 +	cp XenoUtil.py* ../../../../install/lib/python
   15.10  clean:
   15.11  	rm -rf build *.pyc *.pyo *.o *.a *~
    16.1 --- a/tools/xc/py/XenoUtil.py	Sat Jan 31 19:45:13 2004 +0000
    16.2 +++ b/tools/xc/py/XenoUtil.py	Sun Feb 01 22:30:47 2004 +0000
    16.3 @@ -99,6 +99,22 @@ def add_offset_to_ip( ip, off ):
    16.4      return '%d.%d.%d.%d' % ( ((a>>24)&0xff), ((a>>16)&0xff),
    16.5  			     ((a>>8)&0xff), (a&0xff) )
    16.6  
    16.7 +def check_subnet( ip, network, netmask ):
    16.8 +    l = string.split(ip,'.')
    16.9 +    n_ip = ( (string.atoi(l[0])<<24) | (string.atoi(l[1])<<16) | 
   16.10 +	   (string.atoi(l[2])<<8)  | string.atoi(l[3]) ) 
   16.11 +
   16.12 +    l = string.split(network,'.')
   16.13 +    n_net = ( (string.atoi(l[0])<<24) | (string.atoi(l[1])<<16) | 
   16.14 +	   (string.atoi(l[2])<<8)  | string.atoi(l[3]) )
   16.15 +
   16.16 +    l = string.split(netmask,'.')
   16.17 +    n_mask = ( (string.atoi(l[0])<<24) | (string.atoi(l[1])<<16) | 
   16.18 +	   (string.atoi(l[2])<<8)  | string.atoi(l[3]) )
   16.19 +    
   16.20 +    return (n_ip&n_mask)==(n_net&n_mask)
   16.21 +
   16.22 +
   16.23  ##### VBD-related Functions
   16.24  
   16.25  def blkdev_name_to_number(name):
   16.26 @@ -171,6 +187,46 @@ def lookup_disk_uname( uname ):
   16.27  
   16.28  ##### VD Management-related functions
   16.29  
   16.30 +##### By Mark Williamson, <mark.a.williamson@intel.com>
   16.31 +##### (C) Intel Research Cambridge
   16.32 +
   16.33 +# TODO:
   16.34 +#
   16.35 +# Plenty of room for enhancement to this functionality (contributions
   16.36 +# welcome - and then you get to have your name in the source ;-)...
   16.37 +#
   16.38 +# vd_unformat() : want facilities to unallocate virtual disk
   16.39 +# partitions, possibly migrating virtual disks of them, with checks to see if
   16.40 +# it's safe and options to force it anyway
   16.41 +#
   16.42 +# vd_create() : should have an optional argument specifying a physical
   16.43 +# disk preference - useful to allocate for guest doms to do RAID
   16.44 +#
   16.45 +# vd_undelete() : add ability to "best effort" undelete as much of a
   16.46 +# vdisk as is left in the case that some of it has already been
   16.47 +# reallocated.  Some people might still be able to recover some of
   16.48 +# their data this way, even if some of the disk has disappeared.
   16.49 +#
   16.50 +# It'd be nice if we could wipe virtual disks for security purposes -
   16.51 +# should be easy to do this using dev if=/dev/{zero,random} on each
   16.52 +# extent in turn.  There could be another optional flag to vd_create
   16.53 +# in order to allow this.
   16.54 +#
   16.55 +# Error codes could be more expressive - i.e. actually tell why the
   16.56 +# error occurred rather than "it broke".  Currently the code avoids
   16.57 +# using exceptions to make control scripting simpler and more
   16.58 +# accessible to beginners - therefore probably should just use more
   16.59 +# return codes.
   16.60 +#
   16.61 +# Enhancements / additions to the example scripts are also welcome:
   16.62 +# some people will interact with this code mostly through those
   16.63 +# scripts.
   16.64 +#
   16.65 +# More documentation of how this stuff should be used is always nice -
   16.66 +# if you have a novel configuration that you feel isn't discussed
   16.67 +# enough in the HOWTO (which is currently a work in progress), feel
   16.68 +# free to contribute a walkthrough, or something more substantial.
   16.69 +#
   16.70  
   16.71  
   16.72  def __vd_no_database():
   16.73 @@ -179,6 +235,7 @@ def __vd_no_database():
   16.74      print >> sys.stderr, "ERROR: Could not locate the database file at " + VD_DB_FILE
   16.75      sys.exit(1)
   16.76  
   16.77 +
   16.78  def vd_format(partition, extent_size_mb):
   16.79      """Format a partition or drive for use a virtual disk storage.
   16.80      partition [string]: device file representing the partition
   16.81 @@ -496,6 +553,9 @@ def vd_undelete(vdisk_id, expiry_time):
   16.82      if not os.path.isfile(VD_DB_FILE):
   16.83          __vd_no_database()
   16.84  
   16.85 +    if vdisk_id == '0': #  undeleting vdisk 0 isn't sane!
   16.86 +        return -1
   16.87 +
   16.88      cx = sqlite.connect(VD_DB_FILE)
   16.89      cu = cx.cursor()
   16.90