1 from sqlalchemy import *
3 from sqlalchemy.ext.sessioncontext import SessionContext
4 from sqlalchemy.ext.assignmapper import assign_mapper
17 meta = DynamicMetaData()
18 ctx = SessionContext(create_session)
20 machine_table = Table('machines', meta,
21 Column('machine_id', Integer, primary_key=True, nullable=False),
22 Column('name', String, nullable=False),
23 Column('memory', Integer, nullable=False),
24 Column('owner', String, nullable=False),
25 Column('contact', String, nullable=False),
26 Column('uuid', String, nullable=False),
27 Column('boot_off_cd', Boolean, nullable=False, default=False),
28 Column('type_id', String, ForeignKey('types.type_id'), nullable=False),
29 Column('autorestart', Boolean, nullable=False, default=False),
30 Column('cpus', Integer, nullable=False, default=1))
32 nic_table = Table('nics', meta,
33 Column('machine_id', Integer, ForeignKey('machines.machine_id'), nullable=True),
34 Column('mac_addr', String, nullable=False),
35 Column('ip', String, nullable=False),
36 Column('hostname', String, primary_key=True, nullable=False))
38 disk_table = Table('disks', meta,
39 Column('machine_id', Integer, ForeignKey('machines.machine_id'), nullable=False),
40 Column('guest_device_name', String, nullable=False),
41 Column('size', Integer, nullable=False),
42 PrimaryKeyConstraint('machine_id', 'guest_device_name'))
44 types_table = Table('types', meta,
45 Column('type_id', String, primary_key=True, nullable=False),
46 Column('description', String, nullable=False),
47 Column('hvm', Boolean, nullable=False),
48 Column('apic', Boolean, nullable=False),
49 Column('acpi', Boolean, nullable=False),
50 Column('pae', Boolean, nullable=False))
53 class Machine(object):
66 assign_mapper(ctx, Machine, machine_table, \
67 properties={'nics': relation(NIC),
68 'disks': relation(Disk)});
69 assign_mapper(ctx, NIC, nic_table)
70 assign_mapper(ctx, Disk, disk_table)
71 assign_mapper(ctx, Type, types_table)