Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
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
41f26955
authored
Mar 14, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: add StatusModel to Instance
parent
ab7f53b9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
17 deletions
+42
-17
circle/dashboard/templates/dashboard/node-detail.html
+1
-1
circle/dashboard/templates/dashboard/vm-list.html
+1
-1
circle/dashboard/views.py
+5
-6
circle/vm/migrations/0020_add_StatusModel_to_instance.py
+0
-0
circle/vm/models/activity.py
+5
-0
circle/vm/models/instance.py
+30
-9
No files found.
circle/dashboard/templates/dashboard/node-detail.html
View file @
41f26955
...
...
@@ -24,7 +24,7 @@
{% elif node.state == 'MISSING' %}label-danger
{% elif node.state == 'DISABLED' %}label-warning
{% elif node.state == 'OFFLINE' %}label-warning
{% endif %}"
>
{{ node.
state
}}
</span>
{% endif %}"
>
{{ node.
get_status_display|upper
}}
</span>
<div
class=
"btn-group"
>
<button
type=
"button"
class=
"btn {{ btn_size }} btn-warning nojs-dropdown-toogle dropdown-toggle"
data-toggle=
"dropdown"
>
Action
<i
class=
"icon-caret-down"
></i></button>
<ul
class=
"dropdown-menu nojs-dropdown-toogle"
role=
"menu"
>
...
...
circle/dashboard/templates/dashboard/vm-list.html
View file @
41f26955
...
...
@@ -39,7 +39,7 @@
<tr
class=
"{% cycle 'odd' 'even' %}"
>
<td
class=
"pk"
><div
id=
"vm-{{i.pk}}"
>
{{i.pk}}
</div>
</td>
<td
class=
"name"
><a
class=
"real-link"
href=
"{% url "
dashboard
.
views
.
detail
"
i
.
pk
%}"
>
{{ i.name }}
</a>
</td>
<td
class=
"state"
>
{{ i.
cached_state
}}
</td>
<td
class=
"state"
>
{{ i.
get_status_display
}}
</td>
<td>
{{ i.owner }}
</td>
{% if user.is_superuser %}
<td>
{{ i.node.name|default:"-" }}
</td>
{% endif %}
</tr>
...
...
circle/dashboard/views.py
View file @
41f26955
...
...
@@ -117,14 +117,13 @@ class IndexView(LoginRequiredMixin, TemplateView):
}
})
running
=
[
i
for
i
in
instances
if
i
.
cached_state
==
'RUNNING'
]
stopped
=
[
i
for
i
in
instances
if
i
.
cached_state
not
in
[
'RUNNING'
,
'NOSTATE'
]]
running
=
instances
.
filter
(
status
=
'RUNNING'
)
stopped
=
instances
.
exclude
(
status__in
=
(
'RUNNING'
,
'NOSTATE'
))
context
.
update
({
'running_vms'
:
running
,
'running_vm_num'
:
len
(
running
),
'stopped_vm_num'
:
len
(
stopped
)
'running_vms'
:
running
[:
20
]
,
'running_vm_num'
:
running
.
count
(
),
'stopped_vm_num'
:
stopped
.
count
(
)
})
context
[
'templates'
]
=
InstanceTemplate
.
objects
.
all
()[:
5
]
...
...
circle/vm/migrations/0020_add_StatusModel_to_instance.py
0 → 100644
View file @
41f26955
This diff is collapsed.
Click to expand it.
circle/vm/models/activity.py
View file @
41f26955
...
...
@@ -79,6 +79,11 @@ class InstanceActivity(ActivityModel):
act
=
self
.
create_sub
(
code_suffix
,
task_uuid
)
return
activitycontextimpl
(
act
,
on_abort
=
on_abort
,
on_commit
=
on_commit
)
def
save
(
self
,
*
args
,
**
kwargs
):
ret
=
super
(
InstanceActivity
,
self
)
.
save
(
*
args
,
**
kwargs
)
self
.
instance
.
_update_status
()
return
ret
@contextmanager
def
instance_activity
(
code_suffix
,
instance
,
on_abort
=
None
,
on_commit
=
None
,
...
...
circle/vm/models/instance.py
View file @
41f26955
...
...
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
from
datetime
import
timedelta
from
logging
import
getLogger
from
importlib
import
import_module
from
warnings
import
warn
import
string
import
django.conf
...
...
@@ -16,7 +17,8 @@ from django.utils import timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
celery.exceptions
import
TimeLimitExceeded
from
model_utils.models
import
TimeStampedModel
from
model_utils
import
Choices
from
model_utils.models
import
TimeStampedModel
,
StatusModel
from
taggit.managers
import
TaggableManager
from
acl.models
import
AclBase
...
...
@@ -25,7 +27,6 @@ from ..tasks import local_tasks, vm_tasks, agent_tasks
from
.activity
import
(
ActivityInProgressError
,
instance_activity
,
InstanceActivity
)
from
.common
import
BaseResourceConfigModel
,
Lease
from
common.models
import
method_cache
from
.network
import
Interface
from
.node
import
Node
,
Trait
...
...
@@ -162,7 +163,8 @@ class InstanceTemplate(AclBase, VirtualMachineDescModel, TimeStampedModel):
return
(
'dashboard.views.template-detail'
,
None
,
{
'pk'
:
self
.
pk
})
class
Instance
(
AclBase
,
VirtualMachineDescModel
,
TimeStampedModel
):
class
Instance
(
AclBase
,
VirtualMachineDescModel
,
StatusModel
,
TimeStampedModel
):
"""Virtual machine instance.
"""
...
...
@@ -171,6 +173,15 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
(
'operator'
,
_
(
'operator'
)),
# console, networking, change state
(
'owner'
,
_
(
'owner'
)),
# superuser, can delete, delegate perms
)
STATUS
=
Choices
(
(
'NOSTATE'
,
_
(
'no state'
)),
(
'RUNNING'
,
_
(
'running'
)),
(
'STOPPED'
,
_
(
'stopped'
)),
(
'SUSPENDED'
,
_
(
'suspended'
)),
(
'ERROR'
,
_
(
'error'
)),
(
'PENDING'
,
_
(
'pending'
)),
(
'DESTROYED'
,
_
(
'destroyed'
)),
)
name
=
CharField
(
blank
=
True
,
max_length
=
100
,
verbose_name
=
_
(
'name'
),
help_text
=
_
(
"Human readable name of instance."
))
description
=
TextField
(
blank
=
True
,
verbose_name
=
_
(
'description'
))
...
...
@@ -258,13 +269,23 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
return
self
.
state
==
'RUNNING'
@property
@method_cache
(
10
,
5
)
def
cached_state
(
self
):
return
self
.
state
@property
def
state
(
self
):
"""State of the virtual machine instance.
warn
(
'Use Instance.status (or get_status_display) instead.'
,
DeprecationWarning
)
return
self
.
status
def
_update_status
(
self
):
"""Set the proper status of the instance to Instance.status.
"""
old
=
self
.
status
self
.
status
=
self
.
_compute_status
()
if
old
!=
self
.
status
:
logger
.
info
(
'Status of Instance#
%
d changed to
%
s'
,
self
.
pk
,
self
.
status
)
self
.
save
()
def
_compute_status
(
self
):
"""Return the proper status of the instance based on activities.
"""
# check special cases
if
self
.
activity_log
.
filter
(
activity_code__endswith
=
'migrate'
,
...
...
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