Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5f4df6e6
authored
Apr 09, 2020
by
Máhonfai Bálint
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add import disk to disk model
parent
1cb28964
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
10 deletions
+29
-10
circle/storage/models.py
+24
-10
circle/storage/tasks/storage_tasks.py
+5
-0
No files found.
circle/storage/models.py
View file @
5f4df6e6
...
...
@@ -20,31 +20,30 @@
from
__future__
import
unicode_literals
import
logging
from
os.path
import
join
import
uuid
import
re
import
re
from
celery.contrib.abortable
import
AbortableAsyncResult
from
django.db.models
import
(
Model
,
BooleanField
,
CharField
,
DateTimeField
,
ForeignKey
)
from
celery.exceptions
import
TimeoutError
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.urlresolvers
import
reverse
from
django.db.models
import
(
Model
,
BooleanField
,
CharField
,
DateTimeField
,
ForeignKey
)
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
from
model_utils.models
import
TimeStampedModel
from
os.path
import
join
from
sizefield.models
import
FileSizeField
from
.tasks
import
local_tasks
,
storage_tasks
from
celery.exceptions
import
TimeoutError
from
common.models
import
(
WorkerNotFound
,
HumanReadableException
,
humanize_exception
,
method_cache
)
from
.tasks
import
local_tasks
,
storage_tasks
logger
=
logging
.
getLogger
(
__name__
)
class
DataStore
(
Model
):
"""Collection of virtual disks.
"""
name
=
CharField
(
max_length
=
100
,
unique
=
True
,
verbose_name
=
_
(
'name'
))
...
...
@@ -119,7 +118,6 @@ class DataStore(Model):
class
Disk
(
TimeStampedModel
):
"""A virtual disk.
"""
TYPES
=
[(
'qcow2-norm'
,
'qcow2 normal'
),
(
'qcow2-snap'
,
'qcow2 snapshot'
),
...
...
@@ -473,7 +471,23 @@ class Disk(TimeStampedModel):
disk
.
save
()
return
disk
def
export
(
self
,
format
,
upload_link
,
timeout
=
600
):
@classmethod
def
import_disk
(
cls
,
user
,
name
,
download_link
,
timeout
=
3600
):
params
=
{
'name'
:
name
,
'type'
:
'qcow2-norm'
}
disk
=
cls
.
create
(
user
,
**
params
)
queue_name
=
disk
.
get_remote_queue_name
(
'storage'
,
priority
=
'slow'
)
remote
=
storage_tasks
.
import_disk
.
apply_async
(
args
=
[
disk
.
get_disk_desc
(),
download_link
],
queue
=
queue_name
)
disk_size
=
remote
.
get
(
timeout
=
timeout
)
disk
.
size
=
disk_size
disk
.
is_ready
=
True
disk
.
save
()
return
disk
def
export
(
self
,
format
,
upload_link
,
timeout
=
3600
):
exported_name
=
self
.
name
if
self
.
name
!=
''
else
self
.
filename
queue_name
=
self
.
get_remote_queue_name
(
'storage'
,
priority
=
'slow'
)
...
...
@@ -563,7 +577,7 @@ class Disk(TimeStampedModel):
@property
def
is_resizable
(
self
):
return
self
.
type
in
(
'qcow2-norm'
,
'raw-rw'
,
'qcow2-snap'
,
)
return
self
.
type
in
(
'qcow2-norm'
,
'raw-rw'
,
'qcow2-snap'
,)
@property
def
is_exportable
(
self
):
...
...
circle/storage/tasks/storage_tasks.py
View file @
5f4df6e6
...
...
@@ -38,6 +38,11 @@ def download(disk_desc, url):
pass
@celery.task
(
name
=
'storagedriver.import_disk'
)
def
import_disk
(
disk_desc
,
url
):
pass
@celery.task
(
name
=
'storagedriver.export'
)
def
export
(
disk_desc
,
format
):
pass
...
...
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