[one-users] listing images and its vms

2014-02-05 Thread João Pagaime

Hello all

I'm trying to put together a very simple ruby script that outputs 
opennebula's images and its vms


as far as listing opennebula's images, everything is fine, but I get an 
error when trying, for each image, to lists its vms


acording to the 4.2 API documentation the  image class should have a 
vms list/array member, but I get an error when I try to instantiate that


where's the script. The offending statement in red. Any help would be 
appreciated


thanks
joão

-- (snatched from openneb examples and then 
adapted...)


#!/usr/bin/env ruby

##
# Environment Configuration
##
ONE_LOCATION=ENV[ONE_LOCATION]

if !ONE_LOCATION
RUBY_LIB_LOCATION=/usr/lib/one/ruby
else
RUBY_LIB_LOCATION=ONE_LOCATION+/lib/ruby
end

$:  RUBY_LIB_LOCATION

##
# Required libraries
##
require 'opennebula'

include OpenNebula

# OpenNebula credentials
CREDENTIALS = oneadmin:(REMOVED)
# XML_RPC endpoint where OpenNebula is listening
ENDPOINT=http://localhost:2633/RPC2;

client = Client.new(CREDENTIALS, ENDPOINT)

img_pool = ImagePool.new(client, -1)

rc2 = img_pool.info
if OpenNebula.is_error?(rc2)
 puts rc2.message
 exit -1
end

img_pool.each do|img|
   puts img id=#{img.id},#{img.name}
   img.vms.each do|vm|
   end
end


---
___
Users mailing list
Users@lists.opennebula.org
http://lists.opennebula.org/listinfo.cgi/users-opennebula.org


Re: [one-users] listing images and its vms

2014-02-05 Thread Javier Fontan
img does not have a method called vms. You can get the IDs of the
VMs using the retrieve_elements method [1]:

vm_ids=img.retrieve_elements(VMS/ID)

As an example you can check the code for oneimage show [2].

[1] 
http://docs.opennebula.org/doc/4.4/oca/ruby/OpenNebula/XMLElement.html#retrieve_elements-instance_method
[2] 
https://github.com/OpenNebula/one/blob/one-4.4/src/cli/one_helper/oneimage_helper.rb#L301


On Wed, Feb 5, 2014 at 9:44 AM, João Pagaime joao.paga...@gmail.com wrote:
 Hello all

 I'm trying to put together a very simple ruby script that outputs
 opennebula's images and its vms

 as far as listing opennebula's images, everything is fine, but I get an
 error when trying, for each image, to lists its vms

 acording to the 4.2 API documentation the  image class should have a vms
 list/array member, but I get an error when I try to instantiate that

 where's the script. The offending statement in red. Any help would be
 appreciated

 thanks
 joão

 -- (snatched from openneb examples and then
 adapted...)

 #!/usr/bin/env ruby

 ##
 # Environment Configuration
 ##
 ONE_LOCATION=ENV[ONE_LOCATION]

 if !ONE_LOCATION
 RUBY_LIB_LOCATION=/usr/lib/one/ruby
 else
 RUBY_LIB_LOCATION=ONE_LOCATION+/lib/ruby
 end

 $:  RUBY_LIB_LOCATION

 ##
 # Required libraries
 ##
 require 'opennebula'

 include OpenNebula

 # OpenNebula credentials
 CREDENTIALS = oneadmin:(REMOVED)
 # XML_RPC endpoint where OpenNebula is listening
 ENDPOINT= http://localhost:2633/RPC2;

 client = Client.new(CREDENTIALS, ENDPOINT)

 img_pool = ImagePool.new(client, -1)

 rc2 = img_pool.info
 if OpenNebula.is_error?(rc2)
  puts rc2.message
  exit -1
 end

 img_pool.each do |img|
puts img id=#{img.id},#{img.name}
img.vms.each do |vm|
end
 end


 ---

 ___
 Users mailing list
 Users@lists.opennebula.org
 http://lists.opennebula.org/listinfo.cgi/users-opennebula.org




-- 
Javier Fontán Muiños
Developer
OpenNebula - The Open Source Toolkit for Data Center Virtualization
www.OpenNebula.org | @OpenNebula | github.com/jfontan
___
Users mailing list
Users@lists.opennebula.org
http://lists.opennebula.org/listinfo.cgi/users-opennebula.org


Re: [one-users] listing images and its vms

2014-02-05 Thread João Pagaime

thanks, you answer was very useful!

--joão

Em 05-02-2014 11:38, Javier Fontan escreveu:

img does not have a method called vms. You can get the IDs of the
VMs using the retrieve_elements method [1]:

vm_ids=img.retrieve_elements(VMS/ID)

As an example you can check the code for oneimage show [2].

[1] 
http://docs.opennebula.org/doc/4.4/oca/ruby/OpenNebula/XMLElement.html#retrieve_elements-instance_method
[2] 
https://github.com/OpenNebula/one/blob/one-4.4/src/cli/one_helper/oneimage_helper.rb#L301


On Wed, Feb 5, 2014 at 9:44 AM, João Pagaime joao.paga...@gmail.com wrote:

Hello all

I'm trying to put together a very simple ruby script that outputs
opennebula's images and its vms

as far as listing opennebula's images, everything is fine, but I get an
error when trying, for each image, to lists its vms

acording to the 4.2 API documentation the  image class should have a vms
list/array member, but I get an error when I try to instantiate that

where's the script. The offending statement in red. Any help would be
appreciated

thanks
joão

-- (snatched from openneb examples and then
adapted...)

#!/usr/bin/env ruby

##
# Environment Configuration
##
ONE_LOCATION=ENV[ONE_LOCATION]

if !ONE_LOCATION
 RUBY_LIB_LOCATION=/usr/lib/one/ruby
else
 RUBY_LIB_LOCATION=ONE_LOCATION+/lib/ruby
end

$:  RUBY_LIB_LOCATION

##
# Required libraries
##
require 'opennebula'

include OpenNebula

# OpenNebula credentials
CREDENTIALS = oneadmin:(REMOVED)
# XML_RPC endpoint where OpenNebula is listening
ENDPOINT= http://localhost:2633/RPC2;

client = Client.new(CREDENTIALS, ENDPOINT)

img_pool = ImagePool.new(client, -1)

rc2 = img_pool.info
if OpenNebula.is_error?(rc2)
  puts rc2.message
  exit -1
end

img_pool.each do |img|
puts img id=#{img.id},#{img.name}
img.vms.each do |vm|
end
end


---

___
Users mailing list
Users@lists.opennebula.org
http://lists.opennebula.org/listinfo.cgi/users-opennebula.org






___
Users mailing list
Users@lists.opennebula.org
http://lists.opennebula.org/listinfo.cgi/users-opennebula.org