Browse Source

get node counts

Chris Mague 7 years ago
parent
commit
518b9cff88
2 changed files with 5 additions and 1 deletions
  1. 3 1
      lib/neoinfra/vpcs.rb
  2. 2 0
      web/views/view_vpcs.html.erb

+ 3 - 1
lib/neoinfra/vpcs.rb

@@ -20,7 +20,9 @@ module NeoInfra
     end
 
     def list_vpcs
-      Vpc.all.collect{|x| {'vpc_id' => x.vpc_id, 'name'=>x.name, 'region' => x.region.region, 'owner' => x.owned.name, 'cidr' => x.cidr, 'default' => x.default} }.select{ |y| y['default'] == "false"}      
+      node_counts = Hash.new(0)
+      Node.all.each{|x| node_counts[x.subnet.subnet.name]+=1}
+      Vpc.all.collect{|x| {'nodes' => node_counts[x.name], 'vpc_id' => x.vpc_id, 'name'=>x.name, 'region' => x.region.region, 'owner' => x.owned.name, 'cidr' => x.cidr, 'default' => x.default} }.select{ |y| y['default'] == "false"}.sort_by{|h| h['nodes']}.reverse
     end
 
     def load

+ 2 - 0
web/views/view_vpcs.html.erb

@@ -5,6 +5,7 @@
     <thead>
       <tr>
         <th>Name</th>
+        <th>Nodes</th>
         <th>Account</th>
         <th>Region</th>
         <th>CIDR</th>
@@ -16,6 +17,7 @@
 <% vpcs.each do |vpc| %>
 <tr>
 <td><%= vpc['name'] %></td>
+<td><%= vpc['nodes'] %></td>
 <td><%= vpc['owner'] %></td>
 <td><%= vpc['region'] %></td>
 <td><%= vpc['cidr'] %></td>