<commit_before># -*- coding: utf8 -*-
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
from django.core import exceptions as django_exceptions
from django.utils import translation
from django.utils.translation import ugettext_lazy as _

from horizon import exceptions
import horizon.workflows

from tuskar_ui import api
from tuskar_ui.infrastructure.overcloud.workflows\
    import undeployed_configuration
from tuskar_ui.infrastructure.overcloud.workflows import undeployed_overview


class DeploymentValidationMixin(object):
    def validate(self, context):
        requested = sum(context['role_counts'].values())
        free = len(api.Node.list(self.request, associated=False))

        if requested > free:
            m1 = translation.ungettext_lazy('This configuration requires '
                                            '%(requested)d node, ',
                                            'This configuration requires '
                                            '%(requested)d nodes, ',<commit_msg>Fix validation for scaling<commit_after># -*- coding: utf8 -*-
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
from django.core import exceptions as django_exceptions
from django.utils import translation
from django.utils.translation import ugettext_lazy as _

from horizon import exceptions
import horizon.workflows

from tuskar_ui import api
from tuskar_ui.infrastructure.overcloud.workflows\
    import undeployed_configuration
from tuskar_ui.infrastructure.overcloud.workflows import undeployed_overview


class DeploymentValidationMixin(object):
    def validate(self, context):
        requested = sum(context['role_counts'].values())
        # TODO(lsmola) change this when we support more overclouds. It
        # will have to obtain actual free nodes and compare them to
        # number of newly created.
        free = len(api.Node.list(self.request))

        if requested > free:
            m1 = translation.ungettext_lazy('This configuration requires '
                                            '%(requested)d node, ',
                                            'This configuration requires '
                                            '%(requested)d nodes, ',
{'fraction_non_alphanumeric': 0.06880592409750078, 'fraction_numerical': 0.0037025609379821045, 'mean_word_length': 2.7350230414746544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4262071', 'n_tokens_mistral': 784, 'n_tokens_neox': 783, 'n_words': 302}