mirror of https://github.com/jumpserver/jumpserver
fix: 修改db_port_mapper策略; 启动时进行check校验;
parent
3996daf4a7
commit
a19c0bde60
|
@ -19,7 +19,7 @@ logger = get_logger(__file__)
|
|||
def init_db_port_mapper(sender, **kwargs):
|
||||
logger.info('Init db port mapper')
|
||||
try:
|
||||
db_port_manager.init()
|
||||
db_port_manager.check()
|
||||
except (ProgrammingError,) as e:
|
||||
pass
|
||||
|
||||
|
|
|
@ -35,9 +35,22 @@ class DBPortManager(object):
|
|||
def magnus_listen_port_range(self):
|
||||
return settings.MAGNUS_PORTS
|
||||
|
||||
def init(self):
|
||||
@staticmethod
|
||||
def fetch_dbs():
|
||||
with tmp_to_root_org():
|
||||
db_ids = Application.objects.filter(category=AppCategory.db).values_list('id', flat=True)
|
||||
dbs = Application.objects.filter(category=AppCategory.db)
|
||||
return dbs
|
||||
|
||||
def check(self):
|
||||
dbs = self.fetch_dbs()
|
||||
for db in dbs:
|
||||
port = self.get_port_by_db(db, raise_exception=False)
|
||||
if not port:
|
||||
self.add(db)
|
||||
|
||||
def init(self):
|
||||
dbs = self.fetch_dbs()
|
||||
db_ids = dbs.values_list('id', flat=True)
|
||||
db_ids = [str(i) for i in db_ids]
|
||||
mapper = dict(zip(self.all_available_ports, list(db_ids)))
|
||||
self.set_mapper(mapper)
|
||||
|
|
Loading…
Reference in New Issue