Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
0c3be3e9
authored
Mar 14, 2014
by
Guba Sándor
Committed by
Őry Máté
Mar 15, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
node: add decorator to check no availablity
parent
01eb957e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
circle/vm/models/node.py
+19
-0
No files found.
circle/vm/models/node.py
View file @
0c3be3e9
...
@@ -25,6 +25,17 @@ from django.utils import timezone
...
@@ -25,6 +25,17 @@ from django.utils import timezone
logger
=
getLogger
(
__name__
)
logger
=
getLogger
(
__name__
)
def
node_available
(
function
):
"""Decorate methods to ignore disabled Nodes.
"""
def
decorate
(
self
,
*
args
,
**
kwargs
):
if
self
.
enabled
is
True
and
self
.
online
is
True
:
return
function
(
self
,
*
args
,
**
kwargs
)
else
:
return
None
return
decorate
class
Node
(
TimeStampedModel
):
class
Node
(
TimeStampedModel
):
"""A VM host machine, a hypervisor.
"""A VM host machine, a hypervisor.
...
@@ -68,6 +79,7 @@ class Node(TimeStampedModel):
...
@@ -68,6 +79,7 @@ class Node(TimeStampedModel):
online
=
property
(
get_online
)
online
=
property
(
get_online
)
@node_available
@method_cache
(
300
)
@method_cache
(
300
)
def
get_num_cores
(
self
):
def
get_num_cores
(
self
):
"""Number of CPU threads available to the virtual machines.
"""Number of CPU threads available to the virtual machines.
...
@@ -106,6 +118,7 @@ class Node(TimeStampedModel):
...
@@ -106,6 +118,7 @@ class Node(TimeStampedModel):
self
.
get_num_cores
(
invalidate_cache
=
True
)
self
.
get_num_cores
(
invalidate_cache
=
True
)
self
.
get_ram_size
(
invalidate_cache
=
True
)
self
.
get_ram_size
(
invalidate_cache
=
True
)
@node_available
@method_cache
(
300
)
@method_cache
(
300
)
def
get_ram_size
(
self
):
def
get_ram_size
(
self
):
"""Bytes of total memory in the node.
"""Bytes of total memory in the node.
...
@@ -115,6 +128,7 @@ class Node(TimeStampedModel):
...
@@ -115,6 +128,7 @@ class Node(TimeStampedModel):
ram_size
=
property
(
get_ram_size
)
ram_size
=
property
(
get_ram_size
)
@property
@property
@node_available
def
ram_size_with_overcommit
(
self
):
def
ram_size_with_overcommit
(
self
):
"""Bytes of total memory including overcommit margin.
"""Bytes of total memory including overcommit margin.
"""
"""
...
@@ -198,6 +212,7 @@ class Node(TimeStampedModel):
...
@@ -198,6 +212,7 @@ class Node(TimeStampedModel):
else
:
else
:
return
default
return
default
@node_available
def
get_monitor_info
(
self
):
def
get_monitor_info
(
self
):
try
:
try
:
handler
=
GraphiteHandler
()
handler
=
GraphiteHandler
()
...
@@ -229,17 +244,21 @@ class Node(TimeStampedModel):
...
@@ -229,17 +244,21 @@ class Node(TimeStampedModel):
return
collected
return
collected
@property
@property
@node_available
def
cpu_usage
(
self
):
def
cpu_usage
(
self
):
return
float
(
self
.
get_monitor_info
()[
"cpu.usage"
])
/
100
return
float
(
self
.
get_monitor_info
()[
"cpu.usage"
])
/
100
@property
@property
@node_available
def
ram_usage
(
self
):
def
ram_usage
(
self
):
return
float
(
self
.
get_monitor_info
()[
"memory.usage"
])
/
100
return
float
(
self
.
get_monitor_info
()[
"memory.usage"
])
/
100
@property
@property
@node_available
def
byte_ram_usage
(
self
):
def
byte_ram_usage
(
self
):
return
self
.
ram_usage
*
self
.
ram_size
return
self
.
ram_usage
*
self
.
ram_size
@node_available
def
update_vm_states
(
self
):
def
update_vm_states
(
self
):
"""Update state of Instances running on this Node.
"""Update state of Instances running on this Node.
...
...
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