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
fbec88c7
authored
Sep 18, 2013
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding Instance functions
parent
d039ad8a
Hide 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):
...
@@ -432,15 +432,17 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
def
deploy_async
(
self
,
user
=
None
):
def
deploy_async
(
self
,
user
=
None
):
""" Launch celery task to handle the job asynchronously.
""" 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
):
def
deploy
(
self
,
user
=
None
,
task_uuid
=
None
):
""" Deploy new virtual machine with network
""" Deploy new virtual machine with network
1. Schedule
1. Schedule
"""
"""
act
=
InstanceActivity
(
activity_code
=
'vm.Instance.deploy'
,
act
=
InstanceActivity
(
activity_code
=
'vm.Instance.deploy'
)
instance
=
self
,
user
=
user
,
act
.
instance
=
self
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
)
act
.
user
=
user
act
.
started
=
timezone
.
now
()
act
.
task_uuid
=
task_uuid
act
.
save
()
act
.
save
()
# Schedule
# Schedule
...
@@ -470,21 +472,74 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -470,21 +472,74 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
act
.
finish
(
result
=
'SUCCESS'
)
act
.
finish
(
result
=
'SUCCESS'
)
def
stop
(
self
):
def
stop_async
(
self
,
user
=
None
):
# TODO implement
vm_manager
.
stop
.
apply_async
(
args
=
[
self
,
user
],
queue
=
"localhost.man"
)
pass
def
resume
(
self
):
def
stop
(
self
,
user
=
None
,
task_uuid
=
None
):
# TODO implement
act
=
InstanceActivity
(
activity_code
=
'vm.Instance.stop'
)
pass
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
resume_async
(
self
,
user
=
None
):
vm_manager
.
resume
.
apply_async
(
args
=
[
self
,
user
],
queue
=
"localhost.man"
)
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
(
self
):
def
poweroff
_async
(
self
,
user
=
None
):
# TODO implement
vm_manager
.
power_off
.
apply_async
(
args
=
[
self
,
user
],
pass
queue
=
"localhost.man"
)
def
restart
(
self
):
def
poweroff
(
self
,
user
=
None
,
task_uuid
=
None
):
# TODO implement
act
=
InstanceActivity
(
activity_code
=
'vm.Instance.power_off'
)
pass
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'
):
def
renew
(
self
,
which
=
'both'
):
"""Renew virtual machine instance leases.
"""Renew virtual machine instance leases.
...
@@ -497,31 +552,6 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -497,31 +552,6 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
self
.
time_of_delete
=
timezone
.
now
()
+
self
.
lease
.
delete_interval
self
.
time_of_delete
=
timezone
.
now
()
+
self
.
lease
.
delete_interval
self
.
save
()
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'
)
@receiver
(
pre_delete
,
sender
=
Instance
,
dispatch_uid
=
'delete_instance_pre'
)
def
delete_instance_pre
(
sender
,
instance
,
using
,
**
kwargs
):
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