Commit 1698b3d4 by Czémán Arnold

dashboard, vm, storage, settings: fix DataStore queries

parent 9c20e518
...@@ -84,6 +84,8 @@ ADMINS = ( ...@@ -84,6 +84,8 @@ ADMINS = (
EMAIL_SUBJECT_PREFIX = get_env_variable('DJANGO_SUBJECT_PREFIX', '[CIRCLE] ') EMAIL_SUBJECT_PREFIX = get_env_variable('DJANGO_SUBJECT_PREFIX', '[CIRCLE] ')
DEFAULT_DATASTORE = get_env_variable('DEFAULT_DATASTORE', 'default')
########## END MANAGER CONFIGURATION ########## END MANAGER CONFIGURATION
......
...@@ -22,6 +22,7 @@ from optparse import make_option ...@@ -22,6 +22,7 @@ from optparse import make_option
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.conf import settings
from firewall.models import Vlan, VlanGroup, Domain, Firewall, Rule from firewall.models import Vlan, VlanGroup, Domain, Firewall, Rule
from storage.models import DataStore from storage.models import DataStore
...@@ -73,7 +74,8 @@ class Command(BaseCommand): ...@@ -73,7 +74,8 @@ class Command(BaseCommand):
admin.set_password(options['admin_pass']) admin.set_password(options['admin_pass'])
admin.save() admin.save()
self.create(DataStore, 'path', path='/datastore', name='default', self.create(DataStore, 'path', path='/datastore',
name=settings.DEFAULT_DATASTORE,
hostname=options['datastore_queue']) hostname=options['datastore_queue'])
# leases # leases
......
...@@ -37,13 +37,13 @@ class StorageDetail(SuperuserRequiredMixin, UpdateView): ...@@ -37,13 +37,13 @@ class StorageDetail(SuperuserRequiredMixin, UpdateView):
template_name = "dashboard/storage/detail.html" template_name = "dashboard/storage/detail.html"
def get_object(self): def get_object(self):
return DataStore.objects.get() return DataStore.get_default_datastore()
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(StorageDetail, self).get_context_data(**kwargs) context = super(StorageDetail, self).get_context_data(**kwargs)
ds = self.get_object()
try: try:
ds = self.get_object()
context['stats'] = self._get_stats() context['stats'] = self._get_stats()
context['missing_disks'] = ds.get_missing_disks() context['missing_disks'] = ds.get_missing_disks()
context['orphan_disks'] = ds.get_orphan_disks() context['orphan_disks'] = ds.get_orphan_disks()
......
...@@ -24,6 +24,7 @@ from os.path import join ...@@ -24,6 +24,7 @@ from os.path import join
import uuid import uuid
import re import re
from django.conf import settings
from celery.contrib.abortable import AbortableAsyncResult from celery.contrib.abortable import AbortableAsyncResult
from django.db.models import (Model, BooleanField, CharField, DateTimeField, from django.db.models import (Model, BooleanField, CharField, DateTimeField,
ForeignKey) ForeignKey)
...@@ -109,6 +110,16 @@ class DataStore(Model): ...@@ -109,6 +110,16 @@ class DataStore(Model):
disks = Disk.objects.filter(destroyed__isnull=True, is_ready=True) disks = Disk.objects.filter(destroyed__isnull=True, is_ready=True)
return disks.exclude(filename__in=files) return disks.exclude(filename__in=files)
@classmethod
def get_default_datastore(cls):
try:
datastore_name = settings.DEFAULT_DATASTORE
if datastore_name:
return cls.objects.get(name=datastore_name)
except cls.DoesNotExist:
pass
return cls.objects.all()[0] # TODO
class Disk(TimeStampedModel): class Disk(TimeStampedModel):
...@@ -413,7 +424,7 @@ class Disk(TimeStampedModel): ...@@ -413,7 +424,7 @@ class Disk(TimeStampedModel):
@classmethod @classmethod
def __create(cls, user, params): def __create(cls, user, params):
datastore = params.pop('datastore', DataStore.objects.get()) datastore = params.pop('datastore', DataStore.get_default_datastore())
filename = params.pop('filename', str(uuid.uuid4())) filename = params.pop('filename', str(uuid.uuid4()))
disk = cls(filename=filename, datastore=datastore, **params) disk = cls(filename=filename, datastore=datastore, **params)
return disk return disk
......
...@@ -488,7 +488,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -488,7 +488,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
datastore = self.disks.all()[0].datastore datastore = self.disks.all()[0].datastore
except IndexError: except IndexError:
from storage.models import DataStore from storage.models import DataStore
datastore = DataStore.objects.get() datastore = DataStore.get_default_datastore()
path = datastore.path + '/' + self.vm_name + '.dump' path = datastore.path + '/' + self.vm_name + '.dump'
return {'datastore': datastore, 'path': path} return {'datastore': datastore, 'path': path}
......
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