Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
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
f6e1dcbe
authored
Mar 18, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save_as fixes
parent
4db5bd68
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
23 deletions
+41
-23
circle/storage/models.py
+17
-3
circle/storage/tasks/periodic_tasks.py
+6
-5
circle/vm/models/instance.py
+18
-15
No files found.
circle/storage/models.py
View file @
f6e1dcbe
...
...
@@ -107,6 +107,18 @@ class Disk(AclBase, TimeStampedModel):
self
.
disk
=
disk
class
DiskIsNotReady
(
Exception
):
def
__init__
(
self
,
disk
,
message
=
None
):
if
message
is
None
:
message
=
(
"The requested operation can'T be performed on "
"disk '
%
s (
%
s)' because it has never been"
"deployed."
%
(
disk
.
name
,
disk
.
filename
))
Exception
.
__init__
(
self
,
message
)
self
.
disk
=
disk
@property
def
ready
(
self
):
return
self
.
activity_log
.
filter
(
activity_code__endswith
=
"deploy"
,
...
...
@@ -306,6 +318,7 @@ class Disk(AclBase, TimeStampedModel):
datastore
=
params
.
pop
(
'datastore'
,
DataStore
.
objects
.
get
())
disk
=
cls
(
filename
=
str
(
uuid
.
uuid4
()),
datastore
=
datastore
,
**
params
)
disk
.
save
()
logger
.
debug
(
"Disk created:
%
s"
,
params
)
with
disk_activity
(
code_suffix
=
"create"
,
user
=
user
,
disk
=
disk
):
...
...
@@ -366,8 +379,6 @@ class Disk(AclBase, TimeStampedModel):
kwargs
.
setdefault
(
'name'
,
url
.
split
(
'/'
)[
-
1
])
disk
=
Disk
.
create
(
type
=
"iso"
,
instance
=
instance
,
user
=
user
,
size
=
None
,
**
kwargs
)
# TODO get proper datastore
disk
.
datastore
=
DataStore
.
objects
.
get
()
queue_name
=
disk
.
get_remote_queue_name
(
'storage'
)
def
__on_abort
(
activity
,
error
):
...
...
@@ -439,6 +450,7 @@ class Disk(AclBase, TimeStampedModel):
"""
mapping
=
{
'qcow2-snap'
:
(
'qcow2-norm'
,
self
.
base
),
'qcow2-norm'
:
(
'qcow2-norm'
,
self
),
}
if
self
.
type
not
in
mapping
.
keys
():
raise
self
.
WrongDiskTypeError
(
self
.
type
)
...
...
@@ -446,6 +458,9 @@ class Disk(AclBase, TimeStampedModel):
if
self
.
is_in_use
:
raise
self
.
DiskInUseError
(
self
)
if
not
self
.
ready
:
raise
self
.
DiskIsNotReady
(
self
)
# from this point on, the caller has to guarantee that the disk is not
# going to be used until the operation is complete
...
...
@@ -455,7 +470,6 @@ class Disk(AclBase, TimeStampedModel):
name
=
self
.
name
,
size
=
self
.
size
,
type
=
new_type
)
disk
.
save
()
with
disk_activity
(
code_suffix
=
"save_as"
,
disk
=
self
,
user
=
user
,
task_uuid
=
task_uuid
):
with
disk_activity
(
code_suffix
=
"deploy"
,
disk
=
disk
,
...
...
circle/storage/tasks/periodic_tasks.py
View file @
f6e1dcbe
from
storage.models
import
DataStore
import
os
from
manager.mancelery
import
celery
import
logging
from
storage.tasks
import
remote_tasks
...
...
@@ -16,13 +15,15 @@ def garbage_collector(timeout=15):
deletes oldest images from trash.
:param timeout: Seconds before TimeOut exception
:type timeo
i
t: int
:type timeo
u
t: int
"""
for
ds
in
DataStore
.
objects
.
all
():
file_list
=
os
.
listdir
(
ds
.
path
)
disk_list
=
ds
.
get_deletable_disks
()
queue_name
=
ds
.
get_remote_queue_name
(
'storage'
)
for
i
in
set
(
file_list
)
.
intersection
(
disk_list
):
files
=
set
(
remote_tasks
.
list_files
.
apply_async
(
args
=
[
ds
.
path
],
queue
=
queue_name
)
.
get
(
timeout
=
timeout
))
disks
=
set
(
ds
.
get_deletable_disks
())
queue_name
=
ds
.
get_remote_queue_name
(
'storage'
)
for
i
in
disks
&
files
:
logger
.
info
(
"Image:
%
s at Datastore:
%
s moved to trash folder."
%
(
i
,
ds
.
path
))
remote_tasks
.
move_to_trash
.
apply_async
(
...
...
circle/vm/models/instance.py
View file @
f6e1dcbe
...
...
@@ -1128,20 +1128,23 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel,
with
instance_activity
(
code_suffix
=
"save_as_template"
,
instance
=
self
,
task_uuid
=
task_uuid
,
user
=
user
)
as
act
:
# prepare parameters
kwargs
.
setdefault
(
'name'
,
name
)
kwargs
.
setdefault
(
'description'
,
self
.
description
)
kwargs
.
setdefault
(
'parent'
,
self
.
template
)
kwargs
.
setdefault
(
'num_cores'
,
self
.
num_cores
)
kwargs
.
setdefault
(
'ram_size'
,
self
.
ram_size
)
kwargs
.
setdefault
(
'max_ram_size'
,
self
.
max_ram_size
)
kwargs
.
setdefault
(
'arch'
,
self
.
arch
)
kwargs
.
setdefault
(
'priority'
,
self
.
priority
)
kwargs
.
setdefault
(
'boot_menu'
,
self
.
boot_menu
)
kwargs
.
setdefault
(
'raw_data'
,
self
.
raw_data
)
kwargs
.
setdefault
(
'lease'
,
self
.
lease
)
kwargs
.
setdefault
(
'access_method'
,
self
.
access_method
)
kwargs
.
setdefault
(
'system'
,
self
.
template
.
system
if
self
.
template
else
None
)
params
=
{
'access_method'
:
self
.
access_method
,
'arch'
:
self
.
arch
,
'boot_menu'
:
self
.
boot_menu
,
'description'
:
self
.
description
,
'lease'
:
self
.
lease
,
# Can be problem in new VM
'max_ram_size'
:
self
.
max_ram_size
,
'name'
:
name
,
'num_cores'
:
self
.
num_cores
,
'owner'
:
user
,
'parent'
:
self
.
template
,
# Can be problem
'priority'
:
self
.
priority
,
'ram_size'
:
self
.
ram_size
,
'raw_data'
:
self
.
raw_data
,
'system'
:
self
.
template
.
system
if
self
.
template
else
""
,
}
params
.
update
(
kwargs
)
def
__try_save_disk
(
disk
):
try
:
...
...
@@ -1150,7 +1153,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel,
return
disk
# create template and do additional setup
tmpl
=
InstanceTemplate
(
**
kwarg
s
)
tmpl
=
InstanceTemplate
(
**
param
s
)
tmpl
.
full_clean
()
# Avoiding database errors.
tmpl
.
save
()
with
act
.
sub_activity
(
'saving_disks'
):
...
...
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