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
Show 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):
...
@@ -353,7 +353,6 @@ class Disk(object):
if
'qcow'
in
ftype
.
lower
():
if
'qcow'
in
ftype
.
lower
():
move
(
downloaded_file
,
self
.
get_path
())
move
(
downloaded_file
,
self
.
get_path
())
else
:
else
:
logger
.
debug
(
"Calling qemu-img with command line:
%
s"
%
str
(
cmdline
))
cmdline
=
[
'ionice'
,
'-c'
,
'idle'
,
cmdline
=
[
'ionice'
,
'-c'
,
'idle'
,
'qemu-img'
,
'convert'
,
'qemu-img'
,
'convert'
,
'-m'
,
'4'
,
'-O'
,
'qcow2'
,
'-m'
,
'4'
,
'-O'
,
'qcow2'
,
...
@@ -362,36 +361,32 @@ class Disk(object):
...
@@ -362,36 +361,32 @@ class Disk(object):
logger
.
debug
(
"Calling qemu-img with command line:
%
s"
%
str
(
cmdline
))
logger
.
debug
(
"Calling qemu-img with command line:
%
s"
%
str
(
cmdline
))
subprocess
.
check_output
(
cmdline
)
subprocess
.
check_output
(
cmdline
)
except
AbortException
:
except
AbortException
:
if
os
.
path
.
exists
(
downloaded_file
):
os
.
unlink
(
downloaded_file
)
if
os
.
path
.
exists
(
self
.
get_path
()):
if
os
.
path
.
exists
(
self
.
get_path
()):
os
.
unlink
(
self
.
get_path
())
os
.
unlink
(
self
.
get_path
())
logger
.
info
(
"Import of disk
%
s aborted"
%
self
.
name
)
logger
.
info
(
"Import of disk
%
s aborted"
%
self
.
name
)
except
:
except
:
if
os
.
path
.
exists
(
downloaded_file
):
os
.
unlink
(
downloaded_file
)
if
os
.
path
.
exists
(
self
.
get_path
()):
if
os
.
path
.
exists
(
self
.
get_path
()):
os
.
unlink
(
self
.
get_path
())
os
.
unlink
(
self
.
get_path
())
raise
raise
else
:
else
:
if
os
.
path
.
exists
(
downloaded_file
):
os
.
unlink
(
downloaded_file
)
if
not
self
.
check_valid_image
():
if
not
self
.
check_valid_image
():
os
.
unlink
(
self
.
get_path
())
os
.
unlink
(
self
.
get_path
())
raise
Exception
(
"Invalid file format."
)
raise
Exception
(
"Invalid file format."
)
self
.
size
=
Disk
.
get
(
self
.
dir
,
self
.
name
)
.
size
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..."
)
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'
]
cmdline
=
[
'ionice'
,
'-c'
,
'idle'
,
'qemu-img'
,
'convert'
]
if
disk_format
==
'qcow2'
or
disk_format
==
'qcow'
:
if
disk_format
==
'qcow2'
or
disk_format
==
'qcow'
:
cmdline
.
append
(
'-c'
)
cmdline
.
append
(
'-c'
)
cmdline
.
extend
([
'-m'
,
'4'
,
'-O'
,
disk_format
,
self
.
get_path
(),
exported_path
])
cmdline
.
extend
([
'-m'
,
'4'
,
'-O'
,
disk_format
,
self
.
get_path
(),
exported_path
])
logger
.
debug
(
"Calling qemu-img with command line:
%
s"
%
str
(
cmdline
))
logger
.
debug
(
"Calling qemu-img with command line:
%
s"
%
str
(
cmdline
))
subprocess
.
check_output
(
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"
):
def
export_disk
(
self
,
task
,
disk_format
,
upload_link
,
port
=
22
,
identity
=
None
,
mode
=
"scp"
):
logger
.
debug
(
"Start disk export..."
)
logger
.
debug
(
"Start disk export..."
)
...
@@ -431,6 +426,7 @@ class Disk(object):
...
@@ -431,6 +426,7 @@ class Disk(object):
if
proc
.
returncode
==
0
:
if
proc
.
returncode
==
0
:
break
break
else
:
else
:
sleep
(
2
)
logger
.
error
(
"Copy over ssh failed with return code:
%
s, will try
%
s more time(s)..."
%
logger
.
error
(
"Copy over ssh failed with return code:
%
s, will try
%
s more time(s)..."
%
(
str
(
proc
.
returncode
),
str
(
i
)))
(
str
(
proc
.
returncode
),
str
(
i
)))
if
proc
.
stdout
is
not
None
:
if
proc
.
stdout
is
not
None
:
...
@@ -536,7 +532,6 @@ class Disk(object):
...
@@ -536,7 +532,6 @@ class Disk(object):
logger
.
warning
(
"Aborted merge job, removing
%
s"
,
logger
.
warning
(
"Aborted merge job, removing
%
s"
,
new_disk
.
get_path
())
new_disk
.
get_path
())
os
.
unlink
(
new_disk
.
get_path
())
os
.
unlink
(
new_disk
.
get_path
())
except
:
except
:
if
proc
:
if
proc
:
proc
.
terminate
()
proc
.
terminate
()
...
...
storagedriver.py
View file @
bc832dcf
...
@@ -96,8 +96,9 @@ class export_disk_to_datastore(AbortableTask):
...
@@ -96,8 +96,9 @@ class export_disk_to_datastore(AbortableTask):
disk_desc
=
kwargs
[
"disk_desc"
]
disk_desc
=
kwargs
[
"disk_desc"
]
disk_format
=
kwargs
[
"disk_format"
]
disk_format
=
kwargs
[
"disk_format"
]
datastore
=
kwargs
[
"datastore"
]
datastore
=
kwargs
[
"datastore"
]
folder
=
kwargs
[
"folder"
]
disk
=
Disk
.
deserialize
(
disk_desc
)
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
()
@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