def init_or_upgrade(self): # check if under version control, and initialize it otherwise if self.current_version() is None: before = "Unknown" # can be either a very old version, or a fresh install # for very old versions: self.handle_old_releases() # in any case, initialize db from current code and reflect in migrate model.init_tables(self.engine) code_version = migrate.version(self.repository) migrate.version_control(self.url, self.repository, code_version) after = "%s" % self.current_version() logger.info("DBSchema : jumped to version %s" % (after)) else: # use migrate in the usual way before = "%s" % self.current_version() migrate.upgrade(self.url, self.repository) after = "%s" % self.current_version() if before != after: logger.info("DBSchema : upgraded version from %s to %s" % (before, after)) else: logger.debug( "DBSchema : no change needed in db schema (%s==%s)" % (before, after))
def run(self, options): """ Create the special iotlab table, lease_table, in the SFA database. Import everything (users, slices, nodes and sites from OAR and LDAP) into the SFA database. Delete stale records that are no longer in OAR or LDAP. :param options: :type options: """ config = Config() interface_hrn = config.SFA_INTERFACE_HRN root_auth = config.SFA_REGISTRY_ROOT_AUTH testbed_shell = IotlabShell(config) # leases_db = TestbedAdditionalSfaDB(config) #Create special slice table for iotlab if not self.exists('lease_table'): init_tables(engine) self.logger.info("IotlabImporter.run: lease_table table created ") # import site and node records in site into the SFA db. self.import_sites_and_nodes(testbed_shell) #import users and slice into the SFA DB. self.import_persons_and_slices(testbed_shell) ### remove stale records # special records must be preserved system_hrns = [ interface_hrn, root_auth, interface_hrn + '.slicemanager' ] for record in self.all_records: if record.hrn in system_hrns: record.stale = False if record.peer_authority: record.stale = False for record in self.all_records: if record.type == 'user': self.logger.info("IotlabImporter: stale records: hrn %s %s" % (record.hrn, record.stale)) try: stale = record.stale except: stale = True self.logger.warning("stale not found with %s" % record) if stale: self.logger.info("IotlabImporter: deleting stale record: %s" % (record)) try: global_dbsession.delete(record) global_dbsession.commit() except SQLAlchemyError: self.logger.log_exc("IotlabImporter: failed to delete \ stale record %s" % (record))
def run(self, options): """ Create the special iotlab table, lease_table, in the SFA database. Import everything (users, slices, nodes and sites from OAR and LDAP) into the SFA database. Delete stale records that are no longer in OAR or LDAP. :param options: :type options: """ config = Config () interface_hrn = config.SFA_INTERFACE_HRN root_auth = config.SFA_REGISTRY_ROOT_AUTH testbed_shell = IotlabShell(config) # leases_db = TestbedAdditionalSfaDB(config) #Create special slice table for iotlab if not self.exists('lease_table'): init_tables(engine) self.logger.info("IotlabImporter.run: lease_table table created ") # import site and node records in site into the SFA db. self.import_sites_and_nodes(testbed_shell) #import users and slice into the SFA DB. self.import_persons_and_slices(testbed_shell) ### remove stale records # special records must be preserved system_hrns = [interface_hrn, root_auth, interface_hrn + '.slicemanager'] for record in self.all_records: if record.hrn in system_hrns: record.stale = False if record.peer_authority: record.stale = False for record in self.all_records: if record.type == 'user': self.logger.info("IotlabImporter: stale records: hrn %s %s" % (record.hrn, record.stale)) try: stale = record.stale except: stale = True self.logger.warning("stale not found with %s" % record) if stale: self.logger.info("IotlabImporter: deleting stale record: %s" % (record)) try: global_dbsession.delete(record) global_dbsession.commit() except SQLAlchemyError: self.logger.log_exc("IotlabImporter: failed to delete \ stale record %s" % (record))
def init_or_upgrade (self): # check if under version control, and initialize it otherwise if self.current_version() is None: before="Unknown" # can be either a very old version, or a fresh install # for very old versions: self.handle_old_releases() # in any case, initialize db from current code and reflect in migrate model.init_tables(self.engine) code_version = migrate.version (self.repository) migrate.version_control (self.url, self.repository, code_version) after="%s"%self.current_version() logger.info("DBSchema : jumped to version %s"%(after)) else: # use migrate in the usual way before="%s"%self.current_version() migrate.upgrade (self.url, self.repository) after="%s"%self.current_version() if before != after: logger.info("DBSchema : upgraded version from %s to %s"%(before,after)) else: logger.debug("DBSchema : no change needed in db schema (%s==%s)"%(before,after))
def run(self, options): """ Run importer""" if not self._exists("lease_table"): init_tables(engine) self.logger.info("iotlabimporter run lease_table created")