Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Paas CI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
INFN Cloud
Paas CI
Commits
81b668d3
Commit
81b668d3
authored
1 year ago
by
Gioacchino Vino
Browse files
Options
Downloads
Patches
Plain Diff
Reviewed scan python code
parent
f27f044f
No related branches found
Branches containing commit
No related tags found
1 merge request
!108
Updated Python scan code
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
files/gvm_library.py
+16
-14
16 additions, 14 deletions
files/gvm_library.py
with
16 additions
and
14 deletions
files/gvm_library.py
+
16
−
14
View file @
81b668d3
...
...
@@ -171,30 +171,32 @@ class Task:
def
__del__
(
self
):
self
.
delete
()
def
get_progress
(
self
)
->
Tuple
[
str
,
int
]:
res
=
self
.
client
.
get_tasks
(
filter_string
=
self
.
id
)[
0
]
print
(
res
[
'
status
'
],
res
[
'
progress
'
])
status
=
res
[
'
status
'
]
# New -> Requested -> Queued -> Running -> Done
progress
=
int
(
res
[
'
progress
'
])
# 0 0 0 0 -> 100 -1
self
.
status
=
status
self
.
progress
=
progress
return
(
status
,
progress
)
def
update_status
(
self
):
task_info
=
self
.
client
.
get_tasks
(
filter_string
=
self
.
id
)[
0
]
self
.
name
=
task_info
.
xpath
(
'
name/text()
'
)[
0
]
self
.
status
=
task_info
.
xpath
(
'
status/text()
'
)[
0
]
# New -> Requested -> Queued -> Running -> Done
self
.
progress
=
int
(
task_info
.
xpath
(
'
progress/text()
'
)[
0
])
# 0 0 0 0 -> 100 -1
self
.
in_use
=
task_info
.
xpath
(
'
in_use/text()
'
)[
0
]
try
:
self
.
report_id
=
task_info
.
xpath
(
'
last_report/report/@id
'
)[
0
]
except
:
pass
def
wait
(
self
,
timeout
:
int
=
3600
)
->
bool
:
start_time
=
time
()
logging
.
debug
(
"
Waiting for scans ends the task
"
)
while
True
:
s
tatus
,
progress
=
self
.
get_progres
s
()
if
status
not
in
[
"
New
"
,
"
Requested
"
,
"
Queued
"
,
"
Running
"
,
"
Done
"
]:
# ["Interrupted", ...]
logging
.
warning
(
f
"
Task in the undesired status:
'
{
status
}
'"
)
s
elf
.
update_statu
s
()
if
self
.
status
not
in
[
"
New
"
,
"
Requested
"
,
"
Queued
"
,
"
Running
"
,
"
Done
"
]:
# ["Interrupted", ...]
logging
.
warning
(
f
"
Task in the undesired status:
'
{
self
.
status
}
'"
)
return
False
if
status
==
"
Done
"
and
progress
==
-
1
:
if
self
.
status
==
"
Done
"
and
self
.
progress
==
-
1
:
logging
.
info
(
f
"
Task completed
"
)
return
True
if
time
()
-
start_time
>
timeout
:
logging
.
error
(
"
TIMEOUT during waiting for task ending
"
)
return
False
logging
.
debug
(
f
"
Waiting for the task ends. Now
{
int
(
time
()
-
start_time
)
}
s from start. Status:
{
status
}
"
)
logging
.
debug
(
f
"
Waiting for the task ends. Now
{
int
(
time
()
-
start_time
)
}
s from start. Status:
{
self
.
status
}
"
)
sleep
(
10
)
def
save_report
(
self
,
report_format
:
str
,
report_filename
:
str
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment