3aa45ec75d1907e81e0f5c33d1676546d2c9733f
[sfa.git] / sfa / importer / iotlabimporter.py
1 # -*- coding:utf-8 -*-
2 """ Iot-LAB importer class management """
3
4 from sfa.storage.alchemy import engine
5 from sfa.storage.model import init_tables
6 from sqlalchemy import Table, MetaData
7 from sqlalchemy.exc import NoSuchTableError
8
9 class IotLabImporter:
10     """
11     Creates the iotlab specific lease table to keep track
12     of which slice hrn match OAR job
13     """
14
15     def __init__(self, auth_hierarchy, loc_logger):
16         self.logger = loc_logger
17         self.logger.setLevelDebug()
18
19     def add_options (self, parser):
20         """ Not used and need by SFA """
21         pass
22     
23     def _exists(self, tablename):
24         """
25         Checks if the table exists in SFA database.
26         """
27         metadata = MetaData(bind=engine)
28         try:
29             Table(tablename, metadata, autoload=True)
30             return True
31
32         except NoSuchTableError:
33             return False
34      
35
36     def run(self, options):
37         """ Run importer"""
38         if not self._exists('lease_table'):
39             init_tables(engine)
40             self.logger.info("iotlabimporter run lease_table created")