Skip to content

Commit

Permalink
add host details page #28
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lindner committed Nov 20, 2018
1 parent ee491b8 commit 45dde53
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/api/vmapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def get_host(name)
return host
end
end
nil
end


Expand Down
2 changes: 1 addition & 1 deletion app/controllers/vm_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def show
end

def show_host
@host = VmApi.new.get_host(params[:id])
@host = VmApi.new.get_host(params[:id].gsub '%2E', '.')
end

# This controller doesn't use strong parameters
Expand Down
9 changes: 4 additions & 5 deletions app/views/vm/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<h1>
Virtual Machine "<%= @vm[:name]%>"
<small class="text-muted">This is the details page for the VM</small>
Detail for Virtual Machine "<%= @vm[:name]%>"
</h1>

<table class="table">
Expand All @@ -23,14 +22,14 @@
<tr>
<td>Host:</td>
<td>
<%= link_to @vm[:host], controller: "vm", action: "show_host", id: @vm[:host] %>
<%= link_to @vm[:host], controller: "vm", action: "show_host", id: (@vm[:host].gsub '.', '%2E') %>
</td>

<%
committed = @vm[:summary].storage.committed
uncommitted = @vm[:summary].storage.uncommitted
committed_mb = committed / (8 * (1024 ** 2))
uncommitted_mb = uncommitted / (8 * (1024 ** 2))
committed_mb = committed / (1024 ** 2)
uncommitted_mb = uncommitted / (1024 ** 2)
total_mb = committed_mb + uncommitted_mb
total = committed + uncommitted
space_usage_percentage = 0
Expand Down
88 changes: 87 additions & 1 deletion app/views/vm/show_host.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,87 @@
test
<h1>
Details for Host "<%= @host[:name]%>"
</h1>

<table class="table">
<tbody>
<tr>
<td>Vendor:</td>
<td><%= @host[:vendor]%></td>
</tr>

<tr>
<td>Model:</td>
<td><%= @host[:model] %></td>
</tr>

<tr>
<td>Boot time:</td>
<td><%= @host[:bootTime] %> </td>
</tr>

<tr>
<td>Power state:</td>
<td><%= @host[:summary].runtime.powerState %> </td>
</tr>

<tr>
<td>Connection state:</td>
<td><%= @host[:connectionState] %> </td>
</tr>

<tr>
<td>OS:</td>
<td><%= @host[:summary].config.product.osType %> (<%= @host[:summary].config.product.fullName %>)</td>
</tr>

<tr>
<td>CPU model:</td>
<td><%= @host[:summary].hardware.cpuModel %> </td>
</tr>

<tr>
<td>CPU Cores, Threads:</td>
<td><%= @host[:summary].hardware.numCpuCores %>, <%= @host[:summary].hardware.numCpuThreads %></td>
</tr>

<%
cpu_usage = @host[:summary].quickStats.overallCpuUsage
cpu_allocation = @host[:summary].hardware.numCpuCores * @host[:summary].hardware.cpuMhz
memory_allocation = @host[:summary].hardware.memorySize / (1024 ** 2)
memory_usage = @host[:summary].quickStats.overallMemoryUsage
memory_usage_percentage = 0
cpu_usage_percentage = 0


if cpu_allocation != 0
cpu_usage_percentage = (cpu_usage / cpu_allocation.to_f * 100).round()
end

if memory_allocation != 0
memory_usage_percentage = (memory_usage / memory_allocation.to_f * 100).round()
end
%>

<tr>
<td>CPU usage:</td>
<td><%= cpu_usage_percentage %> %</td>
</tr>

<tr>
<td>Memory Usage:</td>
<td><%= memory_usage_percentage %> % (<%= memory_usage %> / <%= memory_allocation %> MB)</td>
</tr>

<tr>
<td>VMs:</td>
<td>
<% @host[:vm_names].each do |vm| %>
<%= link_to vm, controller: "vm", action: "show", id: vm %>
<br />
<% end %>
</td>
</tr>

</tbody>
</table>

11 changes: 11 additions & 0 deletions spec/views/vm/show_host.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
RSpec.describe 'vm/show_host.html.erb', type: :view do
let(:host) do
summary = double
allow(summary).to receive_message_chain(:runtime, :powerState)
allow(summary).to receive_message_chain(:config, :product, :osType)
allow(summary).to receive_message_chain(:config, :product, :fullName)
allow(summary).to receive_message_chain(:hardware, :cpuModel)
allow(summary).to receive_message_chain(:hardware, :numCpuCores).and_return(0)
allow(summary).to receive_message_chain(:hardware, :numCpuThreads).and_return(0)
allow(summary).to receive_message_chain(:hardware, :cpuMhz).and_return(0)
allow(summary).to receive_message_chain(:hardware, :memorySize).and_return(0)
allow(summary).to receive_message_chain(:quickStats, :overallMemoryUsage).and_return(0)
allow(summary).to receive_message_chain(:quickStats, :overallCpuUsage).and_return(0)

{ name: 'aHost',
vm_names: ['vm'],
model: "a cool model",
Expand Down

0 comments on commit 45dde53

Please sign in to comment.