diff --git a/spug_api/apps/host/views.py b/spug_api/apps/host/views.py index 2565f4e..c17df42 100644 --- a/spug_api/apps/host/views.py +++ b/spug_api/apps/host/views.py @@ -101,7 +101,7 @@ def post_import(request): password = request.POST.get('password') file = request.FILES['file'] ws = load_workbook(file, read_only=True)['Sheet1'] - summary = {'invalid': [], 'skip': [], 'fail': [], 'network': [], 'repeat': [], 'success': [], 'error': []} + summary = {'invalid': [], 'skip': [], 'repeat': [], 'success': []} for i, row in enumerate(ws.rows): if i == 0: # 第1行是表头 略过 continue @@ -120,23 +120,15 @@ def post_import(request): if Host.objects.filter(hostname=data.hostname, port=data.port, username=data.username).exists(): summary['skip'].append(i) continue - try: - if valid_ssh(data.hostname, data.port, data.username, data.pop('password') or password, None, - False) is False: - summary['fail'].append(i) - continue - except AuthenticationException: - summary['fail'].append(i) - continue - except socket.error: - summary['network'].append(i) - continue - except Exception: - summary['error'].append(i) - continue if Host.objects.filter(name=data.name).exists(): summary['repeat'].append(i) continue + try: + password = data.pop('password') or password + if valid_ssh(data.hostname, data.port, data.username, password, None, False) is False: + data.is_verified = True + except Exception: + pass host = Host.objects.create(created_by=request.user, **data) if request.user.role: request.user.role.add_host_perm(host.id) diff --git a/spug_web/src/pages/host/Import.js b/spug_web/src/pages/host/Import.js index a7e44dc..5f3ddef 100644 --- a/spug_web/src/pages/host/Import.js +++ b/spug_web/src/pages/host/Import.js @@ -26,12 +26,6 @@ export default observer(function () { title: '导入结果', content:
{res.success.length} - {res['fail'].length > 0 && - {res['fail'].length} - } - {res['network'].length > 0 && - {res['network'].length} - } {res['skip'].length > 0 && {res['skip'].length} } @@ -41,9 +35,6 @@ export default observer(function () { {res['repeat'].length > 0 && {res['repeat'].length} } - {res['error'].length > 0 && - {res['error'].length} - }
}) })