poll_xen_kvm.patch

Luis M Carril Rodriguez, 07/18/2011 11:45 AM

Download (2.08 KB)

View differences:

a/poll_xen_kvm.rb 2011-07-18 13:38:08.472441582 +0200
179 179

  
180 180
module XEN
181 181
    CONF={
182
        'XM_POLL' => 'sudo /usr/sbin/xentop -bi2'
182
        'XM_INFO' => 'sudo /usr/sbin/xm info',
183
        'XM_POLL_XEN_3' => 'sudo /usr/sbin/xentop -bi2',
184
        'XM_POLL_XEN_4' => 'sudo /usr/sbin/xentop -fbi1'
183 185
    }
184 186
    
185 187
    def self.get_vm_info(vm_id)
......
191 193
            return data
192 194
        end
193 195
    end
194
    
196

  
197
    def self.get_xen_version
198
    begin
199
        xen_major=`sudo /usr/sbin/xm info |awk '/xen_major/{print $3}'`.to_i
200
        xen_minor=`sudo /usr/sbin/xm info |awk '/xen_minor/{print $3}'`.to_i
201
        xen_extra=`sudo /usr/sbin/xm info |awk '/xen_minor/{print $3}'`.delete('.').to_i
202
        return [xen_major, xen_minor, xen_extra]
203
    rescue
204
        STDERR.puts "Failed to get Xen version, assuming 3.0.0"
205
        return [3, 0, 0]
206
    end
207
    end
208
 
195 209
    def self.get_all_vm_info
196 210
    begin
197
        text=`#{CONF['XM_POLL']}`
198
        lines=text.strip.split("\n")
199
        block_size=lines.length/2
200
        valid_lines=lines.last(block_size)
201
        
202
        domain_lines=valid_lines[4..-1]
203
        
211
        # The arguments to xentop change depending on the xentop version.
212
        # The headers are not repeated by default in Xen 4.0.1, unless the -f
213
        # option is specified. Older versions of Xentop do not have a -f flag.
214

  
215
        version = get_xen_version
216
        if version[0] <= 3 then
217
            text=`#{CONF['XM_POLL_XEN_3']}`
218
            lines=text.strip.split("\n")
219
            block_size=lines.length/2
220
            valid_lines=lines.last(block_size)
221
            domain_lines=valid_lines[4..-1]
222
        else
223
            text=`#{CONF['XM_POLL_XEN_4']}`
224
            lines=text.strip.split("\n")
225
            domain_lines=lines.last(lines.length - 1)
226
        end
227
 
204 228
        domains=Hash.new
205 229
        
206 230
        domain_lines.each do |dom|
......
221 245
        domains
222 246
    rescue
223 247
        STDERR.puts "Error executing #{CONF['XM_POLL']}"
224
        nil
248
	[]
225 249
    end
226 250
    end
227 251