Ruby - Need to select individual properties from objects in spacewalk api
I have a ruby script that connects to spacewalk via API and returns properties about registered systems with an each loop:
Code:
ID.each { |x| Code:
{"ip6"=>"::1", "hostname"=>"server003.domain001", "ip"=>"10.6.1.103"} http://www.spacewalkproject.org/docu...RelevantErrata You can see that the method system.getNetwork returns several properties: struct - network info string "ip" - IPv4 address of server string "ip6" - IPv6 address of server string "hostname" - Hostname of server I would simply like to select maybe one of these properties like hostname... anyone know how to do that? |
Your @client.call is returning a hash in the first call and a string in the second. The second is obvious :)
The first can be walked through as well using one of the each, each_key, each_pair, each_value commands (see here for more details) As a quick example: Code:
@client.call('system.getNetwork', @key, x.to_i).each{ |k,v| puts "key is #{k} - value is #{v}" } |
Quote:
Code:
server003.domain001 @client.call('system.getNetwork', @key, x.to_i).select{hostname} |
I would try something like:
Code:
@client.call('system.getNetwork', @key, x.to_i)["hostname"] |
All times are GMT -5. The time now is 11:57 PM. |