097e61e5f3c6dcf02e17e3008fef65bfa373e58a
[sfa.git] / sfa / iotlab / iotlabpostgres.py
1 """
2 File holding a class to define the table in the iotlab dedicated table.
3 The table is the SFA dtabase, therefore all the access mecanism
4 (session, engine...) is handled by alchemy.py.
5
6 ..seealso:: alchemy.py
7 """
8
9 from sfa.storage.model import Base
10 from sqlalchemy import Column, Integer, String
11
12
13
14 class LeaseTableXP (Base):
15     """ SQL alchemy class to manipulate the rows of the lease_table table in the
16     SFA database. Handles the records representation and creates.
17     Table creation is made by the importer if it is not in the database yet.
18
19     .. seealso:: init_tables in model.py, run in iotlabimporter.py
20
21     """
22     __tablename__ = 'lease_table'
23
24     slice_hrn = Column(String)
25     experiment_id = Column(Integer, primary_key=True)
26     end_time = Column(Integer, nullable=False)
27
28     def __init__(self, slice_hrn=None, experiment_id=None,  end_time=None):
29         """
30         Defines a row of the lease_table table
31         """
32         if slice_hrn:
33             self.slice_hrn = slice_hrn
34         if experiment_id:
35             self.experiment_id = experiment_id
36         if end_time:
37             self.end_time = end_time
38
39     def __repr__(self):
40         """Prints the SQLAlchemy record to the format defined
41         by the function.
42         """
43         result = "<lease_table : slice_hrn = %s , experiment_id %s \
44             end_time = %s" % (self.slice_hrn, self.experiment_id,
45             self.end_time)
46         result += ">"
47         return result