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
587bde3b
authored
Sep 18, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: implement get_exclusive()
parent
6413c2ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
9 deletions
+26
-9
circle/storage/models.py
+26
-9
No files found.
circle/storage/models.py
View file @
587bde3b
# coding=utf-8
# coding=utf-8
import
logging
import
logging
import
uuid
from
django.db
import
models
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.db.models.signals
import
post_delete
from
django.db.models.signals
import
post_delete
...
@@ -8,7 +10,7 @@ from model_utils.models import TimeStampedModel
...
@@ -8,7 +10,7 @@ from model_utils.models import TimeStampedModel
from
manager
import
storage_manager
from
manager
import
storage_manager
from
.
import
tasks
import
tasks
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -39,9 +41,9 @@ class Disk(TimeStampedModel):
...
@@ -39,9 +41,9 @@ class Disk(TimeStampedModel):
"""
"""
TYPES
=
[(
'qcow2-norm'
,
'qcow2 normal'
),
(
'qcow2-snap'
,
'qcow2 snapshot'
),
TYPES
=
[(
'qcow2-norm'
,
'qcow2 normal'
),
(
'qcow2-snap'
,
'qcow2 snapshot'
),
(
'iso'
,
'iso'
),
(
'raw-ro'
,
'raw read-only'
),
(
'raw-rw'
,
'raw'
)]
(
'iso'
,
'iso'
),
(
'raw-ro'
,
'raw read-only'
),
(
'raw-rw'
,
'raw'
)]
name
=
models
.
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'name'
))
name
=
models
.
CharField
(
blank
=
True
,
max_length
=
100
,
filename
=
models
.
CharField
(
max_length
=
256
,
unique
=
True
,
verbose_name
=
_
(
'name'
))
verbose_name
=
_
(
'filename'
))
filename
=
models
.
CharField
(
max_length
=
256
,
verbose_name
=
_
(
'filename'
))
datastore
=
models
.
ForeignKey
(
DataStore
)
datastore
=
models
.
ForeignKey
(
DataStore
)
type
=
models
.
CharField
(
max_length
=
10
,
choices
=
TYPES
)
type
=
models
.
CharField
(
max_length
=
10
,
choices
=
TYPES
)
size
=
models
.
IntegerField
()
size
=
models
.
IntegerField
()
...
@@ -70,14 +72,29 @@ class Disk(TimeStampedModel):
...
@@ -70,14 +72,29 @@ class Disk(TimeStampedModel):
'raw-rw'
:
'raw'
,
'raw-rw'
:
'raw'
,
}[
self
.
type
]
}[
self
.
type
]
class
WrongDiskTypeError
(
Exception
):
def
__init__
(
self
,
type
):
self
.
type
=
type
def
__str__
(
self
):
return
(
"Operation can't be invoked on a disk of type '
%
s'."
%
self
.
type
)
def
get_exclusive
(
self
):
def
get_exclusive
(
self
):
"""Get an instance of the disk for exclusive usage.
"""Get an instance of the disk for exclusive usage.
It might mean copying the disk, creating a snapshot or creating a
symbolic link to a read-only image.
"""
"""
# TODO implement (or call) logic
if
self
.
type
in
[
'qcow2-snap'
,
'raw-rw'
]:
return
self
raise
self
.
WrongDiskTypeError
(
self
.
type
)
filename
=
str
(
uuid
.
uuid4
())
new_type
=
{
'qcow2-norm'
:
'qcow2-snap'
,
'iso'
:
'iso'
,
'raw-ro'
:
'raw-rw'
,
}[
self
.
type
]
return
Disk
(
base
=
self
,
datastore
=
self
.
datastore
,
filename
=
filename
,
name
=
self
.
name
,
size
=
self
.
size
,
type
=
new_type
)
@property
@property
def
device_type
(
self
):
def
device_type
(
self
):
...
...
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