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
240c7db4
Commit
240c7db4
authored
Mar 14, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fixture] 添加 rerun function
parent
91587313
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
28 deletions
+22
-28
models.py
apps/ops/models.py
+1
-1
tasks.py
apps/ops/tasks.py
+18
-24
utils.py
apps/perms/utils.py
+1
-1
_nav.html
apps/templates/_nav.html
+1
-1
run_server.py
run_server.py
+1
-1
No files found.
apps/ops/models.py
View file @
240c7db4
...
...
@@ -40,7 +40,7 @@ class TaskRecord(models.Model):
from
assets.models
import
Asset
return
[
Asset
.
objects
.
get
(
hostname
=
hostname
)
.
_to_secret_json
()
for
hostname
in
self
.
total_assets
if
Asset
.
objects
.
exists
(
hostname
=
hostname
)]
if
Asset
.
objects
.
filter
(
hostname
=
hostname
)]
@property
def
module_args
(
self
):
...
...
apps/ops/tasks.py
View file @
240c7db4
...
...
@@ -70,8 +70,20 @@ def run_AdHoc(self, task_tuple, assets,
return
summary
@shared_task
(
bind
=
True
)
def
push_users
(
self
,
assets
,
users
):
def
rerun_AdHoc
(
uuid
):
from
.models
import
TaskRecord
record
=
TaskRecord
.
objects
.
get
(
uuid
=
uuid
)
assets
=
record
.
assets_json
task_tuple
=
record
.
module_args
pattern
=
record
.
pattern
task_name
=
record
.
name
task
=
run_AdHoc
.
apply_async
((
task_tuple
,
assets
),
{
'pattern'
:
pattern
,
'task_name'
:
task_name
},
task_id
=
uuid
)
return
task
def
push_users
(
assets
,
users
):
"""
user: {
name: 'web',
...
...
@@ -104,25 +116,7 @@ def push_users(self, assets, users):
))
])
task_name
=
'Push user {}'
.
format
(
','
.
join
([
user
[
'name'
]
for
user
in
users
]))
record
=
TaskRecord
(
name
=
task_name
,
uuid
=
self
.
request
.
id
,
date_start
=
timezone
.
now
(),
assets
=
','
.
join
(
asset
[
'hostname'
]
for
asset
in
assets
))
record
.
save
()
logger
.
info
(
'Runner {0} start {1}'
.
format
(
task_name
,
timezone
.
now
()))
hoc
=
AdHocRunner
(
assets
)
ts_start
=
time
.
time
()
_
=
hoc
.
run
(
task_tuple
)
logger
.
info
(
'Runner {0} complete {1}'
.
format
(
task_name
,
timezone
.
now
()))
result_clean
=
hoc
.
clean_result
()
record
.
time
=
int
(
time
.
time
()
-
ts_start
)
record
.
date_finished
=
timezone
.
now
()
record
.
is_finished
=
True
if
len
(
result_clean
[
'failed'
])
==
0
:
record
.
is_success
=
True
else
:
record
.
is_success
=
False
record
.
result
=
json
.
dumps
(
result_clean
)
record
.
save
()
return
result_clean
task
=
run_AdHoc
.
delay
(
task_tuple
,
assets
,
pattern
=
'all'
,
task_name
=
task_name
)
return
task
apps/perms/utils.py
View file @
240c7db4
...
...
@@ -231,7 +231,7 @@ def push_system_user(assets, system_user):
assets
=
[
asset
.
_to_secret_json
()
for
asset
in
assets
]
system_user
=
system_user
.
_to_secret_json
()
task
=
push_users
.
delay
(
assets
,
system_user
)
task
=
push_users
(
assets
,
system_user
)
return
task
.
id
...
...
apps/templates/_nav.html
View file @
240c7db4
...
...
@@ -49,7 +49,7 @@
<i
class=
"fa fa-coffee"
></i>
<span
class=
"nav-label"
>
{% trans 'Job Center' %}
</span><span
class=
"fa arrow"
></span>
</a>
<ul
class=
"nav nav-second-level"
>
<li
id=
"task"
><a
href=
"{% url 'ops:task-record-list' %}"
>
{% trans 'Task Record' %}
</a></li>
<li
id=
"task
-record
"
><a
href=
"{% url 'ops:task-record-list' %}"
>
{% trans 'Task Record' %}
</a></li>
</ul>
</li>
...
...
run_server.py
View file @
240c7db4
...
...
@@ -29,7 +29,7 @@ def start_django():
def
start_celery
():
os
.
chdir
(
apps_dir
)
os
.
environ
.
setdefault
(
'C_FORCE_ROOT'
,
'1'
)
os
.
environ
.
setdefault
(
'PYTHONOPTIMIZE'
,
1
)
os
.
environ
.
setdefault
(
'PYTHONOPTIMIZE'
,
'1'
)
print
(
'start celery'
)
subprocess
.
call
(
'celery -A common worker -s /tmp/celerybeat-schedule -l debug'
,
shell
=
True
)
...
...
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