~allenap/maas/human-readable-bytes-alt

« back to all changes in this revision

Viewing changes to src/maasserver/forms.py

  • Committer: MAAS Lander
  • Author(s): Blake Rouse, Andres Rodriguez
  • Date: 2016-03-12 05:12:30 UTC
  • mfrom: (4774.1.1 maas)
  • Revision ID: maas_lander-20160312051230-zqj4r6oz5d8b5mtz
[r=andreserl][bug=][author=andreserl] Allow BMC to be on a network where a rack controller does not have direct access.

When a node is to be powered on or off and no direct rack controllers can be identified the region will ask all connected rack controllers to figure out which rack controllers can access that BMC by performing a power query. A many to many relationship between the rack controllers and BMC is updated to mark which rack controllers are routeable and which are not.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
import re
41
41
 
42
42
from django import forms
43
 
from django.contrib import messages
44
43
from django.contrib.auth.forms import (
45
44
    UserChangeForm,
46
45
    UserCreationForm,
77
76
    INTERFACE_TYPE,
78
77
    NODE_TYPE,
79
78
)
80
 
from maasserver.exceptions import (
81
 
    ClusterUnavailable,
82
 
    NodeActionError,
83
 
)
 
79
from maasserver.exceptions import NodeActionError
84
80
from maasserver.fields import (
85
81
    LargeObjectFile,
86
82
    MACAddressFormField,
784
780
        # form deals with an API call which does not change the value of
785
781
        # 'power_type') or invalid: get the machine's current 'power_type'
786
782
        # value or the default value if this form is not linked to a machine.
787
 
        try:
788
 
            power_types = get_power_types()
789
 
        except ClusterUnavailable as e:
790
 
            # If there's no request then this is an API call, so
791
 
            # there's no need to add a UI message, a suitable
792
 
            # ValidationError is raised elsewhere.
793
 
            if form.request is not None:
794
 
                messages.error(
795
 
                    form.request, CLUSTER_NOT_AVAILABLE + e.args[0])
 
783
        power_types = get_power_types(ignore_errors=True)
 
784
        if len(power_types) == 0:
796
785
            return ''
797
786
 
798
787
        if power_type not in power_types:
825
814
        # prevent saving the form as we can't validate the power
826
815
        # parameters and type.
827
816
        if not skip_check:
828
 
            try:
829
 
                get_power_types()
830
 
            except ClusterUnavailable as e:
 
817
            power_types = get_power_types(ignore_errors=True)
 
818
            if len(power_types) == 0:
831
819
                set_form_error(
832
 
                    form, "power_type", CLUSTER_NOT_AVAILABLE + e.args[0])
 
820
                    form, "power_type",
 
821
                    "No rack controllers are connected, unable to "
 
822
                    "validate the power type.")
 
823
 
833
824
            # If power_type is not set and power_parameters_skip_check is not
834
825
            # on, reset power_parameters (set it to the empty string).
835
826
            if cleaned_data.get('power_type', '') == '':