Class: CpOraclecloud::AdminController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/cp_oraclecloud/admin_controller.rb

Instance Method Summary collapse

Instance Method Details

#dashboardObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/cp_oraclecloud/admin_controller.rb', line 2

def dashboard
	@ssh_keys = policy_scope(CpOraclecloud::SshKey)
	@images = policy_scope(CpOraclecloud::Image)
	@instances = CloudInstance.eager_load(environment: :project).where("type LIKE :prefix", prefix: "CpOraclecloud%")

	@totals = {
		:database => {:total => 0, :cost=>0},
		:java => {:total => 0, :cost=>0},
		:soa => {:total => 0, :cost=>0},
		:compute => {:total => 0, :cost=>0}
	}
	@instances.each do |i|
		key = nil
		case i.type
		when "CpOraclecloud::DatabaseInstance"
			key = :database
		when "CpOraclecloud::JavaInstance"
			key = :java
		when "CpOraclecloud::SoaInstance"
			key = :soa
		when "CpOraclecloud::ComputeInstance"
			key = :compute
		end
		if key 
			@totals[key.to_sym][:total] += 1	
			@totals[key.to_sym][:cost] += i.calc_cost(i.environment.start_date, i.environment.end_date)
		end
	end
end