Commit 53fd6dee by Karsa Zoltán István

datastore fun

parent 4ef2a8a8
......@@ -299,8 +299,9 @@ urlpatterns = [
name="dashboard.views.token-login"),
url(r'^vm/opensearch.xml$', OpenSearchDescriptionView.as_view(),
name="dashboard.views.vm-opensearch"),
url(r'^storage/$', StorageDetail.as_view(),
url(r'^storage/(?P<name>[^/]+)/$', StorageDetail.as_view(),
name="dashboard.views.storage"),
url(r'^storage/', StorageDetail.as_view(),
name="dashboard.views.storage"),
url(r'^disk/(?P<pk>\d+)/$', DiskDetail.as_view(),
name="dashboard.views.disk-detail"),
......
......@@ -43,7 +43,10 @@ class StorageDetail(SuperuserRequiredMixin, UpdateView):
template_name = "dashboard/storage/detail.html"
def get_object(self):
return DataStore.objects.get()
datastore = 'default'
if 'name' in self.kwargs:
datastore = self.kwargs['name']
return DataStore.objects.filter(name=datastore).get()
def get_context_data(self, **kwargs):
context = super(StorageDetail, self).get_context_data(**kwargs)
......
# Generated by Django 3.2.3 on 2022-12-31 10:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('storage', '0005_storageactivity'),
]
operations = [
migrations.AddField(
model_name='datastore',
name='driver_cache',
field=models.CharField(default='none', max_length=20, verbose_name='cache-mode - qemu'),
),
migrations.AlterField(
model_name='datastore',
name='hostname',
field=models.CharField(max_length=40, verbose_name='hostname'),
),
]
......@@ -51,8 +51,9 @@ class DataStore(Model):
"""
name = CharField(max_length=100, unique=True, verbose_name=_('name'))
path = CharField(max_length=200, unique=True, verbose_name=_('path'))
hostname = CharField(max_length=40, unique=True,
hostname = CharField(max_length=40, unique=False,
verbose_name=_('hostname'))
driver_cache = CharField(max_length=20, unique=False, verbose_name=_('cache-mode - qemu'), default='none')
class Meta:
ordering = ['name']
......@@ -342,7 +343,7 @@ class Disk(TimeStampedModel):
'name': self.name,
'source': self.path,
'driver_type': self.vm_format,
'driver_cache': 'none',
'driver_cache': self.datastore.driver_cache,
'target_device': self.device_type + self.dev_num,
'target_bus': self.device_bus,
'disk_device': 'cdrom' if self.type == 'iso' else 'disk'
......@@ -419,8 +420,8 @@ class Disk(TimeStampedModel):
return True
@classmethod
def create(cls, user=None, **params):
disk = cls.__create(user, params)
def create(cls, user=None, datastore='default', **params):
disk = cls.__create(user, datastore, params)
disk.clean()
disk.save()
logger.debug("Disk created from: %s",
......@@ -428,8 +429,8 @@ class Disk(TimeStampedModel):
return disk
@classmethod
def __create(cls, user, params):
datastore = params.pop('datastore', DataStore.objects.get())
def __create(cls, user, datastore, params):
datastore = params.pop('datastore', DataStore.objects.filter(name=datastore).get())
filename = params.pop('filename', str(uuid.uuid4()))
disk = cls(filename=filename, datastore=datastore, **params)
return disk
......
# Generated by Django 3.2.3 on 2022-12-31 10:11
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0016_auto_20221228_1416'),
]
operations = [
migrations.AlterField(
model_name='instance',
name='max_ram_size',
field=models.IntegerField(help_text='Upper memory size limit for balloning (or hotplug).', validators=[django.core.validators.MinValueValidator(0)], verbose_name='maximal RAM size'),
),
migrations.AlterField(
model_name='instance',
name='num_cores_max',
field=models.IntegerField(default=0, help_text='Number of max virtual CPU cores available to the virtual machine (for hotplug).', validators=[django.core.validators.MinValueValidator(0)], verbose_name='number of max cores'),
),
migrations.AlterField(
model_name='instancetemplate',
name='max_ram_size',
field=models.IntegerField(help_text='Upper memory size limit for balloning (or hotplug).', validators=[django.core.validators.MinValueValidator(0)], verbose_name='maximal RAM size'),
),
migrations.AlterField(
model_name='instancetemplate',
name='num_cores_max',
field=models.IntegerField(default=0, help_text='Number of max virtual CPU cores available to the virtual machine (for hotplug).', validators=[django.core.validators.MinValueValidator(0)], verbose_name='number of max cores'),
),
migrations.AlterField(
model_name='namedbaseresourceconfig',
name='max_ram_size',
field=models.IntegerField(help_text='Upper memory size limit for balloning (or hotplug).', validators=[django.core.validators.MinValueValidator(0)], verbose_name='maximal RAM size'),
),
migrations.AlterField(
model_name='namedbaseresourceconfig',
name='num_cores_max',
field=models.IntegerField(default=0, help_text='Number of max virtual CPU cores available to the virtual machine (for hotplug).', validators=[django.core.validators.MinValueValidator(0)], verbose_name='number of max cores'),
),
]
......@@ -732,7 +732,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
datastore = self.disks.all()[0].datastore
except IndexError:
from storage.models import DataStore
datastore = DataStore.objects.get()
datastore = DataStore.objects.filter(name='default').get()
path = datastore.path + '/' + self.vm_name + '.dump'
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