{% extends "layout.html" %}
{% from "_helper.html" import image_button %}g
{% block content %}

<script type="text/javascript">

function killall(cloud) {
	var answer = confirm("Delete all selected VMs in "+cloud+"?")
	if (answer){
		window.location = "/cm/delete/"+cloud+"/";
	}
}

</script>


<table>
  <tr>
    <th colspan="1"> Cloud Mesh </th>  
    <th colspan="7">
      {{ image_button ("none", "365_restart", "/table/") }}
      &nbsp;
      {{ image_button ("none", "041_charts", "/table/") }}
      &nbsp;     
      {{ image_button ("none", "044_keys", "/keys/" ) }}
      &nbsp;     
      {{ image_button ("none", "088_adress_book", "/profile/" ) }}

    </th>
    <th colspan="1">
      {{ image_button ("right", "016_bin", "/cm/kill/") }}
    </th>
  </tr>
  <tr> <td> Updated </td>  <td colspan=8> {{ updated }} </td></tr>
  <tr>
    <th> Name </th>
    <th> Login </th>
    <th> Info </th>
    <th> Get Ip </th>
    <th> Stats </th>
    <th> IDs </th>
    <th> Status </th>
    <th> ip </th>
  </tr>
  
  {% for name in order %}
  
  <tr> 
    <th colspan="1"> {{ name }}</th> 
    <th colspan="7">
      {{ image_button ("none", "365_restart", "/cm/refresh/" + name + "/") }}
      &nbsp;
      {{ image_button ("none", "190_circle_plus", "/cm/start/" + name +"/") }}
      &nbsp;
      {{ image_button ("none", "041_charts", "/table/") }}
      &nbsp;     
      {{ image_button ("none", "044_keys", "/updatekeypair/" + name + "/") }}
      &nbsp; &nbsp;
      <form name = "filter" action = "/cm/filter/{{name}}/" method="post">
      <input type="checkbox" name="ACTIVE" value="select" {{v(['table',name,'ACTIVE'])}}> ACTIVE &nbsp;
      <input type="checkbox" name="STOPPED" value="select" {{v(['table',name,'STOPPED'])}}> STOPPED &nbsp;
      <input type="checkbox" name="ERROR" value="select" {{v(['table',name,'ERROR'])}}> ERROR &nbsp;
      <input type="checkbox" name="SHUTOFF" value="select" {{v(['table',name,'SHUTOFF'])}}> SHUTOFF &nbsp;
      <input type="checkbox" name="ME" value="select" {{v(['table',name,'ME'])}}> ME &nbsp;
      <input type="submit" value="Filter">
      </form>
    </th>
    <th colspan="1">
      <input align="right" type="image" 
	     src="{{ url_for('static', filename='img/icons/png/glyphicons_016_bin.png') }}" 
	     onclick="killall('{{ name }}');"
	     width="16" height="16">
    </th>
    
  </tr>
  
  {% for id, server in clouds[name]['servers'].iteritems() %}
  
  <tr>
    <td> {{ server.name }} </td>
    <td> {{ server.cloud }}
      {{ image_button ("none", "368_collapse", "/cm/login/" + name + "/" + id + "/") }}
    </td>
    <td>
      {{ image_button ("right", "195_circle_info", "/cm/info/" + name + "/" + id + "/") }}
   </td>
     <td>      
	<a href="/cm/assignpubip/{{name}}/{{id}}/">  I.P. </a>
    </td>
   <td>
      {{ image_button ("none", "041_charts", "/cm/stats/" + name + "/" + id + "/") }}
    </td>
    <td> {{ server.id }} </td>
    <td> {{ server.status }} </td>
    <td> {{ server.addresses }} </td>
    <td>
      {{ image_button ("right", "016_bin", "/cm/delete/" + name + "/" + id + "/") }}
    </td>
  </tr>
  
  {% endfor %}
  
  {% endfor %}
  
</table>

{% endblock %}
