webee 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/examples/bootstrap.rb +37 -0
- data/examples/test.rb +4 -2
- data/examples/top_abusers.rb +28 -0
- data/lib/webee.rb +24 -3
- metadata +8 -4
@@ -0,0 +1,37 @@
|
|
1
|
+
$: << '../lib'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'webee'
|
4
|
+
require 'md5'
|
5
|
+
|
6
|
+
CIAB_IP = ENV['host'] || '127.0.0.1'
|
7
|
+
|
8
|
+
WeBee::Api.user = ENV['user'] || 'admin'
|
9
|
+
WeBee::Api.password = ENV['pass'] || 'xabiquo'
|
10
|
+
WeBee::Api.url = "http://#{ENV['host'] || 'abiquo'}/api"
|
11
|
+
|
12
|
+
#
|
13
|
+
# Add a license
|
14
|
+
#
|
15
|
+
license_file = ARGV[0]
|
16
|
+
if license_file.nil? or (not File.exist?(license_file))
|
17
|
+
$stderr.puts "Invalid license file"
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
WeBee::Config.add_license File.read(license_file).strip.chomp
|
21
|
+
|
22
|
+
dc = WeBee::Datacenter.create :name => 'BCN'
|
23
|
+
ent = WeBee::Enterprise.all.first
|
24
|
+
ent.set_limits_for_datacenter dc
|
25
|
+
|
26
|
+
rack = dc.add_rack :name => 'rack_1',
|
27
|
+
:ha_enabled => false,
|
28
|
+
:vlan_min_id => 100,
|
29
|
+
:vlan_max_id => 2048,
|
30
|
+
:vlan_per_vdc_expected => 6,
|
31
|
+
:nrsq => 80
|
32
|
+
|
33
|
+
machine = dc.discover_machine :ip => CIAB_IP, :hypervisortype => 'kvm'
|
34
|
+
machine.virtual_switch = machine.virtual_switches.first
|
35
|
+
machine.datastores.first.enabled = true
|
36
|
+
rack.add_machine(machine)
|
37
|
+
vdc = ent.create_vdc :name => 'kvm-vdc', :hypervisortype => 'KVM', :datacenter => dc
|
data/examples/test.rb
CHANGED
@@ -21,6 +21,8 @@ rack = dc.racks.first
|
|
21
21
|
#machine.datastores.first.enabled = true
|
22
22
|
# Add the hypervisor to the rack
|
23
23
|
#rack.add_machine(machine)
|
24
|
-
|
25
|
-
|
24
|
+
user = Enterprise.all.first.users.first
|
25
|
+
|
26
|
+
puts user.enterprise
|
27
|
+
|
26
28
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$: << '../lib'
|
2
|
+
require 'webee'
|
3
|
+
require 'md5'
|
4
|
+
require 'active_support'
|
5
|
+
|
6
|
+
WeBee::Api.user = ENV['user'] || 'admin'
|
7
|
+
WeBee::Api.password = ENV['pass'] || 'xabiquo'
|
8
|
+
WeBee::Api.url = 'http://server/api'
|
9
|
+
|
10
|
+
include WeBee
|
11
|
+
|
12
|
+
abusers = {}
|
13
|
+
|
14
|
+
Enterprise.all.each do |ent|
|
15
|
+
ent.users.each do |user|
|
16
|
+
abusers[user.name] = { :full_name => "#{user.name} #{user.surname}", :email => user.email, :vms => user.virtual_machines.size }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
abusers = abusers.sort do |a,b|
|
21
|
+
a[1][:vms] <=> b[1][:vms]
|
22
|
+
end.reverse
|
23
|
+
|
24
|
+
abusers.each do |a|
|
25
|
+
if a[1][:vms] > 0
|
26
|
+
puts "User: #{a[1][:full_name]}".ljust(40) + "VMs: #{a[1][:vms]}"
|
27
|
+
end
|
28
|
+
end
|
data/lib/webee.rb
CHANGED
@@ -28,7 +28,7 @@ end
|
|
28
28
|
|
29
29
|
module WeBee
|
30
30
|
|
31
|
-
VERSION = '0.3.
|
31
|
+
VERSION = '0.3.2'
|
32
32
|
|
33
33
|
module RestResource
|
34
34
|
|
@@ -725,7 +725,9 @@ module WeBee
|
|
725
725
|
col = []
|
726
726
|
doc = Nokogiri.parse(RestClient.get(Api.url + "/admin/enterprises/#{resource_id}/users"))
|
727
727
|
doc.search('//user').each do |node|
|
728
|
-
|
728
|
+
user = User.parse(node.to_s)
|
729
|
+
col << user
|
730
|
+
user.enterprise_id = resource_id
|
729
731
|
end
|
730
732
|
col
|
731
733
|
end
|
@@ -783,6 +785,9 @@ module WeBee
|
|
783
785
|
element :nick
|
784
786
|
element :active
|
785
787
|
element :id, :as => :user_id
|
788
|
+
element :link, :value => :href, :as => :virtual_machines_url, :with => {:title => "virtualmachines" }
|
789
|
+
element :link, :value => :href, :as => :enterprise_url, :with => {:rel => "enterprise" }
|
790
|
+
element :link, :value => :href, :as => :roles_url, :with => {:rel => "role" }
|
786
791
|
|
787
792
|
#
|
788
793
|
# May raise exception if request is not successful
|
@@ -827,11 +832,27 @@ module WeBee
|
|
827
832
|
u = []
|
828
833
|
doc = Nokogiri.parse(RestClient.get(Api.url + "/admin/enterprises/#{enterprise_id}/users"))
|
829
834
|
doc.search('//user').each do |node|
|
830
|
-
|
835
|
+
user = User.parse(node.to_s)
|
836
|
+
u << user
|
837
|
+
user.enterprise_id = enterprise_id
|
831
838
|
end
|
832
839
|
u
|
833
840
|
end
|
834
841
|
|
842
|
+
def virtual_machines
|
843
|
+
items = []
|
844
|
+
doc = Nokogiri.parse(RestClient.get(Api.url + "/admin/enterprises/#{enterprise_id}/users/#{user_id}/action/virtualmachines" , :accept => :xml))
|
845
|
+
doc.search('//virtualMachine').each do |node|
|
846
|
+
items << VirtualMachine.parse(node.to_s)
|
847
|
+
end
|
848
|
+
items
|
849
|
+
end
|
850
|
+
|
851
|
+
def enterprise
|
852
|
+
doc = Nokogiri.parse(RestClient.get(Api.url + "/admin/enterprises/#{enterprise_id}" , :accept => :xml))
|
853
|
+
Enterprise.parse doc.root.to_s
|
854
|
+
end
|
855
|
+
|
835
856
|
end
|
836
857
|
|
837
858
|
class VirtualMachine
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
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-
|
18
|
+
date: 2011-09-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: sax-machine
|
@@ -131,7 +131,9 @@ files:
|
|
131
131
|
- Rakefile
|
132
132
|
- bin/webee
|
133
133
|
- examples/basics.rb
|
134
|
+
- examples/bootstrap.rb
|
134
135
|
- examples/list_hypervisors.rb
|
136
|
+
- examples/top_abusers.rb
|
135
137
|
- lib/webee.rb
|
136
138
|
- lib/webee/command.rb
|
137
139
|
- lib/webee/commands/appslib.rb
|
@@ -177,9 +179,11 @@ specification_version: 3
|
|
177
179
|
summary: Abiquo API Ruby Implementation
|
178
180
|
test_files:
|
179
181
|
- examples/basics.rb
|
182
|
+
- examples/bootstrap.rb
|
180
183
|
- examples/list_hypervisors.rb
|
181
184
|
- examples/test.rb
|
182
185
|
- examples/test2.rb
|
186
|
+
- examples/top_abusers.rb
|
183
187
|
- test/helper.rb
|
184
188
|
- test/test_appliance_manager.rb
|
185
189
|
- test/test_webee.rb
|