Add maximum disk, vcpu and memory requirement

Sometimes it is necessary to limit the upper value in
a flavor requirement.
This commit enables this opportunity.

Change-Id: I41e71313a8539ba7e89fc2448d926b8edf22ce3f
Closes-Bug: #1525844
This commit is contained in:
Ekaterina Chernova 2015-12-14 14:20:05 +03:00
parent c0d31e59b8
commit 5cb14986ab
5 changed files with 45 additions and 8 deletions

View File

@ -67,7 +67,7 @@ class AppRequirementsTab(tabs.Tab):
for req in reqs:
if req == 'min_disk':
requirements.append(
'Minimum disk size: {0}GB'.format(
'Minimum disk size: {0} GB'.format(
str(reqs[req])))
elif req == 'min_vcpus':
requirements.append(
@ -75,7 +75,19 @@ class AppRequirementsTab(tabs.Tab):
str(reqs[req])))
elif req == 'min_memory_mb':
requirements.append(
'Minimum RAM size: {0}MB'.format(
'Minimum RAM size: {0} MB'.format(
str(reqs[req])))
elif req == 'max_disk':
requirements.append(
'Maximum disk size: {0} GB'.format(
str(reqs[req])))
elif req == 'max_vcpus':
requirements.append(
'Maximum vCPUs: {0}'.format(
str(reqs[req])))
elif req == 'max_memory_mb':
requirements.append(
'Maximum RAM size: {0} MB'.format(
str(reqs[req])))
self.app.requirements.append(requirements)

View File

@ -312,6 +312,15 @@ class FlavorChoiceField(ChoiceField):
continue
if flavor.ram < self.requirements.get('min_memory_mb', 0):
continue
if 'max_vcpus' in self.requirements:
if flavor.vcpus > self.requirements['max_vcpus']:
continue
if 'max_disk' in self.requirements:
if flavor.disk > self.requirements['max_disk']:
continue
if 'max_memory_mb' in self.requirements:
if flavor.ram > self.requirements['max_memory_mb']:
continue
self.choices.append((flavor.name, flavor.name))
# Search through selected flavors
for flavor_name, flavor_name in self.choices:

View File

@ -50,7 +50,8 @@ class MarkImageForm(horizon_forms.SelfHandlingForm):
_metadata = {
'windows.2012': ' Windows Server 2012',
'linux': 'Generic Linux',
'cirros.demo': 'Murano Demo'
'cirros.demo': 'Murano Demo',
'rhel6': 'Test new type'
}
image = forms.ChoiceField(label='Image')

View File

@ -12,11 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from muranodashboard.catalog import tabs
from openstack_dashboard.test import helpers
import mock
class TestLicenseTab(helpers.APITestCase):
def setUp(self):
@ -84,7 +84,10 @@ class TestRequirementsTab(helpers.APITestCase):
'flavor': mock.MagicMock(requirements={
'min_disk': 10,
'min_vcpus': 2,
'min_memory_mb': 2048
'min_memory_mb': 2048,
'max_disk': 25,
'max_vcpus': 5,
'max_memory_mb': 16000,
})
}
mock_services.get_app_forms.return_value = [('', m)]
@ -101,11 +104,17 @@ class TestRequirementsTab(helpers.APITestCase):
self.assertIn('Instance flavor:', r.app.requirements)
flavor_req = r.app.requirements[1]
self.assertIn('Minimum disk size: 10GB',
self.assertIn('Minimum disk size: 10 GB',
flavor_req)
self.assertIn('Minimum vCPUs: 2',
flavor_req)
self.assertIn('Minimum RAM size: 2048MB',
self.assertIn('Minimum RAM size: 2048 MB',
flavor_req)
self.assertIn('Maximum disk size: 25 GB',
flavor_req)
self.assertIn('Maximum vCPUs: 5',
flavor_req)
self.assertIn('Maximum RAM size: 16000 MB',
flavor_req)
@mock.patch('muranodashboard.catalog.tabs.services')

View File

@ -0,0 +1,6 @@
---
features:
- Requierements for the flavor field accpets 'max_vcpus' 'max_disk' and
'max_memory_mb'. Previously only minimum values can be specified in the
flavor requirements.