[one-users] Using Ruby API with OCA gem
KING LABS
kinglabs.in at gmail.com
Mon Nov 29 02:20:54 PST 2010
Thank you I am getting the following error when I used the updated example,
while when I am using xmlrpc script its working .
king at king-desktop:~$ ruby opennebula_ruby_api.rb
opennebula_ruby_api.rb:22:in `<main>': unexpected return (LocalJumpError)
------------------------------------------------------------------------
xmlrpc using ruby:
---------------------------
#!/usr/bin/env ruby
require 'xmlrpc/client'
require 'pp'
server_url="http://192.168.138.230:2633/RPC2"
server=XMLRPC::Client.new2(server_url)
vmpool = server.call("one.vmpool.info
","oneadmin:7bc8559a8fe509e680562b85c337f170956fcb06",-1)
pp vmpool
OUTPUT:
----------------
king at king-desktop:~$ ruby opennebula.rb
[true,
"<VM_POOL><VM><ID>28</ID><UID>0</UID><USERNAME>oneadmin</USERNAME><NAME>test3</NAME><LAST_POLL>1291025778</LAST_POLL><STATE>3</STATE><LCM_STATE>3</LCM_STATE><STIME>1290752714</STIME><ETIME>0</ETIME><DEPLOY_ID>one-28</DEPLOY_ID><MEMORY>131072</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>0</NET_RX><LAST_SEQ>0</LAST_SEQ><TEMPLATE><CPU><![CDATA[1]]></CPU><DISK><CLONE><![CDATA[YES]]></CLONE><DISK_ID><![CDATA[0]]></DISK_ID><IMAGE><![CDATA[UbuntuApp]]></IMAGE><IMAGE_ID><![CDATA[1]]></IMAGE_ID><READONLY><![CDATA[NO]]></READONLY><SAVE><![CDATA[NO]]></SAVE><SOURCE><![CDATA[/var/lib/one//images/2a4e357eac97900cc1eedd570eaa87050e11aa98]]></SOURCE><TARGET><![CDATA[hda]]></TARGET><TYPE><![CDATA[DISK]]></TYPE></DISK><GRAPHICS><LISTEN><![CDATA[0.0.0.0]]></LISTEN><PORT><![CDATA[17]]></PORT><TYPE><![CDATA[vnc]]></TYPE></GRAPHICS><MEMORY><![CDATA[128]]></MEMORY><NAME><![CDATA[test3]]></NAME><NIC><BRIDGE><![CDATA[br0]]></BRIDGE><IP><![CDATA[192.168.138.1]]></IP><MAC><![CDATA[02:00:c0:a8:8a:01]]></MAC><NETWORK><![CDATA[RANGED]]></NETWORK><NETWORK_ID><![CDATA[2]]></NETWORK_ID></NIC><VMID><![CDATA[28]]></VMID></TEMPLATE><HISTORY><SEQ>0</SEQ><HOSTNAME>192.168.138.231</HOSTNAME><HID>0</HID><STIME>1290752718</STIME><ETIME>0</ETIME><PSTIME>1290752718</PSTIME><PETIME>1290752770</PETIME><RSTIME>1290752770</RSTIME><RETIME>0</RETIME><ESTIME>0</ESTIME><EETIME>0</EETIME><REASON>0</REASON></HISTORY></VM><VM><ID>29</ID><UID>0</UID><USERNAME>oneadmin</USERNAME><NAME>test4</NAME><LAST_POLL>1291025838</LAST_POLL><STATE>3</STATE><LCM_STATE>3</LCM_STATE><STIME>1291008373</STIME><ETIME>0</ETIME><DEPLOY_ID>one-29</DEPLOY_ID><MEMORY>131072</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>0</NET_RX><LAST_SEQ>0</LAST_SEQ><TEMPLATE><CPU><![CDATA[1]]></CPU><DISK><CLONE><![CDATA[YES]]></CLONE><DISK_ID><![CDATA[0]]></DISK_ID><IMAGE><![CDATA[UbuntuApp]]></IMAGE><IMAGE_ID><![CDATA[1]]></IMAGE_ID><READONLY><![CDATA[NO]]></READONLY><SAVE><![CDATA[NO]]></SAVE><SOURCE><![CDATA[/var/lib/one//images/2a4e357eac97900cc1eedd570eaa87050e11aa98]]></SOURCE><TARGET><![CDATA[hda]]></TARGET><TYPE><![CDATA[DISK]]></TYPE></DISK><GRAPHICS><LISTEN><![CDATA[0.0.0.0]]></LISTEN><PORT><![CDATA[18]]></PORT><TYPE><![CDATA[vnc]]></TYPE></GRAPHICS><MEMORY><![CDATA[128]]></MEMORY><NAME><![CDATA[test4]]></NAME><NIC><BRIDGE><![CDATA[br0]]></BRIDGE><IP><![CDATA[192.168.138.2]]></IP><MAC><![CDATA[02:00:c0:a8:8a:02]]></MAC><NETWORK><![CDATA[RANGED]]></NETWORK><NETWORK_ID><![CDATA[2]]></NETWORK_ID></NIC><VMID><![CDATA[29]]></VMID></TEMPLATE><HISTORY><SEQ>0</SEQ><HOSTNAME>192.168.138.231</HOSTNAME><HID>0</HID><STIME>1291008378</STIME><ETIME>0</ETIME><PSTIME>1291008378</PSTIME><PETIME>1291008429</PETIME><RSTIME>1291008429</RSTIME><RETIME>0</RETIME><ESTIME>0</ESTIME><EETIME>0</EETIME><REASON>0</REASON></HISTORY></VM></VM_POOL>"]
king at king-desktop:~$
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
I am just tying to understand API. I am new to ruby/opennebula/xml .... can
you please give me the example for the same above script using ruby api ...
that should help me.
Regards
On Mon, Nov 29, 2010 at 2:00 PM, Daniel Molina Aranda
<danmolin at fdi.ucm.es>wrote:
> Hi,
>
> The problem is that the info method returns an OpenNebula error when it
> fails. You should change the return statement to:
>
> --8<------
> rc = vm_pool.info()
>
> if OpenNebula.is_error?(rc)
> return rc.message
> else
> return rc
> end
> ------>8--
>
> I have updated the documentation script [1], if you want to check it.
>
> Hope this helps.
>
> [1] http://www.opennebula.org/documentation:rel2.0:ruby
>
> On 29 November 2010 08:49, KING LABS <kinglabs.in at gmail.com> wrote:
>
>> I have installed ruby oca gem and tried using it with given example script
>> at http://www.opennebula.org/documentation:rel2.0:ruby , script executes
>> with out any results, it doesnt give me any error even when the user
>> credentials given wrong.
>>
>> also i tried with little modified script based on example script is as
>> follows which is giving a error
>>
>>
>> --------------------------------------------------------------------------------------------------------------------------------------------------
>>
>> #!/usr/bin/env ruby
>>
>>
>> ##############################################################################
>> # Required libraries
>>
>> ##############################################################################
>> require 'rubygems'
>> require 'oca'
>>
>> include OpenNebula
>>
>> # OpenNebula credentials
>>
>> CREDENTIALS = "oneadmin:7bc8559a8fe509e680562b85c337f170956fcb06"
>>
>> # XML_RPC endpoint where OpenNebula is listening
>>
>> ENDPOINT = "http://192.168.138.230:2633/RPC2"
>>
>> client = Client.new(CREDENTIALS, ENDPOINT)
>>
>> vm_pool = VirtualMachinePool.new(client, -1)
>>
>> puts vm_pool.info()
>>
>>
>> -------------------------------------------------------------------------------------------------------------------------
>>
>> Output:
>>
>> king at king-desktop:~$ ruby opennebula_ruby_api.rb
>> #<OpenNebula::Error:0x00000002050a80>
>> king at king-desktop:~$
>>
>>
>> Few working examples are welcomed.
>>
>> Regards.
>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.opennebula.org
>> http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
>>
>>
>
>
> --
> Daniel Molina, Cloud Technology Engineer/Researcher
> DSA Research Group: web http://dsa-research.org and blog
> http://blog.dsa-research.org
> OpenNebula Open Source Toolkit for Cloud Computing:
> http://www.OpenNebula.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opennebula.org/pipermail/users-opennebula.org/attachments/20101129/c64a43fa/attachment-0003.htm>
More information about the Users
mailing list