1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

Merge branch 'master' of git.opennebula.org:one

This commit is contained in:
Ruben S. Montero 2011-09-01 17:20:12 +02:00
commit db784373db
3 changed files with 50 additions and 32 deletions

View File

@ -330,10 +330,11 @@ IMAGE_MAD = [
# - STOP, after the VM is stopped (including VM image transfers)
# - DONE, after the VM is deleted or shutdown
# - FAILED, when the VM enters the failed state
# command : path is relative to $ONE_LOCATION/var/remotes/hook (self-contained)
# or to /var/lib/one/remotes (system-wide). That directory will be copied
# on the hosts under SCRIPTS_REMOTE_DIR. It can be an absolute path
# that must exists on the target host.
# command : path is relative to $ONE_LOCATION/var/remotes/hook
# (self-contained) or to /var/lib/one/remotes/hook (system-wide).
# That directory will be copied on the hosts under
# SCRIPTS_REMOTE_DIR. It can be an absolute path that must exist
# on the target host
# arguments : for the hook. You can access to VM information with $
# - $VMID, the ID of the virtual machine
# - $TEMPLATE, the VM template in xml and base64 encoded
@ -349,10 +350,11 @@ IMAGE_MAD = [
# - CREATE, when the Host is created (onehost create)
# - ERROR, when the Host enters the error state
# - DISABLE, when the Host is disabled
# command : path is relative to $ONE_LOCATION/var/remotes/hook (self-contained)
# or to /var/lib/one/remotes (system-wide). That directory will be copied
# on the hosts under SCRIPTS_REMOTE_DIR. It can be an absolute path
# that must exists on the target host.
# command : path is relative to $ONE_LOCATION/var/remotes/hook
# (self-contained) or to /var/lib/one/remotes/hook (system-wide).
# That directory will be copied on the hosts under
# SCRIPTS_REMOTE_DIR. It can be an absolute path that must exist
# on the target host.
# arguments : for the hook. You can use the following Host information:
# - $HID, the ID of the host
# - $TEMPLATE, the Host template in xml and base64 encoded

View File

@ -32,15 +32,24 @@ exit(-1) if $?!=0
xm_text=`sudo #{XM_PATH} info`
exit(-1) if $?!=0
xentop_text.gsub!(/^xentop.*^xentop.*?$/m, "") # Strip first top output
#xentop_text.gsub!(/^xentop.*^xentop.*?$/m, "") # Strip first top output
xentop_text.gsub!("no limit", "no_limit")
xentop_text=xentop_text.split("\n")
xentop_text.reject! {|l| l.strip=="" } # Take out empty lines
lines=xentop_text.split("\n")
block_size=lines.length/2
valid_lines=lines.last(block_size)
first_domain = 4
valid_lines.each_with_index{ |l,i|
if l.match 'NAME STATE'
first_domain=i+1
break
end
}
domain_info_line=xentop_text[0]
memory_info_line=xentop_text[1]
domains_info=xentop_text[3..-1]
domains_info=valid_lines[first_domain..-1]
# Getting information from xm info

View File

@ -29,7 +29,7 @@ module KVM
:domifstat => 'virsh --connect LIBVIRT_URI --readonly domifstat',
'LIBVIRT_URI' => 'qemu:///system'
}
def self.get_vm_info(vm_id)
if !vm_id or vm_id.empty?
STDERR.puts "VM id not specified"
@ -71,7 +71,7 @@ module KVM
values
end
def self.get_all_vm_info
names=get_vm_names
@ -83,10 +83,10 @@ module KVM
vms[vm]=info
end
vms
end
private
def self.virsh(command)
@ -99,7 +99,7 @@ private
return nil if $?.exitstatus != 0
lines=text.split(/\n/)
hash=Hash.new
data=lines.map do |line|
@ -181,7 +181,7 @@ module XEN
CONF={
'XM_POLL' => 'sudo /usr/sbin/xentop -bi2'
}
def self.get_vm_info(vm_id)
data = get_all_vm_info[vm_id]
@ -191,40 +191,48 @@ module XEN
return data
end
end
def self.get_all_vm_info
begin
text=`#{CONF['XM_POLL']}`
lines=text.strip.split("\n")
block_size=lines.length/2
valid_lines=lines.last(block_size)
domain_lines=valid_lines[4..-1]
first_domain = 4
valid_lines.each_with_index{ |l,i|
if l.match 'NAME STATE'
first_domain=i+1
break
end
}
domain_lines=valid_lines[first_domain..-1]
domains=Hash.new
domain_lines.each do |dom|
dom_data=dom.gsub('no limit', 'no-limit').strip.split
dom_hash=Hash.new
dom_hash[:name]=dom_data[0]
dom_hash[:state]=get_state(dom_data[1])
dom_hash[:usedcpu]=dom_data[3]
dom_hash[:usedmemory]=dom_data[4]
dom_hash[:nettx]=dom_data[10]
dom_hash[:netrx]=dom_data[11]
domains[dom_hash[:name]]=dom_hash
end
domains
rescue
STDERR.puts "Error executing #{CONF['XM_POLL']}"
nil
end
end
def self.get_state(state)
case state.gsub('-', '')[-1..-1]
when *%w{r b s d}
@ -263,7 +271,7 @@ def select_hypervisor
hypervisor=XEN
end
end
hypervisor
end
@ -278,10 +286,10 @@ def load_vars(hypervisor)
else
return
end
begin
env=`. #{File.dirname($0)+"/#{file}"};env`
lines=env.split("\n")
vars.each do |var|
lines.each do |line|
@ -345,4 +353,3 @@ if vm_id
else
print_all_vm_info(hypervisor)
end