mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-03 01:17:41 +03:00
Feature VMWARE: Added VMware drivers to OpenNebula. Contributed by C12G
This commit is contained in:
parent
bb4b0c6cea
commit
f95115ae12
6
NOTICE
6
NOTICE
@ -1,6 +1,8 @@
|
||||
OpenNebula Open Source Project
|
||||
--------------------------------------------------------------------------------
|
||||
Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
|
||||
-----------------------------------------
|
||||
Copyright 2010-2011, C12G Labs S.L. (C12G.com)
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
You can find more information about the project, release notes and
|
||||
documentation at www.OpenNebula.org
|
||||
@ -20,6 +22,8 @@ The following people have contributed to the development of the technology
|
||||
- Daniel Molina Aranda (dmolina@opennebula.org)
|
||||
- Hector Sanjuan Redondo (hsanjuan@opennebula.org)
|
||||
|
||||
OpenNebula Project also acknowledges the contributions of C12G Labs developers.
|
||||
|
||||
LICENSE
|
||||
|
||||
OpenNebula is licensed under the Apache License, Version 2.0 (the
|
||||
|
@ -189,6 +189,7 @@ build_scripts=[
|
||||
'src/host/SConstruct',
|
||||
'src/group/SConstruct',
|
||||
'src/mad/SConstruct',
|
||||
'src/mad/utils/SConstruct',
|
||||
'src/nebula/SConstruct',
|
||||
'src/pool/SConstruct',
|
||||
'src/vm/SConstruct',
|
||||
|
54
install.sh
54
install.sh
@ -180,14 +180,13 @@ fi
|
||||
SHARE_DIRS="$SHARE_LOCATION/examples \
|
||||
$SHARE_LOCATION/examples/tm"
|
||||
|
||||
ETC_DIRS="$ETC_LOCATION/im_kvm \
|
||||
$ETC_LOCATION/im_xen \
|
||||
$ETC_LOCATION/im_ec2 \
|
||||
ETC_DIRS="$ETC_LOCATION/im_ec2 \
|
||||
$ETC_LOCATION/vmm_ec2 \
|
||||
$ETC_LOCATION/vmm_exec \
|
||||
$ETC_LOCATION/tm_shared \
|
||||
$ETC_LOCATION/tm_ssh \
|
||||
$ETC_LOCATION/tm_dummy \
|
||||
$ETC_LOCATION/tm_vmware \
|
||||
$ETC_LOCATION/tm_lvm \
|
||||
$ETC_LOCATION/hm \
|
||||
$ETC_LOCATION/auth \
|
||||
@ -210,6 +209,7 @@ LIB_DIRS="$LIB_LOCATION/ruby \
|
||||
$LIB_LOCATION/tm_commands/ssh \
|
||||
$LIB_LOCATION/tm_commands/dummy \
|
||||
$LIB_LOCATION/tm_commands/lvm \
|
||||
$LIB_LOCATION/tm_commands/vmware \
|
||||
$LIB_LOCATION/mads \
|
||||
$LIB_LOCATION/sh \
|
||||
$LIB_LOCATION/ruby/cli \
|
||||
@ -220,9 +220,11 @@ VAR_DIRS="$VAR_LOCATION/remotes \
|
||||
$VAR_LOCATION/remotes/im \
|
||||
$VAR_LOCATION/remotes/im/kvm.d \
|
||||
$VAR_LOCATION/remotes/im/xen.d \
|
||||
$VAR_LOCATION/remotes/im/vmware.d \
|
||||
$VAR_LOCATION/remotes/im/ganglia.d \
|
||||
$VAR_LOCATION/remotes/vmm/xen \
|
||||
$VAR_LOCATION/remotes/vmm/kvm \
|
||||
$VAR_LOCATION/remotes/vmm/xen \
|
||||
$VAR_LOCATION/remotes/vmm/vmware \
|
||||
$VAR_LOCATION/remotes/hooks \
|
||||
$VAR_LOCATION/remotes/hooks/vnm \
|
||||
$VAR_LOCATION/remotes/hooks/ft \
|
||||
@ -327,6 +329,7 @@ INSTALL_FILES=(
|
||||
IM_PROBES_FILES:$VAR_LOCATION/remotes/im
|
||||
IM_PROBES_KVM_FILES:$VAR_LOCATION/remotes/im/kvm.d
|
||||
IM_PROBES_XEN_FILES:$VAR_LOCATION/remotes/im/xen.d
|
||||
IM_PROBES_VMWARE_FILES:$VAR_LOCATION/remotes/im/vmware.d
|
||||
IM_PROBES_GANGLIA_FILES:$VAR_LOCATION/remotes/im/ganglia.d
|
||||
AUTH_SSH_FILES:$VAR_LOCATION/remotes/auth/ssh
|
||||
AUTH_X509_FILES:$VAR_LOCATION/remotes/auth/x509
|
||||
@ -337,10 +340,13 @@ INSTALL_FILES=(
|
||||
AUTH_QUOTA_FILES:$VAR_LOCATION/remotes/auth/quota
|
||||
VMM_EXEC_KVM_SCRIPTS:$VAR_LOCATION/remotes/vmm/kvm
|
||||
VMM_EXEC_XEN_SCRIPTS:$VAR_LOCATION/remotes/vmm/xen
|
||||
VMM_EXEC_VMWARE_SCRIPTS:$VAR_LOCATION/remotes/vmm/vmware
|
||||
SHARED_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/shared
|
||||
SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh
|
||||
VMWARE_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/vmware
|
||||
DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy
|
||||
LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm
|
||||
VMWARE_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/vmware
|
||||
IMAGE_DRIVER_FS_SCRIPTS:$VAR_LOCATION/remotes/image/fs
|
||||
NETWORK_HOOK_SCRIPTS:$VAR_LOCATION/remotes/vnm
|
||||
EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples
|
||||
@ -446,6 +452,7 @@ INSTALL_OZONES_ETC_FILES=(
|
||||
|
||||
INSTALL_ETC_FILES=(
|
||||
ETC_FILES:$ETC_LOCATION
|
||||
VMWARE_ETC_FILES:$ETC_LOCATION
|
||||
VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2
|
||||
VMM_EXEC_ETC_FILES:$ETC_LOCATION/vmm_exec
|
||||
IM_EC2_ETC_FILES:$ETC_LOCATION/im_ec2
|
||||
@ -453,6 +460,7 @@ INSTALL_ETC_FILES=(
|
||||
TM_SSH_ETC_FILES:$ETC_LOCATION/tm_ssh
|
||||
TM_DUMMY_ETC_FILES:$ETC_LOCATION/tm_dummy
|
||||
TM_LVM_ETC_FILES:$ETC_LOCATION/tm_lvm
|
||||
TM_VMWARE_ETC_FILES:$ETC_LOCATION/tm_vmware
|
||||
HM_ETC_FILES:$ETC_LOCATION/hm
|
||||
AUTH_ETC_FILES:$ETC_LOCATION/auth
|
||||
ECO_ETC_FILES:$ETC_LOCATION
|
||||
@ -479,6 +487,7 @@ BIN_FILES="src/nebula/oned \
|
||||
src/cli/oneacl \
|
||||
src/onedb/onedb \
|
||||
src/authm_mad/remotes/quota/onequota \
|
||||
src/mad/utils/tty_expect \
|
||||
share/scripts/one"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -499,6 +508,7 @@ RUBY_LIB_FILES="src/mad/ruby/ActionManager.rb \
|
||||
src/mad/ruby/OpenNebulaDriver.rb \
|
||||
src/mad/ruby/VirtualMachineDriver.rb \
|
||||
src/mad/ruby/Ganglia.rb \
|
||||
src/mad/ruby/vmwarelib.rb \
|
||||
src/oca/ruby/OpenNebula.rb \
|
||||
src/tm_mad/TMScript.rb \
|
||||
src/authm_mad/remotes/ssh/ssh_auth.rb \
|
||||
@ -575,21 +585,36 @@ VMM_EXEC_XEN_SCRIPTS="src/vmm_mad/remotes/xen/cancel \
|
||||
src/vmm_mad/remotes/xen/poll_ganglia \
|
||||
src/vmm_mad/remotes/xen/shutdown"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# VMM Driver VMWARE scripts, to be installed under $REMOTES_LOCATION/vmm/vmware
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
VMM_EXEC_VMWARE_SCRIPTS="src/vmm_mad/remotes/vmware/cancel \
|
||||
src/vmm_mad/remotes/vmware/deploy \
|
||||
src/vmm_mad/remotes/vmware/migrate \
|
||||
src/vmm_mad/remotes/vmware/restore \
|
||||
src/vmm_mad/remotes/vmware/save \
|
||||
src/vmm_mad/remotes/vmware/poll \
|
||||
src/vmm_mad/remotes/vmware/checkpoint \
|
||||
src/vmm_mad/remotes/vmware/shutdown"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Information Manager Probes, to be installed under $REMOTES_LOCATION/im
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
IM_PROBES_FILES="src/im_mad/remotes/run_probes"
|
||||
|
||||
IM_PROBES_KVM_FILES="src/im_mad/remotes/kvm.d/kvm.rb \
|
||||
src/im_mad/remotes/kvm.d/architecture.sh \
|
||||
src/im_mad/remotes/kvm.d/cpu.sh \
|
||||
src/im_mad/remotes/kvm.d/name.sh"
|
||||
|
||||
IM_PROBES_XEN_FILES="src/im_mad/remotes/xen.d/xen.rb \
|
||||
src/im_mad/remotes/xen.d/architecture.sh \
|
||||
src/im_mad/remotes/xen.d/cpu.sh \
|
||||
src/im_mad/remotes/xen.d/name.sh"
|
||||
|
||||
IM_PROBES_KVM_FILES="src/im_mad/remotes/kvm.d/kvm.rb \
|
||||
src/im_mad/remotes/kvm.d/architecture.sh \
|
||||
src/im_mad/remotes/kvm.d/cpu.sh \
|
||||
src/im_mad/remotes/kvm.d/name.sh"
|
||||
IM_PROBES_VMWARE_FILES="src/im_mad/remotes/vmware.d/vmware.rb"
|
||||
|
||||
IM_PROBES_GANGLIA_FILES="src/im_mad/remotes/ganglia.d/ganglia_probe"
|
||||
|
||||
@ -645,8 +670,12 @@ LVM_TM_COMMANDS_LIB_FILES="src/tm_mad/lvm/tm_clone.sh \
|
||||
src/tm_mad/lvm/tm_mv.sh \
|
||||
src/tm_mad/lvm/tm_context.sh"
|
||||
|
||||
VMWARE_TM_COMMANDS_LIB_FILES="src/tm_mad/vmware/tm_clone.sh \
|
||||
src/tm_mad/vmware/tm_ln.sh \
|
||||
src/tm_mad/vmware/tm_mv.sh"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Image Repository drivers, to be installed under $REMOTES_LOCTION/image
|
||||
# Image Repository drivers, to be installed under $REMOTES_LOCATION/image
|
||||
# - FS based Image Repository, $REMOTES_LOCATION/image/fs
|
||||
#-------------------------------------------------------------------------------
|
||||
IMAGE_DRIVER_FS_SCRIPTS="src/image_mad/remotes/fs/cp \
|
||||
@ -675,6 +704,8 @@ ETC_FILES="share/etc/oned.conf \
|
||||
share/etc/defaultrc \
|
||||
src/cli/etc/group.default"
|
||||
|
||||
VMWARE_ETC_FILES="src/vmm_mad/remotes/vmware/vmwarerc"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Virtualization drivers config. files, to be installed under $ETC_LOCATION
|
||||
# - ec2, $ETC_LOCATION/vmm_ec2
|
||||
@ -686,7 +717,8 @@ VMM_EC2_ETC_FILES="src/vmm_mad/ec2/vmm_ec2rc \
|
||||
|
||||
VMM_EXEC_ETC_FILES="src/vmm_mad/exec/vmm_execrc \
|
||||
src/vmm_mad/exec/vmm_exec_kvm.conf \
|
||||
src/vmm_mad/exec/vmm_exec_xen.conf"
|
||||
src/vmm_mad/exec/vmm_exec_xen.conf \
|
||||
src/vmm_mad/exec/vmm_exec_vmware.conf"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Information drivers config. files, to be installed under $ETC_LOCATION
|
||||
@ -716,6 +748,8 @@ TM_DUMMY_ETC_FILES="src/tm_mad/dummy/tm_dummy.conf \
|
||||
TM_LVM_ETC_FILES="src/tm_mad/lvm/tm_lvm.conf \
|
||||
src/tm_mad/lvm/tm_lvmrc"
|
||||
|
||||
TM_VMWARE_ETC_FILES="src/tm_mad/vmware/tm_vmware.conf"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Hook Manager driver config. files, to be installed under $ETC_LOCATION/hm
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -139,6 +139,17 @@ IM_MAD = [
|
||||
# arguments = "xen" ]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# VMware 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
|
||||
#-------------------------------------------------------------------------------
|
||||
#IM_MAD = [
|
||||
# name = "im_vmware",
|
||||
# executable = "one_im_sh",
|
||||
# arguments = "-t 15 -r 0 vmware" ]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# EC2 Information Driver Manager Configuration
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -218,6 +229,19 @@ VM_MAD = [
|
||||
# type = "xen" ]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# VMware 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
|
||||
#-------------------------------------------------------------------------------
|
||||
#VM_MAD = [
|
||||
# name = "vmm_vmware",
|
||||
# executable = "one_vmm_sh",
|
||||
# arguments = "-t 15 -r 0 vmware",
|
||||
# default = "vmm_exec/vmm_exec_vmware.conf",
|
||||
# type = "vmware" ]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# EC2 Virtualization Driver Manager Configuration
|
||||
# arguments: default values for the EC2 driver, can be an absolute path or
|
||||
@ -289,6 +313,15 @@ TM_MAD = [
|
||||
# arguments = "tm_lvm/tm_lvm.conf" ]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# VMware DataStore Transfer Manager Driver Configuration
|
||||
#-------------------------------------------------------------------------------
|
||||
#TM_MAD = [
|
||||
# name = "tm_vmware",
|
||||
# executable = "one_tm",
|
||||
# arguments = "tm_vmware/tm_vmware.conf" ]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#*******************************************************************************
|
||||
# Image Manager Driver Configuration
|
||||
#*******************************************************************************
|
||||
|
118
src/im_mad/remotes/vmware.d/vmware.rb
Executable file
118
src/im_mad/remotes/vmware.d/vmware.rb
Executable file
@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION = "/etc/one" if !defined?(ETC_LOCATION)
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
ETC_LOCATION = ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
|
||||
require 'OpenNebula'
|
||||
include OpenNebula
|
||||
|
||||
begin
|
||||
client = Client.new()
|
||||
rescue Exception => e
|
||||
puts "Error: #{e}"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
def add_info(name, value)
|
||||
value = "0" if value.nil? or value.to_s.empty?
|
||||
@result_str << "#{name}=#{value} "
|
||||
end
|
||||
|
||||
def print_info
|
||||
puts @result_str
|
||||
end
|
||||
|
||||
@result_str = ""
|
||||
|
||||
@host = ARGV[2]
|
||||
|
||||
if !@host
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} --readonly nodeinfo")
|
||||
|
||||
data.split(/\n/).each{|line|
|
||||
if line.match('^CPU\(s\)')
|
||||
$total_cpu = line.split(":")[1].strip.to_i * 100
|
||||
elsif line.match('^CPU frequency')
|
||||
$cpu_speed = line.split(":")[1].strip.split(" ")[0]
|
||||
elsif line.match('^Memory size')
|
||||
$total_memory = line.split(":")[1].strip.split(" ")[0]
|
||||
end
|
||||
}
|
||||
|
||||
# Loop through all vms
|
||||
used_memory = 0
|
||||
used_cpu = 0
|
||||
|
||||
vms = VirtualMachinePool.new(client)
|
||||
|
||||
rc = vms.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
warn "Couldn't reach OpenNebula, aborting."
|
||||
exit -1
|
||||
end
|
||||
|
||||
vm_ids_array = vms.retrieve_elements("/VM_POOL/VM[STATE=3 or STATE=5]/HISTORY_RECORDS/HISTORY[HOSTNAME=\"#{@host}\"]/../ID")
|
||||
|
||||
if vm_ids_array
|
||||
vm_ids_array.each do |vm_id|
|
||||
vm=OpenNebula::VirtualMachine.new_with_id(vm_id, client)
|
||||
rc = vm.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
warn "Couldn't reach OpenNebula, aborting."
|
||||
exit -1
|
||||
end
|
||||
|
||||
used_memory = used_memory + (vm['TEMPLATE/MEMORY'].to_i * 1024)
|
||||
used_cpu = used_cpu + (vm['TEMPLATE/CPU'].to_f * 100)
|
||||
end
|
||||
end
|
||||
|
||||
# 80% of the total free calculated memory to take hypervisor into account
|
||||
free_memory = ($total_memory.to_i - used_memory) * 0.8
|
||||
# assume all the host's CPU is devoted to running Virtual Machines
|
||||
free_cpu = ($total_cpu.to_f - used_cpu)
|
||||
|
||||
add_info("HYPERVISOR","vmware")
|
||||
add_info("TOTALCPU",$total_cpu)
|
||||
add_info("FREECPU",free_cpu.to_i)
|
||||
add_info("CPUSPEED",$cpu_speed)
|
||||
add_info("TOTALMEMORY",$total_memory)
|
||||
add_info("FREEMEMORY",free_memory.to_i)
|
||||
|
||||
print_info
|
@ -41,8 +41,28 @@ DST=`generate_image_path`
|
||||
case $SRC in
|
||||
http://*)
|
||||
log "Downloading $SRC to the image repository"
|
||||
|
||||
exec_and_log "$WGET -O $DST $SRC" \
|
||||
"Error downloading $SRC"
|
||||
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
;;
|
||||
|
||||
vmware://*)
|
||||
SRC=`echo $SRC|sed 's/vmware:\/\///g'`
|
||||
|
||||
if [ `check_restricted $SRC` -eq 1 ]; then
|
||||
log_error "Not allowed to copy images from $RESTRICTED_DIRS"
|
||||
error_message "Not allowed to copy image file $SRC"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
log "Copying local disk folder $SRC to the image repository"
|
||||
|
||||
exec_and_log "cp -rf $SRC $DST" \
|
||||
"Error copying $SRC to $DST"
|
||||
|
||||
exec_and_log "chmod 0770 $DST"
|
||||
;;
|
||||
|
||||
*)
|
||||
@ -53,13 +73,16 @@ http://*)
|
||||
fi
|
||||
|
||||
log "Copying local image $SRC to the image repository"
|
||||
|
||||
exec_and_log "cp -f $SRC $DST" \
|
||||
"Error copying $SRC to $DST"
|
||||
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
;;
|
||||
esac
|
||||
|
||||
# ---------------- Get the size of the image & fix perms ------------
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
|
||||
|
||||
SIZE=`fs_du $DST`
|
||||
|
||||
|
@ -83,3 +83,13 @@ function check_restricted {
|
||||
|
||||
echo 0
|
||||
}
|
||||
|
||||
# Change the permissions of all the files inside directoriers (= VMware disks)
|
||||
function fix_owner_perms {
|
||||
|
||||
find $IMAGE_REPOSITORY_PATH -type d \
|
||||
-mindepth 1 \
|
||||
-maxdepth 1 \
|
||||
-execdir chown \
|
||||
-R $SUDO_USER '{}' \;
|
||||
}
|
@ -44,7 +44,6 @@ fi
|
||||
|
||||
# ------------ Move the image to the repository ------------
|
||||
|
||||
|
||||
case $SRC in
|
||||
http://*)
|
||||
log "Downloading $SRC to the image repository"
|
||||
@ -62,7 +61,12 @@ http://*)
|
||||
;;
|
||||
esac
|
||||
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
if [ -d $DST ]; then
|
||||
exec_and_log "chmod 0770 $DST"
|
||||
fix_owner_perms
|
||||
else
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
fi
|
||||
|
||||
# ---------------- Get the size of the image ------------
|
||||
SIZE=`fs_du $DST`
|
||||
|
@ -37,6 +37,6 @@ SRC=$1
|
||||
|
||||
if [ -e $SRC ] ; then
|
||||
log "Removing $SRC from the image repository"
|
||||
exec_and_log "rm $SRC" \
|
||||
exec_and_log "rm -r $SRC" \
|
||||
"Error deleting $SRC"
|
||||
fi
|
||||
|
@ -16,8 +16,6 @@
|
||||
require 'thread'
|
||||
|
||||
=begin rdoc
|
||||
Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
|
||||
|
||||
This class provides support to handle actions. Class methods, or actions, can be
|
||||
registered in the action manager. The manager will wait for actions to be
|
||||
triggered (thread-safe), and will execute them concurrently. The action manager
|
||||
|
60
src/mad/ruby/vmwarelib.rb
Normal file
60
src/mad/ruby/vmwarelib.rb
Normal file
@ -0,0 +1,60 @@
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Set up the environment for the driver #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION = ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
BIN_LOCATION = "/usr/bin" if !defined?(BIN_LOCATION)
|
||||
ETC_LOCATION = "/etc/one/" if !defined?(ETC_LOCATION)
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
BIN_LOCATION = ONE_LOCATION + "/bin" if !defined?(BIN_LOCATION)
|
||||
ETC_LOCATION = ONE_LOCATION + "/etc/" if !defined?(ETC_LOCATION)
|
||||
if !defined?(RUBY_LIB_LOCATION)
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + "/lib/ruby"
|
||||
end
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
|
||||
require "OpenNebulaDriver"
|
||||
require "CommandManager"
|
||||
|
||||
# Do host sustitution in the libvirt URI
|
||||
LIBVIRT_URI.gsub!('@HOST@', @host)
|
||||
|
||||
# Common functions
|
||||
def perform_action(command)
|
||||
command = BIN_LOCATION + "/tty_expect -u " + USERNAME + " -p " + PASSWORD + " " + command
|
||||
|
||||
action_result = LocalCommand.run(command)
|
||||
|
||||
if action_result.code == 0
|
||||
return action_result.stdout
|
||||
else
|
||||
log(command, action_result.stderr, action_result.stdout)
|
||||
return action_result.code
|
||||
end
|
||||
end
|
||||
|
||||
def log(cmd, stdout, stderr)
|
||||
STDERR.puts "[VMWARE] cmd failed [" + cmd +
|
||||
"]. Stderr: " + stderr + ". Stdout: " + stdout
|
||||
end
|
22
src/mad/utils/SConstruct
Normal file
22
src/mad/utils/SConstruct
Normal file
@ -0,0 +1,22 @@
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
Import('env')
|
||||
import os
|
||||
|
||||
env['LIBS'] = "util"
|
||||
|
||||
env.Program('tty_expect.c')
|
168
src/mad/utils/tty_expect.c
Normal file
168
src/mad/utils/tty_expect.c
Normal file
@ -0,0 +1,168 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2010-2011, C12G Labs S.L. */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include <pty.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int expect_char(int pty, char * expected, int seconds)
|
||||
{
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
|
||||
int rc;
|
||||
char c;
|
||||
|
||||
do
|
||||
{
|
||||
if (seconds != 0)
|
||||
{
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(pty, &rfds);
|
||||
|
||||
tv.tv_sec = seconds;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
rc = select(pty+1,&rfds,0,0, &tv);
|
||||
|
||||
if ( rc <= 0 ) // timeout
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
rc = read(pty, (void *) &c, sizeof(char));
|
||||
|
||||
if ( rc > 0 )
|
||||
{
|
||||
if(expected == 0)
|
||||
{
|
||||
write(1,&c,sizeof(char));
|
||||
}
|
||||
|
||||
if (expected != 0 && c == *expected)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
while ( rc > 0 );
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void write_answer(int pty, const char * answer)
|
||||
{
|
||||
int len, i;
|
||||
|
||||
len = strlen(answer);
|
||||
|
||||
for (i=0; i<len; i++)
|
||||
{
|
||||
write(pty,(void *) &(answer[i]),sizeof(char));
|
||||
}
|
||||
|
||||
write(pty,(void *)"\n",sizeof(char));
|
||||
}
|
||||
|
||||
static const char * myexpect_usage =
|
||||
"\n myexpect [-h] <-p password> <-u username> <command>\n\n"
|
||||
"SYNOPSIS\n"
|
||||
" Wraps the execution of a command and sends username & password\n\n"
|
||||
"OPTIONS\n"
|
||||
"\t-h\tprints this help.\n"
|
||||
"\t-p\tthe password\n"
|
||||
"\t-u\tthe username\n"
|
||||
"\t<virsh command>\tcomplete virsh command\n";
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
char * password = 0;
|
||||
char * username = 0;
|
||||
|
||||
char expect = ':';
|
||||
|
||||
int opt, pty, pid, rc;
|
||||
|
||||
while((opt = getopt(argc,argv,"+hp:u:")) != -1)
|
||||
switch(opt)
|
||||
{
|
||||
case 'h':
|
||||
printf("%s",myexpect_usage);
|
||||
exit(0);
|
||||
break;
|
||||
case 'p':
|
||||
password = strdup(optarg);
|
||||
break;
|
||||
case 'u':
|
||||
username = strdup(optarg);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"Wrong option. Check usage\n");
|
||||
fprintf(stderr,"%s",myexpect_usage);
|
||||
exit(-1);
|
||||
break;
|
||||
}
|
||||
|
||||
if (password == 0 || username == 0 || optind >= argc )
|
||||
{
|
||||
fprintf(stderr,"Wrong number of arguments. Check usage\n");
|
||||
fprintf(stderr,"%s",myexpect_usage);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
pid = forkpty(&pty,0,0,0);
|
||||
|
||||
if(pid == 0)
|
||||
{
|
||||
struct termios tios;
|
||||
|
||||
tcgetattr(pty, &tios);
|
||||
|
||||
tios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
|
||||
tios.c_oflag &= ~(ONLCR);
|
||||
|
||||
tcsetattr(pty, TCSANOW, &tios);
|
||||
|
||||
execvp(argv[optind],&(argv[optind]));
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
else if (pid == -1)
|
||||
{
|
||||
perror("fork\n");
|
||||
}
|
||||
|
||||
expect_char(pty,&expect,1);
|
||||
sleep(1);
|
||||
write_answer(pty,username);
|
||||
expect_char(pty,&expect,1);
|
||||
sleep(1);
|
||||
write_answer(pty,password);
|
||||
|
||||
expect_char(pty,0,0);
|
||||
|
||||
wait(&rc);
|
||||
|
||||
return WEXITSTATUS(rc);
|
||||
}
|
70
src/tm_mad/vmware/tm_clone.sh
Executable file
70
src/tm_mad/vmware/tm_clone.sh
Executable file
@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/usr/lib/one/mads/tm_common.sh
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
get_vmdir
|
||||
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
|
||||
fix_paths
|
||||
|
||||
log_debug "$1 $2"
|
||||
log_debug "DST: $DST_PATH"
|
||||
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
log "Creating directory $DST_DIR"
|
||||
exec_and_log "rm -rf $DST_DIR"
|
||||
exec_and_log "mkdir -p $DST_PATH"
|
||||
exec_and_log "chmod a+w $DST_PATH"
|
||||
|
||||
case $SRC in
|
||||
http://*)
|
||||
log "Downloading $SRC"
|
||||
exec_and_log "$WGET -O $DST_PATH $SRC" \
|
||||
"Error downloading $SRC"
|
||||
;;
|
||||
|
||||
*)
|
||||
log "Cloning $SRC_PATH"
|
||||
exec_and_log "cp -r $SRC_PATH/* $DST_PATH" \
|
||||
"Error copying $SRC to $DST"
|
||||
;;
|
||||
esac
|
||||
|
||||
SRC_FILE_SUFFIX=`echo ${SRC_PATH##*.}`
|
||||
|
||||
if [ "x$SRC_FILE_SUFFIX" == "xiso" ]; then
|
||||
cd $DST_DIR
|
||||
DISK_NAME = `basename $DST_PATH`
|
||||
ln -s $DISK_NAME $DISK_NAME.iso
|
||||
fi
|
||||
|
||||
exec_and_log "chmod a+rw $DST_PATH"
|
||||
|
60
src/tm_mad/vmware/tm_ln.sh
Executable file
60
src/tm_mad/vmware/tm_ln.sh
Executable file
@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/usr/lib/one/mads/tm_common.sh
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
get_vmdir
|
||||
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
|
||||
fix_dst_path
|
||||
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
# SRC_PATH needs to be made relative to $ONE_LOCATION/var
|
||||
VM_FOLDER_NAME=`basename $SRC_PATH`
|
||||
REPO_NAME="images"
|
||||
RELATIVE_SRC_PATH="../../$REPO_NAME/$VM_FOLDER_NAME"
|
||||
|
||||
log "Creating directory $DST_PATH"
|
||||
exec_and_log "rm -rf $DST_PATH"
|
||||
exec_and_log "mkdir -p $DST_PATH"
|
||||
exec_and_log "chmod a+w $DST_PATH"
|
||||
|
||||
log "Link all files in $SRC_PATH to $DST_PATH"
|
||||
IMAGE_DIR=`dirname $DST_PATH`
|
||||
|
||||
cd $IMAGE_DIR
|
||||
|
||||
for file in `find $RELATIVE_SRC_PATH/* -type f`; do
|
||||
file_name=`basename $file`
|
||||
exec_and_log "ln -sf ../$file $DST_PATH/$file_name"
|
||||
done
|
||||
|
||||
|
||||
|
52
src/tm_mad/vmware/tm_mv.sh
Executable file
52
src/tm_mad/vmware/tm_mv.sh
Executable file
@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/usr/lib/one/mads/tm_common.sh
|
||||
VAR_LOCATION=/var/lib/one/
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
|
||||
VAR_LOCATION=$ONE_LOCATION/var/
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
get_vmdir
|
||||
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
|
||||
fix_paths
|
||||
|
||||
DST_PATH=`fix_dir_slashes "$DST_PATH"`
|
||||
SRC_PATH=`fix_dir_slashes "$SRC_PATH"`
|
||||
|
||||
if [ "$SRC_PATH" = "$DST_PATH" ]; then
|
||||
log "Will not move, source and destination are equal"
|
||||
elif echo $SRC_PATH | grep -q 'disk\.[0-9]\+$'; then
|
||||
log "Moving $SRC_PATH"
|
||||
exec_and_log "mv $SRC_PATH $DST_PATH"
|
||||
elif [ -d $SRC_PATH ]; then
|
||||
log "Will not move, is not saving image"
|
||||
else
|
||||
log "Moving $SRC_PATH"
|
||||
exec_and_log "mv $SRC_PATH $DST_PATH"
|
||||
fi
|
22
src/tm_mad/vmware/tm_vmware.conf
Normal file
22
src/tm_mad/vmware/tm_vmware.conf
Normal file
@ -0,0 +1,22 @@
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
CLONE = vmware/tm_clone.sh
|
||||
LN = vmware/tm_ln.sh
|
||||
MKSWAP = dummy/tm_dummy.sh
|
||||
MKIMAGE = dummy/tm_dummy.sh
|
||||
DELETE = shared/tm_delete.sh
|
||||
MV = vmware/tm_mv.sh
|
35
src/vmm_mad/exec/vmm_exec_vmware.conf
Normal file
35
src/vmm_mad/exec/vmm_exec_vmware.conf
Normal file
@ -0,0 +1,35 @@
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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 VMware driver
|
||||
# (all domains will use these values as defaults)
|
||||
# Valid atributes:
|
||||
# - memory
|
||||
# - cpu
|
||||
# - os[arch]
|
||||
# - disk[dirver]
|
||||
# - datastore
|
||||
|
||||
CPU = 1
|
||||
MEMORY = 256
|
||||
OS = [ ARCH = i686 ]
|
||||
DISK = [ DRIVER = file ]
|
||||
|
||||
# Name of the datastore in the remote VMware hypervisors
|
||||
# mounting $ONE_LOCATION/var exported as a nfs share
|
||||
# by the OpenNebula front-end
|
||||
|
||||
DATASTORE = images
|
54
src/vmm_mad/remotes/vmware/cancel
Executable file
54
src/vmm_mad/remotes/vmware/cancel
Executable file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION)
|
||||
else
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
|
||||
end
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
@host = ARGV[1]
|
||||
|
||||
if !@host or !deploy_id
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
# Destroy the VM
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} destroy #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
# Undefine the VM
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} undefine #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
1
src/vmm_mad/remotes/vmware/checkpoint
Normal file
1
src/vmm_mad/remotes/vmware/checkpoint
Normal file
@ -0,0 +1 @@
|
||||
<domainsnapshot><name>checkpoint</name></domainsnapshot>
|
92
src/vmm_mad/remotes/vmware/deploy
Executable file
92
src/vmm_mad/remotes/vmware/deploy
Executable file
@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION)
|
||||
else
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
|
||||
end
|
||||
|
||||
deployment_file = ARGV[0]
|
||||
@host = ARGV[1]
|
||||
|
||||
if !@host or !deployment_file
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
# Define the VM
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} define #{deployment_file}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
domainname = ""
|
||||
success = false
|
||||
|
||||
data.split('\n').each{ |line|
|
||||
domainname = line.match("Domain (.*) defined from (.*)")
|
||||
if domainname
|
||||
success = true
|
||||
break
|
||||
end
|
||||
}
|
||||
|
||||
if !success
|
||||
exit -1
|
||||
end
|
||||
|
||||
domainname = domainname[1]
|
||||
|
||||
# Start the VM
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} start #{domainname}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
definedname = domainname
|
||||
domainname = ""
|
||||
success = false
|
||||
|
||||
data.split('\n').each{ |line|
|
||||
domainname = line.match("Domain (.*) started")
|
||||
if domainname
|
||||
success = true
|
||||
break
|
||||
end
|
||||
}
|
||||
|
||||
if !success
|
||||
exit -1
|
||||
end
|
||||
|
||||
if definedname != domainname[1]
|
||||
exit -1
|
||||
else
|
||||
puts definedname
|
||||
end
|
21
src/vmm_mad/remotes/vmware/migrate
Executable file
21
src/vmm_mad/remotes/vmware/migrate
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
# Action not supported
|
||||
exit -1
|
||||
|
77
src/vmm_mad/remotes/vmware/poll
Executable file
77
src/vmm_mad/remotes/vmware/poll
Executable file
@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION)
|
||||
else
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
|
||||
end
|
||||
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
@host = ARGV[1]
|
||||
|
||||
if !@host or !deploy_id
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
data = perform_action(
|
||||
"virsh -c #{LIBVIRT_URI} --readonly dominfo #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
puts "STATE=d"
|
||||
exit 0
|
||||
end
|
||||
|
||||
state = ""
|
||||
|
||||
data.split('\n').each{ |line|
|
||||
state = line.match("^State: (.*)")
|
||||
|
||||
if state
|
||||
state = state[1].strip
|
||||
break
|
||||
end
|
||||
}
|
||||
|
||||
state_short = ""
|
||||
|
||||
case state
|
||||
when "running","blocked","shutdown","dying"
|
||||
state_short = 'a'
|
||||
when "paused"
|
||||
state_short = 'p'
|
||||
when "crashed"
|
||||
state_short = 'c'
|
||||
else
|
||||
state_short = 'd'
|
||||
end
|
||||
|
||||
puts "STATE=#{state_short}"
|
||||
|
||||
|
||||
|
89
src/vmm_mad/remotes/vmware/restore
Executable file
89
src/vmm_mad/remotes/vmware/restore
Executable file
@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION)
|
||||
else
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
|
||||
end
|
||||
|
||||
file = ARGV[0]
|
||||
@host = ARGV[1]
|
||||
|
||||
if !@host or !file
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
# Define the VM
|
||||
deployment_file = File.dirname(File.dirname(file)) + "/deployment.0"
|
||||
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} define #{deployment_file}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
domainname = ""
|
||||
success = false
|
||||
|
||||
data.split('\n').each{ |line|
|
||||
domainname = line.match("Domain (.*) defined from (.*)")
|
||||
if domainname
|
||||
success = true
|
||||
break
|
||||
end
|
||||
}
|
||||
|
||||
if !success
|
||||
exit -1
|
||||
end
|
||||
|
||||
domainname = domainname[1]
|
||||
|
||||
# Revert snapshot VM
|
||||
# Note: This assumes the checkpoint name is "checkpoint", to change this
|
||||
# it is needed to change also
|
||||
# $ONE_LOCATION/lib/remotes/vmm/vmware/checkpoint
|
||||
|
||||
data = perform_action(
|
||||
"virsh -c #{LIBVIRT_URI} snapshot-revert #{domainname} checkpoint")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
# Delete checkpoint
|
||||
data = perform_action(
|
||||
"virsh -c #{LIBVIRT_URI} snapshot-delete #{domainname} checkpoint")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
68
src/vmm_mad/remotes/vmware/save
Executable file
68
src/vmm_mad/remotes/vmware/save
Executable file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION = "/etc/one" if !defined?(ETC_LOCATION)
|
||||
VAR_LOCATION = "/var/lib/one" if !defined?(VAR_LOCATION)
|
||||
else
|
||||
ETC_LOCATION = ONE_LOCATION + "/etc" if !defined?(ETC_LOCATION)
|
||||
VAR_LOCATION = ONE_LOCATION + "/var" if !defined?(VAR_LOCATION)
|
||||
end
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
file = ARGV[1]
|
||||
@host = ARGV[2]
|
||||
|
||||
if !@host or !deploy_id or !file
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
# Create snapshot
|
||||
checkpoint_xml_file = VAR_LOCATION + "/remotes/vmm/vmware/checkpoint"
|
||||
|
||||
data = perform_action(
|
||||
"virsh -c #{LIBVIRT_URI} snapshot-create #{deploy_id} #{checkpoint_xml_file}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
# Suspend VM
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} suspend #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
# Undefine VM
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} undefine #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
|
62
src/vmm_mad/remotes/vmware/shutdown
Executable file
62
src/vmm_mad/remotes/vmware/shutdown
Executable file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION)
|
||||
else
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
|
||||
end
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
@host = ARGV[1]
|
||||
|
||||
if !@host or !deploy_id
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} shutdown #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
begin
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} list")
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
sleep 2
|
||||
end while data.match(deploy_id)
|
||||
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} undefine #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
|
||||
|
41
src/vmm_mad/remotes/vmware/vmwarerc
Normal file
41
src/vmm_mad/remotes/vmware/vmwarerc
Normal file
@ -0,0 +1,41 @@
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2011, C12G Labs S.L #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
# User configurable variables (Ruby syntax)
|
||||
LIBVIRT_URI = "esx://@HOST@/?no_verify=1"
|
||||
QEMU_PROTOCOL = "qemu"
|
||||
|
||||
# Username and password of the VMware hypervisor
|
||||
USERNAME = "oneadmin"
|
||||
PASSWORD =
|
||||
|
||||
# Loading the vmware library for mads
|
||||
# Please leave this uncommented
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
LIB_LOCATION = "/usr/lib/one" if !defined?(LIB_LOCATION)
|
||||
else
|
||||
LIB_LOCATION = ONE_LOCATION+"/lib" if !defined?(LIB_LOCATION)
|
||||
end
|
||||
|
||||
load LIB_LOCATION + "/ruby/vmwarelib.rb"
|
||||
|
||||
ENV['LANG']='C'
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user