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
64f0baeb
authored
Dec 03, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: move some code around
parent
0d322301
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
116 additions
and
100 deletions
+116
-100
circle/vm/models/__init__.py
+7
-5
circle/vm/models/activity.py
+2
-2
circle/vm/models/common.py
+96
-0
circle/vm/models/instance.py
+7
-41
circle/vm/models/network.py
+1
-1
circle/vm/models/node.py
+3
-51
No files found.
circle/vm/models/__init__.py
View file @
64f0baeb
# flake8: noqa
from
.activity
import
NodeActivity
from
.activity
import
InstanceActivity
from
.activity
import
instance_activity
from
.activity
import
NodeActivity
from
.activity
import
node_activity
from
.common
import
BaseResourceConfigModel
from
.common
import
Lease
from
.common
import
NamedBaseResourceConfig
from
.common
import
Trait
from
.instance
import
InstanceActiveManager
from
.instance
import
BaseResourceConfigModel
from
.instance
import
NamedBaseResourceConfig
from
.instance
import
VirtualMachineDescModel
from
.instance
import
InstanceTemplate
from
.instance
import
Instance
...
...
@@ -12,13 +15,12 @@ from .instance import post_state_changed
from
.instance
import
pre_state_changed
from
.network
import
InterfaceTemplate
from
.network
import
Interface
from
.node
import
Trait
from
.node
import
Node
from
.node
import
Lease
__all__
=
[
'InstanceActivity'
,
'InstanceActiveManager'
,
'BaseResourceConfigModel'
,
'NamedBaseResourceConfig'
,
'VirtualMachineDescModel'
,
'InstanceTemplate'
,
'Instance'
,
'instance_activity'
,
'post_state_changed'
,
'pre_state_changed'
,
'InterfaceTemplate'
,
'Interface'
,
'Trait'
,
'Node'
,
'NodeActivity'
,
'Lease'
,
'node_activity'
,
]
circle/vm/models/activity.py
View file @
64f0baeb
from
__future__
import
unicode_literals
from
__future__
import
absolute_import
,
unicode_literals
from
contextlib
import
contextmanager
from
logging
import
getLogger
...
...
@@ -16,9 +16,9 @@ class InstanceActivity(ActivityModel):
verbose_name
=
_
(
'instance'
))
class
Meta
:
ordering
=
[
'-started'
,
'instance'
,
'-id'
]
app_label
=
'vm'
db_table
=
'vm_instanceactivity'
ordering
=
[
'-started'
,
'instance'
,
'-id'
]
def
__unicode__
(
self
):
if
self
.
parent
:
...
...
circle/vm/models/common.py
0 → 100644
View file @
64f0baeb
from
__future__
import
absolute_import
,
unicode_literals
from
datetime
import
timedelta
from
django.db.models
import
Model
,
CharField
,
IntegerField
from
django.utils.translation
import
ugettext_lazy
as
_
from
model_utils.models
import
TimeStampedModel
ARCHITECTURES
=
((
'x86_64'
,
'x86-64 (64 bit)'
),
(
'i686'
,
'x86 (32 bit)'
))
class
BaseResourceConfigModel
(
Model
):
"""Abstract base for models with base resource configuration parameters.
"""
num_cores
=
IntegerField
(
verbose_name
=
_
(
'number of cores'
),
help_text
=
_
(
'Number of virtual CPU cores '
'available to the virtual machine.'
))
ram_size
=
IntegerField
(
verbose_name
=
_
(
'RAM size'
),
help_text
=
_
(
'Mebibytes of memory.'
))
max_ram_size
=
IntegerField
(
verbose_name
=
_
(
'maximal RAM size'
),
help_text
=
_
(
'Upper memory size limit '
'for balloning.'
))
arch
=
CharField
(
max_length
=
10
,
verbose_name
=
_
(
'architecture'
),
choices
=
ARCHITECTURES
)
priority
=
IntegerField
(
verbose_name
=
_
(
'priority'
),
help_text
=
_
(
'CPU priority.'
))
class
Meta
:
abstract
=
True
class
NamedBaseResourceConfig
(
BaseResourceConfigModel
,
TimeStampedModel
):
"""Pre-created, named base resource configurations.
"""
name
=
CharField
(
max_length
=
50
,
unique
=
True
,
verbose_name
=
_
(
'name'
),
help_text
=
_
(
'Name of base resource configuration.'
))
class
Meta
:
app_label
=
'vm'
db_table
=
'vm_namedbaseresourceconfig'
def
__unicode__
(
self
):
return
self
.
name
class
Lease
(
Model
):
"""Lease times for VM instances.
Specifies a time duration until suspension and deletion of a VM
instance.
"""
name
=
CharField
(
max_length
=
100
,
unique
=
True
,
verbose_name
=
_
(
'name'
))
suspend_interval_seconds
=
IntegerField
(
verbose_name
=
_
(
'suspend interval'
))
delete_interval_seconds
=
IntegerField
(
verbose_name
=
_
(
'delete interval'
))
class
Meta
:
app_label
=
'vm'
db_table
=
'vm_lease'
ordering
=
[
'name'
,
]
@property
def
suspend_interval
(
self
):
return
timedelta
(
seconds
=
self
.
suspend_interval_seconds
)
@suspend_interval.setter
def
suspend_interval
(
self
,
value
):
self
.
suspend_interval_seconds
=
value
.
seconds
@property
def
delete_interval
(
self
):
return
timedelta
(
seconds
=
self
.
delete_interval_seconds
)
@delete_interval.setter
def
delete_interval
(
self
,
value
):
self
.
delete_interval_seconds
=
value
.
seconds
def
__unicode__
(
self
):
return
self
.
name
class
Trait
(
Model
):
name
=
CharField
(
max_length
=
50
,
verbose_name
=
_
(
'name'
))
class
Meta
:
app_label
=
'vm'
db_table
=
'vm_trait'
def
__unicode__
(
self
):
return
self
.
name
circle/vm/models/instance.py
View file @
64f0baeb
from
__future__
import
unicode_literals
from
__future__
import
absolute_import
,
unicode_literals
from
datetime
import
timedelta
from
logging
import
getLogger
from
importlib
import
import_module
import
django.conf
from
django.db.models
import
(
Model
,
ForeignKey
,
ManyToMany
Field
,
IntegerField
,
DateTimeField
,
BooleanField
,
TextField
,
CharField
,
permalink
,
Manager
)
from
django.db.models
import
(
BooleanField
,
CharField
,
DateTime
Field
,
IntegerField
,
ForeignKey
,
Manager
,
ManyToManyField
,
permalink
,
TextField
)
from
django.contrib.auth.models
import
User
from
django.core
import
signing
from
django.dispatch
import
Signal
...
...
@@ -19,9 +19,10 @@ from taggit.managers import TaggableManager
from
acl.models
import
AclBase
from
storage.models
import
Disk
from
..tasks
import
local_tasks
,
vm_tasks
from
.node
import
Node
,
Trait
from
.network
import
Interface
from
.activity
import
instance_activity
from
.common
import
BaseResourceConfigModel
from
.network
import
Interface
from
.node
import
Node
,
Trait
logger
=
getLogger
(
__name__
)
pre_state_changed
=
Signal
(
providing_args
=
[
"new_state"
])
...
...
@@ -29,8 +30,6 @@ post_state_changed = Signal(providing_args=["new_state"])
pwgen
=
User
.
objects
.
make_random_password
scheduler
=
import_module
(
name
=
django
.
conf
.
settings
.
VM_SCHEDULER
)
ARCHITECTURES
=
((
'x86_64'
,
'x86-64 (64 bit)'
),
(
'i686'
,
'x86 (32 bit)'
))
ACCESS_PROTOCOLS
=
django
.
conf
.
settings
.
VM_ACCESS_PROTOCOLS
ACCESS_METHODS
=
[(
key
,
name
)
for
key
,
(
name
,
port
,
transport
)
in
ACCESS_PROTOCOLS
.
iteritems
()]
...
...
@@ -53,39 +52,6 @@ class InstanceActiveManager(Manager):
self
)
.
get_query_set
()
.
filter
(
destroyed
=
None
)
class
BaseResourceConfigModel
(
Model
):
"""Abstract base for models with base resource configuration parameters.
"""
num_cores
=
IntegerField
(
verbose_name
=
_
(
'number of cores'
),
help_text
=
_
(
'Number of virtual CPU cores '
'available to the virtual machine.'
))
ram_size
=
IntegerField
(
verbose_name
=
_
(
'RAM size'
),
help_text
=
_
(
'Mebibytes of memory.'
))
max_ram_size
=
IntegerField
(
verbose_name
=
_
(
'maximal RAM size'
),
help_text
=
_
(
'Upper memory size limit '
'for balloning.'
))
arch
=
CharField
(
max_length
=
10
,
verbose_name
=
_
(
'architecture'
),
choices
=
ARCHITECTURES
)
priority
=
IntegerField
(
verbose_name
=
_
(
'priority'
),
help_text
=
_
(
'CPU priority.'
))
class
Meta
:
abstract
=
True
class
NamedBaseResourceConfig
(
BaseResourceConfigModel
,
TimeStampedModel
):
"""Pre-created, named base resource configurations.
"""
name
=
CharField
(
max_length
=
50
,
unique
=
True
,
verbose_name
=
_
(
'name'
),
help_text
=
_
(
'Name of base resource configuration.'
))
def
__unicode__
(
self
):
return
self
.
name
class
VirtualMachineDescModel
(
BaseResourceConfigModel
):
"""Abstract base for virtual machine describing models.
...
...
circle/vm/models/network.py
View file @
64f0baeb
from
__future__
import
unicode_literals
from
__future__
import
absolute_import
,
unicode_literals
from
logging
import
getLogger
from
netaddr
import
EUI
,
mac_unix
...
...
circle/vm/models/node.py
View file @
64f0baeb
from
__future__
import
unicode_literals
from
datetime
import
timedelta
from
__future__
import
absolute_import
,
unicode_literals
from
logging
import
getLogger
from
django.db.models
import
(
Model
,
CharField
,
IntegerField
,
ForeignKey
,
BooleanField
,
ManyToManyField
,
CharField
,
IntegerField
,
ForeignKey
,
BooleanField
,
ManyToManyField
,
FloatField
,
)
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -15,21 +14,11 @@ from taggit.managers import TaggableManager
from
common.models
import
method_cache
from
firewall.models
import
Host
from
..tasks
import
vm_tasks
from
.common
import
Trait
logger
=
getLogger
(
__name__
)
class
Trait
(
Model
):
name
=
CharField
(
max_length
=
50
,
verbose_name
=
_
(
'name'
))
class
Meta
:
app_label
=
'vm'
db_table
=
'vm_trait'
def
__unicode__
(
self
):
return
self
.
name
class
Node
(
TimeStampedModel
):
"""A VM host machine, a hypervisor.
...
...
@@ -135,40 +124,3 @@ class Node(TimeStampedModel):
for
i
in
domains
.
keys
():
logger
.
info
(
'Node
%
s update: domain
%
s in libvirt but not in db.'
,
self
,
i
)
class
Lease
(
Model
):
"""Lease times for VM instances.
Specifies a time duration until suspension and deletion of a VM
instance.
"""
name
=
CharField
(
max_length
=
100
,
unique
=
True
,
verbose_name
=
_
(
'name'
))
suspend_interval_seconds
=
IntegerField
(
verbose_name
=
_
(
'suspend interval'
))
delete_interval_seconds
=
IntegerField
(
verbose_name
=
_
(
'delete interval'
))
class
Meta
:
app_label
=
'vm'
db_table
=
'vm_lease'
ordering
=
[
'name'
,
]
@property
def
suspend_interval
(
self
):
return
timedelta
(
seconds
=
self
.
suspend_interval_seconds
)
@suspend_interval.setter
def
suspend_interval
(
self
,
value
):
self
.
suspend_interval_seconds
=
value
.
seconds
@property
def
delete_interval
(
self
):
return
timedelta
(
seconds
=
self
.
delete_interval_seconds
)
@delete_interval.setter
def
delete_interval
(
self
,
value
):
self
.
delete_interval_seconds
=
value
.
seconds
def
__unicode__
(
self
):
return
self
.
name
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