Revision c79bff26 src/vmm_mad/remotes/ec2/ec2_driver.rb

View differences:

src/vmm_mad/remotes/ec2/ec2_driver.rb
47 47
require 'VirtualMachineDriver'
48 48
require 'opennebula'
49 49

  
50
require 'thread'
51

  
50 52
# >> /var/log/one/oned.log
51 53
def handle_exception(action, ex, host, did, id = nil, file = nil)
52 54

  
......
507 509
        do_cw = (Time.now.to_i - cw_mon_time) >= 360
508 510

  
509 511
        vpool.each{|vm| onevm_info[vm.deploy_id] = vm }
510
        begin
511
            @ec2.instances.each do |i|
512
                next if i.state.name != 'pending' && i.state.name != 'running'
513
                one_id = i.tags.find {|t| t.key == 'ONE_ID' }
514
                one_id = one_id.value if one_id
512

  
513

  
514
        work_q = Queue.new
515
        @ec2.instances.each{|i| work_q.push i }
516
		workers = (0...20).map do
517
            Thread.new do
518
                begin
519
                    while i = work_q.pop(true)
520
                        next if i.state.name != 'pending' && i.state.name != 'running'
521
                        one_id = i.tags.find {|t| t.key == 'ONE_ID' }
522
                        one_id = one_id.value if one_id
523
                        poll_data=parse_poll(i, onevm_info[i.id], do_cw, cw_mon_time)
524
                        vm_template_to_one = vm_to_one(i)
525
                        vm_template_to_one = Base64.encode64(vm_template_to_one).gsub("\n","")
515 526
                
516
                poll_data=parse_poll(i, onevm_info[i.id], do_cw, cw_mon_time)
517

  
518
                vm_template_to_one = vm_to_one(i)
519
                vm_template_to_one = Base64.encode64(vm_template_to_one).gsub("\n","")
520

  
521
                vms_info << "VM=[\n"
522
                vms_info << "  ID=#{one_id || -1},\n"
523
                vms_info << "  DEPLOY_ID=#{i.instance_id},\n"
524
                vms_info << "  VM_NAME=#{i.instance_id},\n"
525
                vms_info << "  IMPORT_TEMPLATE=\"#{vm_template_to_one}\",\n"
526
                vms_info << "  POLL=\"#{poll_data}\" ]\n"    
527
                if one_id
528
                    name = i.instance_type
529
                    cpu, mem = instance_type_capacity(name)
530
                    usedcpu += cpu
531
                    usedmemory += mem
527
                        vms_info << "VM=[\n"
528
                        vms_info << "  ID=#{one_id || -1},\n"
529
                        vms_info << "  DEPLOY_ID=#{i.instance_id},\n"
530
                        vms_info << "  VM_NAME=#{i.instance_id},\n"
531
                        vms_info << "  IMPORT_TEMPLATE=\"#{vm_template_to_one}\",\n"
532
                        vms_info << "  POLL=\"#{poll_data}\" ]\n"
533
                        if one_id
534
                            name = i.instance_type
535
                            cpu, mem = instance_type_capacity(name)
536
                            usedcpu += cpu
537
                            usedmemory += mem
538
                        end
539
                    end
540
                rescue Exception => e
541
                    STDERR.puts  "#{e.message}\n"
532 542
                end
533

  
534 543
            end
535
        rescue => e            
536
            raise e
537
        end
544
        end; "ok"
545
        workers.map(&:join); "ok"
538 546

  
539 547
        host_info << "USEDMEMORY=#{usedmemory.round}\n"
540 548
        host_info << "USEDCPU=#{usedcpu.round}\n"
......
606 614
    def parse_poll(instance, onevm, do_cw, cw_mon_time)
607 615
        begin
608 616
            if onevm
617
                onevm.info
609 618
                if do_cw
610
                    onevm.info
611 619
                    cloudwatch_str = cloudwatch_monitor_info(instance.instance_id,
612 620
                                                           onevm,
613 621
                                                           cw_mon_time)
614 622
                else
615
                  previous_cpu   = onevm["/VM/MONITORING/CPU"] || 0
616
                  previous_netrx = onevm["/VM/MONITORING/NETRX"] || 0
617
                  previous_nettx = onevm["/VM/MONITORING/NETTX"] || 0
623
                    previous_cpu   = onevm["/VM/MONITORING/CPU"]  || 0
624
                    previous_netrx = onevm["/VM/MONITORING/NETRX"] || 0
625
                    previous_nettx = onevm["/VM/MONITORING/NETTX"] || 0
618 626

  
619
                  cloudwatch_str = "CPU=#{previous_cpu} "\
620
                                   "NETTX=#{previous_nettx} "\
621
                                   "NETRX=#{previous_netrx} "
627
                    cloudwatch_str = "CPU=#{previous_cpu} NETTX=#{previous_nettx} NETRX=#{previous_netrx} "
622 628
                end
623 629
            else
624 630
                cloudwatch_str = ""

Also available in: Unified diff