Merge "Needed auto-discovery modifications"

This commit is contained in:
Jenkins 2014-09-05 12:12:36 +00:00 committed by Gerrit Code Review
commit 053b7d1e94
6 changed files with 31 additions and 63 deletions

View File

@ -16,6 +16,7 @@ import django.forms
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
import horizon.forms
from tuskar_ui import api
import tuskar_ui.forms
@ -210,7 +211,7 @@ NodeFormset = django.forms.formsets.formset_factory(NodeForm, extra=1,
formset=BaseNodeFormset)
class AutoDiscoverNodeForm(django.forms.Form):
class AutoDiscoverNodeForm(horizon.forms.SelfHandlingForm):
id = django.forms.IntegerField(
label="",
required=False,
@ -233,27 +234,24 @@ class AutoDiscoverNodeForm(django.forms.Form):
'rows': 2,
}),
)
mac_addresses = tuskar_ui.forms.MultiMACField(
label=_("NIC MAC Addresses"),
widget=django.forms.Textarea(attrs={
'rows': '2',
}),
)
def get_name(self):
try:
name = self.fields['ssh_address'].value()
except AttributeError:
# when the field is not bound
name = _("Undefined node")
return name
class BaseAutoDiscoverNodeFormset(BaseNodeFormset):
def handle(self, request, data):
success = True
for form in self:
data = form.cleaned_data
try:
mac_addresses = data['mac_addresses'].split()
for mac_address in mac_addresses:
node = api.node.Node.create(
request,
ssh_address=data['ssh_address'],
ssh_username=data.get('ssh_username'),
ssh_key_contents=data.get('ssh_key_contents'),
mac_addresses=[mac_address],
driver='pxe_ssh'
)
api.node.Node.set_maintenance(request,
@ -268,12 +266,4 @@ class BaseAutoDiscoverNodeFormset(BaseNodeFormset):
# TODO(rdopieralski) Somehow find out if any port creation
# failed and remove the mac addresses that succeeded from
# the form.
else:
# TODO(rdopieralski) Remove successful nodes from formset.
pass
return success
AutoDiscoverNodeFormset = django.forms.formsets.formset_factory(
AutoDiscoverNodeForm, extra=1,
formset=BaseAutoDiscoverNodeFormset)

View File

@ -48,6 +48,7 @@ class ActivateNode(tables.BatchAction):
def action(self, request, obj_id):
api.node.Node.set_maintenance(request, obj_id, False)
api.node.Node.set_power_state(request, obj_id, 'off')
class SetPowerStateOn(tables.BatchAction):

View File

@ -4,11 +4,19 @@
{% block form_id %}auto_discover_nodes_form{% endblock %}
{% block form_action %}{% url 'horizon:infrastructure:nodes:auto-discover' %}{% endblock %}
{% block modal_id %}register_nodes_modal{% endblock %}
{% block modal_id %}auto_discover_nodes_modal{% endblock %}
{% block modal-header %}{% trans "Auto-Discover Nodes" %}{% endblock %}
{% block modal-body %}
{% include "formset_table/menu_formset.html" with formset=form form_template="infrastructure/nodes/_auto_discover_nodes_formset_form.html" %}
<div>
<p>{% trans "Autodiscover nodes." %}</p>
</div>
<div>
<fieldset>
{% include "horizon/common/_form_fields.html" %}
</fieldset>
</div>
{% endblock %}
{% block modal-footer %}

View File

@ -1,26 +0,0 @@
{% load i18n %}
<div class="well tab-pane{% if active %} active{% endif %}"
id="tab-{{ form.prefix }}">
<div class="form form-inline"><fieldset>
<div class="row">
<h5>{% trans 'Power Management' %}</h5>
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ssh_address %}
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ssh_username %}
{% include 'infrastructure/nodes/_nodes_formset_field.html' with field=form.ssh_key_contents %}
</div>
</fieldset></div>
</div>
<script type="text/javascript">
(window.$ || window.addHorizonLoadEvent)(function () {
var form_prefix = '{{ form.prefix|escapejs }}';
var $form = $('#tab-' + form_prefix);
var $nav_link = $('a[href="#' + $form.attr('id') + '"]');
var undefined_name = '{{ form.get_name|escapejs }}';
$form.find('input[name$="-ssh_address"]').change(function () {
$nav_link.html($(this).val() || undefined_name);
});
});
</script>

View File

@ -1,4 +1,4 @@
{% extends "base.html" %}
{% extends "infrastructure/base.html" %}
{% load i18n %}
{% block title %}{% trans "Auto-Discover Nodes" %}{% endblock %}

View File

@ -59,17 +59,12 @@ class RegisterView(horizon_forms.ModalFormView):
class AutoDiscoverView(horizon_forms.ModalFormView):
form_class = forms.AutoDiscoverNodeFormset
form_class = forms.AutoDiscoverNodeForm
form_prefix = 'auto_discover_nodes'
template_name = 'infrastructure/nodes/auto_discover.html'
success_url = reverse_lazy(
'horizon:infrastructure:nodes:index')
def get_form(self, form_class):
return form_class(self.request.POST or None,
initial=[],
prefix=self.form_prefix)
class DetailView(horizon_views.APIView):
template_name = 'infrastructure/nodes/details.html'