Permalink
Browse files

show swap disk in listing and forms in flavors syspanel

At the moment the swap disk entry of flavors is not listed in
the syspanel listing of flavors and it's not possible to create
a new flavor or edit an existing flavor with the swap size

Change-Id: I92195671024bb361fa5825cbdcea515850ddee31
  • Loading branch information...
1 parent 6f5fdef commit 06e1d59a5cc3a8a5890af211bc9c76d201733b53 @berendt berendt committed Nov 29, 2012
View
6 openstack_dashboard/api/nova.py
@@ -195,9 +195,9 @@ def server_vnc_console(request, instance_id, console_type='novnc'):
console_type)['console'])
-def flavor_create(request, name, memory, vcpu, disk, ephemeral=0):
- return novaclient(request).flavors.create(name, memory, vcpu,
- disk, ephemeral=ephemeral)
+def flavor_create(request, name, memory, vcpu, disk, ephemeral=0, swap=0):
+ return novaclient(request).flavors.create(name, memory, vcpu, disk,
+ ephemeral=ephemeral, swap=swap)
def flavor_delete(request, flavor_id):
View
7 openstack_dashboard/dashboards/admin/flavors/forms.py
@@ -38,6 +38,7 @@ class CreateFlavor(forms.SelfHandlingForm):
memory_mb = forms.IntegerField(label=_("RAM MB"))
disk_gb = forms.IntegerField(label=_("Root Disk GB"))
eph_gb = forms.IntegerField(label=_("Ephemeral Disk GB"))
+ swap_mb = forms.IntegerField(label=_("Swap Disk MB"))
def clean_name(self):
name = self.cleaned_data.get('name')
@@ -64,7 +65,8 @@ def handle(self, request, data):
data['memory_mb'],
data['vcpus'],
data['disk_gb'],
- ephemeral=data['eph_gb'])
+ ephemeral=data['eph_gb'],
+ swap=data['swap_mb'])
msg = _('Created flavor "%s".') % data['name']
messages.success(request, msg)
return flavor
@@ -95,7 +97,8 @@ def handle(self, request, data):
data['memory_mb'],
data['vcpus'],
data['disk_gb'],
- ephemeral=data['eph_gb'])
+ ephemeral=data['eph_gb'],
+ swap=data['swap_mb'])
if (len(extras_dict) > 0):
api.nova.flavor_extra_set(request, flavor.id, extras_dict)
msg = _('Updated flavor "%s".') % data['name']
View
7 openstack_dashboard/dashboards/admin/flavors/tables.py
@@ -43,6 +43,10 @@ def get_size(flavor):
return _("%sMB") % flavor.ram
+def get_swap_size(flavor):
+ return _("%sMB") % (flavor.swap or 0)
+
+
class FlavorsTable(tables.DataTable):
name = tables.Column('name', verbose_name=_('Flavor Name'))
vcpus = tables.Column('vcpus', verbose_name=_('VCPUs'))
@@ -52,6 +56,9 @@ class FlavorsTable(tables.DataTable):
disk = tables.Column('disk', verbose_name=_('Root Disk'))
ephemeral = tables.Column('OS-FLV-EXT-DATA:ephemeral',
verbose_name=_('Ephemeral Disk'))
+ swap = tables.Column(get_swap_size,
+ verbose_name=_('Swap Disk'),
+ attrs={'data-type': 'size'})
flavor_id = tables.Column('id', verbose_name=('ID'))
class Meta:
View
4 openstack_dashboard/dashboards/admin/flavors/tests.py
@@ -21,6 +21,7 @@ def test_create_new_flavor_when_none_exist(self):
flavor.ram,
flavor.vcpus,
flavor.disk,
+ swap=flavor.swap or 0,
ephemeral=eph).AndReturn(flavor)
api.nova.flavor_list(IsA(http.HttpRequest))
self.mox.ReplayAll()
@@ -34,6 +35,7 @@ def test_create_new_flavor_when_none_exist(self):
'vcpus': flavor.vcpus,
'memory_mb': flavor.ram,
'disk_gb': flavor.disk,
+ 'swap_mb': flavor.swap or 0,
'eph_gb': eph}
resp = self.client.post(url, data)
self.assertRedirectsNoFollow(resp,
@@ -62,6 +64,7 @@ def test_edit_flavor(self):
flavor.ram,
flavor.vcpus + 1,
flavor.disk,
+ swap=flavor.swap or 0,
ephemeral=eph).AndReturn(flavor)
self.mox.ReplayAll()
@@ -77,6 +80,7 @@ def test_edit_flavor(self):
'vcpus': flavor.vcpus + 1,
'memory_mb': flavor.ram,
'disk_gb': flavor.disk,
+ 'swap_mb': flavor.swap or 0,
'eph_gb': eph}
resp = self.client.post(url, data)
self.assertRedirectsNoFollow(resp,
View
1 openstack_dashboard/dashboards/admin/flavors/views.py
@@ -79,4 +79,5 @@ def get_initial(self):
'vcpus': flavor.vcpus,
'memory_mb': flavor.ram,
'disk_gb': flavor.disk,
+ 'swap_mb': flavor.swap or 0,
'eph_gb': getattr(flavor, 'OS-FLV-EXT-DATA:ephemeral', None)}
View
2 openstack_dashboard/test/test_data/nova_data.py
@@ -203,13 +203,15 @@ def data(TEST):
'vcpus': 1,
'disk': 0,
'ram': 512,
+ 'swap': 0,
'OS-FLV-EXT-DATA:ephemeral': 0})
flavor_2 = flavors.Flavor(flavors.FlavorManager(None),
{'id': "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
'name': 'm1.massive',
'vcpus': 1000,
'disk': 1024,
'ram': 10000,
+ 'swap': 0,
'OS-FLV-EXT-DATA:ephemeral': 2048})
TEST.flavors.add(flavor_1, flavor_2)

0 comments on commit 06e1d59

Please sign in to comment.