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
89d48699
authored
Jul 30, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'readable-name-review-rebased'
Conflicts: circle/storage/models.py
parents
3b92a4c0
a2294a09
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
26 deletions
+77
-26
circle/vm/models/instance.py
+6
-3
circle/vm/operations.py
+47
-12
circle/vm/tasks/local_agent_tasks.py
+24
-11
No files found.
circle/vm/models/instance.py
View file @
89d48699
...
...
@@ -439,9 +439,12 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
def
vm_state_changed
(
self
,
new_state
):
# log state change
try
:
act
=
InstanceActivity
.
create
(
code_suffix
=
'vm_state_changed'
,
instance
=
self
,
readable_name
=
"vm state changed"
)
act
=
InstanceActivity
.
create
(
code_suffix
=
'vm_state_changed'
,
readable_name
=
create_readable
(
ugettext_noop
(
"vm state changed to
%(state)
s"
),
state
=
new_state
),
instance
=
self
)
except
ActivityInProgressError
:
pass
# discard state change if another activity is in progress.
else
:
...
...
circle/vm/operations.py
View file @
89d48699
...
...
@@ -24,6 +24,8 @@ from django.core.exceptions import PermissionDenied
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
from
sizefield.utils
import
filesizeformat
from
celery.exceptions
import
TimeLimitExceeded
from
common.models
import
create_readable
,
humanize_exception
...
...
@@ -133,7 +135,9 @@ class AddInterfaceOperation(InstanceOperation):
if
self
.
instance
.
is_running
:
try
:
with
activity
.
sub_activity
(
'attach_network'
):
with
activity
.
sub_activity
(
'attach_network'
,
readable_name
=
ugettext_noop
(
"attach network"
)):
self
.
instance
.
attach_network
(
net
)
except
Exception
as
e
:
if
hasattr
(
e
,
'libvirtError'
):
...
...
@@ -173,14 +177,21 @@ class CreateDiskOperation(InstanceOperation):
self
.
instance
.
disks
.
add
(
disk
)
if
self
.
instance
.
is_running
:
with
activity
.
sub_activity
(
'deploying_disk'
):
with
activity
.
sub_activity
(
'deploying_disk'
,
readable_name
=
ugettext_noop
(
"deploying disk"
)
):
disk
.
deploy
()
with
activity
.
sub_activity
(
'attach_disk'
):
with
activity
.
sub_activity
(
'attach_disk'
,
readable_name
=
ugettext_noop
(
"attach disk"
)
):
self
.
instance
.
attach_disk
(
disk
)
def
get_activity_name
(
self
,
kwargs
):
return
create_readable
(
ugettext_noop
(
"create
%(size)
s disk"
),
size
=
kwargs
[
'size'
])
return
create_readable
(
ugettext_noop
(
"create disk
%(name)
s (
%(size)
s)"
),
size
=
filesizeformat
(
kwargs
[
'size'
]),
name
=
kwargs
[
'name'
])
register_operation
(
CreateDiskOperation
)
...
...
@@ -213,7 +224,10 @@ class DownloadDiskOperation(InstanceOperation):
# TODO iso (cd) hot-plug is not supported by kvm/guests
if
self
.
instance
.
is_running
and
disk
.
type
not
in
[
"iso"
]:
with
activity
.
sub_activity
(
'attach_disk'
):
with
activity
.
sub_activity
(
'attach_disk'
,
readable_name
=
ugettext_noop
(
"attach disk"
)
):
self
.
instance
.
attach_disk
(
disk
)
register_operation
(
DownloadDiskOperation
)
...
...
@@ -402,13 +416,20 @@ class RemoveInterfaceOperation(InstanceOperation):
def
_operation
(
self
,
activity
,
user
,
system
,
interface
):
if
self
.
instance
.
is_running
:
with
activity
.
sub_activity
(
'detach_network'
):
with
activity
.
sub_activity
(
'detach_network'
,
readable_name
=
ugettext_noop
(
"detach network"
)
):
self
.
instance
.
detach_network
(
interface
)
interface
.
shutdown
()
interface
.
destroy
()
interface
.
delete
()
def
get_activity_name
(
self
,
kwargs
):
return
create_readable
(
ugettext_noop
(
"remove
%(vlan)
s interface"
),
vlan
=
kwargs
[
'interface'
]
.
vlan
)
register_operation
(
RemoveInterfaceOperation
)
...
...
@@ -423,10 +444,20 @@ class RemoveDiskOperation(InstanceOperation):
def
_operation
(
self
,
activity
,
user
,
system
,
disk
):
if
self
.
instance
.
is_running
and
disk
.
type
not
in
[
"iso"
]:
with
activity
.
sub_activity
(
'detach_disk'
):
with
activity
.
sub_activity
(
'detach_disk'
,
readable_name
=
ugettext_noop
(
'detach disk'
)
):
self
.
instance
.
detach_disk
(
disk
)
return
self
.
instance
.
disks
.
remove
(
disk
)
with
activity
.
sub_activity
(
'destroy_disk'
,
readable_name
=
ugettext_noop
(
'destroy disk'
)
):
return
self
.
instance
.
disks
.
remove
(
disk
)
def
get_activity_name
(
self
,
kwargs
):
return
create_readable
(
ugettext_noop
(
'remove disk
%(name)
s'
),
name
=
kwargs
[
"disk"
]
.
name
)
register_operation
(
RemoveDiskOperation
)
...
...
@@ -515,9 +546,13 @@ class SaveAsTemplateOperation(InstanceOperation):
return
disk
self
.
disks
=
[]
with
activity
.
sub_activity
(
'saving_disks'
,
readable_name
=
ugettext_noop
(
"save disks"
)):
for
disk
in
self
.
instance
.
disks
.
all
():
for
disk
in
self
.
instance
.
disks
.
all
():
with
activity
.
sub_activity
(
'saving_disk'
,
readable_name
=
create_readable
(
ugettext_noop
(
"saving disk
%(name)
s"
),
name
=
disk
.
name
)
):
self
.
disks
.
append
(
__try_save_disk
(
disk
))
# create template and do additional setup
...
...
circle/vm/tasks/local_agent_tasks.py
View file @
89d48699
...
...
@@ -25,22 +25,25 @@ from StringIO import StringIO
from
tarfile
import
TarFile
,
TarInfo
from
django.conf
import
settings
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_noop
from
celery.result
import
TimeoutError
from
monitor.client
import
Client
def
send_init_commands
(
instance
,
act
,
vm
):
queue
=
instance
.
get_remote_queue_name
(
"agent"
)
with
act
.
sub_activity
(
'cleanup'
):
with
act
.
sub_activity
(
'cleanup'
,
readable_name
=
ugettext_noop
(
'cleanup'
)):
cleanup
.
apply_async
(
queue
=
queue
,
args
=
(
vm
,
))
with
act
.
sub_activity
(
'restart_networking'
):
with
act
.
sub_activity
(
'restart_networking'
,
readable_name
=
ugettext_noop
(
'restart networking'
)):
restart_networking
.
apply_async
(
queue
=
queue
,
args
=
(
vm
,
))
with
act
.
sub_activity
(
'change_password'
):
with
act
.
sub_activity
(
'change_password'
,
readable_name
=
ugettext_noop
(
'change password'
)):
change_password
.
apply_async
(
queue
=
queue
,
args
=
(
vm
,
instance
.
pw
))
with
act
.
sub_activity
(
'set_time'
):
with
act
.
sub_activity
(
'set_time'
,
readable_name
=
ugettext_noop
(
'set time'
)
):
set_time
.
apply_async
(
queue
=
queue
,
args
=
(
vm
,
time
.
time
()))
with
act
.
sub_activity
(
'set_hostname'
):
with
act
.
sub_activity
(
'set_hostname'
,
readable_name
=
ugettext_noop
(
'set hostname'
)):
set_hostname
.
apply_async
(
queue
=
queue
,
args
=
(
vm
,
instance
.
primary_host
.
hostname
))
...
...
@@ -73,13 +76,20 @@ def agent_started(vm, version=None):
initialized
=
InstanceActivity
.
objects
.
filter
(
instance
=
instance
,
activity_code
=
'vm.Instance.agent.cleanup'
)
.
exists
()
with
instance_activity
(
code_suffix
=
'agent'
,
instance
=
instance
)
as
act
:
with
act
.
sub_activity
(
'starting'
):
with
instance_activity
(
code_suffix
=
'agent'
,
readable_name
=
ugettext_noop
(
'agent'
),
instance
=
instance
)
as
act
:
with
act
.
sub_activity
(
'starting'
,
readable_name
=
ugettext_noop
(
'starting'
)):
pass
if
version
and
version
!=
settings
.
AGENT_VERSION
:
try
:
with
act
.
sub_activity
(
'update'
):
with
act
.
sub_activity
(
'update'
,
readable_name
=
ugettext_noop
(
'update to
%(version)
s'
),
version
=
settings
.
AGENT_VERSION
):
update
.
apply_async
(
queue
=
queue
,
args
=
(
vm
,
create_agent_tar
()))
.
get
(
timeout
=
10
)
...
...
@@ -91,7 +101,10 @@ def agent_started(vm, version=None):
measure_boot_time
(
instance
)
send_init_commands
(
instance
,
act
,
vm
)
with
act
.
sub_activity
(
'start_access_server'
):
with
act
.
sub_activity
(
'start_access_server'
,
readable_name
=
ugettext_noop
(
'start access server'
)
):
start_access_server
.
apply_async
(
queue
=
queue
,
args
=
(
vm
,
))
...
...
@@ -122,5 +135,5 @@ def agent_stopped(vm):
qs
=
InstanceActivity
.
objects
.
filter
(
instance
=
instance
,
activity_code
=
'vm.Instance.agent'
)
act
=
qs
.
latest
(
'id'
)
with
act
.
sub_activity
(
'stopping'
):
with
act
.
sub_activity
(
'stopping'
,
readable_name
=
ugettext_noop
(
'stopping'
)
):
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