webee 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -19,6 +19,8 @@ Jeweler::Tasks.new do |gem|
19
19
  gem.add_runtime_dependency 'sax-machine'
20
20
  gem.add_runtime_dependency 'rest-client'
21
21
  gem.add_runtime_dependency 'nokogiri'
22
+ gem.add_runtime_dependency 'builder'
23
+ gem.add_runtime_dependency 'alchemist'
22
24
  gem.add_runtime_dependency 'activesupport'
23
25
  # gem.add_development_dependency 'rspec', '> 1.2.3'
24
26
  end
@@ -0,0 +1,89 @@
1
+ require 'rubygems'
2
+ $: << '../lib'
3
+ require 'webee'
4
+ require 'md5'
5
+ require 'alchemist'
6
+ require 'colorize'
7
+ require 'terminal-table/import'
8
+
9
+ include WeBee
10
+ Alchemist::use_si = true
11
+
12
+ WeBee::Api.user = ENV['user'] || 'admin'
13
+ WeBee::Api.password = ENV['pass'] || 'xabiquo'
14
+ WeBee::Api.url = "http://#{ENV['host']}/api"
15
+
16
+ stats = {
17
+ :free_hd => 0,
18
+ :real_hd => 0,
19
+ :used_hd => 0,
20
+ :hypervisors => 0,
21
+ :free_ram => 0,
22
+ :real_ram => 0,
23
+ :used_ram => 0,
24
+ :available_cpus => 0
25
+ }
26
+
27
+ Datacenter.all.each do |dc|
28
+ dc.racks.each do |rack|
29
+ puts "#" * 80
30
+ puts "Rack: #{rack.name} Datacenter: #{dc.name}"
31
+ rack.machines.each do |m|
32
+ puts "#" * 80
33
+ stats[:hypervisors] += 1
34
+ stats[:used_ram] += m.ram_used.to_i
35
+ stats[:real_ram] += m.real_ram.to_i
36
+ stats[:available_cpus] += m.real_cpu.to_i
37
+ stats[:used_hd] += m.hd_used.to_i.bytes.to.gigabytes.to_f.round
38
+ stats[:real_hd] += m.real_hd.to_i.bytes.to.gigabytes.to_f.round
39
+ ds_table = table do |t|
40
+ t.headings = "Datastores"
41
+ m.datastores.each do |ds|
42
+ t << ["Name: ".light_yellow,"#{ds.name}"]
43
+ t << ["Enabled: ".light_yellow,"#{ds.enabled}"]
44
+ t << ["Size: ".light_yellow,"#{ds.size.to_i.bytes.to.gigabytes.to_i} GB"]
45
+ t << ["Used Size: ".light_yellow,"#{ds.used_size.to_i.bytes.to.gigabytes.to_i} GB"]
46
+ end
47
+ end
48
+ user_table = table do
49
+ self.headings = " #{m.name.upcase.light_green}"
50
+ add_row ["IP:".light_yellow, "#{m.ip}"]
51
+ add_row ["CPUs:".light_yellow, "#{m.real_cpu}"]
52
+ add_row ["State:".light_yellow, "#{m.state}"]
53
+ add_row ["Hypervisor Type:".light_yellow,"#{m.hypervisortype}"]
54
+ add_row ["RAM:".light_yellow,"#{m.real_ram.to_i} MB"]
55
+ add_row ["RAM Used:".light_yellow,"#{m.ram_used.to_i} MB"]
56
+ add_row ["RAM Free:".light_yellow,"#{m.real_ram.to_i - m.ram_used.to_i} MB"]
57
+ add_row ["HD Size:".light_yellow,"#{m.real_hd.to_i.bytes.to.gigabytes.to_i} GB"]
58
+ add_row ["HD Used:".light_yellow,"#{m.hd_used.to_i.bytes.to.gigabytes.to_i} GB"]
59
+ add_row ["HD Free:".light_yellow,"#{(m.real_hd.to_i - m.hd_used.to_i).bytes.to.gigabytes.to_i} GB"]
60
+ add_row ["CPU Used:".light_yellow,"#{m.cpu_used.to_i}"]
61
+ end
62
+ puts user_table
63
+ puts ds_table
64
+ puts "#" * 80
65
+ puts "\n\n"
66
+ end
67
+ end
68
+ end
69
+
70
+ stats[:free_ram] = stats[:real_ram] - stats[:used_ram]
71
+ stats[:free_hd] = stats[:real_hd] - stats[:used_hd]
72
+
73
+ puts "\n"
74
+ puts "#" * 80
75
+ puts "Cloud Stats"
76
+ puts "#" * 80
77
+ user_table = table do
78
+ self.headings = ['Cloud Statistics']
79
+ add_row ["Hypevisors:".light_yellow, "#{stats[:hypervisors]}"]
80
+ add_row ["Available CPUs:".light_yellow, "#{stats[:available_cpus]}"]
81
+ add_row ["Total RAM:".light_yellow,"#{stats[:real_ram].megabytes.to.gigabytes} GB"]
82
+ add_row ["Free RAM:".light_yellow,"#{stats[:free_ram].megabytes.to.gigabytes} GB"]
83
+ add_row ["Used RAM:".light_yellow,"#{stats[:used_ram].megabytes.to.gigabytes} GB"]
84
+ add_row ["Total HD:".light_yellow, "#{stats[:real_hd]} GB"]
85
+ add_row ["Free HD:".light_yellow, "#{stats[:free_hd]} GB"]
86
+ add_row ["Used HD:".light_yellow, "#{stats[:used_hd]} GB"]
87
+ end
88
+ puts user_table
89
+ puts "#" * 80
data/examples/test2.rb CHANGED
@@ -1,12 +1,75 @@
1
1
  $: << '../lib'
2
2
  require 'webee'
3
3
  require 'md5'
4
- require 'active_support'
4
+ require 'alchemist'
5
+ require 'colorize'
5
6
  include WeBee
7
+ Alchemist::use_si = true
6
8
 
7
9
  WeBee::Api.user = ENV['user'] || 'admin'
8
10
  WeBee::Api.password = ENV['pass'] || 'xabiquo'
9
- WeBee::Api.url = 'http://10.60.1.24/api'
11
+ WeBee::Api.url = 'http://mothership/api'
12
+
13
+ stats = {
14
+ :free_hd => 0,
15
+ :real_hd => 0,
16
+ :used_hd => 0,
17
+ :hypervisors => 0,
18
+ :free_ram => 0,
19
+ :real_ram => 0,
20
+ :used_ram => 0,
21
+ :available_cpus => 0
22
+ }
23
+
24
+ Datacenter.all.each do |dc|
25
+ banner = "\n***** Datacenter (#{dc.name}) ******\n\n"
26
+ puts "*" * banner.size
27
+ puts banner
28
+ puts "*" * banner.size
29
+ dc.racks.each do |rack|
30
+ puts "Rack: #{rack.name}"
31
+ rack.machines.each do |m|
32
+ stats[:hypervisors] += 1
33
+ stats[:used_ram] += m.ram_used.to_i
34
+ stats[:real_ram] += m.real_ram.to_i
35
+ stats[:available_cpus] += m.real_cpu.to_i
36
+ stats[:used_hd] += m.hd_used.to_i.bytes.to.gigabytes.to_f.round
37
+ stats[:real_hd] += m.real_hd.to_i.bytes.to.gigabytes.to_f.round
38
+ puts " #{m.name.green}"
39
+ puts " IP: #{m.ip}"
40
+ puts " CPUs: #{m.real_cpu}"
41
+ puts " State: #{m.state}"
42
+ puts " Type: #{m.hypervisortype}"
43
+ puts " RAM: #{m.real_ram.to_i} MB"
44
+ puts " RAM Used: #{m.ram_used.to_i} MB"
45
+ puts " RAM Free: #{m.real_ram.to_i - m.ram_used.to_i} MB"
46
+ puts " HD Size: #{m.real_hd.to_i.bytes.to.gigabytes.to_i} GB"
47
+ puts " HD Used: #{m.hd_used.to_i.bytes.to.gigabytes.to_i} GB"
48
+ puts " HD Free: #{(m.real_hd.to_i - m.hd_used.to_i).bytes.to.gigabytes.to_i} GB"
49
+ puts " CPU Used: #{m.cpu_used.to_i}"
50
+ puts " Datastores:"
51
+ m.datastores.each do |ds|
52
+ puts " Name: #{ds.name}"
53
+ puts " Enabled: #{ds.enabled}"
54
+ puts " Size: #{ds.size.to_i.bytes.to.gigabytes.to_i} GB"
55
+ puts " Used Size: #{ds.used_size.to_i.bytes.to.gigabytes.to_i} GB"
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ stats[:free_ram] = stats[:real_ram] - stats[:used_ram]
62
+ stats[:free_hd] = stats[:real_hd] - stats[:used_hd]
63
+
64
+ puts "\n\n------------------------------------"
65
+ puts " Cloud Statistics"
66
+ puts "------------------------------------"
67
+ puts "Hypevisors: #{stats[:hypervisors]}"
68
+ puts "Available CPUs: #{stats[:available_cpus]}"
69
+ puts "Total RAM: #{stats[:real_ram].megabytes.to.gigabytes} GB"
70
+ puts "Free RAM: #{stats[:free_ram].megabytes.to.gigabytes} GB"
71
+ puts "Used RAM: #{stats[:used_ram].megabytes.to.gigabytes} GB"
72
+ puts "Total HD: #{stats[:real_hd]} GB"
73
+ puts "Free HD: #{stats[:free_hd]} GB"
74
+ puts "Used HD: #{stats[:used_hd]} GB"
10
75
 
11
- require 'pp'
12
- pp VDC.all :datacenter_id => 2, :enterprise_id => 3
data/lib/webee.rb CHANGED
@@ -28,7 +28,7 @@ end
28
28
 
29
29
  module WeBee
30
30
 
31
- VERSION = '0.2'
31
+ VERSION = '0.2.1'
32
32
 
33
33
 
34
34
  module RestResource
@@ -373,8 +373,8 @@ module WeBee
373
373
  element :password
374
374
  element :user
375
375
  element :realCpu, :as => :real_cpu
376
- element :realHd, :as => :real_hd
377
- element :realRam, :as => :real_ram
376
+ element :realHd, :as => :real_hd # in Bytes
377
+ element :realRam, :as => :real_ram # in MB
378
378
  element :state
379
379
  element :type, :as => :hypervisortype
380
380
  element :cpu
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webee
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- version: "0.2"
9
+ - 1
10
+ version: 0.2.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Sergio Rubio
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-09-08 00:00:00 Z
18
+ date: 2011-09-09 00:00:00 Z
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
20
21
  name: sax-machine
@@ -59,7 +60,7 @@ dependencies:
59
60
  type: :runtime
60
61
  version_requirements: *id003
61
62
  - !ruby/object:Gem::Dependency
62
- name: activesupport
63
+ name: builder
63
64
  prerelease: false
64
65
  requirement: &id004 !ruby/object:Gem::Requirement
65
66
  none: false
@@ -72,6 +73,34 @@ dependencies:
72
73
  version: "0"
73
74
  type: :runtime
74
75
  version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: alchemist
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :runtime
89
+ version_requirements: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ name: activesupport
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ type: :runtime
103
+ version_requirements: *id006
75
104
  description: Abiquo API Ruby Implementation
76
105
  email: sergio@rubio.name
77
106
  executables:
@@ -88,6 +117,7 @@ files:
88
117
  - Rakefile
89
118
  - bin/webee
90
119
  - examples/basics.rb
120
+ - examples/list_hypervisors.rb
91
121
  - lib/webee.rb
92
122
  - lib/webee/command.rb
93
123
  - lib/webee/commands/appslib.rb
@@ -133,6 +163,7 @@ specification_version: 3
133
163
  summary: Abiquo API Ruby Implementation
134
164
  test_files:
135
165
  - examples/basics.rb
166
+ - examples/list_hypervisors.rb
136
167
  - examples/test.rb
137
168
  - examples/test2.rb
138
169
  - test/helper.rb