Commit 01dd477c by Karsa Zoltán István

vm disk setup datastore

parent d5d3e15b
...@@ -851,10 +851,12 @@ class VmCreateDiskForm(OperationForm): ...@@ -851,10 +851,12 @@ class VmCreateDiskForm(OperationForm):
widget=FileSizeWidget, initial=(10 << 30), label=_('Size'), widget=FileSizeWidget, initial=(10 << 30), label=_('Size'),
help_text=_('Size of disk to create in bytes or with units ' help_text=_('Size of disk to create in bytes or with units '
'like MB or GB.')) 'like MB or GB.'))
datastore = forms.ModelChoiceField(queryset=None)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
default = kwargs.pop('default', None) default = kwargs.pop('default', None)
super(VmCreateDiskForm, self).__init__(*args, **kwargs) super(VmCreateDiskForm, self).__init__(*args, **kwargs)
self.fields['datastore'].queryset = DataStore.objects.all()
if default: if default:
self.fields['name'].initial = default self.fields['name'].initial = default
...@@ -989,6 +991,11 @@ class VmImportDiskForm(OperationForm): ...@@ -989,6 +991,11 @@ class VmImportDiskForm(OperationForm):
class VmDownloadDiskForm(OperationForm): class VmDownloadDiskForm(OperationForm):
name = forms.CharField(max_length=100, label=_("Name"), required=False) name = forms.CharField(max_length=100, label=_("Name"), required=False)
url = forms.CharField(label=_('URL'), validators=[URLValidator(), ]) url = forms.CharField(label=_('URL'), validators=[URLValidator(), ])
datastore = forms.ModelChoiceField(queryset=None)
def __init__(self, *args, **kwargs):
super(VmDownloadDiskForm, self).__init__(*args, **kwargs)
self.fields['datastore'].queryset = DataStore.objects.all()
def clean(self): def clean(self):
cleaned_data = super(VmDownloadDiskForm, self).clean() cleaned_data = super(VmDownloadDiskForm, self).clean()
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
<div class="panel-body"> <div class="panel-body">
{% for ds in stores %} {% for ds in stores %}
{% if ds.name == name %} {% if ds.name == name %}
<a href="#" class="badge badge-success"> <a href="{% url "dashboard.views.storage.name" name=ds.name %}" class="badge badge-dark">
<i class="fa fa-database"></i> {{ ds.hostname }}/{{ ds.name }} <i class="fa fa-database"></i> {{ ds.hostname }}/{{ ds.name }}
</a> </a>
{% else %} {% else %}
<a href="#" class="badge badge-primary"> <a href="{% url "dashboard.views.storage.name" name=ds.name %}" class="badge badge-primary">
{{ ds.hostname }}/{{ ds.name }} {{ ds.hostname }}/{{ ds.name }}
</a> </a>
{% endif %} {% endif %}
......
...@@ -300,7 +300,7 @@ urlpatterns = [ ...@@ -300,7 +300,7 @@ urlpatterns = [
url(r'^vm/opensearch.xml$', OpenSearchDescriptionView.as_view(), url(r'^vm/opensearch.xml$', OpenSearchDescriptionView.as_view(),
name="dashboard.views.vm-opensearch"), name="dashboard.views.vm-opensearch"),
url(r'^storage/(?P<name>[^/]+)/$', StorageDetail.as_view(), url(r'^storage/(?P<name>[^/]+)/$', StorageDetail.as_view(),
name="dashboard.views.storage"), name="dashboard.views.storage.name"),
url(r'^storage/', StorageDetail.as_view(), url(r'^storage/', StorageDetail.as_view(),
name="dashboard.views.storage"), name="dashboard.views.storage"),
url(r'^disk/(?P<pk>\d+)/$', DiskDetail.as_view(), url(r'^disk/(?P<pk>\d+)/$', DiskDetail.as_view(),
......
...@@ -292,12 +292,12 @@ class CreateDiskOperation(InstanceOperation): ...@@ -292,12 +292,12 @@ class CreateDiskOperation(InstanceOperation):
accept_states = ('STOPPED', 'PENDING', 'RUNNING') accept_states = ('STOPPED', 'PENDING', 'RUNNING')
concurrency_check = False concurrency_check = False
def _operation(self, user, size, activity, name=None): def _operation(self, user, size, activity, datastore, name=None):
from storage.models import Disk from storage.models import Disk
if not name: if not name:
name = "new disk" name = "new disk"
disk = Disk.create(size=size, name=name, type="qcow2-norm") disk = Disk.create(size=size, name=name, datastore=datastore.name, type="qcow2-norm")
disk.full_clean() disk.full_clean()
devnums = list(ascii_lowercase) devnums = list(ascii_lowercase)
for d in self.instance.disks.all(): for d in self.instance.disks.all():
...@@ -365,7 +365,7 @@ class DownloadDiskOperation(InstanceOperation): ...@@ -365,7 +365,7 @@ class DownloadDiskOperation(InstanceOperation):
async_queue = "localhost.man.slow" async_queue = "localhost.man.slow"
concurrency_check = False # warning!!! concurrency_check = False # warning!!!
def _operation(self, user, url, task, activity, name=None): def _operation(self, user, url, task, activity, datastore, name=None):
disk = Disk.download(url=url, name=name, task=task) disk = Disk.download(url=url, name=name, task=task)
devnums = list(ascii_lowercase) devnums = list(ascii_lowercase)
for d in self.instance.disks.all(): for d in self.instance.disks.all():
......
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