Changeset 18


Ignore:
Timestamp:
Jul 15, 2007, 5:14:21 PM (17 years ago)
Author:
nelhage
svk:copy_cache_prev:
17
Message:

Adding ORM tables for the sqlalchemy models

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-database/sipb-xen-database/sipb_xen_database/models.py

    r13 r18  
    11from sqlalchemy import *
    22
     3from sqlalchemy.ext.sessioncontext import SessionContext
     4from sqlalchemy.ext.assignmapper import assign_mapper
     5
    36meta = DynamicMetaData()
     7ctx = SessionContext(create_session)
    48
    59machine_table = Table('machines', meta,
     
    1822       Column('machine_id', Integer, ForeignKey('machines.machine_id'), nullable=True),
    1923       Column('mac_addr', String, nullable=False),
    20        Column('hostname', String, nullable=False))
     24       Column('ip', String, nullable=False),
     25       Column('hostname', String, primary_key=True, nullable=False))
    2126
    2227disk_table = Table('disks', meta,
     
    3338       Column('pae', Boolean, nullable=False))
    3439
     40
     41class Machine(object):
     42    pass
     43
     44class NIC(object):
     45    pass
     46
     47class Disk(object):
     48    pass
     49
     50class Type(object):
     51    pass
     52
     53
     54assign_mapper(ctx, Machine, machine_table, \
     55              properties={'nics': relation(NIC),
     56                          'disks': relation(Disk)});
     57assign_mapper(ctx, NIC, nic_table)
     58assign_mapper(ctx, Disk, disk_table)
     59assign_mapper(ctx, Type, types_table)
     60
Note: See TracChangeset for help on using the changeset viewer.