Auto-discover missing node parameters by default
Remove the "Discover missing attributes" checkbox and run the auto-discovery if any node parameters are missing. Change-Id: I04ae6f636feb8ac21348cf021041ba2f65f5c6df
This commit is contained in:
parent
bd55f0c2c9
commit
cda11a5723
@ -53,16 +53,23 @@ def get_driver_info_dict(data):
|
||||
|
||||
|
||||
def create_node(request, data):
|
||||
cpu_arch = data.get('cpu_arch')
|
||||
cpus = data.get('cpus')
|
||||
memory_mb = data.get('memory_mb')
|
||||
local_gb = data.get('local_gb')
|
||||
|
||||
kwargs = get_driver_info_dict(data)
|
||||
kwargs.update(
|
||||
cpu_arch=data.get('cpu_arch'),
|
||||
cpus=data.get('cpus'),
|
||||
memory_mb=data.get('memory_mb'),
|
||||
local_gb=data.get('local_gb'),
|
||||
cpu_arch=cpu_arch,
|
||||
cpus=cpus,
|
||||
memory_mb=memory_mb,
|
||||
local_gb=local_gb,
|
||||
mac_addresses=data['mac_addresses'].split(),
|
||||
)
|
||||
node = api.node.Node.create(request, **kwargs)
|
||||
if data.get('do_autodiscovery', False):
|
||||
|
||||
# If not all the parameters have been filled in, run the autodiscovery
|
||||
if not all([cpu_arch, cpus, memory_mb, local_gb]):
|
||||
api.node.Node.set_maintenance(request, node.uuid, True)
|
||||
api.node.Node.discover(request, [node.uuid])
|
||||
|
||||
@ -139,13 +146,9 @@ class NodeForm(django.forms.Form):
|
||||
'rows': 2,
|
||||
}),
|
||||
)
|
||||
do_autodiscovery = django.forms.BooleanField(
|
||||
label=_("Discover missing attributes"),
|
||||
required=False,
|
||||
)
|
||||
mac_addresses = tuskar_ui.forms.MultiMACField(
|
||||
label=_("NIC MAC Addresses"),
|
||||
required=False,
|
||||
required=True,
|
||||
widget=django.forms.Textarea(attrs={
|
||||
'placeholder': _('unspecified'),
|
||||
'rows': '2',
|
||||
@ -216,25 +219,14 @@ class NodeForm(django.forms.Form):
|
||||
def clean(self):
|
||||
cleaned_data = super(NodeForm, self).clean()
|
||||
driver = cleaned_data['driver']
|
||||
|
||||
if driver == 'pxe_ipmitool':
|
||||
self._require_field('ipmi_address', cleaned_data)
|
||||
elif driver == 'pxe_ssh':
|
||||
self._require_field('ssh_address', cleaned_data)
|
||||
self._require_field('ssh_username', cleaned_data)
|
||||
self._require_field('ssh_key_contents', cleaned_data)
|
||||
if not cleaned_data.get('do_autodiscovery', False):
|
||||
for field_name in [
|
||||
'mac_addresses',
|
||||
'cpu_arch',
|
||||
'cpus',
|
||||
'memory_mb',
|
||||
'local_gb',
|
||||
]:
|
||||
if not cleaned_data.get(field_name):
|
||||
self._errors[field_name] = self.error_class([(
|
||||
u"This field is required "
|
||||
u"when autodiscovery is disabled."
|
||||
)])
|
||||
|
||||
return cleaned_data
|
||||
|
||||
|
||||
@ -263,7 +255,6 @@ class UploadNodeForm(forms.SelfHandlingForm):
|
||||
ssh_key_contents=row[3],
|
||||
mac_addresses=row[4],
|
||||
driver=driver,
|
||||
do_autodiscovery=True,
|
||||
)
|
||||
elif driver == 'pxe_ipmitool':
|
||||
node = dict(
|
||||
@ -271,7 +262,6 @@ class UploadNodeForm(forms.SelfHandlingForm):
|
||||
ipmi_username=row[2],
|
||||
ipmi_password=row[3],
|
||||
driver=driver,
|
||||
do_autodiscovery=True,
|
||||
)
|
||||
data.append(node)
|
||||
return data
|
||||
|
@ -23,3 +23,7 @@
|
||||
color: #428bca;
|
||||
}
|
||||
}
|
||||
|
||||
.param-section {
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
|
@ -5,31 +5,27 @@
|
||||
id="tab-{{ form.prefix }}">
|
||||
<div class="form form-inline"><fieldset class="well">
|
||||
{% include 'horizon/common/_form_errors.html' with form=form %}
|
||||
<div class="row">
|
||||
<h4>{% trans "Node Detail" %}</h4>
|
||||
<h4>{% trans "Node Detail" %}</h4>
|
||||
<div class="param-section">
|
||||
<h5>{% trans "Power Management" %}</h5>
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.driver required=True %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ipmi_address required=True %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ipmi_username %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ipmi_password %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ssh_address required=True %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ssh_username required=True %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ssh_key_contents required=True %}
|
||||
</div>
|
||||
<h5 class="row">{% trans "Power Management" %}</h5>
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.driver required=True %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ipmi_address required=True %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ipmi_username %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ipmi_password %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ssh_address required=True %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ssh_username required=True %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ssh_key_contents required=True %}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<label class="checkbox">
|
||||
{{ form.do_autodiscovery|add_bootstrap_class }}
|
||||
{{ form.do_autodiscovery.label }}
|
||||
</label>
|
||||
</div>
|
||||
<h5 class="row">{% trans "Networking" %}</h5>
|
||||
<div class="param-section">
|
||||
<h5>{% trans "Networking" %}</h5>
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.mac_addresses required=True %}
|
||||
<h5 class="row">{% trans "Hardware" %}</h5>
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.cpu_arch required=True %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.cpus extra_text=_('units') required=True %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.memory_mb extra_text=_('MB') required=True %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.local_gb extra_text=_('GB') required=True %}
|
||||
</div>
|
||||
<div class="param-section">
|
||||
<h5>{% trans "Hardware" %}</h5>
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.cpu_arch %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.cpus extra_text=_('units') %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.memory_mb extra_text=_('MB') %}
|
||||
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.local_gb extra_text=_('GB') %}
|
||||
</div>
|
||||
</fieldset></div>
|
||||
</div>
|
||||
@ -44,11 +40,5 @@
|
||||
var $nav_link = $('a[href="#' + $form.attr('id') + '"]');
|
||||
$nav_link.html($(this).val() || undefined_name);
|
||||
});
|
||||
|
||||
$form.find('input[name$="-do_autodiscovery"]').change(function () {
|
||||
var $this = $(this);
|
||||
$this.closest('.panel').find(
|
||||
'.form-group .row').toggleClass('required', !($this.attr('checked')));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user