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
Commit
fbec88c7
authored
Sep 18, 2013
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding Instance functions
parent
d039ad8a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
41 deletions
+71
-41
circle/vm/models.py
+71
-41
No files found.
circle/vm/models.py
View file @
fbec88c7
...
...
@@ -432,15 +432,17 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
def
deploy_async
(
self
,
user
=
None
):
""" Launch celery task to handle the job asynchronously.
"""
vm_manager
.
deploy
.
apply_async
(
self
,
user
,
queue
=
"localhost.man"
)
vm_manager
.
deploy
.
apply_async
(
args
=
[
self
,
user
]
,
queue
=
"localhost.man"
)
def
deploy
(
self
,
user
=
None
,
task_uuid
=
None
):
""" Deploy new virtual machine with network
1. Schedule
"""
act
=
InstanceActivity
(
activity_code
=
'vm.Instance.deploy'
,
instance
=
self
,
user
=
user
,
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
)
act
=
InstanceActivity
(
activity_code
=
'vm.Instance.deploy'
)
act
.
instance
=
self
act
.
user
=
user
act
.
started
=
timezone
.
now
()
act
.
task_uuid
=
task_uuid
act
.
save
()
# Schedule
...
...
@@ -470,21 +472,74 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
act
.
finish
(
result
=
'SUCCESS'
)
def
stop
(
self
):
# TODO implement
pass
def
stop_async
(
self
,
user
=
None
):
vm_manager
.
stop
.
apply_async
(
args
=
[
self
,
user
],
queue
=
"localhost.man"
)
def
resume
(
self
):
# TODO implement
pass
def
stop
(
self
,
user
=
None
,
task_uuid
=
None
):
act
=
InstanceActivity
(
activity_code
=
'vm.Instance.stop'
)
act
.
instance
=
self
act
.
user
=
user
act
.
started
=
timezone
.
now
()
act
.
task_uuid
=
task_uuid
act
.
save
()
tasks
.
stop
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
queue
=
self
.
node
.
host
.
hostname
+
".vm"
)
.
get
()
def
poweroff
(
self
):
# TODO implement
pass
def
resume_async
(
self
,
user
=
None
):
vm_manager
.
resume
.
apply_async
(
args
=
[
self
,
user
],
queue
=
"localhost.man"
)
def
restart
(
self
):
# TODO implement
pass
def
resume
(
self
,
user
=
None
,
task_uuid
=
None
):
act
=
InstanceActivity
(
activity_code
=
'vm.Instance.resume'
)
act
.
instance
=
self
act
.
user
=
user
act
.
started
=
timezone
.
now
()
act
.
task_uuid
=
task_uuid
act
.
save
()
tasks
.
resume
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
queue
=
self
.
node
.
host
.
hostname
+
".vm"
)
.
get
()
def
poweroff_async
(
self
,
user
=
None
):
vm_manager
.
power_off
.
apply_async
(
args
=
[
self
,
user
],
queue
=
"localhost.man"
)
def
poweroff
(
self
,
user
=
None
,
task_uuid
=
None
):
act
=
InstanceActivity
(
activity_code
=
'vm.Instance.power_off'
)
act
.
instance
=
self
act
.
user
=
user
act
.
started
=
timezone
.
now
()
act
.
task_uuid
=
task_uuid
act
.
save
()
tasks
.
power_off
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
queue
=
self
.
node
.
host
.
hostname
+
".vm"
)
.
get
()
def
restart_async
(
self
,
user
=
None
):
vm_manager
.
restart
.
apply_async
(
args
=
[
self
,
user
],
queue
=
"localhost.man"
)
def
restart
(
self
,
user
=
None
,
task_uuid
=
None
):
act
=
InstanceActivity
(
activity_code
=
'vm.Instance.restart'
)
act
.
instance
=
self
act
.
user
=
user
act
.
started
=
timezone
.
now
()
act
.
task_uuid
=
task_uuid
act
.
save
()
tasks
.
restart
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
queue
=
self
.
node
.
host
.
hostname
+
".vm"
)
.
get
()
def
save_as_async
(
self
,
user
=
None
):
vm_manager
.
save_as
.
apply_async
(
args
=
[
self
,
user
],
queue
=
"localhost.man"
)
def
save_as
(
self
,
user
=
None
,
task_uuid
=
None
):
act
=
InstanceActivity
(
activity_code
=
'vm.Instance.restart'
)
act
.
instance
=
self
act
.
user
=
user
act
.
started
=
timezone
.
now
()
act
.
task_uuid
=
task_uuid
act
.
save
()
tasks
.
save_as
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
queue
=
self
.
node
.
host
.
hostname
+
".vm"
)
.
get
()
def
renew
(
self
,
which
=
'both'
):
"""Renew virtual machine instance leases.
...
...
@@ -497,31 +552,6 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
self
.
time_of_delete
=
timezone
.
now
()
+
self
.
lease
.
delete_interval
self
.
save
()
def
save_as
(
self
):
"""Save image and shut down."""
imgname
=
"template-
%
d-
%
d"
%
(
self
.
template
.
id
,
self
.
id
)
from
.tasks
import
SaveAsTask
SaveAsTask
.
delay
(
one_id
=
self
.
one_id
,
new_img
=
imgname
)
self
.
_change_state
(
"SHUTDOWN"
)
self
.
save
()
t
=
self
.
template
t
.
state
=
'SAVING'
t
.
save
()
def
check_if_is_save_as_done
(
self
):
if
self
.
state
!=
'DONE'
:
return
False
Disk
.
update
(
delete
=
False
)
imgname
=
"template-
%
d-
%
d"
%
(
self
.
template
.
id
,
self
.
id
)
disks
=
Disk
.
objects
.
filter
(
name
=
imgname
)
if
len
(
disks
)
!=
1
:
return
False
self
.
template
.
disk_id
=
disks
[
0
]
.
id
self
.
template
.
state
=
'READY'
self
.
template
.
save
()
self
.
firewall_host_delete
()
return
True
@receiver
(
pre_delete
,
sender
=
Instance
,
dispatch_uid
=
'delete_instance_pre'
)
def
delete_instance_pre
(
sender
,
instance
,
using
,
**
kwargs
):
...
...
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