1 from sqlalchemy import *
3 from sqlalchemy.ext.sessioncontext import SessionContext
4 from sqlalchemy.ext.assignmapper import assign_mapper
6 meta = DynamicMetaData()
7 ctx = SessionContext(create_session)
9 machine_table = Table('machines', meta,
10 Column('machine_id', Integer, primary_key=True, nullable=False),
11 Column('name', String, nullable=False),
12 Column('memory', Integer, nullable=False),
13 Column('owner', String, nullable=False),
14 Column('contact', String, nullable=False),
15 Column('uuid', String, nullable=False),
16 Column('boot_off_cd', Boolean, nullable=False, default=False),
17 Column('type_id', String, ForeignKey('types.type_id'), nullable=False),
18 Column('autorestart', Boolean, nullable=False, default=False),
19 Column('cpus', Integer, nullable=False, default=1))
21 nic_table = Table('nics', meta,
22 Column('machine_id', Integer, ForeignKey('machines.machine_id'), nullable=True),
23 Column('mac_addr', String, nullable=False),
24 Column('ip', String, nullable=False),
25 Column('hostname', String, primary_key=True, nullable=False))
27 disk_table = Table('disks', meta,
28 Column('machine_id', Integer, ForeignKey('machines.machine_id'), nullable=False),
29 Column('guest_device_name', String, nullable=False),
30 Column('size', Integer, nullable=False),
31 PrimaryKeyConstraint('machine_id', 'guest_device_name'))
33 types_table = Table('types', meta,
34 Column('type_id', String, primary_key=True, nullable=False),
35 Column('description', String, nullable=False),
36 Column('apic', Boolean, nullable=False),
37 Column('acpi', Boolean, nullable=False),
38 Column('pae', Boolean, nullable=False))
41 class Machine(object):
54 assign_mapper(ctx, Machine, machine_table, \
55 properties={'nics': relation(NIC),
56 'disks': relation(Disk)});
57 assign_mapper(ctx, NIC, nic_table)
58 assign_mapper(ctx, Disk, disk_table)
59 assign_mapper(ctx, Type, types_table)