{% load parse_date %}
{% load i18n%}
<table id="instances" class="zebra-striped">
  <tr>
    <th>{% trans "Name"%}</th>
    <th>{% trans "Tenant"%}</th>
    <th>{% trans "User"%}</th>
    <th>{% trans "Host"%}</th>
    <th>{% trans "Created"%}</th>
    <th>{% trans "Image"%}</th>
    <th>{% trans "IPs"%}</th>
    <th>{% trans "State"%}</th>
    <th>{% trans "Actions"%}</th>
  </tr>
  {% for instance in instances %}
    <tr id="{{instance.id}}" class="{% cycle "odd" "even" %}">
      <td><a href="{% url horizon:syspanel:instances:detail instance.id %}">{{instance.name}} <small>(id: {{instance.id}})</small></a></td>
      <td>{{instance.attrs.tenant_id}}</td>
      <td>{{instance.attrs.user_id}}</td>
      <td class="name">{{instance.attrs.host}}</td>
      <td>{{instance.attrs.launched_at|parse_date}}</td>
      <td>{{instance.image_name}}</td>

      <td class="ip_list">
        {% for ip_group, addresses in instance.addresses.items %}
          {% if instance.addresses.items|length > 1 %}
          <h4>{{ip_group}}</h4>
          <ul>
            {% for address in addresses %}
              <li>{{address.addr}}</li>
            {% endfor %}
          </ul>
          {% else %}
          <ul>
            {% for address in addresses %}
              <li>{{address.addr}}</li>
            {% endfor %}
          </ul>
          {% endif %}
        {% endfor %}
      </td>

      <td>{{instance.status|lower|capfirst}}</td>
      <td id="actions">
        <ul>
          <li class="form">{% include "syspanel/instances/_terminate.html" with form=terminate_form %}</li>
          <li class="form">{% include "syspanel/instances/_reboot.html" with form=reboot_form %}</li>
          <li><a class="btn small" target="_blank" href="{% url horizon:nova:instances:console instance.id %}">{% trans "Console Log"%}</a></li>
          <li><a class="btn small" target="_blank" href="{% url horizon:nova:instances:vnc instance.id %}">{% trans "VNC Console"%}</a></li>
        </ul>
      </td>
    </tr>
  {% endfor %}
</table>
