{% extends "dashboard/operate.html" %}
{% load i18n %}
{% load sizefieldtags %}
{% load crispy_forms_tags %}

{% block question %}
<p>
{% blocktrans with obj=object op=op.name %}
Choose a compute node to migrate {{obj}} to.
{% endblocktrans %}
</p>
<p class="text-info">{{op.name}}: {{op.description}}</p>
{% endblock %}

{% block formfields %}
  <ul id="vm-migrate-node-list" class="list-unstyled">
  {% with current=object.node.pk recommended=form.fields.to_node.initial.pk %}
    {% for n in form.fields.to_node.queryset.all %}
      <li class="panel panel-default"><div class="panel-body">
        <label for="migrate-to-{{n.pk}}">
          <strong>{{ n }}</strong>
          <div class="label label-primary">
            <i class="fa {{n.get_status_icon}}"></i> {{n.get_status_display}}</div>
          {% if current == n.pk %}<div class="label label-info">{% trans "current" %}</div>{% endif %}
          {% if recommended == n.pk %}<div class="label label-success">{% trans "recommended" %}</div>{% endif %}
          {% if n.pk not in nodes_w_traits %}
            <div class="label label-warning">
              <i class="fa fa-warning"></i>
              {% trans "missing traits" %}</div>
          {% endif %}
        </label>
        <input id="migrate-to-{{n.pk}}" type="radio" name="to_node" value="{{ n.pk }}" style="float: right;"
          {% if current == n.pk %}disabled="disabled"{% endif %}
          {% if recommended == n.pk and n.pk != current %}checked="checked"{% endif %}
        />
        {% if n.pk not in nodes_w_traits %}
          <span class="vm-migrate-node-property">
            {% trans "Node traits" %}:
            {% if n.traits.all %}
              {{ n.traits.all|join:", " }}
            {% else %}
              -
            {% endif %}
          </span>
          <span class="vm-migrate-node-property">
            {% trans "Required traits" %}:
            {% if object.req_traits.all %}
              {{ object.req_traits.all|join:", " }}
            {% else %}
              -
            {% endif %}
          </span>
          <hr />
        {% endif %}
        <span class="vm-migrate-node-property">{% trans "CPU load" %}: {{ n.cpu_usage }}</span>
        <span class="vm-migrate-node-property">
          {% trans "RAM usage" %}: {{ n.byte_ram_usage|filesize }}/{{ n.ram_size|filesize }}</span>
        <div style="clear: both;"></div>
      </li>
    {% endfor %}
  {% endwith %}
  </ul>
  {{ form.live_migration|as_crispy_field }}
{% endblock %}
