def reset_all_zones(self): """ Reset all zones """ self._begin_op() db_session = self.db_session id_query = db_session.query(ZoneSM.id_, ZoneSM.name) id_query = ZoneSM.query_is_not_disabled_deleted(id_query) id_result = id_query.all() for zone_id, zone_name in id_result: try: zone_sm = db_session.query(ZoneSM)\ .filter(ZoneSM.id_ == zone_id).one() except NoResultFound: raise ZoneNotFoundByZoneId(zone_id) exec_zonesm(zone_sm, ZoneSMDoReset) self._finish_op()
def restore_named_db(self): """ Dump dms DB to Named zone files and include file For quick DR secnario """ self._begin_op() # Exception processing make the both of the following a bit of a # rats nest # Check that named is not running cmdline = [settings['rndc_path'], 'status'] try: check_output(cmdline, stderr=STDOUT) except CalledProcessError as exc: if exc.returncode != 1: raise exc pass else: raise NamedStillRunning(0) # Check that dmsdmd is not running try: pid_file = open(settings['pid_file'],'r') dmsdmd_pid = int(pid_file.readline().strip()) pid_file.close() # The following throws exceptions if process does not exist etc! # Sending signal 0 does not touch process, but call succeeds # if it exists os.kill(dmsdmd_pid, 0) except ValueError as exc: # Error from int() type conversion above raise PidFileValueError(pid_file, exc) except (IOError,OSError) as exc: if (exc.errno in (errno.ESRCH,)): # This is from kill() raise DmsdmdStillRunning(dmsdmd_pid) # File IO causes this elif (exc.errno in (errno.ENOENT,)): # This file may be removed by dameon nicely shutting down. pass else: # No exceptions, dmsdmd is running!!! raise DmsdmdStillRunning(dmsdmd_pid) # Dump out each zone file db_session = self.db_session id_query = db_session.query(ZoneSM.id_, ZoneSM.name) id_query = ZoneSM.query_is_not_disabled_deleted(id_query) id_result = id_query.all() for zone_id, zone_name in id_result: try: zone_sm = db_session.query(ZoneSM)\ .filter(ZoneSM.id_ == zone_id).one() except NoResultFound: raise ZoneNotFoundByZoneId(zone_id) try: zone_sm.write_zone_file(db_session, ZoneFileWriteInternalError) zone_sm.state = ZSTATE_PUBLISHED db_session.commit() except ZoneFileWriteInternalError as exc: db_session.rollback() raise ZoneFileWriteError(str(exc)) # Write out config file include master_sm = get_master_sm(db_session) try: master_sm.write_named_conf_includes(db_session, NamedConfWriteInternalError) except NamedConfWriteInternalError as exc: raise NamedConfWriteError(str(exc)) self._finish_op()