Skip to content

Commit

Permalink
Merge pull request #7 from yanghongfei/master
Browse files Browse the repository at this point in the history
[Update]做一些优化
  • Loading branch information
yanghongfei authored Jun 4, 2019
2 parents 85a053c + e4468f5 commit b60077f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
19 changes: 4 additions & 15 deletions biz/handlers/hand_update_asset_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,25 @@


class HandUpdateAssetHandler(BaseHandler):
_thread_pool = ThreadPoolExecutor(6)
_thread_pool = ThreadPoolExecutor(1)

@run_on_executor(executor='_thread_pool')
def asset_update(self, id_list):
# 检查下状态,是true的话直接推送资产
with DBContext('r', None, True) as session:
for i in id_list:

server_list = session.query(Server.ip, Server.port, AdminUser.system_user,
AdminUser.user_key, Server.state).outerjoin(AdminUser,
AdminUser.admin_user == Server.admin_user).filter(
Server.id == i).all()
# server_list = [('47.100.231.147', 22, 'root', '-----BEGIN RSA PRIVATE KEYxxxxxEND RSA PRIVATE KEY-----', 'false')]
server_state = server_list[0][4]
if server_state == 'true':
ins_log.read_log('info', '机器状态为True,开始更新资产')
# 选中的是true,直接更新资产
ins_log.read_log('info', '手动触发更新资产')
rsync_sucess_list = rsync_public_key(server_list)
if rsync_sucess_list:
asset_data = get_server_sysinfo(server_list)
ins_log.read_log('info', '资产信息:{}'.format(asset_data))
update_asset(asset_data)

else:
# 选中的是其余的状态,那就先推送key, 拿到推送成功的key,更新资产
ins_log.read_log('info', '状态为非True,先推送公钥再进行更新资产')
rsync_sucess_list = rsync_public_key(server_list)
if rsync_sucess_list:
asset_data = get_server_sysinfo(server_list)
ins_log.read_log('info', '资产信息:{}'.format(asset_data))
update_asset(asset_data)

@gen.coroutine
def post(self, *args, **kwargs):
data = json.loads(self.request.body.decode("utf-8"))
Expand Down
2 changes: 1 addition & 1 deletion libs/server/collect_asset_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


from libs.ansibleAPI.runner import Runner
from libs.common import M2human,exec_thread
from libs.common import M2human



Expand Down
2 changes: 1 addition & 1 deletion libs/server/server_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def rsync_public_key(server_list):
:return: 只返回推送成功的,失败的直接写错误日志
"""
# server_list = [('47.100.231.147', 22, 'root', '-----BEGIN RSA PRIVATE KEYxxxxxEND RSA PRIVATE KEY-----', 'false')]
ins_log.read_log('info', 'first, rsync public key to server')
ins_log.read_log('info', 'rsync public key to server')
rsync_error_list = []
rsync_sucess_list = []
sync_key_obj = RsyncPublicKey()
Expand Down

0 comments on commit b60077f

Please sign in to comment.