Merge "Reset role's nodes to 0 if it has no flavor"

This commit is contained in:
Jenkins 2015-01-26 13:43:24 +00:00 committed by Gerrit Code Review
commit 67a52dc978
2 changed files with 13 additions and 1 deletions

View File

@ -57,3 +57,12 @@ class EditPlan(forms.EditPlan):
LOG.exception(e)
return False
return result
def clean(self):
cleaned_data = super(EditPlan, self).clean()
# If a role has no flavor, it should have no nodes.
for key, value in cleaned_data.items():
if key.endswith('-flavor'):
if not value:
cleaned_data[key.replace('-flavor', '-count')] = 0
return cleaned_data

View File

@ -139,11 +139,14 @@ class IndexView(views.IndexView):
if 'form' in data:
role['flavor_field'] = data['form'][role['id'] + '-flavor']
flavor = role['role'].flavor(data['plan'])
if flavor and flavor.id in [f.id for f in flavors]:
if flavor and flavor.name in [f.name for f in flavors]:
role['flavor_name'] = flavor.name
flavor_roles.setdefault(flavor.name, []).append(role)
else:
role['flavor_name'] = ''
field = role.get('flavor_field')
if field:
field.initial = 0
free_roles.append(role)
data['free_roles'] = free_roles
data['flavors'] = list(