Class: CloudstackStats::Collect

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudstack_stats/collect.rb

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Collect

Returns a new instance of Collect.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cloudstack_stats/collect.rb', line 8

def initialize(settings)
  @settings = settings.dup
  @config = if @settings[:cloudstack_url] &&
    @settings[:cloudstack_api_key] &&
    @settings[:cloudstack_secret_key]
    {
      url: @settings[:cloudstack_url],
      api_key: @settings[:cloudstack_api_key],
      secret_key: @settings[:cloudstack_secret_key]
    }
  else
    @settings[:config_file] = @settings[:cloudstack_config]
    CloudstackClient::Configuration.load(@settings)
  end
  @cs ||= CloudstackClient::Client.new(
    @config[:url],
    @config[:api_key],
    @config[:secret_key]
  )
  @cs.debug = true if @settings[:debug]
  @cs
end

Instance Method Details

#account_statsObject



31
32
33
34
35
36
# File 'lib/cloudstack_stats/collect.rb', line 31

def 
  {
    type: "account",
    stats: @cs.list_accounts(client_options)
  }
end

#project_statsObject



38
39
40
41
42
43
# File 'lib/cloudstack_stats/collect.rb', line 38

def project_stats
  {
    type: "project",
    stats: @cs.list_projects(client_options)
  }
end