Guest User

Untitled

a guest
Aug 12th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.88 KB | None | 0 0
  1. # -*- mode: python; -*-
  2. #============================================================================
  3. # Example Python setup script for Debian guest installation.
  4. #============================================================================
  5. #
  6. # Standard options are configured as normal. Only a subset are included below.
  7. # See /usr/share/doc/xen-utils-common/examples for full examples.
  8. #
  9. # After standard options are configure use
  10. # xm create xm-debian.cfg install=true"
  11. # to start the Debian Installer.
  12. #
  13. # In the installation case the following additional variables exist:
  14. #
  15. # COMMON OPTIONS
  16. # install-method: "cdrom" or "network"
  17. # install-arch: which architecture to install. e.g. i386 or amd64
  18. # install-installer: URL or path to the Debian Installer bits. By
  19. # default for a network install these are located under
  20. # install-mirror. For a CDROM install the default is a fixed path on
  21. # the CD.
  22. # install-kernel, install-ramdisk: URL/path to the installer kernel and
  23. # ramdisk to use, by default these are located via install-installer.
  24. # install-extra: extra command line arguments
  25. #
  26. # CDROM SPECIFIC OPTIONS
  27. # install-media: Path to the Debian install media (i.e. an ISO)
  28. # install-cdrom-device: Name of the CD-ROM device within the guest.
  29. #
  30. # NETWORK SPECIFIC OPTIONS
  31. # install-suite: which Debian version to install. e.g. lenny, squeeze or sid
  32. # install-mirror: which Debian mirror to use
  33. # e.g. http://ftp.uk.debian.org/debian
  34. #============================================================================
  35.  
  36.  
  37. #----------------------------------------------------------------------------
  38. # Standard variables
  39.  
  40. # Initial memory allocation (in megabytes) for the new domain.
  41. memory = 256
  42.  
  43. # A name for your domain. All domains must have different names.
  44. name = "Deluge"
  45.  
  46. # 128-bit UUID for the domain. The default behavior is to generate a new UUID
  47. # on each call to 'xm create'.
  48. #uuid = "06ed00fe-1162-4fc4-b5d8-11993ee4a8b9"
  49.  
  50. # List of which CPUS this domain is allowed to use, default Xen picks
  51. #cpus = "" # leave to Xen to pick
  52. #cpus = "0" # all vcpus run on CPU0
  53. #cpus = "0-3,5,^1" # run on cpus 0,2,3,5
  54.  
  55. # Number of Virtual CPUS to use, default is 1
  56. vcpus = 1
  57.  
  58. #----------------------------------------------------------------------------
  59. # Define network interfaces.
  60.  
  61. # By default, no network interfaces are configured. You may have one created
  62. # with sensible defaults using an empty vif clause:
  63. #
  64. # vif = ['']
  65. #
  66. # or optionally override backend, bridge, ip, mac, script, type, or vifname:
  67. #
  68. # vif = ['mac=00:16:3e:00:00:11, bridge=xenbr0']
  69. #
  70. # or more than one interface may be configured:
  71. #
  72. # vif = ['', 'bridge=xenbr1']
  73.  
  74. #vif = ['']
  75. vif = ['mac=aa:00:00:00:00:01','bridge=br0']
  76.  
  77.  
  78. #----------------------------------------------------------------------------
  79. # Define the disk devices you want the domain to have access to, and
  80. # what you want them accessible as.
  81. # Each disk entry is of the form phy:UNAME,DEV,MODE
  82. # where UNAME is the device, DEV is the device name the domain will see,
  83. # and MODE is r for read-only, w for read-write.
  84. #
  85. # NB: Only xvd devices are supported by the kernel in Debian Lenny and later.
  86.  
  87. disk = ['file:/work/virtual_machines/deluge/deluge.img,xvda,w']
  88.  
  89. #----------------------------------------------------------------------------
  90. # Define frame buffer device.
  91. #
  92. # By default, no frame buffer device is configured.
  93. #
  94. # To create one using the SDL backend and sensible defaults:
  95. #
  96. # vfb = [ 'type=sdl' ]
  97. #
  98. # This uses environment variables XAUTHORITY and DISPLAY. You
  99. # can override that:
  100. #
  101. # vfb = [ 'type=sdl,xauthority=/home/bozo/.Xauthority,display=:1' ]
  102. #
  103. # To create one using the VNC backend and sensible defaults:
  104. #
  105. # vfb = [ 'type=vnc' ]
  106. #
  107. # The backend listens on 127.0.0.1 port 5900+N by default, where N is
  108. # the domain ID. You can override both address and N:
  109. #
  110. # vfb = [ 'type=vnc,vnclisten=0.0.0.0' ]
  111. #
  112. # Or you can bind the first unused port above 5900:
  113. #
  114. # vfb = [ 'type=vnc,vnclisten=0.0.0.0,vnunused=1' ]
  115. #
  116. # You can override the password:
  117. #
  118. # vfb = [ type=vnc,vncpasswd=deluge' ]
  119. #
  120. # Empty password disables authentication. Defaults to the vncpasswd
  121. # configured in xend-config.sxp.
  122.  
  123.  
  124. #============================================================================
  125. # Debian Installer specific variables
  126.  
  127. def check_bool(name, value):
  128. value = str(value).lower()
  129. if value in ('t', 'tr', 'tru', 'true'):
  130. return True
  131. return False
  132.  
  133. global var_check_with_default
  134. def var_check_with_default(default, var, val):
  135. if val:
  136. return val
  137. return default
  138.  
  139. xm_vars.var('install', use='Install Debian, default: false', check=check_bool)
  140. xm_vars.var("install-method",
  141. use='Installation method to use "cdrom" or "network" (default: network)',
  142. check=lambda var, val: var_check_with_default('network', var, val))
  143.  
  144. # install-method == "network"
  145. xm_vars.var("install-mirror",
  146. use='Debian mirror to install from (default: http://ftp.debian.org/debian)',
  147. check=lambda var, val: var_check_with_default('http://ftp.debian.org/debian', var, val))
  148. xm_vars.var("install-suite",
  149. use='Debian suite to install (default: squeeze)',
  150. check=lambda var, val: var_check_with_default('squeeze', var, val))
  151.  
  152. # install-method == "cdrom"
  153. xm_vars.var("install-media",
  154. use='Installation media to use (default: None)',
  155. check=lambda var, val: var_check_with_default(None, var, val))
  156. xm_vars.var("install-cdrom-device",
  157. use='Installation media to use (default: xvdd)',
  158. check=lambda var, val: var_check_with_default('xvdd', var, val))
  159.  
  160. # Common options
  161. xm_vars.var("install-arch",
  162. use='Debian mirror to install from (default: amd64)',
  163. check=lambda var, val: var_check_with_default('amd64', var, val))
  164. xm_vars.var("install-extra",
  165. use='Extra command line options (default: None)',
  166. check=lambda var, val: var_check_with_default(None, var, val))
  167. xm_vars.var("install-installer",
  168. use='Debian installer to use (default: network uses install-mirror; cdrom uses /install.ARCH)',
  169. check=lambda var, val: var_check_with_default(None, var, val))
  170. xm_vars.var("install-kernel",
  171. use='Debian installer kernel to use (default: uses install-installer)',
  172. check=lambda var, val: var_check_with_default(None, var, val))
  173. xm_vars.var("install-ramdisk",
  174. use='Debian installer ramdisk to use (default: uses install-installer)',
  175. check=lambda var, val: var_check_with_default(None, var, val))
  176.  
  177. xm_vars.check()
  178.  
  179. if not xm_vars.env.get('install'):
  180. bootloader="pygrub"
  181. elif xm_vars.env['install-method'] == "network":
  182. import os.path
  183. print "Install Mirror: %s" % xm_vars.env['install-mirror']
  184. print "Install Suite: %s" % xm_vars.env['install-suite']
  185. if xm_vars.env['install-installer']:
  186. installer = xm_vars.env['install-installer']
  187. else:
  188. installer = xm_vars.env['install-mirror']+"/dists/"+xm_vars.env['install-suite'] + \
  189. "/main/installer-"+xm_vars.env['install-arch']+"/current/images"
  190. print "Installer: %s" % installer
  191.  
  192. print
  193. print "WARNING: Installer kernel and ramdisk are not authenticated."
  194. print
  195.  
  196. if xm_vars.env.get('install-kernel'):
  197. kernelurl = xm_vars.env['install-kernel']
  198. else:
  199. kernelurl = installer + "/netboot/xen/vmlinuz"
  200.  
  201. if xm_vars.env.get('install-ramdisk'):
  202. ramdiskurl = xm_vars.env['install-ramdisk']
  203. else:
  204. ramdiskurl = installer + "/netboot/xen/initrd.gz"
  205.  
  206. import urllib
  207. class MyUrlOpener(urllib.FancyURLopener):
  208. def http_error_default(self, req, fp, code, msg, hdrs):
  209. raise IOError("%s %s" % (code, msg))
  210. urlopener = MyUrlOpener()
  211.  
  212. try:
  213. print "Fetching %s" % kernelurl
  214. kernel, _ = urlopener.retrieve(kernelurl)
  215. print "Fetching %s" % ramdiskurl
  216. ramdisk, _ = urlopener.retrieve(ramdiskurl)
  217. except IOError, _:
  218. raise
  219.  
  220. elif xm_vars.env['install-method'] == "cdrom":
  221. arch_path = { 'i386': "/install.386",
  222. 'amd64': "/install.amd" }
  223.  
  224. if xm_vars.env['install-media']:
  225. print "Install Media: %s" % xm_vars.env['install-media']
  226. else:
  227. raise OptionError("No installation media given.")
  228.  
  229. if xm_vars.env['install-installer']:
  230. installer = xm_vars.env['install-installer']
  231. else:
  232. installer = arch_path[xm_vars.env['install-arch']]
  233.  
  234. print "Installer: %s" % installer
  235.  
  236. if xm_vars.env.get('install-kernel'):
  237. kernelpath = xm_vars.env['install-kernel']
  238. else:
  239. kernelpath = installer + "/xen/vmlinuz"
  240.  
  241. if xm_vars.env.get('install-ramdisk'):
  242. ramdiskpath = xm_vars.env['install-ramdisk']
  243. else:
  244. ramdiskpath = installer + "/xen/initrd.gz"
  245.  
  246. disk.insert(0, 'file:%s,%s:cdrom,r' % (xm_vars.env['install-media'],
  247. xm_vars.env['install-cdrom-device']))
  248.  
  249. bootloader="pygrub"
  250. bootargs="--kernel=%s --ramdisk=%s" % (kernelpath, ramdiskpath)
  251. print "From CD"
  252. else:
  253. print "WARNING: Unknown install-method: %s." % xm_vars.env['install-method']
  254.  
  255. if xm_vars.env.get('install'):
  256. # Figure out command line
  257. if xm_vars.env['install-extra']:
  258. extras=[xm_vars.env['install-extra']]
  259. else:
  260. extras=[]
  261.  
  262. # Reboot will just restart the installer since this file is not
  263. # reparsed, so halt and restart that way.
  264. extras.append("debian-installer/exit/always_halt=true")
  265. extras.append("--")
  266. extras.append("quiet")
  267.  
  268. console="hvc0"
  269. try:
  270. if len(vfb) >= 1:
  271. console="tty0"
  272. except NameError, e:
  273. pass
  274.  
  275. extras.append("console="+ console)
  276.  
  277. extra = str.join(" ", extras)
  278. print "command line is \"%s\"" % extra
Advertisement
Add Comment
Please, Sign In to add comment