mirror of https://github.com/jumpserver/jumpserver
fix: 修改db_port_mapper策略; 启动时进行check校验;
parent
f4b0ba43a2
commit
5d865ffd54
|
@ -45,7 +45,7 @@ def on_applet_create(sender, instance, created=False, **kwargs):
|
|||
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
|
||||
|
||||
|
|
|
@ -34,9 +34,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 = Asset.objects.filter(platform__category=Category.DATABASE).values_list('id', flat=True)
|
||||
dbs = Asset.objects.filter(platform__category=Category.DATABASE).order_by('id')
|
||||
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