Commit 64f0baeb by Dudás Ádám

vm: move some code around

parent 0d322301
# flake8: noqa # flake8: noqa
from .activity import NodeActivity
from .activity import InstanceActivity from .activity import InstanceActivity
from .activity import instance_activity 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 InstanceActiveManager
from .instance import BaseResourceConfigModel
from .instance import NamedBaseResourceConfig
from .instance import VirtualMachineDescModel from .instance import VirtualMachineDescModel
from .instance import InstanceTemplate from .instance import InstanceTemplate
from .instance import Instance from .instance import Instance
...@@ -12,13 +15,12 @@ from .instance import post_state_changed ...@@ -12,13 +15,12 @@ from .instance import post_state_changed
from .instance import pre_state_changed from .instance import pre_state_changed
from .network import InterfaceTemplate from .network import InterfaceTemplate
from .network import Interface from .network import Interface
from .node import Trait
from .node import Node from .node import Node
from .node import Lease
__all__ = [ __all__ = [
'InstanceActivity', 'InstanceActiveManager', 'BaseResourceConfigModel', 'InstanceActivity', 'InstanceActiveManager', 'BaseResourceConfigModel',
'NamedBaseResourceConfig', 'VirtualMachineDescModel', 'InstanceTemplate', 'NamedBaseResourceConfig', 'VirtualMachineDescModel', 'InstanceTemplate',
'Instance', 'instance_activity', 'post_state_changed', 'pre_state_changed', 'Instance', 'instance_activity', 'post_state_changed', 'pre_state_changed',
'InterfaceTemplate', 'Interface', 'Trait', 'Node', 'NodeActivity', 'Lease', 'InterfaceTemplate', 'Interface', 'Trait', 'Node', 'NodeActivity', 'Lease',
'node_activity',
] ]
from __future__ import unicode_literals from __future__ import absolute_import, unicode_literals
from contextlib import contextmanager from contextlib import contextmanager
from logging import getLogger from logging import getLogger
...@@ -16,9 +16,9 @@ class InstanceActivity(ActivityModel): ...@@ -16,9 +16,9 @@ class InstanceActivity(ActivityModel):
verbose_name=_('instance')) verbose_name=_('instance'))
class Meta: class Meta:
ordering = ['-started', 'instance', '-id']
app_label = 'vm' app_label = 'vm'
db_table = 'vm_instanceactivity' db_table = 'vm_instanceactivity'
ordering = ['-started', 'instance', '-id']
def __unicode__(self): def __unicode__(self):
if self.parent: if self.parent:
......
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
from __future__ import unicode_literals from __future__ import absolute_import, unicode_literals
from datetime import timedelta from datetime import timedelta
from logging import getLogger from logging import getLogger
from importlib import import_module from importlib import import_module
import django.conf import django.conf
from django.db.models import (Model, ForeignKey, ManyToManyField, from django.db.models import (BooleanField, CharField, DateTimeField,
IntegerField, DateTimeField, BooleanField, IntegerField, ForeignKey, Manager,
TextField, CharField, permalink, Manager) ManyToManyField, permalink, TextField)
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core import signing from django.core import signing
from django.dispatch import Signal from django.dispatch import Signal
...@@ -19,9 +19,10 @@ from taggit.managers import TaggableManager ...@@ -19,9 +19,10 @@ from taggit.managers import TaggableManager
from acl.models import AclBase from acl.models import AclBase
from storage.models import Disk from storage.models import Disk
from ..tasks import local_tasks, vm_tasks from ..tasks import local_tasks, vm_tasks
from .node import Node, Trait
from .network import Interface
from .activity import instance_activity from .activity import instance_activity
from .common import BaseResourceConfigModel
from .network import Interface
from .node import Node, Trait
logger = getLogger(__name__) logger = getLogger(__name__)
pre_state_changed = Signal(providing_args=["new_state"]) pre_state_changed = Signal(providing_args=["new_state"])
...@@ -29,8 +30,6 @@ post_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 pwgen = User.objects.make_random_password
scheduler = import_module(name=django.conf.settings.VM_SCHEDULER) 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_PROTOCOLS = django.conf.settings.VM_ACCESS_PROTOCOLS
ACCESS_METHODS = [(key, name) for key, (name, port, transport) ACCESS_METHODS = [(key, name) for key, (name, port, transport)
in ACCESS_PROTOCOLS.iteritems()] in ACCESS_PROTOCOLS.iteritems()]
...@@ -53,39 +52,6 @@ class InstanceActiveManager(Manager): ...@@ -53,39 +52,6 @@ class InstanceActiveManager(Manager):
self).get_query_set().filter(destroyed=None) 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): class VirtualMachineDescModel(BaseResourceConfigModel):
"""Abstract base for virtual machine describing models. """Abstract base for virtual machine describing models.
......
from __future__ import unicode_literals from __future__ import absolute_import, unicode_literals
from logging import getLogger from logging import getLogger
from netaddr import EUI, mac_unix from netaddr import EUI, mac_unix
......
from __future__ import unicode_literals from __future__ import absolute_import, unicode_literals
from datetime import timedelta
from logging import getLogger from logging import getLogger
from django.db.models import ( from django.db.models import (
Model, CharField, IntegerField, ForeignKey, BooleanField, ManyToManyField, CharField, IntegerField, ForeignKey, BooleanField, ManyToManyField,
FloatField, FloatField,
) )
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -15,21 +14,11 @@ from taggit.managers import TaggableManager ...@@ -15,21 +14,11 @@ from taggit.managers import TaggableManager
from common.models import method_cache from common.models import method_cache
from firewall.models import Host from firewall.models import Host
from ..tasks import vm_tasks from ..tasks import vm_tasks
from .common import Trait
logger = getLogger(__name__) 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): class Node(TimeStampedModel):
"""A VM host machine, a hypervisor. """A VM host machine, a hypervisor.
...@@ -135,40 +124,3 @@ class Node(TimeStampedModel): ...@@ -135,40 +124,3 @@ class Node(TimeStampedModel):
for i in domains.keys(): for i in domains.keys():
logger.info('Node %s update: domain %s in libvirt but not in db.', logger.info('Node %s update: domain %s in libvirt but not in db.',
self, i) 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment