Commit 5069b23e by Karsa Zoltán István

datastore update

parent 8380e20d
......@@ -90,11 +90,14 @@ class OperationForm(NoFormTagMixin, forms.Form):
class VmSaveForm(OperationForm):
name = forms.CharField(max_length=100, label=_('Name'),
help_text=_('Human readable name of template.'))
datastore = forms.ModelChoiceField(queryset=None, initial=0, empty_label=None,
help_text=_('Backing file location'))
def __init__(self, *args, **kwargs):
default = kwargs.pop('default', None)
clone = kwargs.pop('clone', False)
super(VmSaveForm, self).__init__(*args, **kwargs)
self.fields['datastore'].queryset = DataStore.objects.all()
if default:
self.fields['name'].initial = default
if clone:
......@@ -851,7 +854,7 @@ class VmCreateDiskForm(OperationForm):
widget=FileSizeWidget, initial=(10 << 30), label=_('Size'),
help_text=_('Size of disk to create in bytes or with units '
'like MB or GB.'))
datastore = forms.ModelChoiceField(queryset=None)
datastore = forms.ModelChoiceField(queryset=None, initial=0, empty_label=None)
def __init__(self, *args, **kwargs):
default = kwargs.pop('default', None)
......@@ -991,7 +994,7 @@ class VmImportDiskForm(OperationForm):
class VmDownloadDiskForm(OperationForm):
name = forms.CharField(max_length=100, label=_("Name"), required=False)
url = forms.CharField(label=_('URL'), validators=[URLValidator(), ])
datastore = forms.ModelChoiceField(queryset=None)
datastore = forms.ModelChoiceField(queryset=None, initial=0, empty_label=None)
def __init__(self, *args, **kwargs):
super(VmDownloadDiskForm, self).__init__(*args, **kwargs)
......
# Generated by Django 3.2.3 on 2023-01-13 16:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('storage', '0006_auto_20221231_1011'),
]
operations = [
migrations.AddField(
model_name='disk',
name='cache_size',
field=models.IntegerField(default=1024, help_text='Disk metadata cache max size (Kbyte)', verbose_name='cache size'),
),
]
......@@ -29,7 +29,7 @@ from celery.result import allow_join_result
from celery.exceptions import TimeoutError
from django.core.exceptions import ObjectDoesNotExist
from django.urls import reverse
from django.db.models import (Model, BooleanField, CharField, DateTimeField,
from django.db.models import (Model, BooleanField, CharField, DateTimeField, IntegerField,
ForeignKey)
from django.db import models
from django.utils import timezone
......@@ -147,6 +147,9 @@ class Disk(TimeStampedModel):
destroyed = DateTimeField(blank=True, default=None, null=True)
ci_disk = BooleanField(default=False)
is_ready = BooleanField(default=False)
cache_size = IntegerField(default=1024,
help_text=_("Disk metadata cache max size (Kbyte)"),
verbose_name=_('cache size'))
class Meta:
ordering = ['name']
......@@ -346,7 +349,8 @@ class Disk(TimeStampedModel):
'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'
'disk_device': 'cdrom' if self.type == 'iso' else 'disk',
'cache_size': self.cache_size
}
def get_disk_desc(self):
......@@ -358,7 +362,8 @@ class Disk(TimeStampedModel):
'format': self.format,
'size': self.size,
'base_name': self.base.filename if self.base else None,
'type': 'snapshot' if self.base else 'normal'
'type': 'snapshot' if self.base else 'normal',
'cache_size': self.cache_size
}
def get_remote_queue_name(self, queue_id='storage', priority=None,
......@@ -559,7 +564,7 @@ class Disk(TimeStampedModel):
args=[self.datastore.path, self.filename],
queue=queue_name).get(timeout=timeout)
def save_as(self, task=None, user=None, task_uuid=None, timeout=300):
def save_as(self, task=None, user=None, task_uuid=None, datastore=None, timeout=300):
"""Save VM as template.
Based on disk type:
......@@ -588,7 +593,9 @@ class Disk(TimeStampedModel):
new_type, new_base = mapping[self.type]
disk = Disk.create(datastore=self.datastore,
if not datastore:
datastore = self.datastore
disk = Disk.create(datastore=datastore,
base=new_base,
name=self.name, size=self.size,
type=new_type, dev_num=self.dev_num)
......
......@@ -857,7 +857,7 @@ class SaveAsTemplateOperation(InstanceOperation):
disk.destroy()
def _operation(self, activity, user, system, name=None,
with_shutdown=True, clone=False, task=None, **kwargs):
with_shutdown=True, clone=False, task=None, datastore='default', **kwargs):
try:
self.instance._cleanup(parent_activity=activity, user=user)
except:
......@@ -898,9 +898,9 @@ class SaveAsTemplateOperation(InstanceOperation):
from storage.models import Disk
def __try_save_disk(disk):
def __try_save_disk(disk, datastore):
try:
return disk.save_as(task)
return disk.save_as(task, datastore=datastore)
except Disk.WrongDiskTypeError:
return disk
......@@ -913,7 +913,7 @@ class SaveAsTemplateOperation(InstanceOperation):
ugettext_noop("saving disk %(name)s"),
name=disk.name)
):
self.disks.append(__try_save_disk(disk))
self.disks.append(__try_save_disk(disk, datastore=datastore))
# create template and do additional setup
tmpl = InstanceTemplate(**params)
......
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