Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lu Xu
slapos.toolbox
Commits
b5cc2bee
Commit
b5cc2bee
authored
Aug 07, 2019
by
Bryton Lacquement
🚪
Committed by
Julien Muchembled
Aug 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixup! Add support for Python 3
/reviewed-on
nexedi/slapos.toolbox!63
parent
789d2d56
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
15 deletions
+13
-15
slapos/promise/check_computer_memory/__init__.py
slapos/promise/check_computer_memory/__init__.py
+3
-3
slapos/promise/plugin/check_free_disk_space.py
slapos/promise/plugin/check_free_disk_space.py
+6
-4
slapos/promise/plugin/trafficserver_cache_availability.py
slapos/promise/plugin/trafficserver_cache_availability.py
+1
-5
slapos/qemuqmpclient/__init__.py
slapos/qemuqmpclient/__init__.py
+3
-3
No files found.
slapos/promise/check_computer_memory/__init__.py
View file @
b5cc2bee
...
@@ -7,7 +7,7 @@ Uses:
...
@@ -7,7 +7,7 @@ Uses:
- /proc/meminfo
- /proc/meminfo
"""
"""
from
__future__
import
print_function
from
__future__
import
division
,
print_function
import
sys
import
sys
import
sqlite3
import
sqlite3
...
@@ -41,8 +41,8 @@ def getMemoryInfo(database, time, date):
...
@@ -41,8 +41,8 @@ def getMemoryInfo(database, time, date):
finally
:
finally
:
database
.
close
()
database
.
close
()
memory_info
[
"used_percent"
]
=
memory_info
[
"used"
]
*
100
.0
/
memory_info
[
"total"
]
memory_info
[
"used_percent"
]
=
memory_info
[
"used"
]
*
100
/
memory_info
[
"total"
]
memory_info
[
"free_percent"
]
=
memory_info
[
"free"
]
*
100
.0
/
memory_info
[
"total"
]
memory_info
[
"free_percent"
]
=
memory_info
[
"free"
]
*
100
/
memory_info
[
"total"
]
return
(
memory_info
,
""
)
return
(
memory_info
,
""
)
def
checkMemoryUsage
(
database_path
,
time
,
date
,
threshold
,
key
=
"used"
,
unit
=
"byte"
):
def
checkMemoryUsage
(
database_path
,
time
,
date
,
threshold
,
key
=
"used"
,
unit
=
"byte"
):
...
...
slapos/promise/plugin/check_free_disk_space.py
View file @
b5cc2bee
from
__future__
import
division
from
zope.interface
import
implementer
from
zope.interface
import
implementer
from
slapos.grid.promise
import
interface
from
slapos.grid.promise
import
interface
from
slapos.grid.promise.generic
import
GenericPromise
from
slapos.grid.promise.generic
import
GenericPromise
...
@@ -81,14 +83,14 @@ class RunPromise(GenericPromise):
...
@@ -81,14 +83,14 @@ class RunPromise(GenericPromise):
usage_output
=
""
usage_output
=
""
total_inode
=
stat
.
f_files
total_inode
=
stat
.
f_files
free_inode
=
stat
.
f_ffree
free_inode
=
stat
.
f_ffree
usage
=
round
((
float
(
total_inode
-
free_inode
)
/
total_inode
),
4
)
*
100
usage
=
round
(((
total_inode
-
free_inode
)
/
total_inode
),
4
)
*
100
if
usage
>
max_inode_usage
:
if
usage
>
max_inode_usage
:
return
"Disk Inodes usages is really high: %s%%"
%
usage
return
"Disk Inodes usages is really high: %s%%"
%
usage
elif
os
.
path
.
exists
(
'/tmp'
):
elif
os
.
path
.
exists
(
'/tmp'
):
# check if /tmp is mounted on another disk than path
# check if /tmp is mounted on another disk than path
tmp_stat
=
os
.
statvfs
(
'/tmp'
)
tmp_stat
=
os
.
statvfs
(
'/tmp'
)
if
tmp_stat
.
f_blocks
!=
stat
.
f_blocks
:
if
tmp_stat
.
f_blocks
!=
stat
.
f_blocks
:
tmp_usage
=
round
((
float
(
tmp_stat
.
f_files
-
tmp_stat
.
f_ffree
)
/
tmp_stat
.
f_files
),
4
)
*
100
tmp_usage
=
round
(((
tmp_stat
.
f_files
-
tmp_stat
.
f_ffree
)
/
tmp_stat
.
f_files
),
4
)
*
100
if
tmp_usage
>
max_inode_usage
:
if
tmp_usage
>
max_inode_usage
:
return
"Disk Inodes usage is high: %s%%"
%
tmp_usage
return
"Disk Inodes usage is high: %s%%"
%
tmp_usage
return
""
return
""
...
@@ -160,8 +162,8 @@ class RunPromise(GenericPromise):
...
@@ -160,8 +162,8 @@ class RunPromise(GenericPromise):
self
.
logger
.
info
(
"Disk usage: OK"
)
self
.
logger
.
info
(
"Disk usage: OK"
)
return
return
free_space
=
round
(
free_space
/
(
1024
.0
*
1024
*
1024
),
2
)
free_space
=
round
(
free_space
/
(
1024
*
1024
*
1024
),
2
)
min_space
=
round
(
min_free_size
/
(
1024
.0
*
1024
*
1024
),
2
)
min_space
=
round
(
min_free_size
/
(
1024
*
1024
*
1024
),
2
)
self
.
logger
.
error
(
'Free disk space low: remaining %s G (threshold: %s G)'
%
(
self
.
logger
.
error
(
'Free disk space low: remaining %s G (threshold: %s G)'
%
(
free_space
,
min_space
))
free_space
,
min_space
))
...
...
slapos/promise/plugin/trafficserver_cache_availability.py
View file @
b5cc2bee
...
@@ -30,11 +30,7 @@ class RunPromise(GenericPromise):
...
@@ -30,11 +30,7 @@ class RunPromise(GenericPromise):
return
return
try
:
try
:
subprocess
.
subprocess
.
check_output
(
subprocess
.
check_output
(
args
,
stderr
=
subprocess
.
STDOUT
)
args
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
)
except
subprocess
.
CalledProcessError
as
e
:
except
subprocess
.
CalledProcessError
as
e
:
result
=
e
.
output
.
strip
()
result
=
e
.
output
.
strip
()
self
.
logger
.
error
(
message
,
result
if
str
is
bytes
else
self
.
logger
.
error
(
message
,
result
if
str
is
bytes
else
...
...
slapos/qemuqmpclient/__init__.py
View file @
b5cc2bee
...
@@ -540,7 +540,7 @@ class QemuQMPWrapper(object):
...
@@ -540,7 +540,7 @@ class QemuQMPWrapper(object):
memory_id_list
.
append
({
memory_id_list
.
append
({
'memdev'
:
mem_dev
,
'memdev'
:
mem_dev
,
'id'
:
dimm
[
'data'
][
'id'
],
'id'
:
dimm
[
'data'
][
'id'
],
'size'
:
dimm
[
'data'
][
'size'
]
/
(
1024
*
1024
),
'size'
:
dimm
[
'data'
][
'size'
]
/
/
(
1024
*
1024
),
})
})
memory_id_list
=
sorted
(
memory_id_list
,
key
=
itemgetter
(
'id'
))
memory_id_list
=
sorted
(
memory_id_list
,
key
=
itemgetter
(
'id'
))
...
@@ -558,7 +558,7 @@ class QemuQMPWrapper(object):
...
@@ -558,7 +558,7 @@ class QemuQMPWrapper(object):
if
(
mem_size
%
slot_size
)
!=
0
:
if
(
mem_size
%
slot_size
)
!=
0
:
raise
ValueError
(
"Memory size %r is not a multiple of %r"
%
(
mem_size
,
raise
ValueError
(
"Memory size %r is not a multiple of %r"
%
(
mem_size
,
slot_size
))
slot_size
))
if
(
mem_size
/
slot_size
)
>
slot_amount
:
if
(
mem_size
/
/
slot_size
)
>
slot_amount
:
raise
ValueError
(
"No enough slots available to add %sMB of RAM"
%
mem_size
)
raise
ValueError
(
"No enough slots available to add %sMB of RAM"
%
mem_size
)
current_size
//=
(
1024
*
1024
)
current_size
//=
(
1024
*
1024
)
...
@@ -616,7 +616,7 @@ class QemuQMPWrapper(object):
...
@@ -616,7 +616,7 @@ class QemuQMPWrapper(object):
final_mem_size
=
0
final_mem_size
=
0
for
mem
in
mem_info
[
'hotplugged'
]:
for
mem
in
mem_info
[
'hotplugged'
]:
final_mem_size
+=
mem
[
'size'
]
final_mem_size
+=
mem
[
'size'
]
final_mem_size
=
final_mem_size
/
(
1024
*
1024
)
# get size in MB
final_mem_size
//=
(
1024
*
1024
)
# get size in MB
if
mem_size
!=
final_mem_size
:
if
mem_size
!=
final_mem_size
:
raise
ValueError
(
"Consistency error: Expected %s MB of hotplugged RAM "
\
raise
ValueError
(
"Consistency error: Expected %s MB of hotplugged RAM "
\
"but current RAM size is %s MB"
%
(
mem_size
,
final_mem_size
))
"but current RAM size is %s MB"
%
(
mem_size
,
final_mem_size
))
...
...
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