Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
43b4b7c5
Commit
43b4b7c5
authored
7 years ago
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feature] 资产节点增加批量测试可连接性和更新硬件信息
parent
f59f03ad
master
auditor_jym
audits
dev
dev_beta
dev_beta_db
gengmei
node_service
password
rbac
restrict_access
test
v52
wph
1.5.2
1.5.1
1.5.0
1.4.10
1.4.9
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.3
1.3.2
1.3.1
1.3.0
1.2.1
1.2.0
1.1.1
1.1.0
1.0.0
v1.4.10
v1.4.7
v1.4.4
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
157 additions
and
62 deletions
+157
-62
node.py
apps/assets/api/node.py
+31
-1
signals_handler.py
apps/assets/signals_handler.py
+1
-1
tasks.py
apps/assets/tasks.py
+9
-10
asset_list.html
apps/assets/templates/assets/asset_list.html
+45
-0
api_urls.py
apps/assets/urls/api_urls.py
+2
-0
django.mo
apps/i18n/zh/LC_MESSAGES/django.mo
+0
-0
django.po
apps/i18n/zh/LC_MESSAGES/django.po
+69
-50
No files found.
apps/assets/api/node.py
View file @
43b4b7c5
...
...
@@ -18,10 +18,12 @@ from rest_framework.views import APIView
from
rest_framework.response
import
Response
from
rest_framework_bulk
import
BulkModelViewSet
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.shortcuts
import
get_object_or_404
from
common.utils
import
get_logger
,
get_object_or_none
from
..hands
import
IsSuperUser
from
..models
import
Node
from
..tasks
import
update_assets_hardware_info_util
,
test_asset_connectability_util
from
..
import
serializers
...
...
@@ -29,7 +31,8 @@ logger = get_logger(__file__)
__all__
=
[
'NodeViewSet'
,
'NodeChildrenApi'
,
'NodeAddAssetsApi'
,
'NodeRemoveAssetsApi'
,
'NodeAddChildrenApi'
,
'NodeAddChildrenApi'
,
'RefreshNodeHardwareInfoApi'
,
'TestNodeConnectiveApi'
]
...
...
@@ -117,3 +120,30 @@ class NodeRemoveAssetsApi(generics.UpdateAPIView):
instance
=
self
.
get_object
()
if
instance
!=
Node
.
root
():
instance
.
assets
.
remove
(
*
tuple
(
assets
))
class
RefreshNodeHardwareInfoApi
(
APIView
):
permission_classes
=
(
IsSuperUser
,)
model
=
Node
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
node_id
=
kwargs
.
get
(
'pk'
)
node
=
get_object_or_404
(
self
.
model
,
id
=
node_id
)
assets
=
node
.
assets
.
all
()
task_name
=
_
(
"Refresh node assets hardware info: {}"
.
format
(
node
.
name
))
update_assets_hardware_info_util
.
delay
(
assets
,
task_name
=
task_name
)
return
Response
({
"msg"
:
"Task created"
})
class
TestNodeConnectiveApi
(
APIView
):
permission_classes
=
(
IsSuperUser
,)
model
=
Node
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
node_id
=
kwargs
.
get
(
'pk'
)
node
=
get_object_or_404
(
self
.
model
,
id
=
node_id
)
assets
=
node
.
assets
.
all
()
task_name
=
_
(
"Test node assets connective: {}"
.
format
(
node
.
name
))
test_asset_connectability_util
.
delay
(
assets
,
task_name
=
task_name
)
return
Response
({
"msg"
:
"Task created"
})
This diff is collapsed.
Click to expand it.
apps/assets/signals_handler.py
View file @
43b4b7c5
...
...
@@ -21,7 +21,7 @@ def update_asset_hardware_info_on_created(asset):
def
test_asset_conn_on_created
(
asset
):
logger
.
debug
(
"Test asset `{}` connectability"
.
format
(
asset
))
test_asset_connectability_util
.
delay
(
asset
)
test_asset_connectability_util
.
delay
(
[
asset
]
)
def
set_asset_root_node
(
asset
):
...
...
This diff is collapsed.
Click to expand it.
apps/assets/tasks.py
View file @
43b4b7c5
...
...
@@ -213,12 +213,12 @@ def test_admin_user_connectability_manual(admin_user):
@shared_task
def
test_asset_connectability_util
(
asset
,
task_name
=
None
):
def
test_asset_connectability_util
(
asset
s
,
task_name
=
None
):
from
ops.utils
import
update_or_create_ansible_task
if
task_name
is
None
:
task_name
=
_
(
"Test asset connectability"
)
hosts
=
[
asset
.
hostname
]
task_name
=
_
(
"Test asset
s
connectability"
)
hosts
=
[
asset
.
hostname
for
asset
in
assets
]
if
not
hosts
:
logger
.
info
(
"No hosts, passed"
)
return
{}
...
...
@@ -229,18 +229,17 @@ def test_asset_connectability_util(asset, task_name=None):
)
result
=
task
.
run
()
summary
=
result
[
1
]
if
summary
.
get
(
'dark'
):
cache
.
set
(
const
.
ASSET_ADMIN_CONN_CACHE_KEY
.
format
(
asset
.
hostname
),
0
,
CACHE_MAX_TIME
)
else
:
cache
.
set
(
const
.
ASSET_ADMIN_CONN_CACHE_KEY
.
format
(
asset
.
hostname
),
1
,
CACHE_MAX_TIME
)
for
k
in
summary
.
get
(
'dark'
):
cache
.
set
(
const
.
ASSET_ADMIN_CONN_CACHE_KEY
.
format
(
k
),
0
,
CACHE_MAX_TIME
)
for
k
in
summary
.
get
(
'contacted'
):
cache
.
set
(
const
.
ASSET_ADMIN_CONN_CACHE_KEY
.
format
(
k
),
1
,
CACHE_MAX_TIME
)
return
summary
@shared_task
def
test_asset_connectability_manual
(
asset
):
summary
=
test_asset_connectability_util
(
asset
)
summary
=
test_asset_connectability_util
(
[
asset
]
)
if
summary
.
get
(
'dark'
):
return
False
,
summary
[
'dark'
]
...
...
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/asset_list.html
View file @
43b4b7c5
...
...
@@ -119,6 +119,8 @@
<ul
class=
"dropdown-menu"
>
<li
id=
"menu_asset_create"
class=
"btn-create-asset"
tabindex=
"-1"
><a>
{% trans 'Create asset' %}
</a></li>
<li
id=
"menu_asset_add"
class=
"btn-add-asset"
data-toggle=
"modal"
data-target=
"#asset_list_modal"
tabindex=
"0"
><a>
{% trans 'Add asset' %}
</a></li>
<li
id=
"menu_refresh_hardware_info"
class=
"btn-refresh-hardware"
tabindex=
"-1"
><a>
{% trans 'Refresh node hardware info' %}
</a></li>
<li
id=
"menu_test_connective"
class=
"btn-test-connective"
tabindex=
"-1"
><a>
{% trans 'Test node connective' %}
</a></li>
<li
class=
"divider"
></li>
<li
id=
"m_create"
tabindex=
"-1"
onclick=
"addTreeNode();"
><a>
{% trans 'Add node' %}
</a></li>
<li
id=
"m_del"
tabindex=
"-1"
onclick=
"editTreeNode();"
><a>
{% trans 'Rename node' %}
</a></li>
...
...
@@ -476,6 +478,49 @@ $(document).ready(function(){
}
window
.
open
(
url
,
'_self'
);
})
.
on
(
'click'
,
'.btn-refresh-hardware'
,
function
()
{
var
url
=
"{% url 'api-assets:node-refresh-hardware-info' pk=DEFAULT_PK %}"
;
var
nodes
=
zTree
.
getSelectedNodes
();
var
current_node
;
if
(
nodes
&&
nodes
.
length
===
1
){
current_node
=
nodes
[
0
];
}
else
{
return
null
;
}
var
the_url
=
url
.
replace
(
"{{ DEFAULT_PK }}"
,
current_node
.
id
);
function
success
()
{
rMenu
.
css
({
"visibility"
:
"hidden"
});
}
APIUpdateAttr
({
url
:
the_url
,
method
:
"GET"
,
success_message
:
"更新硬件信息任务下发成功"
,
success
:
success
});
})
.
on
(
'click'
,
'.btn-test-connective'
,
function
()
{
var
url
=
"{% url 'api-assets:node-test-connective' pk=DEFAULT_PK %}"
;
var
nodes
=
zTree
.
getSelectedNodes
();
var
current_node
;
if
(
nodes
&&
nodes
.
length
===
1
){
current_node
=
nodes
[
0
];
}
else
{
return
null
;
}
var
the_url
=
url
.
replace
(
"{{ DEFAULT_PK }}"
,
current_node
.
id
);
function
success
()
{
rMenu
.
css
({
"visibility"
:
"hidden"
});
}
APIUpdateAttr
({
url
:
the_url
,
method
:
"GET"
,
success_message
:
"测试可连接性任务下发成功"
,
success
:
success
});
})
.
on
(
'click'
,
'.btn_asset_delete'
,
function
()
{
var
$this
=
$
(
this
);
var
$data_table
=
$
(
"#asset_list_table"
).
DataTable
();
...
...
This diff is collapsed.
Click to expand it.
apps/assets/urls/api_urls.py
View file @
43b4b7c5
...
...
@@ -47,6 +47,8 @@ urlpatterns = [
url
(
r'^v1/nodes/(?P<pk>[0-9a-zA-Z\-]{36})/children/add/$'
,
api
.
NodeAddChildrenApi
.
as_view
(),
name
=
'node-add-children'
),
url
(
r'^v1/nodes/(?P<pk>[0-9a-zA-Z\-]{36})/assets/add/$'
,
api
.
NodeAddAssetsApi
.
as_view
(),
name
=
'node-add-assets'
),
url
(
r'^v1/nodes/(?P<pk>[0-9a-zA-Z\-]{36})/assets/remove/$'
,
api
.
NodeRemoveAssetsApi
.
as_view
(),
name
=
'node-remove-assets'
),
url
(
r'^v1/nodes/(?P<pk>[0-9a-zA-Z\-]{36})/refresh-hardware-info/$'
,
api
.
RefreshNodeHardwareInfoApi
.
as_view
(),
name
=
'node-refresh-hardware-info'
),
url
(
r'^v1/nodes/(?P<pk>[0-9a-zA-Z\-]{36})/test-connective/$'
,
api
.
TestNodeConnectiveApi
.
as_view
(),
name
=
'node-test-connective'
),
]
urlpatterns
+=
router
.
urls
...
...
This diff is collapsed.
Click to expand it.
apps/i18n/zh/LC_MESSAGES/django.mo
View file @
43b4b7c5
No preview for this file type
This diff is collapsed.
Click to expand it.
apps/i18n/zh/LC_MESSAGES/django.po
View file @
43b4b7c5
...
...
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Jumpserver 0.3.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-03-
07 21:1
8+0800\n"
"POT-Creation-Date: 2018-03-
12 11:2
8+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: ibuler <ibuler@qq.com>\n"
"Language-Team: Jumpserver team<ibuler@qq.com>\n"
...
...
@@ -17,10 +17,18 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: assets/api/node.py:5
5
#: assets/api/node.py:5
8
msgid "New node {}"
msgstr "新节点 {}"
#: assets/api/node.py:133
msgid "Refresh node assets hardware info: {}"
msgstr "更新一些资产硬件信息: {}"
#: assets/api/node.py:146
msgid "Test node assets connective: {}"
msgstr "测试节点资产可连接性"
#: assets/forms/asset.py:23 assets/forms/asset.py:54 assets/forms/user.py:125
#: assets/models/asset.py:53 assets/models/user.py:218
#: assets/templates/assets/asset_detail.html:181
...
...
@@ -52,7 +60,7 @@ msgstr ""
"不支持ansible, 任意设置一个即可"
#: assets/forms/asset.py:80 assets/forms/asset.py:84 assets/forms/label.py:15
#: perms/templates/perms/asset_permission_asset.html:88 users/forms.py:24
2
#: perms/templates/perms/asset_permission_asset.html:88 users/forms.py:24
4
msgid "Select assets"
msgstr "选择资产"
...
...
@@ -89,7 +97,7 @@ msgid "Password or private key passphrase"
msgstr "密码或密钥密码"
#: assets/forms/user.py:25 assets/models/user.py:30 common/forms.py:113
#: users/forms.py:16 users/forms.py:2
4
users/templates/users/login.html:59
#: users/forms.py:16 users/forms.py:2
5
users/templates/users/login.html:59
#: users/templates/users/reset_password.html:52
#: users/templates/users/user_create.html:11
#: users/templates/users/user_password_update.html:40
...
...
@@ -358,7 +366,7 @@ msgstr "默认资产组"
#: terminal/templates/terminal/command_list.html:32
#: terminal/templates/terminal/command_list.html:72
#: terminal/templates/terminal/session_list.html:33
#: terminal/templates/terminal/session_list.html:71 users/forms.py:19
0
#: terminal/templates/terminal/session_list.html:71 users/forms.py:19
2
#: users/models/user.py:30 users/models/user.py:254
#: users/templates/users/user_group_detail.html:78
#: users/templates/users/user_group_list.html:13 users/views/user.py:333
...
...
@@ -424,43 +432,45 @@ msgstr "系统用户"
msgid "%(value)s is not an even number"
msgstr "%(value)s is not an even number"
#: assets/tasks.py:9
2
#: assets/tasks.py:9
4
msgid "Update some assets hardware info"
msgstr "更新一些资产硬件信息"
#: assets/tasks.py:1
08
#: assets/tasks.py:1
10
msgid "Update asset hardware info"
msgstr "更新资产硬件信息"
#: assets/tasks.py:12
2
#: assets/tasks.py:12
8
msgid "Update assets hardware info period"
msgstr "定期更新资产硬件信息"
#: assets/tasks.py:
19
5
#: assets/tasks.py:
20
5
msgid "Test admin user connectability period: {}"
msgstr "定期测试管理用户可连接性: {}"
#: assets/tasks.py:2
0
1
#: assets/tasks.py:2
1
1
msgid "Test admin user connectability: {}"
msgstr "测试管理用户可连接性: {}"
#: assets/tasks.py:210
msgid "Test asset connectability"
#: assets/tasks.py:220
#, fuzzy
#| msgid "Test asset connectability"
msgid "Test assets connectability"
msgstr "测试资产可连接性"
#: assets/tasks.py:2
81
#: assets/tasks.py:2
90
msgid "Test system user connectability: {}"
msgstr "测试系统用户可连接性: {}"
#: assets/tasks.py:
292
#: assets/tasks.py:
305
msgid "test system user connectability period: {}"
msgstr "测试系统用户可连接性: {}"
#: assets/tasks.py:3
69
#: assets/tasks.py:3
82
msgid "Push system user to node: {} => {}"
msgstr "推送系统用户到节点: {}->{}"
#: assets/tasks.py:4
07
#: assets/tasks.py:4
20
msgid "Push system users to node: {}"
msgstr "推送系统用户到节点: {}"
...
...
@@ -627,7 +637,7 @@ msgstr "提交"
#: assets/templates/assets/admin_user_detail.html:24
#: assets/templates/assets/admin_user_list.html:84
#: assets/templates/assets/asset_detail.html:24
#: assets/templates/assets/asset_list.html:16
6
#: assets/templates/assets/asset_list.html:16
8
#: assets/templates/assets/label_list.html:38
#: assets/templates/assets/system_user_detail.html:26
#: assets/templates/assets/system_user_list.html:85
...
...
@@ -646,7 +656,7 @@ msgstr "更新"
#: assets/templates/assets/admin_user_detail.html:28
#: assets/templates/assets/admin_user_list.html:85
#: assets/templates/assets/asset_detail.html:28
#: assets/templates/assets/asset_list.html:16
7
#: assets/templates/assets/asset_list.html:16
9
#: assets/templates/assets/label_list.html:39
#: assets/templates/assets/system_user_detail.html:30
#: assets/templates/assets/system_user_list.html:86
...
...
@@ -764,7 +774,7 @@ msgstr "替换资产的管理员"
#: assets/templates/assets/admin_user_detail.html:100
#: assets/templates/assets/asset_detail.html:198
#: assets/templates/assets/asset_list.html:5
41
#: assets/templates/assets/asset_list.html:5
86
#: assets/templates/assets/system_user_detail.html:183
#: assets/templates/assets/system_user_list.html:135 templates/_modal.html:16
#: terminal/templates/terminal/session_detail.html:108
...
...
@@ -869,27 +879,35 @@ msgstr "从节点移除"
msgid "Add asset"
msgstr "添加资产到节点"
#: assets/templates/assets/asset_list.html:122
msgid "Refresh node hardware info"
msgstr "更新节点资产硬件信息"
#: assets/templates/assets/asset_list.html:123
msgid "Test node connective"
msgstr "测试节点资产可连接性"
#: assets/templates/assets/asset_list.html:125
msgid "Add node"
msgstr "新建节点"
#: assets/templates/assets/asset_list.html:12
4
#: assets/templates/assets/asset_list.html:12
6
msgid "Rename node"
msgstr "重命名节点"
#: assets/templates/assets/asset_list.html:12
6
#: assets/templates/assets/asset_list.html:12
8
msgid "Delete node"
msgstr "删除节点"
#: assets/templates/assets/asset_list.html:20
1
#: assets/templates/assets/asset_list.html:20
3
msgid "Create node failed"
msgstr "创建节点失败"
#: assets/templates/assets/asset_list.html:21
4
#: assets/templates/assets/asset_list.html:21
6
msgid "Have child node, cancel"
msgstr "存在子节点,不能删除"
#: assets/templates/assets/asset_list.html:5
36
#: assets/templates/assets/asset_list.html:5
81
#: assets/templates/assets/system_user_list.html:130
#: users/templates/users/user_detail.html:334
#: users/templates/users/user_detail.html:359
...
...
@@ -898,20 +916,20 @@ msgstr "存在子节点,不能删除"
msgid "Are you sure?"
msgstr "你确认吗?"
#: assets/templates/assets/asset_list.html:5
37
#: assets/templates/assets/asset_list.html:5
82
msgid "This will delete the selected assets !!!"
msgstr "删除选择资产"
#: assets/templates/assets/asset_list.html:5
45
#: assets/templates/assets/asset_list.html:5
90
msgid "Asset Deleted."
msgstr "已被删除"
#: assets/templates/assets/asset_list.html:5
46
#: assets/templates/assets/asset_list.html:5
51
#: assets/templates/assets/asset_list.html:5
91
#: assets/templates/assets/asset_list.html:5
96
msgid "Asset Delete"
msgstr "删除"
#: assets/templates/assets/asset_list.html:5
50
#: assets/templates/assets/asset_list.html:5
95
msgid "Asset Deleting failed."
msgstr "删除失败"
...
...
@@ -1598,7 +1616,7 @@ msgstr "添加"
msgid "Add asset group to this permission"
msgstr "添加资产组"
#: perms/templates/perms/asset_permission_asset.html:116 users/forms.py:24
5
#: perms/templates/perms/asset_permission_asset.html:116 users/forms.py:24
7
msgid "Select asset groups"
msgstr "选择资产组"
...
...
@@ -1627,7 +1645,7 @@ msgstr "资产组数量"
msgid "System user count"
msgstr "系统用户数量"
#: perms/templates/perms/asset_permission_detail.html:144 users/forms.py:2
48
#: perms/templates/perms/asset_permission_detail.html:144 users/forms.py:2
50
msgid "Select system users"
msgstr "选择系统用户"
...
...
@@ -2061,51 +2079,59 @@ msgstr ""
msgid "Invalid token or cache refreshed."
msgstr ""
#: users/forms.py:43 users/templates/users/user_detail.html:187
#: users/forms.py:28 users/models/user.py:38
#: users/templates/users/_select_user_modal.html:15
#: users/templates/users/user_detail.html:87
#: users/templates/users/user_list.html:25
#: users/templates/users/user_profile.html:55
msgid "Role"
msgstr "角色"
#: users/forms.py:45 users/templates/users/user_detail.html:187
msgid "Join user groups"
msgstr "添加到用户组"
#: users/forms.py:7
4
#: users/forms.py:7
6
msgid "Old password"
msgstr "原来密码"
#: users/forms.py:
79
#: users/forms.py:
81
msgid "New password"
msgstr "新密码"
#: users/forms.py:8
4
#: users/forms.py:8
6
msgid "Confirm password"
msgstr "确认密码"
#: users/forms.py:9
4
#: users/forms.py:9
6
msgid "Old password error"
msgstr "原来密码错误"
#: users/forms.py:10
2
#: users/forms.py:10
4
msgid "Password does not match"
msgstr "密码不一致"
#: users/forms.py:11
4
#: users/forms.py:11
6
msgid "ssh public key"
msgstr "ssh公钥"
#: users/forms.py:11
5
#: users/forms.py:11
7
msgid "ssh-rsa AAAA..."
msgstr ""
#: users/forms.py:11
6
#: users/forms.py:11
8
msgid "Paste your id_rsa.pub here."
msgstr "复制你的公钥到这里"
#: users/forms.py:1
29
#: users/forms.py:1
31
msgid "Public key should not be the same as your old one."
msgstr "不能和原来的密钥相同"
#: users/forms.py:13
3
users/serializers.py:42
#: users/forms.py:13
5
users/serializers.py:42
msgid "Not a valid ssh public key"
msgstr "ssh密钥不合法"
#: users/forms.py:14
7 users/forms.py:152 users/forms.py:164 users/forms.py:194
#: users/forms.py:14
9 users/forms.py:154 users/forms.py:166 users/forms.py:196
msgid "Select users"
msgstr "选择用户"
...
...
@@ -2146,13 +2172,6 @@ msgstr "应用程序"
msgid "Email"
msgstr "邮件"
#: users/models/user.py:38 users/templates/users/_select_user_modal.html:15
#: users/templates/users/user_detail.html:87
#: users/templates/users/user_list.html:25
#: users/templates/users/user_profile.html:55
msgid "Role"
msgstr "角色"
#: users/models/user.py:39
msgid "Avatar"
msgstr "头像"
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment