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
6a239833
Unverified
Commit
6a239833
authored
Dec 11, 2018
by
老广
Committed by
GitHub
Dec 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Command (#2142)
* [Update] 修改节点 * [Update] 优化命令运行失败日志
parent
18e590ef
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
11 deletions
+31
-11
node.py
apps/assets/models/node.py
+8
-11
callback.py
apps/ops/ansible/callback.py
+23
-0
No files found.
apps/assets/models/node.py
View file @
6a239833
...
...
@@ -203,17 +203,14 @@ class Node(OrgModelMixin):
# 如果使用current_org 在set_current_org时会死循环
_current_org
=
get_current_org
()
with
transaction
.
atomic
():
if
_current_org
.
is_root
():
key
=
'0'
elif
_current_org
.
is_default
():
key
=
'1'
else
:
set_current_org
(
Organization
.
root
())
org_nodes_roots
=
cls
.
objects
.
filter
(
key__regex
=
r'^[0-9]+$'
)
org_nodes_roots_keys
=
org_nodes_roots
.
values_list
(
'key'
,
flat
=
True
)
or
[
'1'
]
key
=
max
([
int
(
k
)
for
k
in
org_nodes_roots_keys
])
key
=
str
(
key
+
1
)
if
key
!=
0
else
'2'
set_current_org
(
_current_org
)
if
not
_current_org
.
is_real
():
return
cls
.
default_node
()
set_current_org
(
Organization
.
root
())
org_nodes_roots
=
cls
.
objects
.
filter
(
key__regex
=
r'^[0-9]+$'
)
org_nodes_roots_keys
=
org_nodes_roots
.
values_list
(
'key'
,
flat
=
True
)
or
[
'1'
]
key
=
max
([
int
(
k
)
for
k
in
org_nodes_roots_keys
])
key
=
str
(
key
+
1
)
if
key
!=
0
else
'2'
set_current_org
(
_current_org
)
root
=
cls
.
objects
.
create
(
key
=
key
,
value
=
_current_org
.
name
)
return
root
...
...
apps/ops/ansible/callback.py
View file @
6a239833
# ~*~ coding: utf-8 ~*~
import
datetime
import
json
from
collections
import
defaultdict
from
ansible
import
constants
as
C
...
...
@@ -163,6 +164,28 @@ class CommandResultCallback(AdHocResultCallback):
self
.
_play
=
play
self
.
_display
.
banner
(
msg
)
def
v2_runner_on_unreachable
(
self
,
result
):
self
.
results_summary
[
'success'
]
=
False
self
.
gather_result
(
"unreachable"
,
result
)
msg
=
result
.
_result
.
get
(
"msg"
)
if
not
msg
:
msg
=
json
.
dumps
(
result
.
_result
,
indent
=
4
)
self
.
_display
.
display
(
"
%
s | FAILED! =>
\n
%
s"
%
(
result
.
_host
.
get_name
(),
msg
,
),
color
=
C
.
COLOR_ERROR
)
def
v2_runner_on_failed
(
self
,
result
,
ignore_errors
=
False
):
self
.
results_summary
[
'success'
]
=
False
self
.
gather_result
(
"failed"
,
result
)
msg
=
result
.
_result
.
get
(
"msg"
)
or
result
.
_result
.
get
(
"module_stdout"
)
if
not
msg
:
msg
=
json
.
dumps
(
result
.
_result
,
indent
=
4
)
self
.
_display
.
display
(
"
%
s | FAILED! =>
\n
%
s"
%
(
result
.
_host
.
get_name
(),
msg
,
),
color
=
C
.
COLOR_ERROR
)
def
_print_task_banner
(
self
,
task
):
pass
...
...
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