ia64/xen-unstable

view tools/examples/xc_vd_tool.py @ 1372:5a6113c65ead

bitkeeper revision 1.891.1.12 (40a248b0WTGoOa9206iWkyGN0mTPNw)

Allow forcing of IRQ trigger-type to edge or level
(NB. DANGEROUS!).
author kaf24@scramble.cl.cam.ac.uk
date Wed May 12 15:54:24 2004 +0000 (2004-05-12)
parents a6e98694ed63
children
line source
1 #!/usr/bin/env python
3 import xenctl.utils, sys, re, string
5 def usage():
7 print >>sys.stderr,"""
8 Usage: %s command <params>
10 initialise [dev] [[ext_size]] - init. a physcial partition to store vd's
11 create [size] [[expiry]] - allocate a vd of specified size (and expiry)
12 enlarge [vdid] [extra_size] - enlarge a specified vd by some amount
13 delete [vdid] - delete a vd
14 import [filename] [[expiry]] - create a vd and populate w/ image from file
15 export [vdid] [filename] - copy vd's contents to a file
16 setexpiry [vdid] [[expiry]] - update the expiry time for a vd
17 list - list all the unexpired virtual disks
18 undelete [vdid] [[expiry]] - attempts to recover an expired vd
19 freespace - print out the amount of space in free pool
21 notes:
22 vdid - the virtual disk's identity string
23 size - measured in MB
24 expiry - is the expiry time of the virtual disk in seconds from now
25 (0 = don't expire)
26 device - physical partition to 'format' to hold vd's. e.g. hda4
27 ext_size - extent size (default 64MB)
28 """ % sys.argv[0]
30 if len(sys.argv) < 2:
31 usage()
32 sys.exit(-1)
34 rc=''
35 src=''
36 expiry_time = 0
37 cmd = sys.argv[1]
39 if cmd == 'initialise':
41 dev = sys.argv[2]
43 if len(sys.argv) > 3:
44 extent_size = int(sys.argv[3])
45 else:
46 print """No extent size specified - using default size of 64MB"""
47 extent_size = 64
49 print "Formatting for virtual disks"
50 print "Device: " + dev
51 print "Extent size: " + str(extent_size) + "MB"
53 rc = xenctl.utils.vd_format(dev, extent_size)
55 elif cmd == 'create':
57 size = int(sys.argv[2])
59 if len(sys.argv) > 3:
60 expiry_time = int(sys.argv[3])
62 print "Creating a virtual disk"
63 print "Size: %d" % size
64 print "Expiry time (seconds from now): %d" % expiry_time
66 src = xenctl.utils.vd_create(size, expiry_time)
68 elif cmd == 'enlarge':
70 id = sys.argv[2]
72 extra_size = int(sys.argv[3])
74 rc = xenctl.utils.vd_enlarge(id, extra_size)
76 elif cmd == 'delete':
78 id = sys.argv[2]
80 print "Deleting a virtual disk with ID: " + id
82 rc = xenctl.utils.vd_delete(id)
84 elif cmd == 'import':
86 file = sys.argv[2]
88 if len(sys.argv) > 3:
89 expiry_time = int(sys.argv[3])
91 print "Allocate new virtual disk and populate from file : %s" % file
93 print xenctl.utils.vd_read_from_file(file, expiry_time)
95 elif cmd == 'export':
97 id = sys.argv[2]
98 file = sys.argv[3]
100 print "Dump contents of virtual disk to file : %s" % file
102 rc = xenctl.utils.vd_cp_to_file(id, file )
104 elif cmd == 'setexpiry':
106 id = sys.argv[2]
108 if len(sys.argv) > 3:
109 expiry_time = int(sys.argv[3])
111 print "Refreshing a virtual disk"
112 print "Id: " + id
113 print "Expiry time (seconds from now [or 0]): " + str(expiry_time)
115 rc = xenctl.utils.vd_refresh(id, expiry_time)
117 elif cmd == 'list':
118 print 'ID Size(MB) Expiry'
120 for vbd in xenctl.utils.vd_list():
121 vbd['size_mb'] = vbd['size'] / 2048
122 vbd['expiry'] = (vbd['expires'] and vbd['expiry_time']) or 'never'
123 print '%(vdisk_id)-4s %(size_mb)-12d %(expiry)s' % vbd
125 elif cmd == 'freespace':
127 print xenctl.utils.vd_freespace()
129 elif cmd == 'undelete':
131 id = sys.argv[2]
133 if len(sys.argv) > 3:
134 expiry_time = int(sys.argv[3])
136 if xenctl.utils.vd_undelete(id, expiry_time):
137 print "Undelete operation failed for virtual disk: " + id
138 else:
139 print "Undelete operation succeeded for virtual disk: " + id
141 else:
142 usage()
143 sys.exit(-1)
146 if src != '':
147 print "Returned virtual disk id is : %s" % src
149 if rc != '':
150 print "return code %d" % rc