Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
storagedriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
eed9c4e8
authored
Feb 24, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
driver: added make_free_space function
parent
41d42a18
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
storagedriver.py
+22
-0
No files found.
storagedriver.py
View file @
eed9c4e8
...
@@ -91,3 +91,25 @@ def move_to_trash(datastore, disk_name):
...
@@ -91,3 +91,25 @@ def move_to_trash(datastore, disk_name):
mkdir
(
trash_path
)
mkdir
(
trash_path
)
#TODO: trash dir configurable?
#TODO: trash dir configurable?
move
(
disk_path
,
trash_path
)
move
(
disk_path
,
trash_path
)
@celery.task
def
make_free_space
(
datastore
,
percent
=
10
):
''' Check for free space on datastore.
If free space is less than the given percent
removes oldest files to satisfy the given requirement.
'''
trash_path
=
path
.
join
(
datastore
,
trash_directory
)
files
=
sorted
(
listdir
(
trash_path
),
key
=
lambda
x
:
path
.
getctime
(
path
.
join
(
trash_path
,
x
)))
logger
.
info
(
"Free space on datastore:
%
s"
%
get_storage_stat
(
trash_path
)
.
get
(
'free_percent'
))
while
get_storage_stat
(
trash_path
)
.
get
(
'free_percent'
)
<
percent
:
logger
.
debug
(
get_storage_stat
(
trash_path
))
try
:
f
=
files
.
pop
(
0
)
unlink
(
path
.
join
(
trash_path
,
f
))
logger
.
info
(
'Image:
%
s removed.'
%
f
)
except
IndexError
:
raise
Exception
(
"Trash folder is empty."
)
return
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