Method: CCBuilder::ONEClient#list
- Defined in:
- lib/ONEClient.rb
#list ⇒ Object
API-method list
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ONEClient.rb', line 39 def list n = 3 vmpool = OpenNebula::VirtualMachinePool.new(@one_client, -1) result = vmpool.info vms = Array.new queue = Queue.new # queue to hold ids which need to be looked up threads = Array.new n.times do |i| # Launch n threads which do the lookups# threads[i] = Thread.new do id = queue.pop until id == 0 vm = OpenNebula::VirtualMachine.new_with_id(id, @one_client) vm.info ip = vm.template_str.scan(/IP=(\d+\.\d+\.\d+\.\d+),/)[0][0] status = vm.status vmhost = vm["HISTORY/HOSTNAME"] host = Resolv::getname(ip) Thread.pass puts "VM ##{id} with ip #{ip} resolved to name #{host}" if @verbose vms << { 'id' => id, 'ip' => ip, 'host' => host, 'status' => status, 'vmhost' => vmhost } STDOUT.flush id = queue.pop end end end vmpool.map do |vm| queue << vm.id end n.times { queue << 0 } # send 0 to terminate threads n.times { |i| threads[i].join } # wait until threads finished return vms ensure n.times { |i| threads[i].terminate } end |