Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
39025b6e
authored
Nov 09, 2016
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Divide SaveAsTemplateOperation to suboperations
parent
dceb22e2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
22 deletions
+43
-22
circle/vm/operations.py
+39
-22
circle/vm/tasks/agent_tasks.py
+4
-0
No files found.
circle/vm/operations.py
View file @
39025b6e
...
@@ -718,15 +718,22 @@ class SaveAsTemplateOperation(InstanceOperation):
...
@@ -718,15 +718,22 @@ class SaveAsTemplateOperation(InstanceOperation):
description
=
_
(
"Save virtual machine as a template so they can be shared "
description
=
_
(
"Save virtual machine as a template so they can be shared "
"with users and groups. Anyone who has access to a "
"with users and groups. Anyone who has access to a "
"template (and to the networks it uses) will be able to "
"template (and to the networks it uses) will be able to "
"start an instance of it."
)
"start an instance of it.
\n
"
"For linux run 'sudo waagent -deprovision+user' "
"before this operation"
)
required_perms
=
(
'vm.create_template'
,
)
required_perms
=
(
'vm.create_template'
,
)
accept_states
=
(
'RUNNING'
,
'STOPPED'
)
accept_states
=
(
'RUNNING'
)
async_queue
=
"localhost.man.slow"
def
is_preferred
(
self
):
def
is_preferred
(
self
):
return
(
self
.
instance
.
is_base
and
return
(
self
.
instance
.
is_base
and
self
.
instance
.
status
==
self
.
instance
.
STATUS
.
RUNNING
)
self
.
instance
.
status
==
self
.
instance
.
STATUS
.
RUNNING
)
def
on_abort
(
self
,
activity
,
error
):
activity
.
resultant_state
=
'RUNNING'
def
on_commit
(
self
,
activity
):
activity
.
resultant_state
=
'STOPPED'
@staticmethod
@staticmethod
def
_rename
(
name
):
def
_rename
(
name
):
m
=
search
(
r" v(\d+)$"
,
name
)
m
=
search
(
r" v(\d+)$"
,
name
)
...
@@ -737,25 +744,39 @@ class SaveAsTemplateOperation(InstanceOperation):
...
@@ -737,25 +744,39 @@ class SaveAsTemplateOperation(InstanceOperation):
v
=
1
v
=
1
return
"
%
s v
%
d"
%
(
name
,
v
)
return
"
%
s v
%
d"
%
(
name
,
v
)
def
on_abort
(
self
,
activity
,
error
):
if
hasattr
(
self
,
'disks'
):
for
disk
in
self
.
disks
:
disk
.
destroy
()
def
_operation
(
self
,
activity
,
user
,
system
,
name
=
None
,
def
_operation
(
self
,
activity
,
user
,
system
,
name
=
None
,
with_shutdown
=
True
,
clone
=
False
,
task
=
None
,
**
kwargs
):
with_shutdown
=
True
,
clone
=
False
,
task
=
None
,
**
kwargs
):
try
:
self
.
instance
.
_deprovision
(
parent_activity
=
activity
)
self
.
instance
.
_cleanup
(
parent_activity
=
activity
,
user
=
user
)
self
.
instance
.
_for_template_shutdown
(
parent_activity
=
activity
)
except
:
self
.
instance
.
_capture
(
parent_activity
=
activity
,
name
=
name
,
pass
user
=
user
,
kwargs
=
kwargs
,
clone
=
clone
)
if
with_shutdown
:
@register_operation
try
:
class
DeprovisionOperation
(
SubOperationMixin
,
InstanceOperation
):
self
.
instance
.
shutdown
(
parent_activity
=
activity
,
id
=
'_deprovision'
user
=
user
,
task
=
task
)
name
=
_
(
"deprovision"
)
except
Instance
.
WrongStateError
:
pass
def
_operation
(
self
):
agent_tasks
.
deprovision
.
apply_async
(
args
=
[
self
.
instance
.
name
],
queue
=
"localhost.localdomain.agent"
)
.
get
(
timeout
=
1200
)
@register_operation
class
ShutdownOperation
(
SubOperationMixin
,
InstanceOperation
):
id
=
'_for_template_shutdown'
name
=
_
(
"Shutdown"
)
def
_operation
(
self
):
vm_tasks
.
shutdown
.
apply_async
(
args
=
[
self
.
instance
.
name
],
queue
=
"localhost.vm.fast"
)
.
get
(
timeout
=
1200
)
@register_operation
class
CaptureOperation
(
SubOperationMixin
,
InstanceOperation
):
id
=
'_capture'
name
=
_
(
"capture"
)
def
_operation
(
self
,
name
,
user
,
kwargs
,
clone
):
# prepare parameters
# prepare parameters
params
=
{
params
=
{
'access_method'
:
self
.
instance
.
access_method
,
'access_method'
:
self
.
instance
.
access_method
,
...
@@ -778,8 +799,6 @@ class SaveAsTemplateOperation(InstanceOperation):
...
@@ -778,8 +799,6 @@ class SaveAsTemplateOperation(InstanceOperation):
params
.
update
(
kwargs
)
params
.
update
(
kwargs
)
params
.
pop
(
"parent_activity"
,
None
)
params
.
pop
(
"parent_activity"
,
None
)
#TODO: create data disks
# create template and do additional setup
# create template and do additional setup
tmpl
=
InstanceTemplate
(
**
params
)
tmpl
=
InstanceTemplate
(
**
params
)
tmpl
.
full_clean
()
# Avoiding database errors.
tmpl
.
full_clean
()
# Avoiding database errors.
...
@@ -792,7 +811,6 @@ class SaveAsTemplateOperation(InstanceOperation):
...
@@ -792,7 +811,6 @@ class SaveAsTemplateOperation(InstanceOperation):
tmpl
.
set_level
(
self
.
instance
.
template
.
owner
,
'owner'
)
tmpl
.
set_level
(
self
.
instance
.
template
.
owner
,
'owner'
)
tmpl
.
set_level
(
user
,
'owner'
)
tmpl
.
set_level
(
user
,
'owner'
)
try
:
try
:
#TODO: add data disks
# create interface templates
# create interface templates
for
i
in
self
.
instance
.
interface_set
.
all
():
for
i
in
self
.
instance
.
interface_set
.
all
():
i
.
save_as_template
(
tmpl
)
i
.
save_as_template
(
tmpl
)
...
@@ -817,7 +835,6 @@ class SaveAsTemplateOperation(InstanceOperation):
...
@@ -817,7 +835,6 @@ class SaveAsTemplateOperation(InstanceOperation):
template
=
reverse
(
'dashboard.views.template-detail'
,
template
=
reverse
(
'dashboard.views.template-detail'
,
kwargs
=
{
'pk'
:
tmpl
.
pk
}))
kwargs
=
{
'pk'
:
tmpl
.
pk
}))
@register_operation
@register_operation
class
ShutdownOperation
(
InstanceOperation
):
class
ShutdownOperation
(
InstanceOperation
):
id
=
'shutdown'
id
=
'shutdown'
...
...
circle/vm/tasks/agent_tasks.py
View file @
39025b6e
...
@@ -17,6 +17,10 @@
...
@@ -17,6 +17,10 @@
from
manager.mancelery
import
celery
from
manager.mancelery
import
celery
@celery.task
(
name
=
'agent.deprovision'
)
def
deprovision
(
vm_name
):
pass
@celery.task
(
name
=
'agent.install_diagnostics_extension'
)
@celery.task
(
name
=
'agent.install_diagnostics_extension'
)
def
install_diagnostics_extension
(
vm_name
):
def
install_diagnostics_extension
(
vm_name
):
pass
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