Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
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
1450d8ee
authored
Nov 22, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
manager: basic scheduler w/ mock monitor data
parent
4ddd2e68
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
6 deletions
+63
-6
circle/manager/scheduler.py
+63
-6
No files found.
circle/manager/scheduler.py
View file @
1450d8ee
from
django.db.models
import
Sum
class
NotEnoughMemoryException
(
Exception
):
def
__init__
(
self
,
message
=
None
):
if
message
is
None
:
message
=
"No node has enough memory to accomodate the guest."
Exception
.
__init__
(
self
,
message
)
class
TraitsUnsatisfiableException
(
Exception
):
def
__init__
(
self
,
message
=
None
):
if
message
is
None
:
message
=
"No node can satisfy all required traits of the guest."
Exception
.
__init__
(
self
,
message
)
def
get_node
(
instance
,
nodes
):
def
get_node
(
instance
,
nodes
):
''' Select a node for hosting an instance based on its requirements.
''' Select a node for hosting an instance based on its requirements.
'''
'''
# Return first Node or None
# check required traits
try
:
nodes
=
[
n
for
n
in
nodes
if
has_traits
(
instance
.
req_traits
.
all
(),
n
)]
req_traits
=
set
(
instance
.
req_traits
.
all
())
if
not
nodes
:
nodes
=
[
n
for
n
in
nodes
if
req_traits
.
issubset
(
n
.
traits
.
all
())]
raise
TraitsUnsatisfiableException
()
# check required RAM
nodes
=
[
n
for
n
in
nodes
if
has_enough_ram
(
instance
.
ram_size
,
n
)]
if
not
nodes
:
raise
NotEnoughMemoryException
()
# sort nodes first by processor usage, then priority
nodes
.
sort
(
key
=
lambda
n
:
n
.
priority
,
reverse
=
True
)
nodes
.
sort
(
key
=
processor_usage
)
return
nodes
[
0
]
return
nodes
[
0
]
except
:
return
None
def
has_traits
(
traits
,
node
):
"""True, if the node has all specified traits; otherwise, false.
"""
traits
=
set
(
traits
)
return
traits
.
issubset
(
node
.
traits
.
all
())
def
has_enough_ram
(
ram_size
,
node
):
"""True, if the node has enough memory to accomodate a guest requiring
ram_size mebibytes of memory; otherwise, false.
"""
total
=
node
.
ram_size
used
=
512
# TODO replace mock value with data from monitor
unused
=
total
-
used
overcommit
=
node
.
ram_size_with_overcommit
reserved
=
node
.
instance_set
.
aggregate
(
r
=
Sum
(
'ram_size'
))[
'r'
]
or
0
free
=
overcommit
-
reserved
return
ram_size
<
unused
and
ram_size
<
free
def
processor_usage
(
node
):
"""Get a number indicating processor usage on the node.
Lower values indicate lower usage.
"""
return
0
# TODO replace mock value with data from monitor
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