grnet/ganetimgr

[PATCH] Definition of minimum memory

Closed this issue · 2 comments

The lower memory limit for a VM is defined in two different places, which makes it awkward if you want to allow a smaller instance. This patch avoids the duplication, so you only have to set VALID_MEMORY_VALUES.

--- a/apply/forms.py
+++ b/apply/forms.py
@@ -36,9 +36,9 @@ from django.utils.html import escape, conditional_escape
 # Taken from ganeti and patched to avoid non-bind9 friendly VM names
 _VALID_NAME_RE = re.compile("^[a-z0-9.-]{1,255}$")

-VALID_MEMORY_VALUES = ['512', '768', '1024', '1500', '2048', '3072', '4096']
+VALID_MEMORY_VALUES = [512, 768, 1024, 1500, 2048, 3072, 4096]

-MEMORY_CHOICES = [(m, filesizeformat(int(m) * 1024**2))
+MEMORY_CHOICES = [(str(m), filesizeformat(m * 1024**2))
                   for m in VALID_MEMORY_VALUES]


@@ -183,7 +183,7 @@ class InstanceApplicationForm(InstanceForm):


 class InstanceApplicationReviewForm(InstanceForm):
-    memory = forms.IntegerField(min_value=512, initial=1024)
+    memory = forms.IntegerField(min_value=min(VALID_MEMORY_VALUES), initial=1024)
     vcpus = forms.IntegerField(min_value=1, initial=1, label="Virtual CPUs")
     disk_size = forms.IntegerField(min_value=2, initial=5,
                                    label=ugettext_lazy("Disk size (GB)"))

LGTM, let's merge this

Fixed in c37bffa