Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
storagedriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bc832dcf
authored
Dec 14, 2023
by
Carpoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add folder option to disk export
add folder option to disk export use finally insted of repat clenup code
parent
944ddb8b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
13 deletions
+9
-13
disk.py
+7
-12
storagedriver.py
+2
-1
No files found.
disk.py
View file @
bc832dcf
...
...
@@ -353,7 +353,6 @@ class Disk(object):
if
'qcow'
in
ftype
.
lower
():
move
(
downloaded_file
,
self
.
get_path
())
else
:
logger
.
debug
(
"Calling qemu-img with command line:
%
s"
%
str
(
cmdline
))
cmdline
=
[
'ionice'
,
'-c'
,
'idle'
,
'qemu-img'
,
'convert'
,
'-m'
,
'4'
,
'-O'
,
'qcow2'
,
...
...
@@ -362,36 +361,32 @@ class Disk(object):
logger
.
debug
(
"Calling qemu-img with command line:
%
s"
%
str
(
cmdline
))
subprocess
.
check_output
(
cmdline
)
except
AbortException
:
if
os
.
path
.
exists
(
downloaded_file
):
os
.
unlink
(
downloaded_file
)
if
os
.
path
.
exists
(
self
.
get_path
()):
os
.
unlink
(
self
.
get_path
())
logger
.
info
(
"Import of disk
%
s aborted"
%
self
.
name
)
except
:
if
os
.
path
.
exists
(
downloaded_file
):
os
.
unlink
(
downloaded_file
)
if
os
.
path
.
exists
(
self
.
get_path
()):
os
.
unlink
(
self
.
get_path
())
raise
else
:
if
os
.
path
.
exists
(
downloaded_file
):
os
.
unlink
(
downloaded_file
)
if
not
self
.
check_valid_image
():
os
.
unlink
(
self
.
get_path
())
raise
Exception
(
"Invalid file format."
)
self
.
size
=
Disk
.
get
(
self
.
dir
,
self
.
name
)
.
size
finally
:
if
os
.
path
.
exists
(
downloaded_file
):
os
.
unlink
(
downloaded_file
)
def
export_disk_to_datastore
(
self
,
task
,
disk_format
,
datastore
):
def
export_disk_to_datastore
(
self
,
task
,
disk_format
,
datastore
,
folder
=
"exports"
):
logger
.
debug
(
"Start disk export to datastore..."
)
exported_path
=
os
.
path
.
join
(
datastore
,
"exports"
,
os
.
path
.
basename
(
self
.
get_path
())
+
'.'
+
disk_format
)
exported_path
=
os
.
path
.
join
(
datastore
,
folder
,
os
.
path
.
basename
(
self
.
get_path
())
+
'.'
+
disk_format
)
cmdline
=
[
'ionice'
,
'-c'
,
'idle'
,
'qemu-img'
,
'convert'
]
if
disk_format
==
'qcow2'
or
disk_format
==
'qcow'
:
cmdline
.
append
(
'-c'
)
cmdline
.
extend
([
'-m'
,
'4'
,
'-O'
,
disk_format
,
self
.
get_path
(),
exported_path
])
logger
.
debug
(
"Calling qemu-img with command line:
%
s"
%
str
(
cmdline
))
subprocess
.
check_output
(
cmdline
)
return
os
.
path
.
basename
(
exported_path
)
def
export_disk
(
self
,
task
,
disk_format
,
upload_link
,
port
=
22
,
identity
=
None
,
mode
=
"scp"
):
logger
.
debug
(
"Start disk export..."
)
...
...
@@ -431,6 +426,7 @@ class Disk(object):
if
proc
.
returncode
==
0
:
break
else
:
sleep
(
2
)
logger
.
error
(
"Copy over ssh failed with return code:
%
s, will try
%
s more time(s)..."
%
(
str
(
proc
.
returncode
),
str
(
i
)))
if
proc
.
stdout
is
not
None
:
...
...
@@ -536,7 +532,6 @@ class Disk(object):
logger
.
warning
(
"Aborted merge job, removing
%
s"
,
new_disk
.
get_path
())
os
.
unlink
(
new_disk
.
get_path
())
except
:
if
proc
:
proc
.
terminate
()
...
...
storagedriver.py
View file @
bc832dcf
...
...
@@ -96,8 +96,9 @@ class export_disk_to_datastore(AbortableTask):
disk_desc
=
kwargs
[
"disk_desc"
]
disk_format
=
kwargs
[
"disk_format"
]
datastore
=
kwargs
[
"datastore"
]
folder
=
kwargs
[
"folder"
]
disk
=
Disk
.
deserialize
(
disk_desc
)
return
disk
.
export_disk_to_datastore
(
self
,
disk_format
,
datastore
)
return
disk
.
export_disk_to_datastore
(
self
,
disk_format
,
datastore
,
folder
)
@celery.task
()
...
...
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