1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

remove xen from the code (except from Sunstone)

This commit is contained in:
Jaime Melis 2016-04-06 12:11:23 +02:00
parent f12b01f7e5
commit df0065c9de
38 changed files with 724 additions and 2118 deletions

View File

@ -241,11 +241,7 @@ LIB_DIRS="$LIB_LOCATION/ruby \
VAR_DIRS="$VAR_LOCATION/remotes \
$VAR_LOCATION/remotes/im \
$VAR_LOCATION/remotes/im/kvm.d \
$VAR_LOCATION/remotes/im/xen3.d \
$VAR_LOCATION/remotes/im/xen4.d \
$VAR_LOCATION/remotes/im/kvm-probes.d \
$VAR_LOCATION/remotes/im/xen3-probes.d \
$VAR_LOCATION/remotes/im/xen4-probes.d \
$VAR_LOCATION/remotes/im/vmware.d \
$VAR_LOCATION/remotes/im/vcenter.d \
$VAR_LOCATION/remotes/im/ec2.d \
@ -253,8 +249,6 @@ VAR_DIRS="$VAR_LOCATION/remotes \
$VAR_LOCATION/remotes/im/az.d \
$VAR_LOCATION/remotes/vmm \
$VAR_LOCATION/remotes/vmm/kvm \
$VAR_LOCATION/remotes/vmm/xen3 \
$VAR_LOCATION/remotes/vmm/xen4 \
$VAR_LOCATION/remotes/vmm/vmware \
$VAR_LOCATION/remotes/vmm/vcenter \
$VAR_LOCATION/remotes/vmm/ec2 \
@ -383,10 +377,6 @@ INSTALL_FILES=(
IM_PROBES_FILES:$VAR_LOCATION/remotes/im
IM_PROBES_KVM_FILES:$VAR_LOCATION/remotes/im/kvm.d
IM_PROBES_KVM_PROBES_FILES:$VAR_LOCATION/remotes/im/kvm-probes.d
IM_PROBES_XEN3_FILES:$VAR_LOCATION/remotes/im/xen3.d
IM_PROBES_XEN3_PROBES_FILES:$VAR_LOCATION/remotes/im/xen3-probes.d
IM_PROBES_XEN4_FILES:$VAR_LOCATION/remotes/im/xen4.d
IM_PROBES_XEN4_PROBES_FILES:$VAR_LOCATION/remotes/im/xen4-probes.d
IM_PROBES_VMWARE_FILES:$VAR_LOCATION/remotes/im/vmware.d
IM_PROBES_VCENTER_FILES:$VAR_LOCATION/remotes/im/vcenter.d
IM_PROBES_EC2_FILES:$VAR_LOCATION/remotes/im/ec2.d
@ -400,9 +390,6 @@ INSTALL_FILES=(
AUTH_SERVER_CIPHER_FILES:$VAR_LOCATION/remotes/auth/server_cipher
AUTH_DUMMY_FILES:$VAR_LOCATION/remotes/auth/dummy
AUTH_PLAIN_FILES:$VAR_LOCATION/remotes/auth/plain
VMM_EXEC_KVM_SCRIPTS:$VAR_LOCATION/remotes/vmm/kvm
VMM_EXEC_XEN3_SCRIPTS:$VAR_LOCATION/remotes/vmm/xen3
VMM_EXEC_XEN4_SCRIPTS:$VAR_LOCATION/remotes/vmm/xen4
VMM_EXEC_VMWARE_SCRIPTS:$VAR_LOCATION/remotes/vmm/vmware
VMM_EXEC_VCENTER_SCRIPTS:$VAR_LOCATION/remotes/vmm/vcenter
VMM_EXEC_EC2_SCRIPTS:$VAR_LOCATION/remotes/vmm/ec2
@ -692,49 +679,6 @@ VMM_EXEC_KVM_SCRIPTS="src/vmm_mad/remotes/kvm/cancel \
src/vmm_mad/remotes/kvm/prereconfigure"
#-------------------------------------------------------------------------------
# VMM SH Driver Xen scripts, to be installed under $REMOTES_LOCATION/vmm/xen
#-------------------------------------------------------------------------------
VMM_EXEC_XEN3_SCRIPTS="src/vmm_mad/remotes/xen/cancel \
src/vmm_mad/remotes/xen/deploy \
src/vmm_mad/remotes/xen/xen3/xenrc \
src/vmm_mad/remotes/xen/xen3/migrate \
src/vmm_mad/remotes/xen/restore \
src/vmm_mad/remotes/xen/reboot \
src/vmm_mad/remotes/xen/xen3/reset \
src/vmm_mad/remotes/xen/save \
src/vmm_mad/remotes/xen/poll \
src/vmm_mad/remotes/xen/attach_disk \
src/vmm_mad/remotes/xen/detach_disk \
src/vmm_mad/remotes/xen/attach_nic \
src/vmm_mad/remotes/xen/detach_nic \
src/vmm_mad/remotes/xen/snapshot_create \
src/vmm_mad/remotes/xen/snapshot_revert \
src/vmm_mad/remotes/xen/snapshot_delete \
src/vmm_mad/remotes/xen/shutdown \
src/vmm_mad/remotes/xen/reconfigure \
src/vmm_mad/remotes/xen/prereconfigure"
VMM_EXEC_XEN4_SCRIPTS="src/vmm_mad/remotes/xen/cancel \
src/vmm_mad/remotes/xen/deploy \
src/vmm_mad/remotes/xen/xen4/xenrc \
src/vmm_mad/remotes/xen/xen4/migrate \
src/vmm_mad/remotes/xen/restore \
src/vmm_mad/remotes/xen/reboot \
src/vmm_mad/remotes/xen/xen4/reset \
src/vmm_mad/remotes/xen/save \
src/vmm_mad/remotes/xen/poll \
src/vmm_mad/remotes/xen/attach_disk \
src/vmm_mad/remotes/xen/detach_disk \
src/vmm_mad/remotes/xen/attach_nic \
src/vmm_mad/remotes/xen/detach_nic \
src/vmm_mad/remotes/xen/snapshot_create \
src/vmm_mad/remotes/xen/snapshot_revert \
src/vmm_mad/remotes/xen/snapshot_delete \
src/vmm_mad/remotes/xen/shutdown \
src/vmm_mad/remotes/xen/reconfigure \
src/vmm_mad/remotes/xen/prereconfigure"
#-------------------------------------------------------------------------------
# VMM Driver VMWARE scripts, to be installed under $REMOTES_LOCATION/vmm/vmware
#-------------------------------------------------------------------------------
@ -871,30 +815,6 @@ IM_PROBES_KVM_PROBES_FILES="src/im_mad/remotes/kvm-probes.d/kvm.rb \
src/im_mad/remotes/common.d/version.sh \
src/im_mad/remotes/common.d/collectd-client-shepherd.sh"
IM_PROBES_XEN3_FILES="src/im_mad/remotes/xen.d/collectd-client_control.sh \
src/im_mad/remotes/xen.d/collectd-client.rb"
IM_PROBES_XEN3_PROBES_FILES="src/im_mad/remotes/xen-probes.d/xen.rb \
src/im_mad/remotes/xen-probes.d/architecture.sh \
src/im_mad/remotes/xen-probes.d/cpu.sh \
src/im_mad/remotes/xen-probes.d/poll3.sh \
src/im_mad/remotes/xen-probes.d/name.sh
src/im_mad/remotes/common.d/monitor_ds.sh \
src/im_mad/remotes/common.d/version.sh \
src/im_mad/remotes/common.d/collectd-client-shepherd.sh"
IM_PROBES_XEN4_FILES="src/im_mad/remotes/xen.d/collectd-client_control.sh \
src/im_mad/remotes/xen.d/collectd-client.rb"
IM_PROBES_XEN4_PROBES_FILES="src/im_mad/remotes/xen-probes.d/xen.rb \
src/im_mad/remotes/xen-probes.d/architecture.sh \
src/im_mad/remotes/xen-probes.d/cpu.sh \
src/im_mad/remotes/xen-probes.d/poll4.sh \
src/im_mad/remotes/xen-probes.d/name.sh \
src/im_mad/remotes/common.d/monitor_ds.sh \
src/im_mad/remotes/common.d/version.sh \
src/im_mad/remotes/common.d/collectd-client-shepherd.sh"
IM_PROBES_VMWARE_FILES="src/im_mad/remotes/vmware.d/vmware.rb"
IM_PROBES_VCENTER_FILES="src/im_mad/remotes/vcenter.d/vcenter.rb"
@ -1387,8 +1307,6 @@ AZ_ETC_FILES="src/vmm_mad/remotes/az/az_driver.conf \
VMM_EXEC_ETC_FILES="src/vmm_mad/exec/vmm_execrc \
src/vmm_mad/exec/vmm_exec_kvm.conf \
src/vmm_mad/exec/vmm_exec_xen3.conf \
src/vmm_mad/exec/vmm_exec_xen4.conf \
src/vmm_mad/exec/vmm_exec_vmware.conf \
src/vmm_mad/exec/vmm_exec_vcenter.conf"

View File

@ -180,7 +180,6 @@ MAC_PREFIX = "02:00"
# DEFAULT_DEVICE_PREFIX: This can be set to
# hd IDE prefix
# sd SCSI
# xvd XEN Virtual Disk
# vd KVM virtual disk
#
# DEFAULT_CDROM_DEVICE_PREFIX: Same as above but for CDROM devices.
@ -215,10 +214,9 @@ DEFAULT_CDROM_DEVICE_PREFIX = "hd"
#*******************************************************************************
#-------------------------------------------------------------------------------
# Information Collector for KVM and Xen IM's.
# Information Collector for KVM IM's.
#-------------------------------------------------------------------------------
# This driver CANNOT BE ASSIGNED TO A HOST, and needs to be used with KVM or
# Xen drivers
# This driver CANNOT BE ASSIGNED TO A HOST, and needs to be used with KVM
# -h prints this help.
# -a Address to bind the collectd sockect (defults 0.0.0.0)
# -p UDP port to listen for monitor information (default 4124)
@ -256,44 +254,6 @@ IM_MAD = [
# arguments = "-r 3 -t 15 kvm-probes" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# XEN UDP-push Information Driver Manager Configuration
# -r number of retries when monitoring a host
# -t number of threads, i.e. number of hosts monitored at the same time
#-------------------------------------------------------------------------------
# Driver for Xen 3.x
#IM_MAD = [
# name = "xen",
# executable = "one_im_ssh",
# arguments = "-r 3 -t 15 xen3" ]
# Driver for Xen 4.x
#IM_MAD = [
# name = "xen",
# executable = "one_im_ssh",
# arguments = "-r 3 -t 15 xen4" ]
#-------------------------------------------------------------------------------
# XEN SSH-pull Information Driver Manager Configuration
# -r number of retries when monitoring a host
# -t number of threads, i.e. number of hosts monitored at the same time
#-------------------------------------------------------------------------------
# Driver for Xen 3.x
#IM_MAD = [
# name = "xen",
# executable = "one_im_ssh",
# arguments = "-r 0 -t 15 xen3-probes" ]
# Driver for Xen 4.x
#IM_MAD = [
# name = "xen",
# executable = "one_im_ssh",
# arguments = "-r 0 -t 15 xen4-probes" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# VMware Information Driver Manager Configuration
# -r number of retries when monitoring a host
@ -361,34 +321,6 @@ VM_MAD = [
type = "kvm" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# XEN Virtualization Driver Manager Configuration
# -r number of retries when monitoring a host
# -t number of threads, i.e. number of hosts monitored at the same time
# -l <actions[=command_name]> actions executed locally, command can be
# overridden for each action.
# Valid actions: deploy, shutdown, cancel, save, restore, migrate, poll
# An example: "-l migrate,save"
#-------------------------------------------------------------------------------
# Driver for Xen 3.x
#VM_MAD = [
# name = "xen",
# executable = "one_vmm_exec",
# arguments = "-t 15 -r 0 xen3",
# default = "vmm_exec/vmm_exec_xen3.conf",
# type = "xen" ]
# Driver for Xen 4.x
#VM_MAD = [
# name = "xen",
# executable = "one_vmm_exec",
# arguments = "-t 15 -r 0 xen4",
# default = "vmm_exec/vmm_exec_xen4.conf",
# type = "xen" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# VMware Virtualization Driver Manager Configuration
# -r number of retries when monitoring a host

View File

@ -213,7 +213,6 @@ MAC_PREFIX = "02:00"
# DEFAULT_DEVICE_PREFIX: This can be set to
# hd IDE prefix
# sd SCSI
# xvd XEN Virtual Disk
# vd KVM virtual disk
#
# DEFAULT_CDROM_DEVICE_PREFIX: Same as above but for CDROM devices.
@ -248,10 +247,9 @@ DEFAULT_CDROM_DEVICE_PREFIX = "hd"
#*******************************************************************************
#-------------------------------------------------------------------------------
# Information Collector for KVM and Xen IM's.
# Information Collector for KVM IM's.
#-------------------------------------------------------------------------------
# This driver CANNOT BE ASSIGNED TO A HOST, and needs to be used with KVM or
# Xen drivers
# This driver CANNOT BE ASSIGNED TO A HOST, and needs to be used with KVM
# -h prints this help.
# -a Address to bind the collectd sockect (defults 0.0.0.0)
# -p UDP port to listen for monitor information (default 4124)
@ -289,42 +287,6 @@ IM_MAD = [
# arguments = "-r 3 -t 15 kvm-probes" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# XEN UDP-push Information Driver Manager Configuration
# -r number of retries when monitoring a host
# -t number of threads, i.e. number of hosts monitored at the same time
#-------------------------------------------------------------------------------
# Driver for Xen 3.x
#IM_MAD = [
# name = "xen",
# executable = "one_im_ssh",
# arguments = "-r 3 -t 15 xen3" ]
# Driver for Xen 4.x
#IM_MAD = [
# name = "xen",
# executable = "one_im_ssh",
# arguments = "-r 3 -t 15 xen4" ]
#-------------------------------------------------------------------------------
# XEN SSH-pull Information Driver Manager Configuration
# -r number of retries when monitoring a host
# -t number of threads, i.e. number of hosts monitored at the same time
#-------------------------------------------------------------------------------
# Driver for Xen 3.x
#IM_MAD = [
# name = "xen",
# executable = "one_im_ssh",
# arguments = "-r 0 -t 15 xen3-probes" ]
# Driver for Xen 4.x
#IM_MAD = [
# name = "xen",
# executable = "one_im_ssh",
# arguments = "-r 0 -t 15 xen4-probes" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
@ -464,46 +426,6 @@ VM_MAD = [
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# XEN Virtualization Driver Manager Configuration
# -r number of retries when monitoring a host
# -t number of threads, i.e. number of hosts monitored at the same time
# -l <actions[=command_name]> actions executed locally, command can be
# overridden for each action.
# Valid actions: deploy, shutdown, cancel, save, restore, migrate, poll
# An example: "-l migrate,save"
# -p more than one action per host in parallel, needs support from hypervisor
# -s <shell> to execute commands, bash by default
# -d default snapshot strategy. It can be either 'detach' or 'suspend'. It
# defaults to 'suspend'.
#-------------------------------------------------------------------------------
#
# Driver for Xen 3.x
#VM_MAD = [
# name = "xen",
# executable = "one_vmm_exec",
# arguments = "-t 15 -r 0 xen3",
# default = "vmm_exec/vmm_exec_xen3.conf",
# type = "xen",
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, disk-attach,
# disk-detach, nic-attach, nic-detach, snap-create, snap-delete"
#]
#
# Driver for Xen 4.x
#VM_MAD = [
# name = "xen",
# executable = "one_vmm_exec",
# arguments = "-t 15 -r 0 xen4",
# default = "vmm_exec/vmm_exec_xen4.conf",
# type = "xen",
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, disk-attach,
# disk-detach, nic-attach, nic-detach, snap-create, snap-delete"
#]
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# VMware Virtualization Driver Manager Configuration
# -r number of retries when monitoring a host

View File

@ -1,19 +0,0 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
echo ARCH=`uname -m`

View File

@ -1,25 +0,0 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
if [ -f /proc/cpuinfo ]; then
echo -n "MODELNAME=\""
grep -m 1 "model name" /proc/cpuinfo | cut -d: -f2 | sed -e 's/^ *//' | sed -e 's/$/"/'
fi

View File

@ -1,21 +0,0 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
echo HOSTNAME=`uname -n`

View File

@ -1,20 +0,0 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
../../vmm/xen3/poll --xen -t

View File

@ -1,20 +0,0 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
../../vmm/xen4/poll --xen -t

View File

@ -1,120 +0,0 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require "pp"
XENTOP_PATH="/usr/sbin/xentop"
dir=File.basename(Dir.pwd)
if dir.match(/^xen4/)
XM_PATH="/usr/sbin/xl"
else
XM_PATH="/usr/sbin/xm"
end
def print_info(name, value)
value = "0" if value.nil? or value.to_s.strip.empty?
puts "#{name}=#{value}"
end
xentop_text=`sudo #{XENTOP_PATH} -bi2`
exit(-1) if $?.exitstatus != 0
xm_text=`sudo #{XM_PATH} info`
exit(-1) if $?.exitstatus != 0
#xentop_text.gsub!(/^xentop.*^xentop.*?$/m, "") # Strip first top output
xentop_text.gsub!("no limit", "no_limit")
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=valid_lines[first_domain..-1]
# Getting information from xm info
memory_info=Hash.new
cpu_info=Hash.new
free_memory=nil
max_free_memory=nil
xm_text.each_line {|line|
columns=line.split(":").collect {|c| c.strip }
case columns[0]
when 'total_memory'
memory_info[:total]=columns[1].to_i*1024
when 'max_free_memory'
max_free_memory=columns[1].to_i*1024
when 'free_memory'
free_memory=columns[1].to_i*1024
when 'nr_cpus'
cpu_info[:total]=columns[1].to_f*100
when 'cpu_mhz'
cpu_info[:speed]=columns[1]
end
}
if max_free_memory
memory_info[:free]=max_free_memory
else
memory_info[:free]=free_memory
end
memory_info[:used]=memory_info[:total]-memory_info[:free]
# DOMAINS LINES
vm_info=Hash.new
vm_info[:cpu]=0.0
vm_info[:nettx]=0
vm_info[:netrx]=0
domains_info.each {|line|
l=line.strip.split
vm_info[:cpu]+=l[3].to_f
vm_info[:nettx]+=l[10].to_i
vm_info[:netrx]+=l[11].to_i
}
# WRITE INFO
print_info("HYPERVISOR","xen")
print_info("TOTALCPU",cpu_info[:total].round.to_s)
print_info("CPUSPEED",cpu_info[:speed])
print_info("TOTALMEMORY",memory_info[:total].to_s)
print_info("FREEMEMORY",memory_info[:free].to_s)
print_info("USEDMEMORY",memory_info[:used].to_s)
print_info("USEDCPU",vm_info[:cpu].round.to_s)
print_info("FREECPU",(cpu_info[:total]-vm_info[:cpu]).round.to_s)
print_info("NETTX",vm_info[:nettx].to_s)
print_info("NETRX",vm_info[:netrx].to_s)

View File

@ -1 +0,0 @@
../common.d/collectd-client.rb

View File

@ -1 +0,0 @@
../common.d/collectd-client_control.sh

View File

@ -1,33 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
# Default configuration attributes for the Xen driver
# (all domains will use these values as defaults). These values can
# be overridden in each VM template. Valid atributes are:
# - credit
# - os [kernel,initrd,root,kernel_cmd]
# - vcpu
# - disk[driver]
# - nic[model]
# - raw
#VCPU = 1
#OS = [ kernel="/vmlinuz", initrd="/initrd.img", root="sda1", kernel_cmd="ro" ]
CREDIT = 256
DISK = [ driver = "tap:aio:" ]
#RAW = "data = \"on_crash=destroy\""

View File

@ -1,35 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
# Default configuration attributes for the Xen driver
# (all domains will use these values as defaults). These values can
# be overridden in each VM template. Valid atributes are:
# - credit
# - os [kernel,initrd,root,kernel_cmd,hvm]
# - vcpu
# - features [acpi, pae, apic, device_model, localtime]
# - disk[driver]
# - nic[model]
# - raw
#VCPU = 1
#OS = [ kernel="/vmlinuz", initrd="/initrd.img", root="sda1", kernel_cmd="ro", hvm="yes" ]
#FEATURES = [ PAE = "no", ACPI = "yes", APIC = "yes" ]
CREDIT = 256
DISK = [ driver = "raw:" ]
#RAW = "data = \"on_crash=destroy\""

View File

@ -1 +0,0 @@
../poll_xen_kvm.rb

586
src/vmm_mad/remotes/kvm/poll Executable file
View File

@ -0,0 +1,586 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
$: << File.join(File.dirname(__FILE__), '../lib')
require 'pp'
require 'rexml/document'
require 'base64'
require 'uri'
require "poll_common"
begin
require 'rubygems'
require 'json'
JSON_LOADED = true
rescue LoadError
JSON_LOADED = false
end
ENV['LANG']='C'
ENV['LC_ALL']='C'
################################################################################
#
# KVM Monitor Module
#
################################################################################
module KVM
# Constants for KVM operations
CONF={
:dominfo => 'virsh --connect LIBVIRT_URI --readonly dominfo',
:list => 'virsh --connect LIBVIRT_URI --readonly list',
:dumpxml => 'virsh --connect LIBVIRT_URI --readonly dumpxml',
:domifstat => 'virsh --connect LIBVIRT_URI --readonly domifstat',
:top => 'top -b -d2 -n 2 -p ',
'LIBVIRT_URI' => 'qemu:///system'
}
# Execute a virsh command using the predefined command strings and URI
# @param command [Symbol] as defined in the module CONF constant
def self.virsh(command)
CONF[command].gsub('LIBVIRT_URI', CONF['LIBVIRT_URI'])
end
# Get the information of a single VM. In case of error the VM is reported
# as not found.
# @param vm_id [String] with the VM information
def self.get_vm_info(one_vm)
dominfo = dom_info(one_vm)
return { :state => '-' } if !dominfo
psinfo = process_info(dominfo['UUID'])
vm = Hash.new
vm[:name] = one_vm
vm[:pid] = psinfo[1]
cpu = get_cpu_info({one_vm => vm})
resident_mem = psinfo[5].to_i
max_mem = dominfo['Max memory'].split(/\s+/).first.to_i
values=Hash.new
values[:state] = get_state(dominfo['State'])
values[:cpu] = cpu[vm[:pid]] if cpu[vm[:pid]]
values[:memory] = [resident_mem, max_mem].max
xml = dump_xml(one_vm)
values.merge!(get_interface_statistics(one_vm, xml))
return values
end
# Gets the information of all VMs
#
# @return [Hash, nil] Hash with the VM information or nil in case of error
def self.get_all_vm_info
vms_info = Hash.new
vms = Hash.new
text=`#{virsh(:list)}`
return nil if $?.exitstatus != 0
lines = text.split(/\n/)[2..-1]
names = lines.map do |line|
line.split(/\s+/).delete_if {|d| d.empty? }[1]
end
return vms_info if names.length == 0
names.each do |vm|
dominfo = dom_info(vm)
if dominfo
psinfo = process_info(dominfo['UUID'])
info= Hash.new
info[:dominfo] = dominfo
info[:psinfo] = psinfo
info[:name] = vm
info[:pid] = psinfo[1]
vms[vm]=info
end
end
cpu = get_cpu_info(vms)
vms.each do |name, vm|
ps_data = vm[:psinfo]
dominfo = vm[:dominfo]
resident_mem = ps_data[5].to_i
max_mem = dominfo['Max memory'].split(/\s+/).first.to_i
values = Hash.new
values[:state] = get_state(dominfo['State'])
values[:cpu] = cpu[vm[:pid]] if cpu[vm[:pid]]
values[:memory] = [resident_mem, max_mem].max
xml = dump_xml(name)
values.merge!(get_interface_statistics(name, xml))
values.merge!(get_disk_usage(xml))
if !name.match(/^one-\d+/)
uuid, template = xml_to_one(xml)
values[:template] = Base64.encode64(template).delete("\n")
values[:vm_name] = name
vm[:name] = uuid
end
vms_info[vm[:name]] = values
end
return vms_info
end
# Gathers process information from a set of VMs.
# @param vms [Hash] of vms indexed by name. Value is a hash with :pid
# @return [Hash] with ps information
def self.get_cpu_info(vms)
pids = vms.map {|name, vm| vm[:pid] }
pids.compact!
cpu = Hash.new
pids.each_slice(20) do |slice|
data = %x{#{CONF[:top]} #{slice.join(',')}}
lines = data.strip.split("\n")
block_size = lines.length/2
valid_lines = lines.last(block_size)
first_domain = 7
cpu_field = nil
valid_lines.each_with_index{ |l,i|
if l.match 'PID USER'
first_domain=i+1
cpu_field = l.strip.split.index("%CPU")
break
end
}
domain_lines = valid_lines[first_domain..-1]
domain_lines.each do |line|
d = line.split
cpu[d[0]] = d[cpu_field]
end
end
cpu
end
# Process information for a KVM domain by its UUID
# @param uid [String] with user id
# @return [Array] of user processes
def self.process_info(uuid)
ps=`ps auxwww | grep -- '-uuid #{uuid}' | grep -v grep`
ps.split(/\s+/)
end
# Gets the info of a domain by its id
# @param the ID of the VM as defined in libvirt
# @return [Hash] with the output of virsh dominfo, indexed by name (Id...)
# Example execution of dominfo
# Id: 5
# Name: one-6
# UUID: 06bc1876-fc6a-4dca-b41d-d7f2093b6b59
# OS Type: hvm
# State: running
# CPU(s): 1
# CPU time: 11.1s
# Max memory: 524288 KiB
# Used memory: 524288 KiB
# Persistent: no
# Autostart: disable
# Managed save: no
# Security model: none
# Security DOI: 0
def self.dom_info(vmid)
text = `#{virsh(:dominfo)} #{vmid}`
return nil if $?.exitstatus != 0
lines = text.split(/\n/)
hash = Hash.new
lines.map do |line|
parts = line.split(/:\s+/)
hash[parts[0]] = parts[1]
end
hash
end
# Get dumpxml output of a VM
# @param the ID of the VM as defined in libvirt
# @return [String] xml output of virsh dumpxml
def self.dump_xml(vmid)
`#{virsh(:dumpxml)} '#{vmid}'`
end
# Aggregate statics of all VM NICs
# @param the ID of the VM as defined in libvirt
# @param text [nil, String] dumpxml output or nil to execute dumpxml
# @return [Hash] with network stats, by name [symbol] :netrx, :nettx
def self.get_interface_statistics(vmid, text = nil)
text = dump_xml(vmid) if !text
return {} if $?.exitstatus != 0
doc = REXML::Document.new(text)
interfaces = Array.new
doc.elements.each('domain/devices/interface/target') do |ele|
interfaces << ele.attributes["dev"]
end
return {} if interfaces.empty?
values = Hash.new
values[:netrx] = 0
values[:nettx] = 0
interfaces.each do |interface|
text=`#{virsh(:domifstat)} #{vmid} #{interface}`
next if $?.exitstatus != 0
text.each_line do |line|
columns = line.split(/\s+/)
case columns[1]
when 'rx_bytes'
values[:netrx] += columns[2].to_i
when 'tx_bytes'
values[:nettx]+=columns[2].to_i
end
end
end
values
end
# Translate libvirt state to Opennebula monitor state
# @param state [String] libvirt state
# @return [String] OpenNebula state
#
# Libvirt states for the guest are
# * 'running' state refers to guests which are currently active on a CPU.
# * 'blocked' not running or runnable (waiting on I/O or in a sleep mode).
# * 'paused' after virsh suspend.
# * 'shutdown' guest in the process of shutting down.
# * 'dying' the domain has not completely shutdown or crashed.
# * 'crashed' guests have failed while running and are no longer running.
#
def self.get_state(state)
case state.gsub('-', '')
when *%w{running blocked shutdown dying idle paused}
'a'
when 'crashed'
'e'
else
'-'
end
end
def self.get_disk_usage(xml)
return {} if !JSON_LOADED
doc = REXML::Document.new(xml)
size = 0
systemds = doc.elements['domain/metadata/system_datastore'] rescue nil
systemds = systemds.text.gsub(/\/+/, '/') if systemds
data = {
:disk_size => [],
:snapshot_size => []
}
begin
doc.elements.each('domain/devices/disk/source') do |ele|
# read the disk path (for regular disks)
file = ele.attributes['file'] rescue nil
# get protocol and name (for ceph)
protocol = ele.attributes['protocol'] rescue nil
name = ele.attributes['name'] rescue nil
if protocol == "rbd"
# Ceph
auth = ele.parent.elements["auth"].attributes["username"] rescue nil
auth = "--id #{auth}" if !auth.nil?
pool, image = name.split('/')
disk_id = image.split('-')[-1].to_i
images_list = rbd_pool(pool, auth)
images_doc = REXML::Document.new(images_list)
xpath = "images/image[image='#{image}']/size"
disk_size = images_doc.elements[xpath].text.to_f/1024/1024
data[:disk_size] << {:id => disk_id, :size => disk_size.round}
images_doc.elements.each("images/snapshot") do |snap|
next unless snap.elements["image"].text.start_with?(image)
snap_id = snap.elements["snapshot"].text.to_i
snapshot_size = snap.elements["size"].text.to_f/1024/1024
data[:snapshot_size] << { :id => snap_id, :disk_id => disk_id, :size => snapshot_size.round}
end
elsif file
# Search the disk in system datastore when the source
# is a persistent image with snapshots
source = nil
current_snap_id = nil
if !file.match(/.*disk\.\d+$/) && systemds
source = file.gsub(%r{/+}, '/')
disks = Dir["#{systemds}/disk.*"]
disks.each do |disk|
next if !File.symlink?(disk)
link = File.readlink(disk).gsub(%r{/+}, '/')
if link == source
file = disk
current_snap_id = link.split('/').last
break
end
end
else
if File.symlink?(file)
link = File.readlink(file)
current_snap_id = link.split('/').last
end
end
# Regular Disk
text = `qemu-img info --output=json #{file}`
next if !$? || !$?.success?
json = JSON.parse(text)
disk_id = file.split(".")[-1]
disk_size = json['actual-size'].to_f/1024/1024
data[:disk_size] << {:id => disk_id, :size => disk_size.round}
# Get snapshots
Dir[file + '.snap/*'].each do |snap|
if current_snap_id
next if snap.split('/').last == current_snap_id
else
next if source == snap
end
text = `qemu-img info --output=json #{snap}`
next if !$? || !$?.success?
json = JSON.parse(text)
snap_id = snap.split("/")[-1]
snap_size = json['actual-size'].to_f/1024/1024
data[:snapshot_size] << { :id => snap_id, :disk_id => disk_id, :size => snap_size.round}
end
end
end
rescue Exception => e
STDERR.puts "Error getting disk information."
STDERR.puts e.message
STDERR.puts e.backtrace.join("\n ")
end
data
end
# Convert the output of dumpxml to an OpenNebula template
# @param xml [String] output of dumpxml
# @return [Array] uuid and OpenNebula template encoded in base64
def self.xml_to_one(xml)
doc = REXML::Document.new(xml)
name = REXML::XPath.first(doc, '/domain/name').text
uuid = REXML::XPath.first(doc, '/domain/uuid').text
vcpu = REXML::XPath.first(doc, '/domain/vcpu').text
memory = REXML::XPath.first(doc, '/domain/memory').text.to_i / 1024
arch = REXML::XPath.first(doc, '/domain/os/type').attributes['arch']
=begin
disks = []
REXML::XPath.each(doc, '/domain/devices/disk') do |d|
type = REXML::XPath.first(d, '//disk').attributes['type']
driver = REXML::XPath.first(d, '//disk/driver').attributes['type']
source = REXML::XPath.first(d, '//disk/source').attributes[type]
target = REXML::XPath.first(d, '//disk/target').attributes['dev']
disks << {
:type => type,
:driver => driver,
:source => source,
:target => target
}
end
disks_txt = ''
disks.each do |disk|
disks_txt << "DISK=[\n"
disks_txt << " SOURCE=\"#{disk[:source]}\",\n"
disks_txt << " DRIVER=\"#{disk[:driver]}\",\n"
disks_txt << " TARGET=\"#{disk[:target]}\""
disks_txt << "]\n"
end
interfaces = []
REXML::XPath.each(doc,
"/domain/devices/interface[@type='bridge']") do |i|
mac = REXML::XPath.first(i, '//interface/mac').
attributes['address']
bridge = REXML::XPath.first(i, '//interface/source').
attributes['bridge']
model = REXML::XPath.first(i, '//interface/model').
attributes['type']
interfaces << {
:mac => mac,
:bridge => bridge,
:model => model
}
end
interfaces_txt = ''
interfaces.each do |interface|
interfaces_txt << "NIC=[\n"
interfaces_txt << " MAC=\"#{interface[:mac]}\",\n"
interfaces_txt << " BRIDGE=\"#{interface[:bridge]}\",\n"
interfaces_txt << " MODEL=\"#{interface[:model]}\""
interfaces_txt << "]\n"
end
=end
spice = REXML::XPath.first(doc,
"/domain/devices/graphics[@type='spice']")
spice = spice.attributes['port'] if spice
spice_txt = ''
if spice
spice_txt = %Q<GRAPHICS = [ TYPE="spice", PORT="#{spice}" ]>
end
vnc = REXML::XPath.first(doc, "/domain/devices/graphics[@type='vnc']")
vnc = vnc.attributes['port'] if vnc
vnc_txt = ''
if vnc
vnc_txt = %Q<GRAPHICS = [ TYPE="vnc", PORT="#{vnc}" ]>
end
feature_list = %w{acpi apic pae}
features = []
feature_list.each do |feature|
if REXML::XPath.first(doc, "/domain/features/#{feature}")
features << feature
end
end
feat = []
features.each do |feature|
feat << %Q[ #{feature.upcase}="yes"]
end
features_txt = "FEATURES=[\n"
features_txt << feat.join(",\n")
features_txt << "]\n"
template = <<EOT
NAME="#{name}"
CPU=#{vcpu}
VCPU=#{vcpu}
MEMORY=#{memory}
HYPERVISOR="kvm"
IMPORT_VM_ID="#{uuid}"
OS=[ARCH="#{arch}"]
#{features_txt}
#{spice_txt}
#{vnc_txt}
EOT
return uuid, template
end
def self.rbd_pool(pool, auth = nil)
@@rbd_pool ||= {}
if @@rbd_pool[pool].nil?
@@rbd_pool[pool] = `rbd #{auth} ls -l -p #{pool} --format xml`
end
@@rbd_pool[pool]
end
end
################################################################################
# MAIN PROGRAM
################################################################################
hypervisor = KVM
file = 'kvmrc'
vars = %w{LIBVIRT_URI}
load_vars(hypervisor, file, vars)
vm_id = ARGV[0]
if vm_id == '-t'
print_all_vm_template(hypervisor)
elsif vm_id
print_one_vm_info(hypervisor, vm_id)
else
print_all_vm_info(hypervisor)
end

View File

@ -0,0 +1,134 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
################################################################################
# Functions to interface hypervisor information
################################################################################
# Loads the rc variables and overrides the default values
# @param hypervisor [Module] The hypervisor Module
# @param file [String] Name of the configuration file
# @param vars [Array] Array of variables to read
def load_vars(hypervisor, file, vars)
begin
env = `. #{File.dirname($0)+"/#{file}"};env`
lines = env.split("\n")
vars.each do |var|
lines.each do |line|
if a = line.match(/^(#{var})=(.*)$/)
hypervisor::CONF[var] = a[2]
break
end
end
end
rescue
end
end
# Returns an OpenNebula monitor string
# @param name [String] of the monitor metric
# @param value [String] of the monitor metric
# @return [String, nil]
def print_data(name, value)
return nil if value.nil? || (value.respond_to?(:empty?) && value.empty?)
if value.instance_of? Array
data_str = ""
value.each do |v|
data_str += print_data(name, v)
end
return data_str
elsif value.instance_of? Hash
values = value.map do |k,v|
"#{k.to_s.upcase}=#{v}"
end.join(", ")
return "#{name.to_s.upcase}=[ #{values} ] "
else
return "#{name.to_s.upcase}=#{value}"
end
end
# Puts to STDOUT a string in the form "VAL1=VAR1 VAL2=VAR2" with the monitor
# attributes of the VM
# @param hypervisor [Module]
# @param vm_id [String] with the VM ID
def print_one_vm_info(hypervisor, vm_id)
info = hypervisor.get_vm_info(vm_id)
exit(-1) if !info
values = info.map do |key, value|
print_data(key, value)
end
puts values.zip.join(' ')
end
def print_all_vm_info(hypervisor)
require 'yaml'
require 'zlib'
vms = hypervisor.get_all_vm_info
return nil if vms.nil?
compressed = Zlib::Deflate.deflate(vms.to_yaml)
puts Base64.encode64(compressed).delete("\n")
end
def print_all_vm_template(hypervisor)
vms=hypervisor.get_all_vm_info
return nil if vms.nil?
puts "VM_POLL=YES"
vms.each do |name, data|
number = -1
if (name =~ /^one-\d*$/)
number = name.split('-').last
end
vm_name = data[:vm_name]
string = "VM=[\n"
string << " ID=#{number},\n"
string << " DEPLOY_ID=#{name},\n"
string << %Q( VM_NAME="#{vm_name}",\n) if vm_name
if data[:template]
string << %Q( IMPORT_TEMPLATE="#{data[:template]}",\n)
data.delete(:template)
end
values = data.map do |key, value|
print_data(key, value)
end
monitor = values.zip.join(' ')
string << " POLL=\"#{monitor}\" ]"
puts string
end
end

View File

@ -1,919 +0,0 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require 'pp'
require 'rexml/document'
require 'base64'
require 'uri'
begin
require 'rubygems'
require 'json'
JSON_LOADED = true
rescue LoadError
JSON_LOADED = false
end
ENV['LANG']='C'
ENV['LC_ALL']='C'
################################################################################
#
# KVM Monitor Module
#
################################################################################
module KVM
# Constants for KVM operations
CONF={
:dominfo => 'virsh --connect LIBVIRT_URI --readonly dominfo',
:list => 'virsh --connect LIBVIRT_URI --readonly list',
:dumpxml => 'virsh --connect LIBVIRT_URI --readonly dumpxml',
:domifstat => 'virsh --connect LIBVIRT_URI --readonly domifstat',
:top => 'top -b -d2 -n 2 -p ',
'LIBVIRT_URI' => 'qemu:///system'
}
# Execute a virsh command using the predefined command strings and URI
# @param command [Symbol] as defined in the module CONF constant
def self.virsh(command)
CONF[command].gsub('LIBVIRT_URI', CONF['LIBVIRT_URI'])
end
# Get the information of a single VM. In case of error the VM is reported
# as not found.
# @param vm_id [String] with the VM information
def self.get_vm_info(one_vm)
dominfo = dom_info(one_vm)
return { :state => '-' } if !dominfo
psinfo = process_info(dominfo['UUID'])
vm = Hash.new
vm[:name] = one_vm
vm[:pid] = psinfo[1]
cpu = get_cpu_info({one_vm => vm})
resident_mem = psinfo[5].to_i
max_mem = dominfo['Max memory'].split(/\s+/).first.to_i
values=Hash.new
values[:state] = get_state(dominfo['State'])
values[:cpu] = cpu[vm[:pid]] if cpu[vm[:pid]]
values[:memory] = [resident_mem, max_mem].max
xml = dump_xml(one_vm)
values.merge!(get_interface_statistics(one_vm, xml))
return values
end
# Gets the information of all VMs
#
# @return [Hash, nil] Hash with the VM information or nil in case of error
def self.get_all_vm_info
vms_info = Hash.new
vms = Hash.new
text=`#{virsh(:list)}`
return nil if $?.exitstatus != 0
lines = text.split(/\n/)[2..-1]
names = lines.map do |line|
line.split(/\s+/).delete_if {|d| d.empty? }[1]
end
return vms_info if names.length == 0
names.each do |vm|
dominfo = dom_info(vm)
if dominfo
psinfo = process_info(dominfo['UUID'])
info= Hash.new
info[:dominfo] = dominfo
info[:psinfo] = psinfo
info[:name] = vm
info[:pid] = psinfo[1]
vms[vm]=info
end
end
cpu = get_cpu_info(vms)
vms.each do |name, vm|
ps_data = vm[:psinfo]
dominfo = vm[:dominfo]
resident_mem = ps_data[5].to_i
max_mem = dominfo['Max memory'].split(/\s+/).first.to_i
values = Hash.new
values[:state] = get_state(dominfo['State'])
values[:cpu] = cpu[vm[:pid]] if cpu[vm[:pid]]
values[:memory] = [resident_mem, max_mem].max
xml = dump_xml(name)
values.merge!(get_interface_statistics(name, xml))
values.merge!(get_disk_usage(xml))
if !name.match(/^one-\d+/)
uuid, template = xml_to_one(xml)
values[:template] = Base64.encode64(template).delete("\n")
values[:vm_name] = name
vm[:name] = uuid
end
vms_info[vm[:name]] = values
end
return vms_info
end
# Gathers process information from a set of VMs.
# @param vms [Hash] of vms indexed by name. Value is a hash with :pid
# @return [Hash] with ps information
def self.get_cpu_info(vms)
pids = vms.map {|name, vm| vm[:pid] }
pids.compact!
cpu = Hash.new
pids.each_slice(20) do |slice|
data = %x{#{CONF[:top]} #{slice.join(',')}}
lines = data.strip.split("\n")
block_size = lines.length/2
valid_lines = lines.last(block_size)
first_domain = 7
cpu_field = nil
valid_lines.each_with_index{ |l,i|
if l.match 'PID USER'
first_domain=i+1
cpu_field = l.strip.split.index("%CPU")
break
end
}
domain_lines = valid_lines[first_domain..-1]
domain_lines.each do |line|
d = line.split
cpu[d[0]] = d[cpu_field]
end
end
cpu
end
# Process information for a KVM domain by its UUID
# @param uid [String] with user id
# @return [Array] of user processes
def self.process_info(uuid)
ps=`ps auxwww | grep -- '-uuid #{uuid}' | grep -v grep`
ps.split(/\s+/)
end
# Gets the info of a domain by its id
# @param the ID of the VM as defined in libvirt
# @return [Hash] with the output of virsh dominfo, indexed by name (Id...)
# Example execution of dominfo
# Id: 5
# Name: one-6
# UUID: 06bc1876-fc6a-4dca-b41d-d7f2093b6b59
# OS Type: hvm
# State: running
# CPU(s): 1
# CPU time: 11.1s
# Max memory: 524288 KiB
# Used memory: 524288 KiB
# Persistent: no
# Autostart: disable
# Managed save: no
# Security model: none
# Security DOI: 0
def self.dom_info(vmid)
text = `#{virsh(:dominfo)} #{vmid}`
return nil if $?.exitstatus != 0
lines = text.split(/\n/)
hash = Hash.new
lines.map do |line|
parts = line.split(/:\s+/)
hash[parts[0]] = parts[1]
end
hash
end
# Get dumpxml output of a VM
# @param the ID of the VM as defined in libvirt
# @return [String] xml output of virsh dumpxml
def self.dump_xml(vmid)
`#{virsh(:dumpxml)} '#{vmid}'`
end
# Aggregate statics of all VM NICs
# @param the ID of the VM as defined in libvirt
# @param text [nil, String] dumpxml output or nil to execute dumpxml
# @return [Hash] with network stats, by name [symbol] :netrx, :nettx
def self.get_interface_statistics(vmid, text = nil)
text = dump_xml(vmid) if !text
return {} if $?.exitstatus != 0
doc = REXML::Document.new(text)
interfaces = Array.new
doc.elements.each('domain/devices/interface/target') do |ele|
interfaces << ele.attributes["dev"]
end
return {} if interfaces.empty?
values = Hash.new
values[:netrx] = 0
values[:nettx] = 0
interfaces.each do |interface|
text=`#{virsh(:domifstat)} #{vmid} #{interface}`
next if $?.exitstatus != 0
text.each_line do |line|
columns = line.split(/\s+/)
case columns[1]
when 'rx_bytes'
values[:netrx] += columns[2].to_i
when 'tx_bytes'
values[:nettx]+=columns[2].to_i
end
end
end
values
end
# Translate libvirt state to Opennebula monitor state
# @param state [String] libvirt state
# @return [String] OpenNebula state
#
# Libvirt states for the guest are
# * 'running' state refers to guests which are currently active on a CPU.
# * 'blocked' not running or runnable (waiting on I/O or in a sleep mode).
# * 'paused' after virsh suspend.
# * 'shutdown' guest in the process of shutting down.
# * 'dying' the domain has not completely shutdown or crashed.
# * 'crashed' guests have failed while running and are no longer running.
#
def self.get_state(state)
case state.gsub('-', '')
when *%w{running blocked shutdown dying idle paused}
'a'
when 'crashed'
'e'
else
'-'
end
end
def self.get_disk_usage(xml)
return {} if !JSON_LOADED
doc = REXML::Document.new(xml)
size = 0
systemds = doc.elements['domain/metadata/system_datastore'] rescue nil
systemds = systemds.text.gsub(/\/+/, '/') if systemds
data = {
:disk_size => [],
:snapshot_size => []
}
begin
doc.elements.each('domain/devices/disk/source') do |ele|
# read the disk path (for regular disks)
file = ele.attributes['file'] rescue nil
# get protocol and name (for ceph)
protocol = ele.attributes['protocol'] rescue nil
name = ele.attributes['name'] rescue nil
if protocol == "rbd"
# Ceph
auth = ele.parent.elements["auth"].attributes["username"] rescue nil
auth = "--id #{auth}" if !auth.nil?
pool, image = name.split('/')
disk_id = image.split('-')[-1].to_i
images_list = rbd_pool(pool, auth)
images_doc = REXML::Document.new(images_list)
xpath = "images/image[image='#{image}']/size"
disk_size = images_doc.elements[xpath].text.to_f/1024/1024
data[:disk_size] << {:id => disk_id, :size => disk_size.round}
images_doc.elements.each("images/snapshot") do |snap|
next unless snap.elements["image"].text.start_with?(image)
snap_id = snap.elements["snapshot"].text.to_i
snapshot_size = snap.elements["size"].text.to_f/1024/1024
data[:snapshot_size] << { :id => snap_id, :disk_id => disk_id, :size => snapshot_size.round}
end
elsif file
# Search the disk in system datastore when the source
# is a persistent image with snapshots
source = nil
current_snap_id = nil
if !file.match(/.*disk\.\d+$/) && systemds
source = file.gsub(%r{/+}, '/')
disks = Dir["#{systemds}/disk.*"]
disks.each do |disk|
next if !File.symlink?(disk)
link = File.readlink(disk).gsub(%r{/+}, '/')
if link == source
file = disk
current_snap_id = link.split('/').last
break
end
end
else
if File.symlink?(file)
link = File.readlink(file)
current_snap_id = link.split('/').last
end
end
# Regular Disk
text = `qemu-img info --output=json #{file}`
next if !$? || !$?.success?
json = JSON.parse(text)
disk_id = file.split(".")[-1]
disk_size = json['actual-size'].to_f/1024/1024
data[:disk_size] << {:id => disk_id, :size => disk_size.round}
# Get snapshots
Dir[file + '.snap/*'].each do |snap|
if current_snap_id
next if snap.split('/').last == current_snap_id
else
next if source == snap
end
text = `qemu-img info --output=json #{snap}`
next if !$? || !$?.success?
json = JSON.parse(text)
snap_id = snap.split("/")[-1]
snap_size = json['actual-size'].to_f/1024/1024
data[:snapshot_size] << { :id => snap_id, :disk_id => disk_id, :size => snap_size.round}
end
end
end
rescue Exception => e
STDERR.puts "Error getting disk information."
STDERR.puts e.message
STDERR.puts e.backtrace.join("\n ")
end
data
end
# Convert the output of dumpxml to an OpenNebula template
# @param xml [String] output of dumpxml
# @return [Array] uuid and OpenNebula template encoded in base64
def self.xml_to_one(xml)
doc = REXML::Document.new(xml)
name = REXML::XPath.first(doc, '/domain/name').text
uuid = REXML::XPath.first(doc, '/domain/uuid').text
vcpu = REXML::XPath.first(doc, '/domain/vcpu').text
memory = REXML::XPath.first(doc, '/domain/memory').text.to_i / 1024
arch = REXML::XPath.first(doc, '/domain/os/type').attributes['arch']
=begin
disks = []
REXML::XPath.each(doc, '/domain/devices/disk') do |d|
type = REXML::XPath.first(d, '//disk').attributes['type']
driver = REXML::XPath.first(d, '//disk/driver').attributes['type']
source = REXML::XPath.first(d, '//disk/source').attributes[type]
target = REXML::XPath.first(d, '//disk/target').attributes['dev']
disks << {
:type => type,
:driver => driver,
:source => source,
:target => target
}
end
disks_txt = ''
disks.each do |disk|
disks_txt << "DISK=[\n"
disks_txt << " SOURCE=\"#{disk[:source]}\",\n"
disks_txt << " DRIVER=\"#{disk[:driver]}\",\n"
disks_txt << " TARGET=\"#{disk[:target]}\""
disks_txt << "]\n"
end
interfaces = []
REXML::XPath.each(doc,
"/domain/devices/interface[@type='bridge']") do |i|
mac = REXML::XPath.first(i, '//interface/mac').
attributes['address']
bridge = REXML::XPath.first(i, '//interface/source').
attributes['bridge']
model = REXML::XPath.first(i, '//interface/model').
attributes['type']
interfaces << {
:mac => mac,
:bridge => bridge,
:model => model
}
end
interfaces_txt = ''
interfaces.each do |interface|
interfaces_txt << "NIC=[\n"
interfaces_txt << " MAC=\"#{interface[:mac]}\",\n"
interfaces_txt << " BRIDGE=\"#{interface[:bridge]}\",\n"
interfaces_txt << " MODEL=\"#{interface[:model]}\""
interfaces_txt << "]\n"
end
=end
spice = REXML::XPath.first(doc,
"/domain/devices/graphics[@type='spice']")
spice = spice.attributes['port'] if spice
spice_txt = ''
if spice
spice_txt = %Q<GRAPHICS = [ TYPE="spice", PORT="#{spice}" ]>
end
vnc = REXML::XPath.first(doc, "/domain/devices/graphics[@type='vnc']")
vnc = vnc.attributes['port'] if vnc
vnc_txt = ''
if vnc
vnc_txt = %Q<GRAPHICS = [ TYPE="vnc", PORT="#{vnc}" ]>
end
feature_list = %w{acpi apic pae}
features = []
feature_list.each do |feature|
if REXML::XPath.first(doc, "/domain/features/#{feature}")
features << feature
end
end
feat = []
features.each do |feature|
feat << %Q[ #{feature.upcase}="yes"]
end
features_txt = "FEATURES=[\n"
features_txt << feat.join(",\n")
features_txt << "]\n"
template = <<EOT
NAME="#{name}"
CPU=#{vcpu}
VCPU=#{vcpu}
MEMORY=#{memory}
HYPERVISOR="kvm"
IMPORT_VM_ID="#{uuid}"
OS=[ARCH="#{arch}"]
#{features_txt}
#{spice_txt}
#{vnc_txt}
EOT
return uuid, template
end
def self.rbd_pool(pool, auth = nil)
@@rbd_pool ||= {}
if @@rbd_pool[pool].nil?
@@rbd_pool[pool] = `rbd #{auth} ls -l -p #{pool} --format xml`
end
@@rbd_pool[pool]
end
end
################################################################################
#
# Xen Monitor Module
#
################################################################################
module XEN
# Default configuration variables. It can be overridden through xenrc
CONF={
'XM_POLL' => 'sudo /usr/sbin/xentop -bi2'
}
# Get the information of a single VM. In case of error the VM is reported
# as not found.
# @param vm_id [String] with the VM information
def self.get_vm_info(vm_id)
data = get_all_vm_info
if !data
return {:STATE => 'd'}
else
return data[vm_id]
end
end
# Gets the information of all VMs
#
# @return [Hash, nil] Hash with the VM information or nil in case of error
def self.get_all_vm_info
begin
begin
list_long = get_vm_list_long
rescue
list_long = []
end
vm_templates = get_vm_templates(list_long)
vm_disk_stats = get_vm_disk_stats(list_long)
text = `#{CONF['XM_POLL']}`
return nil if $?.exitstatus != 0
lines = text.strip.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_lines = valid_lines[first_domain..-1]
domains = Hash.new
domain_lines.each do |dom|
dom_data = dom.gsub('no limit', 'no-limit').strip.split
name = dom_data[0]
dom_hash = Hash.new
dom_hash[:name] = name
dom_hash[:vm_name] = name
dom_hash[:state] = get_state(dom_data[1])
dom_hash[:cpu] = dom_data[3]
dom_hash[:memory] = dom_data[4]
dom_hash[:nettx] = dom_data[10].to_i * 1024
dom_hash[:netrx] = dom_data[11].to_i * 1024
if !name.match(/^one-\d/) && vm_templates[name]
dom_hash[:template] =
Base64.encode64(vm_templates[name]).delete("\n")
end
dom_hash.merge!(vm_disk_stats[name]) if vm_disk_stats[name]
domains[name] = dom_hash
end
domains
rescue
STDERR.puts "Error executing #{CONF['XM_POLL']}"
nil
end
end
# Returns an OpenNebula state from the Xen status
# @param state [String] with the Xen status
# @return [String] OpenNebula monitor state
#
# Xentop states are:
# 'd' domain is dying
# 's' domain shutting down
# 'b' blocked domain
# 'c' domain crashed
# 'p' domain paused
# 'r' domain is actively ruining on one of the CPU
def self.get_state(state)
case state.gsub('-', '')[-1..-1]
when *%w{r b s d p}
'a'
when 'c'
'e'
else
'-'
end
end
def self.get_vm_list_long
return {} if !JSON_LOADED
text = `#{CONF['XM_LIST']} -l`
doms = JSON.parse(text)
end
def self.get_vm_templates(doms)
dom_tmpl = {}
doms.each do |dom|
name = dom['config']['c_info']['name']
name = URI.escape(name)
tmp = %Q<NAME = "#{name}"\n>
tmp << %Q<IMPORT_VM_ID = "#{name}"\n>
vcpus = dom['config']['b_info']['max_vcpus'].to_i
vcpus = 1 if vcpus < 1
tmp << %Q<CPU = #{vcpus}\n>
tmp << %Q<VCPU = #{vcpus}\n>
memory = dom['config']['b_info']['max_memkb']
memory /= 1024
tmp << %Q<MEMORY = #{memory}\n>
dom_tmpl[name] = tmp
end
dom_tmpl
end
def self.get_vm_disk_stats(doms)
dom_disk_stats = {}
doms.each do |dom|
data = {
:disk_size => [],
:snapshot_size => []
}
dom['config']['disks'].each do |disk|
next if !disk['pdev_path']
path = disk['pdev_path']
text = `qemu-img info --output=json #{path}`
next if !$? || !$?.success?
json = JSON.parse(text)
disk_id = path.split(".")[-1]
disk_size = json['actual-size'].to_f/1024/1024
data[:disk_size] << {:id => disk_id, :size => disk_size.round}
end
data
end
dom_disk_stats
end
end
################################################################################
# Functions to interface hypervisor information
################################################################################
# Selects the hypervisor to be used based on the arguments or probe location
# This function also loads the associated configuration variables.
# @return [Module] with the hypervisor XEN, KVM
def setup_hypervisor
hypervisor = nil
params = ARGV.clone
params.each_with_index do |param, index|
case param
when '--kvm'
hypervisor = KVM
ARGV.delete_at(index)
when '--xen'
hypervisor = XEN
ARGV.delete_at(index)
end
end
if !hypervisor
case $0
when %r{/vmm\/kvm/}
hypervisor=KVM
when %r{/vmm\/xen\d?/}
hypervisor=XEN
end
end
case hypervisor.name
when 'XEN'
file = 'xenrc'
vars = %w{XM_POLL XM_LIST}
when 'KVM'
file = 'kvmrc'
vars = %w{LIBVIRT_URI}
else
return nil
end
# Load the rc variables and override the default values
begin
env = `. #{File.dirname($0)+"/#{file}"};env`
lines = env.split("\n")
vars.each do |var|
lines.each do |line|
if a = line.match(/^(#{var})=(.*)$/)
hypervisor::CONF[var] = a[2]
break
end
end
end
rescue
end
return hypervisor
end
# Returns an OpenNebula monitor string
# @param name [String] of the monitor metric
# @param value [String] of the monitor metric
# @return [String, nil]
def print_data(name, value)
return nil if value.nil? || (value.respond_to?(:empty?) && value.empty?)
if value.instance_of? Array
data_str = ""
value.each do |v|
data_str += print_data(name, v)
end
return data_str
elsif value.instance_of? Hash
values = value.map do |k,v|
"#{k.to_s.upcase}=#{v}"
end.join(", ")
return "#{name.to_s.upcase}=[ #{values} ] "
else
return "#{name.to_s.upcase}=#{value}"
end
end
# Puts to STDOUT a string in the form "VAL1=VAR1 VAL2=VAR2" with the monitor
# attributes of the VM
# @param hypervisor [Module]
# @param vm_id [String] with the VM ID
def print_one_vm_info(hypervisor, vm_id)
info = hypervisor.get_vm_info(vm_id)
exit(-1) if !info
values = info.map do |key, value|
print_data(key, value)
end
puts values.zip.join(' ')
end
def print_all_vm_info(hypervisor)
require 'yaml'
require 'zlib'
vms = hypervisor.get_all_vm_info
return nil if vms.nil?
compressed = Zlib::Deflate.deflate(vms.to_yaml)
puts Base64.encode64(compressed).delete("\n")
end
def print_all_vm_template(hypervisor)
vms=hypervisor.get_all_vm_info
return nil if vms.nil?
puts "VM_POLL=YES"
vms.each do |name, data|
number = -1
if (name =~ /^one-\d*$/)
number = name.split('-').last
end
vm_name = data[:vm_name]
string = "VM=[\n"
string << " ID=#{number},\n"
string << " DEPLOY_ID=#{name},\n"
string << %Q( VM_NAME="#{vm_name}",\n) if vm_name
if data[:template]
string << %Q( IMPORT_TEMPLATE="#{data[:template]}",\n)
data.delete(:template)
end
values = data.map do |key, value|
print_data(key, value)
end
monitor = values.zip.join(' ')
string << " POLL=\"#{monitor}\" ]"
puts string
end
end
################################################################################
# MAIN PROGRAM
################################################################################
hypervisor = setup_hypervisor
if !hypervisor
STDERR.puts "Could not detect hypervisor"
exit(-1)
end
vm_id = ARGV[0]
if vm_id == '-t'
print_all_vm_template(hypervisor)
elsif vm_id
print_one_vm_info(hypervisor, vm_id)
else
print_all_vm_info(hypervisor)
end

View File

@ -1,76 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
DRIVER_PATH=$(dirname $0)
DOMAIN="$1"
SOURCE="$2"
TARGET="$3"
TARGET_INDEX="$4"
DRV_ACTION="$5"
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb -b $DRV_ACTION"
unset i XPATH_ELEMENTS
DISK_XPATH="/VMM_DRIVER_ACTION_DATA/VM/TEMPLATE/DISK[ATTACH='YES']"
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <($XPATH $DISK_XPATH/DRIVER \
$DISK_XPATH/TYPE \
$DISK_XPATH/READONLY \
$DISK_XPATH/BUS \
$DISK_XPATH/CACHE)
DRIVER="${XPATH_ELEMENTS[0]:-$DEFAULT_TYPE}"
TYPE="${XPATH_ELEMENTS[1]}"
READONLY="${XPATH_ELEMENTS[2]}"
BUS="${XPATH_ELEMENTS[3]}"
CACHE="${XPATH_ELEMENTS[4]}"
if [ -z "$DEFAULT_FILE_PREFIX" ]; then
DEFAULT_FILE_PREFIX="file"
fi
case "$TYPE" in
block)
FILE_PREFIX="phy"
;;
*)
FILE_PREFIX="$DEFAULT_FILE_PREFIX"
;;
esac
if [ -n "$DRIVER" ]; then
FILE_PREFIX="$DRIVER"
fi
FULL_DISK="${FILE_PREFIX%:}:$SOURCE"
if [ "$READONLY" = "YES" ]; then
MODE="r"
else
MODE="w"
fi
exec_and_log "$XM_ATTACH_DISK $DOMAIN $FULL_DISK ${TARGET_PREFIX}$TARGET $MODE" \
"Could not attach $FULL_DISK ($TARGET) to $DOMAIN"

View File

@ -1,28 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
DOMAIN=$1
MAC=$2
SOURCE=$3
MODEL=$4
exec_and_log "$XM_ATTACH_NIC $DOMAIN bridge=$SOURCE mac=$MAC" \
"Could not attach NIC ($MAC) to $DOMAIN"

View File

@ -1,43 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
function gdm {
$XM_LIST | grep "$deploy_id "
}
OUT=$(gdm)
if [ -z "$OUT" ]; then
exit 0
fi
exec_and_log "$XM_CANCEL $deploy_id" \
"Could not destroy $deploy_id"
OUT=$(gdm)
while [ -n "$OUT" ]; do
sleep 1
OUT=$(gdm)
done

View File

@ -1,59 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
function error_exit() {
exit_code=$1
message=$2
if [ "x$exit_code" != "x0" ]; then
error_message $message
exit $exit_code
fi
}
domain=$1
id=$2
host=$3
mkdir -p `dirname $domain`
cat > $domain
output=`$XM_CREATE $domain`
error_exit $? "Unable to create domain"
domain_name=`grep -e '^name =' < $domain | cut -d= -f2 | tr -d ' ' | tr -d "\'" | cut -d' ' -f1`
out=`grep -e '^\#O CPU_CREDITS =' < $domain`
if [ "x$?" = "x0" ]; then
credits=`echo $out | cut -d= -f2 | tr -d ' '`
log_debug "Credits set to $credits"
$XM_CREDITS -d $domain_name -w $credits
if [ "x$?" != "x0" ]; then
log_error "Unable to set VM credits"
fi
fi
echo $domain_name

View File

@ -1,28 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
DOMAIN="$1"
SOURCE="$2"
TARGET="$3"
TARGET_INDEX="$4"
exec_and_log "$XM_DETACH_DISK $DOMAIN ${TARGET_PREFIX}$TARGET" \
"Could not detach $TARGET from $DOMAIN"

View File

@ -1,28 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
DOMAIN=$1
MAC=$2
ID=`$XM_NETWORK_LIST $DOMAIN | grep -i $MAC | cut -d' ' -f1`
exec_and_log "$XM_DETACH_NIC $DOMAIN $ID" \
"Could not detach NIC ($MAC) from $DOMAIN"

View File

@ -1 +0,0 @@
../poll_xen_kvm.rb

View File

@ -1 +0,0 @@
../common/dummy.sh

View File

@ -1,24 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
exec_and_log "$XM_REBOOT $deploy_id" "Could not reboot domain $deploy_id"

View File

@ -1 +0,0 @@
../common/dummy.sh

View File

@ -1,26 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
file=$1
exec_and_log "$XM_RESTORE $file" \
"Could not restore from $file"

View File

@ -1,34 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
file=$2
if [ -f $file ]; then
log "Moving old checkpoint file $file"
epoch=`date +%s`
exec_and_log "mv $file $file.$epoch" \
"Could not move $file to $file.$epoch"
fi
exec_and_log "$XM_SAVE $deploy_id $file" \
"Could not save $deploy_id to $file"

View File

@ -1,43 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
if [ -z "$SHUTDOWN_TIMEOUT" ]; then
TIMEOUT=120
else
TIMEOUT=$SHUTDOWN_TIMEOUT
fi
function monitor
{
$XM_LIST "$deploy_id" > /dev/null
[ "x$?" != "x0" ]
}
exec_and_log "$XM_SHUTDOWN $deploy_id" \
"Could not shutdown $deploy_id"
retry $TIMEOUT monitor
force_shutdown "$deploy_id" "$XM_CANCEL $deploy_id"

View File

@ -1,21 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/../../scripts_common.sh
log_error "Snapshotting is not yet supported for Xen."
exit 1

View File

@ -1,22 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/../../scripts_common.sh
log_error "Snapshotting is not yet supported for Xen."
exit 1

View File

@ -1,22 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/../../scripts_common.sh
log_error "Snapshotting is not yet supported for Xen."
exit 1

View File

@ -1,26 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
dest_host=$2
exec_and_log "$XM_MIGRATE $deploy_id $dest_host" \
"Could not migrate $deploy_id to $dest_host"

View File

@ -1,24 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
exec_and_log "$XM_RESET $deploy_id" "Could not reset domain $deploy_id"

View File

@ -1,55 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
export LANG=C
export XM_PATH="/usr/sbin/xm"
export XM_CANCEL="sudo $XM_PATH destroy"
export XM_CREATE="sudo $XM_PATH create"
export XM_CREDITS="sudo $XM_PATH sched-cred"
export XM_MIGRATE="sudo $XM_PATH migrate -l"
export XM_SAVE="sudo $XM_PATH save"
export XM_REBOOT="sudo $XM_PATH reboot"
export XM_RESET="sudo $XM_PATH reset"
export XM_RESTORE="sudo $XM_PATH restore"
export XM_LIST="sudo $XM_PATH list"
export XM_SHUTDOWN="sudo $XM_PATH shutdown"
export XM_POLL="sudo /usr/sbin/xentop -fbi2"
export XM_ATTACH_DISK="sudo $XM_PATH block-attach"
export XM_DETACH_DISK="sudo $XM_PATH block-detach"
export XM_ATTACH_NIC="sudo $XM_PATH network-attach"
export XM_DETACH_NIC="sudo $XM_PATH network-detach"
export XM_NETWORK_LIST="sudo $XM_PATH network-list"
# In xen 4.1 the credit scheduler command is called sched-credit,
# uncomment this line if you are using this version
#export XM_CREDITS="sudo $XM_PATH sched-credit"
# Xen 4 uses the new blktap2 and tap:aio handler is no longer supported.
# To make it work uncomment this line. This will be used as the default
# handler for disk hot plug
#export DEFAULT_FILE_PREFIX="tap:tapdisk:aio"
export DEFAULT_FILE_PREFIX="file"
# attach and detach disk target prefix
TARGET_PREFIX="/dev/"
# Seconds to wait after shutdown until timeout
export SHUTDOWN_TIMEOUT=300
# Uncomment this line to force VM cancellation after shutdown timeout
#export FORCE_DESTROY=yes

View File

@ -1,30 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
dest_host=$2
USERNAME=$(whoami)
CMD="$SSH $dest_host $XM_MIGRATE_RECEIVE"
CMD="$XM_MIGRATE -s \"su - $USERNAME -c '$CMD'\" $deploy_id $dest_host"
multiline_exec_and_log "$CMD" "Could not migrate $deploy_id to $dest_host"

View File

@ -1,24 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
exec_and_log "$XM_REBOOT -F $deploy_id" "Could not reset domain $deploy_id"

View File

@ -1,55 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
export LANG=C
export XM_PATH="/usr/sbin/xl"
export XM_CANCEL="sudo $XM_PATH destroy"
export XM_CREATE="sudo $XM_PATH create"
export XM_CREDITS="sudo $XM_PATH sched-cred"
export XM_MIGRATE="sudo $XM_PATH migrate"
export XM_MIGRATE_RECEIVE="sudo $XM_PATH migrate-receive"
export XM_SAVE="sudo $XM_PATH save"
export XM_REBOOT="sudo $XM_PATH reboot"
export XM_RESET="sudo $XM_PATH reset"
export XM_RESTORE="sudo $XM_PATH restore"
export XM_LIST="sudo $XM_PATH list"
export XM_SHUTDOWN="sudo $XM_PATH shutdown"
export XM_POLL="sudo /usr/sbin/xentop -fbi2"
export XM_ATTACH_DISK="sudo $XM_PATH block-attach"
export XM_DETACH_DISK="sudo $XM_PATH block-detach"
export XM_ATTACH_NIC="sudo $XM_PATH network-attach"
export XM_DETACH_NIC="sudo $XM_PATH network-detach"
export XM_NETWORK_LIST="sudo $XM_PATH network-list"
# In xen 4.1 the credit scheduler command is called sched-credit,
# uncomment this line if you are using this version
export XM_CREDITS="sudo $XM_PATH sched-credit"
# Xen 4 uses the new blktap2 and tap:aio handler is no longer supported.
# To make it work uncomment this line. This will be used as the default
# handler for disk hot plug
export DEFAULT_FILE_PREFIX="raw"
# attach and detach disk target prefix
TARGET_PREFIX=""
# Seconds to wait after shutdown until timeout
export SHUTDOWN_TIMEOUT=300
# Uncomment this line to force VM cancellation after shutdown timeout
#export FORCE_DESTROY=yes