webee 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/examples/test.rb +3 -17
  2. data/lib/webee.rb +77 -3
  3. metadata +4 -4
@@ -5,25 +5,11 @@ require 'active_support'
5
5
 
6
6
  WeBee::Api.user = ENV['user'] || 'admin'
7
7
  WeBee::Api.password = ENV['pass'] || 'xabiquo'
8
- WeBee::Api.url = 'http://10.60.1.24/api'
8
+ WeBee::Api.url = 'http://mothership/api'
9
9
 
10
10
  include WeBee
11
11
 
12
12
  dc = Datacenter.all.first
13
- ent = Enterprise.all.first
14
- puts ent.name
15
- rack = dc.racks.first
16
-
17
- #machine = dc.discover_machine :ip => '10.60.1.24', :hypervisortype => 'kvm'
18
- # Use the first virtual switch we find
19
- #machine.virtual_switch = machine.virtual_switches.first
20
- # Enable the first datastore found
21
- #machine.datastores.first.enabled = true
22
- # Add the hypervisor to the rack
23
- #rack.add_machine(machine)
24
- user = Enterprise.all.first.users.first
25
-
26
- user.virtual_mathines.each do
13
+ dc.find_vms_by_name('1dee').each do |vm|
14
+ puts vm.raw
27
15
  end
28
-
29
-
@@ -6,6 +6,7 @@ require 'active_support/core_ext/hash'
6
6
  require 'uri'
7
7
  require 'json'
8
8
  require 'builder'
9
+ require 'alchemist'
9
10
 
10
11
  #
11
12
  # Monkeypatch SAXMachine to keep the raw XMK
@@ -28,7 +29,7 @@ end
28
29
 
29
30
  module WeBee
30
31
 
31
- VERSION = '0.3.4'
32
+ VERSION = '0.3.5'
32
33
 
33
34
  module RestResource
34
35
 
@@ -163,6 +164,43 @@ module WeBee
163
164
  element :vlanHard, :as => :vlan_hard
164
165
  element :location
165
166
 
167
+ #
168
+ # Return Datacenter Statistics
169
+ # RAM in MB
170
+ # HD in GB
171
+ #
172
+ def stats
173
+ s = {
174
+ :free_hd => 0,
175
+ :real_hd => 0,
176
+ :used_hd => 0,
177
+ :machines => 0,
178
+ :free_ram => 0,
179
+ :real_ram => 0,
180
+ :used_ram => 0,
181
+ :real_cpus => 0,
182
+ :virtual_machines => 0,
183
+ }
184
+ Datacenter.all.each do |dc|
185
+ dc.racks.each do |rack|
186
+ rack.machines.each do |m|
187
+ s[:machines] += 1
188
+ s[:used_ram] += m.ram_used.to_i
189
+ s[:real_ram] += m.real_ram.to_i
190
+ s[:real_cpus] += m.real_cpu.to_i
191
+ s[:used_hd] += m.hd_used.to_i.bytes.to.gigabytes.to_f.round
192
+ s[:real_hd] += m.real_hd.to_i.bytes.to.gigabytes.to_f.round
193
+ m.virtual_machines.each do |vm|
194
+ s[:virtual_machines] += 1
195
+ end
196
+ end
197
+ end
198
+ end
199
+ s[:free_ram] = s[:real_ram] - s[:used_ram]
200
+ s[:free_hd] = s[:real_hd] - s[:used_hd]
201
+ return s
202
+ end
203
+
166
204
  def self.create(attributes)
167
205
  if attributes[:remote_services].nil?
168
206
  attributes[:remote_services] = WeBee::RemoteService.create_for_host(Api.host)
@@ -233,6 +271,24 @@ module WeBee
233
271
  machine = Machine.parse res
234
272
  end
235
273
 
274
+ #
275
+ # Find a WeBee::VirtualMachine by name in this
276
+ # Datacenter.
277
+ #
278
+ # returns a WeBee::VirtualMachine
279
+ #
280
+ def find_vms_by_name(regexp)
281
+ matches = []
282
+ self.racks.each do |rack|
283
+ rack.machines.each do |m|
284
+ m.virtual_machines.each do |vm|
285
+ matches << vm if vm.name =~ /#{regexp}/i
286
+ end
287
+ end
288
+ end
289
+ matches
290
+ end
291
+
236
292
  end
237
293
 
238
294
  class RemoteService
@@ -443,6 +499,14 @@ module WeBee
443
499
  items
444
500
  end
445
501
 
502
+ def find_vms_by_name(name)
503
+ matches = []
504
+ self.virtual_machines.each do |vm|
505
+ matches << vm if vm.name =~ /#{regexp}/i
506
+ end
507
+ matches
508
+ end
509
+
446
510
  end
447
511
 
448
512
  class RemoteServiceType
@@ -886,10 +950,11 @@ module WeBee
886
950
  element :idType, :as => :id_type
887
951
  element :link, :value => :href, :as => :vdc_url, :with => {:rel => "virtualdatacenter" }
888
952
  element :link, :value => :href, :as => :enterprise_url, :with => {:rel => "enterprise" }
953
+ element :link, :value => :href, :as => :machine_url, :with => {:rel => "machine" }
954
+ element :link, :value => :href, :as => :user_url, :with => {:rel => "user" }
889
955
 
890
956
  def vdc
891
957
  return nil if not managed?
892
- # FIXME: Buggy Abiquo ABI missing some relations
893
958
  doc = Nokogiri.parse(RestClient.get(Api.build_url(vdc_url) , :accept => :xml))
894
959
  Rack.parse doc.root.to_s
895
960
  end
@@ -900,11 +965,20 @@ module WeBee
900
965
 
901
966
  def enterprise
902
967
  return nil if not managed?
903
- # FIXME: Buggy Abiquo ABI missing some relations
904
968
  doc = Nokogiri.parse(RestClient.get(Api.build_url(enterprise_url) , :accept => :xml))
905
969
  Enterprise.parse doc.root.to_s
906
970
  end
907
971
 
972
+ def machine
973
+ doc = Nokogiri.parse(RestClient.get(Api.build_url(machine_url) , :accept => :xml))
974
+ Machine.parse doc.root.to_s
975
+ end
976
+
977
+ def user
978
+ doc = Nokogiri.parse(RestClient.get(Api.build_url(user_url) , :accept => :xml))
979
+ User.parse doc.root.to_s
980
+ end
981
+
908
982
  end
909
983
 
910
984
  class UserRole
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webee
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
9
+ - 5
10
+ version: 0.3.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sergio Rubio
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-14 00:00:00 Z
18
+ date: 2011-09-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: sax-machine