1 # -*- mode: python; -*-
2 from invirt.database import models, connect
3 from invirt.config import structs as config
9 # 'machine_name', and optionally 'cdrom_image', should get passed in
10 # from the xm create call
17 machine = models.Machine.query().filter_by(name=machine_name).one()
18 check(machine is not None)
19 machine_type = machine.type
21 if 'cdrom_image' in locals():
22 cdrom = models.CDROM.query().filter_by(cdrom_id=cdrom_image).one()
23 check(cdrom is not None)
25 memory = machine.memory
27 check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
28 name = prefix + machine.name
29 check(re.match('^[0-9a-f-]+$', machine.uuid))
37 pae = machine_type.pae
38 acpi = machine_type.acpi
39 apic = machine_type.apic
50 if 'installer_options' in locals(): #Installer
51 disk.append('phy:/dev/xenvg/s_install_hda,hdb,r')
54 release = os.uname()[2]
55 kernel = '/boot/vmlinuz-%s' % release
56 ramdisk = '/boot/initrd.img-%s' % release
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 += ' %s' % installer_options
68 memory = max(memory, 512)
69 elif cdrom is not None:
70 disk.append('phy:/dev/xenvg/image_' + cdrom.cdrom_id + ',hdc:cdrom,r')
76 viftype = "type=ioemu, "
77 kernel = '/usr/lib/xen/boot/hvmloader'
80 device_model = '/usr/sbin/qemu-dm-invirt'
82 elif codepath == 'paravm':
83 bootloader = '/usr/bin/pygrub'
86 for n in machine.nics:
87 check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
88 d = ('%smac=%s, ip=%s, script=vif-invirtroute netdev=%s'
89 % (viftype, n.mac_addr, n.ip, config.xen.network.iface))
92 for d in machine.disks:
93 check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
94 device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
95 dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
100 on_poweroff = 'destroy'
101 on_reboot = 'restart'
103 if machine.autorestart: