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
739932b0
Commit
739932b0
authored
Apr 12, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 更新资产导入
parent
24f144fd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
+13
-8
tasks.py
apps/assets/tasks.py
+3
-0
asset.py
apps/assets/views/asset.py
+10
-8
No files found.
apps/assets/tasks.py
View file @
739932b0
...
@@ -96,6 +96,9 @@ def update_assets_hardware_info_util(assets, task_name=None):
...
@@ -96,6 +96,9 @@ def update_assets_hardware_info_util(assets, task_name=None):
task_name
=
_
(
"更新资产硬件信息"
)
task_name
=
_
(
"更新资产硬件信息"
)
tasks
=
const
.
UPDATE_ASSETS_HARDWARE_TASKS
tasks
=
const
.
UPDATE_ASSETS_HARDWARE_TASKS
hostname_list
=
[
asset
.
hostname
for
asset
in
assets
if
asset
.
is_active
and
asset
.
is_unixlike
()]
hostname_list
=
[
asset
.
hostname
for
asset
in
assets
if
asset
.
is_active
and
asset
.
is_unixlike
()]
if
not
hostname_list
:
logger
.
info
(
"Not hosts get, may be asset is not active or not unixlike platform"
)
return
{}
task
,
created
=
update_or_create_ansible_task
(
task
,
created
=
update_or_create_ansible_task
(
task_name
,
hosts
=
hostname_list
,
tasks
=
tasks
,
pattern
=
'all'
,
task_name
,
hosts
=
hostname_list
,
tasks
=
tasks
,
pattern
=
'all'
,
options
=
const
.
TASK_OPTIONS
,
run_as_admin
=
True
,
created_by
=
'System'
,
options
=
const
.
TASK_OPTIONS
,
run_as_admin
=
True
,
created_by
=
'System'
,
...
...
apps/assets/views/asset.py
View file @
739932b0
...
@@ -284,24 +284,26 @@ class BulkImportAssetView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
...
@@ -284,24 +284,26 @@ class BulkImportAssetView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
if
set
(
row
)
==
{
''
}:
if
set
(
row
)
==
{
''
}:
continue
continue
asset_dict
=
dict
(
zip
(
attr
,
row
))
asset_dict
_raw
=
dict
(
zip
(
attr
,
row
))
id_
=
asset_dict
.
pop
(
'id'
,
0
)
asset_dict
=
dict
(
)
for
k
,
v
in
asset_dict
.
items
():
for
k
,
v
in
asset_dict
_raw
.
items
():
v
=
v
.
strip
()
v
=
v
.
strip
()
if
k
==
'is_active'
:
if
k
==
'is_active'
:
v
=
True
if
v
in
[
'TRUE'
,
1
,
'true'
]
else
Fals
e
v
=
False
if
v
in
[
'False'
,
0
,
'false'
]
else
Tru
e
elif
k
==
'admin_user'
:
elif
k
==
'admin_user'
:
v
=
get_object_or_none
(
AdminUser
,
name
=
v
)
v
=
get_object_or_none
(
AdminUser
,
name
=
v
)
elif
k
in
[
'port'
,
'cpu_count'
,
'cpu_cores'
]:
elif
k
in
[
'port'
,
'cpu_count'
,
'cpu_cores'
]:
try
:
try
:
v
=
int
(
v
)
v
=
int
(
v
)
except
ValueError
:
except
ValueError
:
v
=
0
v
=
''
elif
k
==
'domain'
:
elif
k
==
'domain'
:
v
=
get_object_or_none
(
Domain
,
name
=
v
)
v
=
get_object_or_none
(
Domain
,
name
=
v
)
asset_dict
[
k
]
=
v
asset
=
get_object_or_none
(
Asset
,
id
=
id_
)
if
is_uuid
(
id_
)
else
None
if
v
!=
''
:
asset_dict
[
k
]
=
v
asset
=
get_object_or_none
(
Asset
,
id
=
asset_dict
.
pop
(
'id'
,
0
))
if
not
asset
:
if
not
asset
:
try
:
try
:
if
len
(
Asset
.
objects
.
filter
(
hostname
=
asset_dict
.
get
(
'hostname'
))):
if
len
(
Asset
.
objects
.
filter
(
hostname
=
asset_dict
.
get
(
'hostname'
))):
...
@@ -316,7 +318,7 @@ class BulkImportAssetView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
...
@@ -316,7 +318,7 @@ class BulkImportAssetView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
failed
.
append
(
'
%
s:
%
s'
%
(
asset_dict
[
'hostname'
],
str
(
e
)))
failed
.
append
(
'
%
s:
%
s'
%
(
asset_dict
[
'hostname'
],
str
(
e
)))
else
:
else
:
for
k
,
v
in
asset_dict
.
items
():
for
k
,
v
in
asset_dict
.
items
():
if
v
:
if
v
!=
''
:
setattr
(
asset
,
k
,
v
)
setattr
(
asset
,
k
,
v
)
try
:
try
:
asset
.
save
()
asset
.
save
()
...
...
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