1 # -*- mode: python; -*-
2 from invirt.database import models, connect
3 from invirt.config import structs as config
6 from subprocess import call
11 # 'machine_name', and optionally 'cdrom_image', should get passed in
12 # from the xm create call
19 machine = models.Machine.query().filter_by(name=machine_name).one()
20 check(machine is not None)
21 machine_type = machine.type
23 if 'cdrom_image' in locals():
24 cdrom = models.CDROM.query().filter_by(name=cdrom_image).one()
25 check(cdrom is not None)
27 memory = machine.memory
29 check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
30 name = prefix + machine.name
31 check(re.match('^[0-9a-f-]+$', machine.uuid))
39 pae = machine_type.pae
40 acpi = machine_type.acpi
41 apic = machine_type.apic
52 if 'mirror' in locals(): #Installer
53 disk.append('phy:/dev/xenvg/s_install_hda,hdb,r')
55 kernel = '/boot/vmlinuz-2.6.24-19-xen' #From hardy
56 ramdisk = '/boot/initrd.img-2.6.24-19-xen'
59 raise RuntimeError('You must have a nic to autoinstall')
62 extra += (' ip=%s::%s:%s:%s:eth0:off'
63 % (n.ip, config.dhcp.gateway, config.dhcp.netmask, machine.name))
64 extra += ' mirror=%s dist=%s' % (mirror, dist)
65 extra += ' imagesize=%s' % imagesize
66 if 'noinstall' in locals():
70 elif cdrom is not None:
71 disk.append('phy:/etc/xenvg/image_' + cdrom.cdrom_id + ',hdc:cdrom,r')
77 viftype = "type=ioemu, "
78 kernel = '/usr/lib/xen/boot/hvmloader'
82 device_model = '/usr/sbin/qemu-dm-sipb'
84 elif codepath == 'paravm':
85 bootloader = '/usr/lib/xen-default/bin/pygrub'
88 for n in machine.nics:
89 check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
90 d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip)
93 for d in machine.disks:
94 check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
95 device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
96 dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
101 on_poweroff = 'destroy'
102 on_reboot = 'restart'
104 if machine.autorestart: