Revision cc103c51

View differences:

src/vmm_mad/remotes/poll_xen_kvm.rb
19 19
require 'pp'
20 20
require 'rexml/document'
21 21
require 'base64'
22
require 'uri'
22 23

  
23 24
ENV['LANG']='C'
24 25

  
......
447 448
    # @return [Hash, nil] Hash with the VM information or nil in case of error
448 449
    def self.get_all_vm_info
449 450
        begin
451
            begin
452
                vm_templates = get_vm_templates
453
            rescue
454
                vm_templates = {}
455
            end
456

  
450 457
            text  = `#{CONF['XM_POLL']}`
451 458

  
452 459
            return nil if $?.exitstatus != 0
......
481 488
                dom_hash[:nettx]      = dom_data[10].to_i * 1024
482 489
                dom_hash[:netrx]      = dom_data[11].to_i * 1024
483 490

  
491
                if !dom_data[0].match(/^one-\d/) && vm_templates[dom_data[0]]
492
                    dom_hash[:template] =
493
                        Base64.encode64(vm_templates[dom_data[0]]).delete("\n")
494
                end
495

  
484 496
                domains[dom_hash[:name]] = dom_hash
485 497
            end
486 498

  
......
512 524
            '-'
513 525
        end
514 526
    end
527

  
528
    def self.get_vm_templates
529
        begin
530
            require 'rubygems'
531
            require 'json'
532
        rescue LoadError
533
            return {}
534
        end
535

  
536
        text = `#{CONF['XM_LIST']} -l`
537
        doms = JSON.parse(text)
538

  
539
        dom_tmpl = {}
540

  
541
        doms.each do |dom|
542
            name = dom['config']['c_info']['name']
543
            name = URI.escape(name)
544

  
545
            tmp = %Q<NAME = "#{name}"\n>
546

  
547
            vcpus = dom['config']['b_info']['max_vcpus'].to_i
548
            vcpus = 1 if vcpus < 1
549

  
550
            tmp << %Q<CPU = #{vcpus}\n>
551
            tmp << %Q<VCPU = #{vcpus}\n>
552

  
553
            memory = dom['config']['b_info']['max_memkb']
554
            memory /= 1024
555

  
556
            tmp << %Q<MEMORY = #{memory}\n>
557

  
558
            dom_tmpl[name] = tmp
559
        end
560

  
561
        dom_tmpl
562
    end
515 563
end
516 564

  
517 565
################################################################################
......
548 596
    case hypervisor.name
549 597
        when 'XEN'
550 598
            file = 'xenrc'
551
            vars = %w{XM_POLL}
599
            vars = %w{XM_POLL XM_LIST}
552 600
        when 'KVM'
553 601
            file = 'kvmrc'
554 602
            vars = %w{LIBVIRT_URI}

Also available in: Unified diff