From 445c8029b3bf1951279272768e2dab67ecfcfd1d Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Mon, 5 Dec 2011 18:23:24 +0100 Subject: [PATCH 01/35] feature-#1020: Add ssh support --- install.sh | 9 +++- src/tm_mad/vmware-ssh/tm_clone.sh | 53 ++++++++++++++++++++++++ src/tm_mad/vmware-ssh/tm_ln.sh | 32 ++++++++++++++ src/tm_mad/vmware-ssh/tm_vmware_ssh.conf | 24 +++++++++++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100755 src/tm_mad/vmware-ssh/tm_clone.sh create mode 100755 src/tm_mad/vmware-ssh/tm_ln.sh create mode 100644 src/tm_mad/vmware-ssh/tm_vmware_ssh.conf diff --git a/install.sh b/install.sh index a8ded00a12..f1f6115192 100755 --- a/install.sh +++ b/install.sh @@ -210,6 +210,7 @@ LIB_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/tm_commands/dummy \ $LIB_LOCATION/tm_commands/lvm \ $LIB_LOCATION/tm_commands/vmware \ + $LIB_LOCATION/tm_commands/vmware-ssh \ $LIB_LOCATION/mads \ $LIB_LOCATION/sh \ $LIB_LOCATION/ruby/cli \ @@ -348,6 +349,7 @@ INSTALL_FILES=( 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 + VMWARE_TM_SSH_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/vmware-ssh DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm IMAGE_DRIVER_FS_SCRIPTS:$VAR_LOCATION/remotes/image/fs @@ -683,6 +685,10 @@ 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" +VMWARE_TM_SSH_COMMANDS_LIB_FILES="src/tm_mad/vmware-ssh/tm_clone.sh \ + src/tm_mad/vmware-ssh/tm_ln.sh" + + #------------------------------------------------------------------------------- # Image Repository drivers, to be installed under $REMOTES_LOCATION/image # - FS based Image Repository, $REMOTES_LOCATION/image/fs @@ -757,7 +763,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" +TM_VMWARE_ETC_FILES="src/tm_mad/vmware/tm_vmware.conf \ + src/tm_mad/vmware/tm_vmware_ssh.conf" #------------------------------------------------------------------------------- # Hook Manager driver config. files, to be installed under $ETC_LOCATION/hm diff --git a/src/tm_mad/vmware-ssh/tm_clone.sh b/src/tm_mad/vmware-ssh/tm_clone.sh new file mode 100755 index 0000000000..29b0e8295c --- /dev/null +++ b/src/tm_mad/vmware-ssh/tm_clone.sh @@ -0,0 +1,53 @@ +#!/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 + +DST_PATH=`arg_path $DST` +DST_HOST=`arg_host $DST` + +log "$1 $2" +log "DST_HOST: $DST_HOST" +log "DST_PATH: $DST_PATH" + +log "Creating directory $DST_PATH" +exec_and_log "$SSH $DST_HOST mkdir -p $DST_PATH" + +case $SRC in +http://*) + log "Downloading $SRC" + exec_and_log "$SSH $DST_HOST $WGET -O $DST_PATH $SRC" + ;; + +*) + log "Cloning $SRC" + exec_and_log "$SCP -r $SRC/* $DST" + ;; +esac + +exec_and_log "$SSH $DST_HOST chmod a+rwx $DST_PATH" + diff --git a/src/tm_mad/vmware-ssh/tm_ln.sh b/src/tm_mad/vmware-ssh/tm_ln.sh new file mode 100755 index 0000000000..8b1d41f77f --- /dev/null +++ b/src/tm_mad/vmware-ssh/tm_ln.sh @@ -0,0 +1,32 @@ +#!/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 + TM_COMMANDS_LOCATION=/usr/lib/one/tm_commands/ +else + TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh + TM_COMMANDS_LOCATION=$ONE_LOCATION/lib/tm_commands/ +fi + +. $TMCOMMON + +exec $TM_COMMANDS_LOCATION/vmware-ssh/tm_clone.sh $SRC $DST diff --git a/src/tm_mad/vmware-ssh/tm_vmware_ssh.conf b/src/tm_mad/vmware-ssh/tm_vmware_ssh.conf new file mode 100644 index 0000000000..8b2bca4d20 --- /dev/null +++ b/src/tm_mad/vmware-ssh/tm_vmware_ssh.conf @@ -0,0 +1,24 @@ +# ---------------------------------------------------------------------------- # +# 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-ssh/tm_clone.sh +LN = vmware-ssh/tm_ln.sh +MKSWAP = ssh/tm_mkswap.sh +MKIMAGE = ssh/tm_mkimage.sh +DELETE = ssh/tm_delete.sh +MV = ssh/tm_mv.sh +CONTEXT = ssh/tm_context.sh + From de5fda93e68f0f11732539583c8f5d271093297d Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Mon, 5 Dec 2011 19:12:16 +0100 Subject: [PATCH 02/35] feature-#1020: Add ssh configuration file --- src/tm_mad/vmware/tm_vmware_ssh.conf | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/tm_mad/vmware/tm_vmware_ssh.conf diff --git a/src/tm_mad/vmware/tm_vmware_ssh.conf b/src/tm_mad/vmware/tm_vmware_ssh.conf new file mode 100644 index 0000000000..e7aa47207f --- /dev/null +++ b/src/tm_mad/vmware/tm_vmware_ssh.conf @@ -0,0 +1,10 @@ +#HEADER + +CLONE = vmware_ssh/tm_clone.sh +LN = vmware_ssh/tm_ln.sh +MKSWAP = ssh/tm_mkswap.sh +MKIMAGE = ssh/tm_mkimage.sh +DELETE = ssh/tm_delete.sh +MV = ssh/tm_mv.sh +CONTEXT = ssh/tm_context.sh + From d062e6f3511a59cbe346e81d6869ebcdb88b30ff Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Wed, 7 Dec 2011 16:26:41 +0100 Subject: [PATCH 03/35] feature-#1020: Add contextualization driver for vmware --- install.sh | 1 + src/tm_mad/vmware/tm_context.sh | 67 ++++++++++++++++++++++++++++ src/tm_mad/vmware/tm_vmware.conf | 1 + src/tm_mad/vmware/tm_vmware_ssh.conf | 2 +- 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100755 src/tm_mad/vmware/tm_context.sh diff --git a/install.sh b/install.sh index f1f6115192..b05900c66a 100755 --- a/install.sh +++ b/install.sh @@ -684,6 +684,7 @@ LVM_TM_COMMANDS_LIB_FILES="src/tm_mad/lvm/tm_clone.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" + src/tm_mad/vmware/tm_context.sh" VMWARE_TM_SSH_COMMANDS_LIB_FILES="src/tm_mad/vmware-ssh/tm_clone.sh \ src/tm_mad/vmware-ssh/tm_ln.sh" diff --git a/src/tm_mad/vmware/tm_context.sh b/src/tm_mad/vmware/tm_context.sh new file mode 100755 index 0000000000..89137fb04d --- /dev/null +++ b/src/tm_mad/vmware/tm_context.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- +# Copyright 2010, C12G Labs S.L. +# +# This file is part of OpenNebula VMware Drivers. +# +# OpenNebula VMware Drivers is free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation, either version 3 of +# the License, or the hope That it will be useful, but (at your +# option) any later version. +# +# OpenNebula VMware Drivers is distributed in WITHOUT ANY WARRANTY; +# without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License +# along with OpenNebula VMware Drivers . If not, see +# +# -------------------------------------------------------------------------- + +while (( "$#" )); do + if [ "$#" == "1" ]; then + DST=$1 + else + SRC="$SRC $1" + fi + shift +done + + +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 + +DST_PATH=`arg_path $DST` + +fix_dst_path + +DST_DIR=`dirname $DST_PATH` +ISO_DIR=$DST_DIR/isofiles + +exec_and_log "mkdir -p $ISO_DIR" + +for f in $SRC; do + case $f in + http://*) + exec_and_log "$WGET -O $ISO_DIR $f" + ;; + + *) + exec_and_log "cp -R $f $ISO_DIR" + ;; + esac +done + +exec_and_log "$MKISOFS -o $DST_PATH.iso -J -R $ISO_DIR" + +exec_and_log "rm -rf $ISO_DIR" diff --git a/src/tm_mad/vmware/tm_vmware.conf b/src/tm_mad/vmware/tm_vmware.conf index c7fc099ed3..0de9eeb95e 100644 --- a/src/tm_mad/vmware/tm_vmware.conf +++ b/src/tm_mad/vmware/tm_vmware.conf @@ -20,3 +20,4 @@ MKSWAP = dummy/tm_dummy.sh MKIMAGE = dummy/tm_dummy.sh DELETE = shared/tm_delete.sh MV = vmware/tm_mv.sh +CONTEXT = vmware/tm_context.sh diff --git a/src/tm_mad/vmware/tm_vmware_ssh.conf b/src/tm_mad/vmware/tm_vmware_ssh.conf index e7aa47207f..a71a10b5ce 100644 --- a/src/tm_mad/vmware/tm_vmware_ssh.conf +++ b/src/tm_mad/vmware/tm_vmware_ssh.conf @@ -6,5 +6,5 @@ MKSWAP = ssh/tm_mkswap.sh MKIMAGE = ssh/tm_mkimage.sh DELETE = ssh/tm_delete.sh MV = ssh/tm_mv.sh -CONTEXT = ssh/tm_context.sh +CONTEXT = vmware/tm_context.sh From 2011bc30ebd17d0ff011b65251a948b4131493ca Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Wed, 7 Dec 2011 19:26:48 +0100 Subject: [PATCH 04/35] feature #1020: Fix for install.sh --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index fdde7aa8c1..2db3e5ff92 100755 --- a/install.sh +++ b/install.sh @@ -727,7 +727,7 @@ LVM_TM_COMMANDS_LIB_FILES="src/tm_mad/lvm/tm_clone.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" + src/tm_mad/vmware/tm_mv.sh \ src/tm_mad/vmware/tm_context.sh" VMWARE_TM_SSH_COMMANDS_LIB_FILES="src/tm_mad/vmware-ssh/tm_clone.sh \ From fb34a12573fdf815314d4fa33c064db963f7ffbd Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Wed, 7 Dec 2011 19:57:04 +0100 Subject: [PATCH 05/35] feature #1020: Fix typo in configuration file --- src/tm_mad/vmware/tm_context.sh | 35 ++++++++++++---------------- src/tm_mad/vmware/tm_vmware_ssh.conf | 20 +++++++++++++--- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/tm_mad/vmware/tm_context.sh b/src/tm_mad/vmware/tm_context.sh index 89137fb04d..6292d391f2 100755 --- a/src/tm_mad/vmware/tm_context.sh +++ b/src/tm_mad/vmware/tm_context.sh @@ -1,25 +1,20 @@ #!/bin/bash -# -------------------------------------------------------------------------- -# Copyright 2010, C12G Labs S.L. -# -# This file is part of OpenNebula VMware Drivers. -# -# OpenNebula VMware Drivers is free software: you can redistribute it -# and/or modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or the hope That it will be useful, but (at your -# option) any later version. -# -# OpenNebula VMware Drivers is distributed in WITHOUT ANY WARRANTY; -# without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License -# along with OpenNebula VMware Drivers . If not, see -# -# -------------------------------------------------------------------------- +# ---------------------------------------------------------------------------- # +# 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. # +# ---------------------------------------------------------------------------- # while (( "$#" )); do if [ "$#" == "1" ]; then diff --git a/src/tm_mad/vmware/tm_vmware_ssh.conf b/src/tm_mad/vmware/tm_vmware_ssh.conf index a71a10b5ce..f01bbb537f 100644 --- a/src/tm_mad/vmware/tm_vmware_ssh.conf +++ b/src/tm_mad/vmware/tm_vmware_ssh.conf @@ -1,7 +1,21 @@ -#HEADER +# ---------------------------------------------------------------------------- # +# 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_ssh/tm_clone.sh -LN = vmware_ssh/tm_ln.sh +CLONE = vmware-ssh/tm_clone.sh +LN = vmware-ssh/tm_ln.sh MKSWAP = ssh/tm_mkswap.sh MKIMAGE = ssh/tm_mkimage.sh DELETE = ssh/tm_delete.sh From 787aab9f40b29886fdf4137f864f98faede1e801 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 18 Dec 2011 01:43:59 +0100 Subject: [PATCH 06/35] Feature: Re-structure of the vmware driver --- src/mad/ruby/scripts_common.rb | 2 +- src/mad/ruby/vmwarelib.rb | 289 ++++++++++++++++++++++++---- src/vmm_mad/remotes/vmware/deploy | 75 ++------ src/vmm_mad/remotes/vmware/vmwarerc | 29 +-- 4 files changed, 269 insertions(+), 126 deletions(-) diff --git a/src/mad/ruby/scripts_common.rb b/src/mad/ruby/scripts_common.rb index 8251ae48ff..8ded7d72cb 100644 --- a/src/mad/ruby/scripts_common.rb +++ b/src/mad/ruby/scripts_common.rb @@ -46,7 +46,7 @@ module OpenNebula STDERR.puts format_error_message(message) end - #This function formats an error message for OpenNebula Copyright e + #This function formats an error message for OpenNebula def self.format_error_message(message) error_str = "ERROR MESSAGE --8<------\n" error_str << message diff --git a/src/mad/ruby/vmwarelib.rb b/src/mad/ruby/vmwarelib.rb index a763e7f660..296346ff0e 100644 --- a/src/mad/ruby/vmwarelib.rb +++ b/src/mad/ruby/vmwarelib.rb @@ -14,47 +14,260 @@ # 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 "scripts_common" require "CommandManager" -# Do host sustitution in the libvirt URI -LIBVIRT_URI.gsub!('@HOST@', @host) +class VmWareDriver + # -------------------------------------------------------------------------# + # Set up the environment for the driver # + # -------------------------------------------------------------------------# + ONE_LOCATION = ENV["ONE_LOCATION"] -# 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 + if !ONE_LOCATION + BIN_LOCATION = "/usr/bin" + LIB_LOCATION = "/usr/lib/one" + ETC_LOCATION = "/etc/one/" else - log(command, action_result.stderr, action_result.stdout) - return action_result.code + LIB_LOCATION = ONE_LOCATION + "/lib" + BIN_LOCATION = ONE_LOCATION + "/bin" + ETC_LOCATION = ONE_LOCATION + "/etc/" end -end -def log(cmd, stdout, stderr) - STDERR.puts "[VMWARE] cmd failed [" + cmd + - "]. Stderr: " + stderr + ". Stdout: " + stdout -end + CONF_FILE = ETC_LOCATION + "/vmwarerc" + CHECKPOINT = VAR_LOCATION + "/remotes/vmm/vmware/checkpoint" + + ENV['LANG'] = 'C' + + SHUTDOWN_INTERVAL = 5 + SHUTDOWN_TIMEOUT = 500 + + def initialize(host) + conf = YAML::load(File.read(CONF_FILE)) + + @uri = conf[:libvirt_uri].gsub!('@HOST@', host) + @user = conf[:password] + @pass = conf[:username] + + end + + # ######################################################################## # + # VMWARE DRIVER ACTIONS # + # ######################################################################## # + + # ------------------------------------------------------------------------ # + # Deploy & define a VM based on its description file # + # ------------------------------------------------------------------------ # + def deploy(dfile) + # Define the VM + deploy_id = define_domain(dfile) + + exit -1 if deploy_id.nil? + + # Start the VM + rc, info = do_action("virsh -c #{@uri} start #{deploy_id}") + + if rc == false + undefine_domain(deploy_id) + exit info + end + + return deploy_id + end + + # ------------------------------------------------------------------------ # + # Cancels & undefine the VM # + # ------------------------------------------------------------------------ # + def cancel(deploy_id) + # Destroy the VM + rc, info = perform_action("virsh -c #{@uri} destroy #{deploy_id}") + + if rc == false + exit info + end + + # Undefine the VM + exit undefine_domain(deploy_id) + end + + # ------------------------------------------------------------------------ # + # Migrate # + # ------------------------------------------------------------------------ # + def migrate + OpenNebula.log_error("TBD") + exit -1 + end + + # ------------------------------------------------------------------------ # + # Monitor a VM # + # ------------------------------------------------------------------------ # + def poll(deploy_id) + rc, info = do_action("virsh -c #{@uri} --readonly dominfo #{deploy_id}") + + if rc == false + puts "STATE=d" + exit 0 + end + + state = "" + + info.split('\n').each{ |line| + mdata = line.match("^State: (.*)") + + if mdata + state = mdata[1].strip + break + end + } + + case state + when "running","blocked","shutdown","dying" + state = 'a' + when "paused" + state = 'p' + when "crashed" + state = 'c' + else + state = 'd' + end + + return "STATE=#{state_short}" + end + + # ------------------------------------------------------------------------ # + # Restore a VM from a previously saved checkpoint # + # ------------------------------------------------------------------------ # + def restore(checkpoint) + begin + # Define the VM + dfile = File.dirname(File.dirname(checkpoint)) + "/deployment.0" + rescue => e + OpenNebula.log_error("Can not open checkpoint #{e.message}") + exit -1 + end + + deploy_id = define_domain(dfile) + + exit -1 if did.nil? + + # Revert snapshot VM + # Note: This assumes the checkpoint name is "checkpoint", to change + # this it is needed to change also [1] + # + # [1] $ONE_LOCATION/lib/remotes/vmm/vmware/checkpoint + + rc, info = do_action( + "virsh -c #{@uri} snapshot-revert #{deploy_id} checkpoint") + + exit info if rc == false + + # Delete checkpoint + rc, info = do_action( + "virsh -c #{@uri} snapshot-delete #{deploy_id} checkpoint") + + OpenNebula.log_error("Could not delete snapshot") if rc == false + end + + # ------------------------------------------------------------------------ # + # Saves a VM taking a snapshot # + # ------------------------------------------------------------------------ # + def save(deploy_id) + # Take a snapshot for the VM + rc, info = do_action( + "virsh -c #{@uri} snapshot-create #{deploy_id} #{CHECKPOINT}") + + exit info if rc == false + + # Suspend VM + rc, info = do_action("virsh -c #{@uri} suspend #{deploy_id}") + + exit info if rc == false + + # Undefine VM + undefine_domain(deploy_id) + end + + # ------------------------------------------------------------------------ # + # Shutdown a VM # + # ------------------------------------------------------------------------ # + def shutdown(deploy_id) + rc, info = do_action("virsh -c #{@uri} shutdown #{deploy_id}") + + exit info if rc == false + + counter = 0 + + begin + rc, info = do_action("virsh -c #{@uri} list") + info = "" if rc == false + + sleep SHUTDOWN_INTERVAL + + counter = counter + SHUTDOWN_INTERVAL + end while info.match(deploy_id) and counter < SHUTDOWN_TIMEOUT + + if counter >= SHUTDOWN_TIMEOUT + OpenNebula.error_message( + "Timeout reached, VM #{deploy_id} is still alive") + exit - 1 + end + + undefine_domain(deploy_id) + end + + # ######################################################################## # + # DRIVER HELPER FUNCTIONS # + # ######################################################################## # + + private + + #Generates an ESX command using ttyexpect + def esx_cmd(command) + cmd = BIN_LOCATION + cmd << "/tty_expect -u " << @user << " -p " << @pass << " " << command + end + + #Performs a action usgin libvirt + def do_action(cmd) + rc = LocalCommand.run(esx_cmd(command)) + + if rc.code = 0 + return [true, rc.stdout] + else + err = "Error executing: #{cmd} err: #{rc.stderr} out: #{rc.stdout}" + OpenNebula.log_error(err) + return [false, rc.code] + end + end + + # Undefines a domain in the ESX hypervisor + def undefine_domain(id) + rc, info = do_action("virsh -c #{@uri} undefine #{id}") + + if rc == false + OpenNebula.log_error("Error undefining domain #{id}") + OpenNebula.log_error("Domain #{id} has to be undefined manually") + return info + end + + return 0 + end + + #defines a domain in the ESX hypervisor + def define_domain(dfile) + deploy_id = nil + rc, info = do_action("virsh -c #{@uri} define #{dfile}") + + return nil if rc == false + + data.split('\n').each{ |line| + mdata = line.match("Domain (.*) defined from (.*)") + + if mdata + deploy_id = mdata[1] + break + end + } + + return deploy_id + end +end \ No newline at end of file diff --git a/src/vmm_mad/remotes/vmware/deploy b/src/vmm_mad/remotes/vmware/deploy index 24b3623ba6..aae48e318c 100755 --- a/src/vmm_mad/remotes/vmware/deploy +++ b/src/vmm_mad/remotes/vmware/deploy @@ -16,77 +16,24 @@ # limitations under the License. # # ---------------------------------------------------------------------------- # -ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION) +ONE_LOCATION=ENV["ONE_LOCATION"] if !ONE_LOCATION - ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION) + RUBY_LIB_LOCATION="/usr/lib/one/ruby" else - ETC_LOCATION=ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION) + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" end -deployment_file = ARGV[0] -@host = ARGV[1] +$: << RUBY_LIB_LOCATION +$: << File.dirname(__FILE__) -if !@host or !deployment_file - exit -1 -end +require 'vmwarelib' -load ETC_LOCATION + "/vmwarerc" +dfile = ARGV[0] +host = ARGV[1] -if USERNAME.class!=String || PASSWORD.class!=String - warn "Bad ESX credentials, aborting" - exit -1 -end +vmware_drv = VMWareDriver.new(host) -# Define the VM -data = perform_action("virsh -c #{LIBVIRT_URI} define #{deployment_file}") +puts vmware_drv.deploy(dfile) -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 +exit 0 diff --git a/src/vmm_mad/remotes/vmware/vmwarerc b/src/vmm_mad/remotes/vmware/vmwarerc index e3267f3ea6..4f789d2f31 100644 --- a/src/vmm_mad/remotes/vmware/vmwarerc +++ b/src/vmm_mad/remotes/vmware/vmwarerc @@ -14,28 +14,11 @@ # limitations under the License. # # ---------------------------------------------------------------------------- # -# User configurable variables (Ruby syntax) -LIBVIRT_URI = "esx://@HOST@/?no_verify=1" -QEMU_PROTOCOL = "qemu" +# Libvirt configuration + +: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' - - - - +:username: "oneadmin" +:password: \ No newline at end of file From 9db35eb64d09e99aa01d53681962318d2a847615 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 18 Dec 2011 22:20:22 +0100 Subject: [PATCH 07/35] feature #1020: Fix wrong variable name in check --- src/mad/ruby/vmwarelib.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mad/ruby/vmwarelib.rb b/src/mad/ruby/vmwarelib.rb index 296346ff0e..d2b58e25c7 100644 --- a/src/mad/ruby/vmwarelib.rb +++ b/src/mad/ruby/vmwarelib.rb @@ -147,7 +147,7 @@ class VmWareDriver deploy_id = define_domain(dfile) - exit -1 if did.nil? + exit -1 if deploy_id.nil? # Revert snapshot VM # Note: This assumes the checkpoint name is "checkpoint", to change From 4da7c9060f36eb40a1d5b07377487fb6375af137 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Thu, 22 Dec 2011 16:33:28 +0100 Subject: [PATCH 08/35] bug #1031: now the folder deleted is just disk.n --- src/tm_mad/vmware/tm_ln.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tm_mad/vmware/tm_ln.sh b/src/tm_mad/vmware/tm_ln.sh index 878b0785f7..f590a7894d 100755 --- a/src/tm_mad/vmware/tm_ln.sh +++ b/src/tm_mad/vmware/tm_ln.sh @@ -42,7 +42,7 @@ 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 "rm -rf $DST" exec_and_log "mkdir -p $DST_PATH" exec_and_log "chmod a+w $DST_PATH" From 3cf891ff66ce44811a9571f515694977af5d0cf3 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Thu, 22 Dec 2011 18:21:24 +0100 Subject: [PATCH 09/35] feature 1020: Revamping IM for vmware --- src/im_mad/remotes/vmware.d/vmware.rb | 18 +++++++----------- src/mad/ruby/vmwarelib.rb | 16 +++++++++++++++- src/vmm_mad/remotes/vmware/cancel | 22 ++++++++++++++++++++++ src/vmm_mad/remotes/vmware/deploy | 6 +++--- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/im_mad/remotes/vmware.d/vmware.rb b/src/im_mad/remotes/vmware.d/vmware.rb index 5552818cf3..8ee8853b00 100755 --- a/src/im_mad/remotes/vmware.d/vmware.rb +++ b/src/im_mad/remotes/vmware.d/vmware.rb @@ -30,6 +30,7 @@ $: << RUBY_LIB_LOCATION require 'OpenNebula' include OpenNebula +require 'vmwarelib' begin client = Client.new() @@ -40,29 +41,24 @@ end def add_info(name, value) value = "0" if value.nil? or value.to_s.empty? - @result_str << "#{name}=#{value} " + result_str << "#{name}=#{value} " end def print_info - puts @result_str + puts result_str end -@result_str = "" +result_str = "" -@host = ARGV[2] +host = ARGV[2] if !@host exit -1 end -load ETC_LOCATION + "/vmwarerc" +vmware_drv = VMWareDriver.new(host) -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 = vmware_drv.poll_hypervisor data.split(/\n/).each{|line| if line.match('^CPU\(s\)') diff --git a/src/mad/ruby/vmwarelib.rb b/src/mad/ruby/vmwarelib.rb index d2b58e25c7..164f76c042 100644 --- a/src/mad/ruby/vmwarelib.rb +++ b/src/mad/ruby/vmwarelib.rb @@ -86,7 +86,7 @@ class VmWareDriver end # Undefine the VM - exit undefine_domain(deploy_id) + undefine_domain(deploy_id) end # ------------------------------------------------------------------------ # @@ -214,6 +214,20 @@ class VmWareDriver undefine_domain(deploy_id) end + # ------------------------------------------------------------------------ # + # Poll a VMware hypervisor # + # ------------------------------------------------------------------------ # + def poll_hypervisor + # Destroy the VM + rc, info = perform_action("virsh -c #{@uri} --readonly nodeinfo") + + if rc == false + exit info + end + + return info + end + # ######################################################################## # # DRIVER HELPER FUNCTIONS # # ######################################################################## # diff --git a/src/vmm_mad/remotes/vmware/cancel b/src/vmm_mad/remotes/vmware/cancel index aa01113c91..8ca9d3dc59 100755 --- a/src/vmm_mad/remotes/vmware/cancel +++ b/src/vmm_mad/remotes/vmware/cancel @@ -18,6 +18,28 @@ ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION) +if !ONE_LOCATION + RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION) +else + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION) +end + +$: << RUBY_LIB_LOCATION +$: << File.dirname(__FILE__) + +require 'vmwarelib' + +dfile = ARGV[0] +host = ARGV[1] + +vmware_drv = VMWareDriver.new(host) + +puts vmware_drv.deploy(dfile) + +exit 0 + +ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION) + if !ONE_LOCATION ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION) else diff --git a/src/vmm_mad/remotes/vmware/deploy b/src/vmm_mad/remotes/vmware/deploy index aae48e318c..8b923be19b 100755 --- a/src/vmm_mad/remotes/vmware/deploy +++ b/src/vmm_mad/remotes/vmware/deploy @@ -16,12 +16,12 @@ # limitations under the License. # # ---------------------------------------------------------------------------- # -ONE_LOCATION=ENV["ONE_LOCATION"] +ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION) if !ONE_LOCATION - RUBY_LIB_LOCATION="/usr/lib/one/ruby" + RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION) else - RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION) end $: << RUBY_LIB_LOCATION From cb5e13c1490a435b8113c965d4cbb241e7200e51 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Thu, 22 Dec 2011 18:34:24 +0100 Subject: [PATCH 10/35] feature #1020: Fix for better vmware disk moving --- src/tm_mad/vmware/tm_ln.sh | 3 +++ src/tm_mad/vmware/tm_mv.sh | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tm_mad/vmware/tm_ln.sh b/src/tm_mad/vmware/tm_ln.sh index f590a7894d..d815341511 100755 --- a/src/tm_mad/vmware/tm_ln.sh +++ b/src/tm_mad/vmware/tm_ln.sh @@ -56,5 +56,8 @@ for file in `find $RELATIVE_SRC_PATH/* -type f`; do exec_and_log "ln -sf ../$file $DST_PATH/$file_name" done +# Put the symlink mark for tm_mv +exec_and_log "ln -sf $RELATIVE_SRC_PATH $DST_PATH/.disk" + diff --git a/src/tm_mad/vmware/tm_mv.sh b/src/tm_mad/vmware/tm_mv.sh index 29d895a212..8a4b27f875 100755 --- a/src/tm_mad/vmware/tm_mv.sh +++ b/src/tm_mad/vmware/tm_mv.sh @@ -41,9 +41,11 @@ SRC_PATH=`fix_dir_slashes "$SRC_PATH"` if [ "$SRC_PATH" = "$DST_PATH" ]; then log "Will not move, source and destination are equal" +elif [ -f "$SRC_PATH/.disk" ]; then # This link was set in tm_ln.sh +  exec_and_log "mv $SRC_PATH/.disk $DST_PATH" elif echo $SRC_PATH | grep -q 'disk\.[0-9]\+$'; then - log "Moving $SRC_PATH" - exec_and_log "mv $SRC_PATH $DST_PATH" +    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 From 4e9dbbfa1d88724c8f556c6ade7a6162de03ef72 Mon Sep 17 00:00:00 2001 From: "Ruben S.Montero" Date: Thu, 22 Dec 2011 20:18:14 +0100 Subject: [PATCH 11/35] feature #1020: fixes some bugs --- src/mad/ruby/vmwarelib.rb | 9 ++++++--- src/vmm_mad/remotes/vmware/deploy | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mad/ruby/vmwarelib.rb b/src/mad/ruby/vmwarelib.rb index d2b58e25c7..5a8b646c35 100644 --- a/src/mad/ruby/vmwarelib.rb +++ b/src/mad/ruby/vmwarelib.rb @@ -15,6 +15,7 @@ # ---------------------------------------------------------------------------- # require "scripts_common" +require 'yaml' require "CommandManager" class VmWareDriver @@ -27,10 +28,12 @@ class VmWareDriver BIN_LOCATION = "/usr/bin" LIB_LOCATION = "/usr/lib/one" ETC_LOCATION = "/etc/one/" + VAR_LOCATION = "/var/lib/one" else LIB_LOCATION = ONE_LOCATION + "/lib" BIN_LOCATION = ONE_LOCATION + "/bin" ETC_LOCATION = ONE_LOCATION + "/etc/" + VAR_LOCATION = ONE_LOCATION + "/var/" end CONF_FILE = ETC_LOCATION + "/vmwarerc" @@ -228,9 +231,9 @@ class VmWareDriver #Performs a action usgin libvirt def do_action(cmd) - rc = LocalCommand.run(esx_cmd(command)) + rc = LocalCommand.run(esx_cmd(cmd)) - if rc.code = 0 + if rc.code == 0 return [true, rc.stdout] else err = "Error executing: #{cmd} err: #{rc.stderr} out: #{rc.stdout}" @@ -270,4 +273,4 @@ class VmWareDriver return deploy_id end -end \ No newline at end of file +end diff --git a/src/vmm_mad/remotes/vmware/deploy b/src/vmm_mad/remotes/vmware/deploy index aae48e318c..8192ce7127 100755 --- a/src/vmm_mad/remotes/vmware/deploy +++ b/src/vmm_mad/remotes/vmware/deploy @@ -32,7 +32,7 @@ require 'vmwarelib' dfile = ARGV[0] host = ARGV[1] -vmware_drv = VMWareDriver.new(host) +vmware_drv = VmWareDriver.new(host) puts vmware_drv.deploy(dfile) From 9a8272e6086bc6bcf6c405260302bf06ee20d18d Mon Sep 17 00:00:00 2001 From: "Ruben S.Montero" Date: Fri, 23 Dec 2011 01:04:46 +0100 Subject: [PATCH 12/35] feature #1020: Fixes some bugs in base VMware driver class --- src/mad/ruby/vmwarelib.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/mad/ruby/vmwarelib.rb b/src/mad/ruby/vmwarelib.rb index 2ecd2bb076..3c39aacb79 100644 --- a/src/mad/ruby/vmwarelib.rb +++ b/src/mad/ruby/vmwarelib.rb @@ -48,9 +48,9 @@ class VmWareDriver conf = YAML::load(File.read(CONF_FILE)) @uri = conf[:libvirt_uri].gsub!('@HOST@', host) - @user = conf[:password] - @pass = conf[:username] + @user = conf[:username] + @pass = conf[:password] end # ######################################################################## # @@ -66,6 +66,8 @@ class VmWareDriver exit -1 if deploy_id.nil? + OpenNebula.log_debug("Successfully defined domain #{deploy_id}.") + # Start the VM rc, info = do_action("virsh -c #{@uri} start #{deploy_id}") @@ -239,8 +241,7 @@ class VmWareDriver #Generates an ESX command using ttyexpect def esx_cmd(command) - cmd = BIN_LOCATION - cmd << "/tty_expect -u " << @user << " -p " << @pass << " " << command + cmd = "#{BIN_LOCATION}/tty_expect -u #{@user} -p #{@pass} #{command}" end #Performs a action usgin libvirt @@ -276,7 +277,7 @@ class VmWareDriver return nil if rc == false - data.split('\n').each{ |line| + info.split('\n').each{ |line| mdata = line.match("Domain (.*) defined from (.*)") if mdata @@ -285,6 +286,8 @@ class VmWareDriver end } + deploy_id.strip! + return deploy_id end end From 81879f1acba5f1a5806c5e6a885118ed7460b61e Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 23 Dec 2011 13:04:26 +0100 Subject: [PATCH 13/35] feature #1020: Rename base vmware disk to disk.vmdk --- src/image_mad/remotes/fs/cp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/image_mad/remotes/fs/cp b/src/image_mad/remotes/fs/cp index bbb2a67783..0c96ae96d5 100755 --- a/src/image_mad/remotes/fs/cp +++ b/src/image_mad/remotes/fs/cp @@ -61,6 +61,11 @@ vmware://*) exec_and_log "cp -rf $SRC $DST" \ "Error copying $SRC to $DST" + + BASE_DISK_FILE=`ls $DST | grep -v '.*-s[0-9]*\.vmdk'` + + exec_and_log "mv $BASE_DISK_FILE $DST/disk.vmdk" \ + "Error renaming disk file $BASE_DISK_FILE to disk.vmdk" exec_and_log "chmod 0770 $DST" ;; From d50c9fd86cbd96c9fb087dc93fe7a2dcf70d36bd Mon Sep 17 00:00:00 2001 From: "Ruben S.Montero" Date: Fri, 23 Dec 2011 13:10:23 +0100 Subject: [PATCH 14/35] feature #1020: Fix PATH to rename base image file for vmware --- src/image_mad/remotes/fs/cp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/image_mad/remotes/fs/cp b/src/image_mad/remotes/fs/cp index 0c96ae96d5..e60f43a159 100755 --- a/src/image_mad/remotes/fs/cp +++ b/src/image_mad/remotes/fs/cp @@ -64,7 +64,7 @@ vmware://*) BASE_DISK_FILE=`ls $DST | grep -v '.*-s[0-9]*\.vmdk'` - exec_and_log "mv $BASE_DISK_FILE $DST/disk.vmdk" \ + exec_and_log "mv $DST/$BASE_DISK_FILE $DST/disk.vmdk" \ "Error renaming disk file $BASE_DISK_FILE to disk.vmdk" exec_and_log "chmod 0770 $DST" @@ -91,4 +91,4 @@ esac SIZE=`fs_du $DST` -echo "$DST $SIZE" \ No newline at end of file +echo "$DST $SIZE" From ccd099c957caf4b53227f39bfded000c921d4808 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 23 Dec 2011 13:06:34 +0100 Subject: [PATCH 15/35] feature #1020: Improved actions for vmm and im vmware drivers --- src/im_mad/remotes/vmware.d/vmware.rb | 42 +++++++++++++--- src/mad/ruby/vmwarelib.rb | 25 +++------- src/vmm_mad/remotes/vmware/cancel | 43 +--------------- src/vmm_mad/remotes/vmware/deploy | 2 +- src/vmm_mad/remotes/vmware/poll | 59 ++++------------------ src/vmm_mad/remotes/vmware/restore | 70 ++++----------------------- src/vmm_mad/remotes/vmware/save | 50 ++++--------------- src/vmm_mad/remotes/vmware/shutdown | 45 ++++------------- 8 files changed, 84 insertions(+), 252 deletions(-) diff --git a/src/im_mad/remotes/vmware.d/vmware.rb b/src/im_mad/remotes/vmware.d/vmware.rb index 8ee8853b00..d3437f5e4a 100755 --- a/src/im_mad/remotes/vmware.d/vmware.rb +++ b/src/im_mad/remotes/vmware.d/vmware.rb @@ -19,18 +19,18 @@ 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 "scripts_common" +require 'yaml' +require "CommandManager" require 'OpenNebula' include OpenNebula -require 'vmwarelib' begin client = Client.new() @@ -39,6 +39,28 @@ rescue Exception => e exit(-1) end +# ######################################################################## # +# DRIVER HELPER FUNCTIONS # +# ######################################################################## # + +#Generates an ESX command using ttyexpect +def esx_cmd(command) + cmd = "#{BIN_LOCATION}/tty_expect -u #{@user} -p #{@pass} #{command}" +end + +#Performs a action usgin libvirt +def do_action(cmd) + rc = LocalCommand.run(esx_cmd(cmd)) + + if rc.code == 0 + return [true, rc.stdout] + else + err = "Error executing: #{cmd} err: #{rc.stderr} out: #{rc.stdout}" + OpenNebula.log_error(err) + return [false, rc.code] + end +end + def add_info(name, value) value = "0" if value.nil? or value.to_s.empty? result_str << "#{name}=#{value} " @@ -48,17 +70,25 @@ def print_info puts result_str end +# ######################################################################## # +# Main Procedure # +# ######################################################################## # + result_str = "" host = ARGV[2] -if !@host +if !host exit -1 end -vmware_drv = VMWareDriver.new(host) +# Poll the VMware hypervisor -data = vmware_drv.poll_hypervisor +rc, data = do_action("virsh -c #{@uri} --readonly nodeinfo") + +if rc == false + exit info +end data.split(/\n/).each{|line| if line.match('^CPU\(s\)') diff --git a/src/mad/ruby/vmwarelib.rb b/src/mad/ruby/vmwarelib.rb index 3c39aacb79..6de5172548 100644 --- a/src/mad/ruby/vmwarelib.rb +++ b/src/mad/ruby/vmwarelib.rb @@ -18,7 +18,7 @@ require "scripts_common" require 'yaml' require "CommandManager" -class VmWareDriver +class VMwareDriver # -------------------------------------------------------------------------# # Set up the environment for the driver # # -------------------------------------------------------------------------# @@ -66,7 +66,7 @@ class VmWareDriver exit -1 if deploy_id.nil? - OpenNebula.log_debug("Successfully defined domain #{deploy_id}.") + OpenNebula.log_debug("Successfully defined domain #{deploy_id}.") # Start the VM rc, info = do_action("virsh -c #{@uri} start #{deploy_id}") @@ -90,6 +90,8 @@ class VmWareDriver exit info end + OpenNebula.log_debug("Successfully canceled domain #{deploy_id}.") + # Undefine the VM undefine_domain(deploy_id) end @@ -98,7 +100,7 @@ class VmWareDriver # Migrate # # ------------------------------------------------------------------------ # def migrate - OpenNebula.log_error("TBD") + OpenNebula.log_error("Migration action is currently not supported") exit -1 end @@ -109,8 +111,7 @@ class VmWareDriver rc, info = do_action("virsh -c #{@uri} --readonly dominfo #{deploy_id}") if rc == false - puts "STATE=d" - exit 0 + return "STATE=d" end state = "" @@ -219,20 +220,6 @@ class VmWareDriver undefine_domain(deploy_id) end - # ------------------------------------------------------------------------ # - # Poll a VMware hypervisor # - # ------------------------------------------------------------------------ # - def poll_hypervisor - # Destroy the VM - rc, info = perform_action("virsh -c #{@uri} --readonly nodeinfo") - - if rc == false - exit info - end - - return info - end - # ######################################################################## # # DRIVER HELPER FUNCTIONS # # ######################################################################## # diff --git a/src/vmm_mad/remotes/vmware/cancel b/src/vmm_mad/remotes/vmware/cancel index 8ca9d3dc59..e5567189bf 100755 --- a/src/vmm_mad/remotes/vmware/cancel +++ b/src/vmm_mad/remotes/vmware/cancel @@ -32,45 +32,6 @@ require 'vmwarelib' dfile = ARGV[0] host = ARGV[1] -vmware_drv = VMWareDriver.new(host) - -puts vmware_drv.deploy(dfile) - -exit 0 - -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 +vmware_drv = VMwareDriver.new(host) +vmware_drv.cancel(dfile) diff --git a/src/vmm_mad/remotes/vmware/deploy b/src/vmm_mad/remotes/vmware/deploy index 1171e3fa6c..fe0e4106dd 100755 --- a/src/vmm_mad/remotes/vmware/deploy +++ b/src/vmm_mad/remotes/vmware/deploy @@ -32,7 +32,7 @@ require 'vmwarelib' dfile = ARGV[0] host = ARGV[1] -vmware_drv = VmWareDriver.new(host) +vmware_drv = VMwareDriver.new(host) puts vmware_drv.deploy(dfile) diff --git a/src/vmm_mad/remotes/vmware/poll b/src/vmm_mad/remotes/vmware/poll index c304b45f3b..c4454bec60 100755 --- a/src/vmm_mad/remotes/vmware/poll +++ b/src/vmm_mad/remotes/vmware/poll @@ -16,62 +16,23 @@ # 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 +$: << File.dirname(__FILE__) + +require 'vmwarelib' 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}" - +host = ARGV[1] +vmware_drv = VMwareDriver.new(host) +puts vmware_drv.poll(deploy_id) diff --git a/src/vmm_mad/remotes/vmware/restore b/src/vmm_mad/remotes/vmware/restore index f50ac54d36..7f8702dfbc 100755 --- a/src/vmm_mad/remotes/vmware/restore +++ b/src/vmm_mad/remotes/vmware/restore @@ -19,71 +19,19 @@ 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 -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 +$: << RUBY_LIB_LOCATION +$: << File.dirname(__FILE__) +require 'vmwarelib' +checkpoint_file = ARGV[0] +host = ARGV[1] +vmware_drv = VMwareDriver.new(host) +vmware_drv.restore(checkpoint_file) diff --git a/src/vmm_mad/remotes/vmware/save b/src/vmm_mad/remotes/vmware/save index d88d1923ce..a8dbf6e35d 100755 --- a/src/vmm_mad/remotes/vmware/save +++ b/src/vmm_mad/remotes/vmware/save @@ -19,50 +19,20 @@ 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) + RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION) else - ETC_LOCATION = ONE_LOCATION + "/etc" if !defined?(ETC_LOCATION) - VAR_LOCATION = ONE_LOCATION + "/var" if !defined?(VAR_LOCATION) + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION) end +$: << RUBY_LIB_LOCATION +$: << File.dirname(__FILE__) + +require 'vmwarelib' + 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 +host = ARGV[2] +vmware_drv = VMwareDriver.new(host) +vmware_drv.save(deploy_id) diff --git a/src/vmm_mad/remotes/vmware/shutdown b/src/vmm_mad/remotes/vmware/shutdown index 04bcb64238..a32849172e 100755 --- a/src/vmm_mad/remotes/vmware/shutdown +++ b/src/vmm_mad/remotes/vmware/shutdown @@ -19,44 +19,19 @@ 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 +$: << File.dirname(__FILE__) + +require 'vmwarelib' + 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 - +host = ARGV[1] +vmware_drv = VMwareDriver.new(host) +vmware_drv.shutdown(deploy_id) From 52839a40cbb789b2480157ffcf8025f7c6316166 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 23 Dec 2011 13:07:29 +0100 Subject: [PATCH 16/35] feature #1020: Revert vmware ssh drivers --- src/tm_mad/vmware-ssh/tm_clone.sh | 53 ------------------------ src/tm_mad/vmware-ssh/tm_ln.sh | 32 -------------- src/tm_mad/vmware-ssh/tm_vmware_ssh.conf | 24 ----------- src/tm_mad/vmware/tm_vmware_ssh.conf | 24 ----------- 4 files changed, 133 deletions(-) delete mode 100755 src/tm_mad/vmware-ssh/tm_clone.sh delete mode 100755 src/tm_mad/vmware-ssh/tm_ln.sh delete mode 100644 src/tm_mad/vmware-ssh/tm_vmware_ssh.conf delete mode 100644 src/tm_mad/vmware/tm_vmware_ssh.conf diff --git a/src/tm_mad/vmware-ssh/tm_clone.sh b/src/tm_mad/vmware-ssh/tm_clone.sh deleted file mode 100755 index 29b0e8295c..0000000000 --- a/src/tm_mad/vmware-ssh/tm_clone.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/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 - -DST_PATH=`arg_path $DST` -DST_HOST=`arg_host $DST` - -log "$1 $2" -log "DST_HOST: $DST_HOST" -log "DST_PATH: $DST_PATH" - -log "Creating directory $DST_PATH" -exec_and_log "$SSH $DST_HOST mkdir -p $DST_PATH" - -case $SRC in -http://*) - log "Downloading $SRC" - exec_and_log "$SSH $DST_HOST $WGET -O $DST_PATH $SRC" - ;; - -*) - log "Cloning $SRC" - exec_and_log "$SCP -r $SRC/* $DST" - ;; -esac - -exec_and_log "$SSH $DST_HOST chmod a+rwx $DST_PATH" - diff --git a/src/tm_mad/vmware-ssh/tm_ln.sh b/src/tm_mad/vmware-ssh/tm_ln.sh deleted file mode 100755 index 8b1d41f77f..0000000000 --- a/src/tm_mad/vmware-ssh/tm_ln.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/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 - TM_COMMANDS_LOCATION=/usr/lib/one/tm_commands/ -else - TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh - TM_COMMANDS_LOCATION=$ONE_LOCATION/lib/tm_commands/ -fi - -. $TMCOMMON - -exec $TM_COMMANDS_LOCATION/vmware-ssh/tm_clone.sh $SRC $DST diff --git a/src/tm_mad/vmware-ssh/tm_vmware_ssh.conf b/src/tm_mad/vmware-ssh/tm_vmware_ssh.conf deleted file mode 100644 index 8b2bca4d20..0000000000 --- a/src/tm_mad/vmware-ssh/tm_vmware_ssh.conf +++ /dev/null @@ -1,24 +0,0 @@ -# ---------------------------------------------------------------------------- # -# 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-ssh/tm_clone.sh -LN = vmware-ssh/tm_ln.sh -MKSWAP = ssh/tm_mkswap.sh -MKIMAGE = ssh/tm_mkimage.sh -DELETE = ssh/tm_delete.sh -MV = ssh/tm_mv.sh -CONTEXT = ssh/tm_context.sh - diff --git a/src/tm_mad/vmware/tm_vmware_ssh.conf b/src/tm_mad/vmware/tm_vmware_ssh.conf deleted file mode 100644 index f01bbb537f..0000000000 --- a/src/tm_mad/vmware/tm_vmware_ssh.conf +++ /dev/null @@ -1,24 +0,0 @@ -# ---------------------------------------------------------------------------- # -# 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-ssh/tm_clone.sh -LN = vmware-ssh/tm_ln.sh -MKSWAP = ssh/tm_mkswap.sh -MKIMAGE = ssh/tm_mkimage.sh -DELETE = ssh/tm_delete.sh -MV = ssh/tm_mv.sh -CONTEXT = vmware/tm_context.sh - From d2e84f33187d05a692a85e98d5eb00b5a6823289 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 23 Dec 2011 13:18:45 +0100 Subject: [PATCH 17/35] feature #1020: Remove traces of vmware ssh files from install.sh --- install.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/install.sh b/install.sh index 0eac11fd07..b0e0421029 100755 --- a/install.sh +++ b/install.sh @@ -211,7 +211,6 @@ LIB_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/tm_commands/dummy \ $LIB_LOCATION/tm_commands/lvm \ $LIB_LOCATION/tm_commands/vmware \ - $LIB_LOCATION/tm_commands/vmware-ssh \ $LIB_LOCATION/mads \ $LIB_LOCATION/sh \ $LIB_LOCATION/ruby/cli \ @@ -355,7 +354,6 @@ INSTALL_FILES=( 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 - VMWARE_TM_SSH_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/vmware-ssh DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm IMAGE_DRIVER_FS_SCRIPTS:$VAR_LOCATION/remotes/image/fs @@ -732,10 +730,6 @@ VMWARE_TM_COMMANDS_LIB_FILES="src/tm_mad/vmware/tm_clone.sh \ src/tm_mad/vmware/tm_mv.sh \ src/tm_mad/vmware/tm_context.sh" -VMWARE_TM_SSH_COMMANDS_LIB_FILES="src/tm_mad/vmware-ssh/tm_clone.sh \ - src/tm_mad/vmware-ssh/tm_ln.sh" - - #------------------------------------------------------------------------------- # Image Repository drivers, to be installed under $REMOTES_LOCATION/image # - FS based Image Repository, $REMOTES_LOCATION/image/fs @@ -814,8 +808,7 @@ 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 \ - src/tm_mad/vmware/tm_vmware_ssh.conf" +TM_VMWARE_ETC_FILES="src/tm_mad/vmware/tm_vmware.conf" #------------------------------------------------------------------------------- # Hook Manager driver config. files, to be installed under $ETC_LOCATION/hm From 0f1363c13728778018bef9e881df977ffe3ae87e Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 23 Dec 2011 13:38:13 +0100 Subject: [PATCH 18/35] feature #1020: Fix locations for vmware im --- src/im_mad/remotes/vmware.d/vmware.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/im_mad/remotes/vmware.d/vmware.rb b/src/im_mad/remotes/vmware.d/vmware.rb index d3437f5e4a..34df2fef73 100755 --- a/src/im_mad/remotes/vmware.d/vmware.rb +++ b/src/im_mad/remotes/vmware.d/vmware.rb @@ -16,12 +16,18 @@ # limitations under the License. # # ---------------------------------------------------------------------------- # -ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION) - if !ONE_LOCATION - RUBY_LIB_LOCATION = "/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION) + BIN_LOCATION = "/usr/bin" + LIB_LOCATION = "/usr/lib/one" + ETC_LOCATION = "/etc/one/" + VAR_LOCATION = "/var/lib/one" + RUBY_LIB_LOCATION = "/usr/lib/one/ruby" else - RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION) + LIB_LOCATION = ONE_LOCATION + "/lib" + BIN_LOCATION = ONE_LOCATION + "/bin" + ETC_LOCATION = ONE_LOCATION + "/etc/" + VAR_LOCATION = ONE_LOCATION + "/var/" + RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby" end $: << RUBY_LIB_LOCATION From 83c0541ee9993b9a874d38ea9bbb0158e1d43559 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 23 Dec 2011 13:47:29 +0100 Subject: [PATCH 19/35] feature #1020: Add missing ONE_LOCATION variable --- src/im_mad/remotes/vmware.d/vmware.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/im_mad/remotes/vmware.d/vmware.rb b/src/im_mad/remotes/vmware.d/vmware.rb index 34df2fef73..f1df591736 100755 --- a/src/im_mad/remotes/vmware.d/vmware.rb +++ b/src/im_mad/remotes/vmware.d/vmware.rb @@ -16,6 +16,8 @@ # limitations under the License. # # ---------------------------------------------------------------------------- # +ONE_LOCATION=ENV["ONE_LOCATION"] + if !ONE_LOCATION BIN_LOCATION = "/usr/bin" LIB_LOCATION = "/usr/lib/one" From 4a63ee16c79dd308fa7e445404cb6d15f3ceb2cb Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 23 Dec 2011 13:56:08 +0100 Subject: [PATCH 20/35] feature #1020: conf file read for vmware im --- src/im_mad/remotes/vmware.d/vmware.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/im_mad/remotes/vmware.d/vmware.rb b/src/im_mad/remotes/vmware.d/vmware.rb index f1df591736..b15b491479 100755 --- a/src/im_mad/remotes/vmware.d/vmware.rb +++ b/src/im_mad/remotes/vmware.d/vmware.rb @@ -34,6 +34,10 @@ end $: << RUBY_LIB_LOCATION +CONF_FILE = ETC_LOCATION + "/vmwarerc" + +ENV['LANG'] = 'C' + require "scripts_common" require 'yaml' require "CommandManager" @@ -90,6 +94,13 @@ if !host exit -1 end +conf = YAML::load(File.read(CONF_FILE)) + +@uri = conf[:libvirt_uri].gsub!('@HOST@', host) + +@user = conf[:username] +@pass = conf[:password] + # Poll the VMware hypervisor rc, data = do_action("virsh -c #{@uri} --readonly nodeinfo") From 27fa2959817f0ce691e4dac8c8c3ba59af341607 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 23 Dec 2011 14:00:44 +0100 Subject: [PATCH 21/35] feature #1020: Bug in result_str in vmware im --- src/im_mad/remotes/vmware.d/vmware.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/im_mad/remotes/vmware.d/vmware.rb b/src/im_mad/remotes/vmware.d/vmware.rb index b15b491479..b4c061656c 100755 --- a/src/im_mad/remotes/vmware.d/vmware.rb +++ b/src/im_mad/remotes/vmware.d/vmware.rb @@ -73,21 +73,21 @@ def do_action(cmd) end end +@result_str = "" + def add_info(name, value) value = "0" if value.nil? or value.to_s.empty? - result_str << "#{name}=#{value} " + @result_str << "#{name}=#{value} " end def print_info - puts result_str + puts @result_str end # ######################################################################## # # Main Procedure # # ######################################################################## # -result_str = "" - host = ARGV[2] if !host From f4fa0dcee8ce544c96e4877c95f5ed9341be3341 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 23 Dec 2011 16:51:30 +0100 Subject: [PATCH 22/35] feature #1020: force moving even if the target exists in TM VMware --- src/image_mad/remotes/fs/cp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image_mad/remotes/fs/cp b/src/image_mad/remotes/fs/cp index e60f43a159..f1a557eb63 100755 --- a/src/image_mad/remotes/fs/cp +++ b/src/image_mad/remotes/fs/cp @@ -64,7 +64,7 @@ vmware://*) BASE_DISK_FILE=`ls $DST | grep -v '.*-s[0-9]*\.vmdk'` - exec_and_log "mv $DST/$BASE_DISK_FILE $DST/disk.vmdk" \ + exec_and_log "mv -f $DST/$BASE_DISK_FILE $DST/disk.vmdk" \ "Error renaming disk file $BASE_DISK_FILE to disk.vmdk" exec_and_log "chmod 0770 $DST" From d9aab984142ff714c2b1d5369f9cd1e4611c1e7b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 24 Dec 2011 00:32:15 +0100 Subject: [PATCH 23/35] feature #1020: Do not fail deployments if the domain is already defined. IDs are unique. --- src/mad/ruby/vmwarelib.rb | 21 ++++++++++++++++----- src/vmm_mad/remotes/vmware/deploy | 3 ++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/mad/ruby/vmwarelib.rb b/src/mad/ruby/vmwarelib.rb index 6de5172548..217fa784c1 100644 --- a/src/mad/ruby/vmwarelib.rb +++ b/src/mad/ruby/vmwarelib.rb @@ -60,11 +60,16 @@ class VMwareDriver # ------------------------------------------------------------------------ # # Deploy & define a VM based on its description file # # ------------------------------------------------------------------------ # - def deploy(dfile) - # Define the VM - deploy_id = define_domain(dfile) + def deploy(dfile, id) + # Define the domain if it is not already defined (e.g. from UNKNOWN) - exit -1 if deploy_id.nil? + if not domain_defined?(id) + deploy_id = define_domain(dfile) + + exit -1 if deploy_id.nil? + else + deploy_id = "one-#{id}" + end OpenNebula.log_debug("Successfully defined domain #{deploy_id}.") @@ -273,8 +278,14 @@ class VMwareDriver end } - deploy_id.strip! + deploy_id.strip! return deploy_id end + + def domain_defined?(one_id) + rc, info = do_action("virsh -c #{@uri} dominfo one-#{one_id}") + + return rc + end end diff --git a/src/vmm_mad/remotes/vmware/deploy b/src/vmm_mad/remotes/vmware/deploy index fe0e4106dd..290bd60a74 100755 --- a/src/vmm_mad/remotes/vmware/deploy +++ b/src/vmm_mad/remotes/vmware/deploy @@ -31,8 +31,9 @@ require 'vmwarelib' dfile = ARGV[0] host = ARGV[1] +id = ARGV[3] -vmware_drv = VMwareDriver.new(host) +vmware_drv = VMwareDriver.new(host, id) puts vmware_drv.deploy(dfile) From 8f3442a5e4a2f9f405b0d6223a03c12e27207811 Mon Sep 17 00:00:00 2001 From: "Ruben S.Montero" Date: Sat, 24 Dec 2011 00:35:08 +0100 Subject: [PATCH 24/35] Feature #1020: Fix bug for VM poll --- src/mad/ruby/vmwarelib.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mad/ruby/vmwarelib.rb b/src/mad/ruby/vmwarelib.rb index 6de5172548..f730e39922 100644 --- a/src/mad/ruby/vmwarelib.rb +++ b/src/mad/ruby/vmwarelib.rb @@ -127,13 +127,13 @@ class VMwareDriver case state when "running","blocked","shutdown","dying" - state = 'a' + state_short = 'a' when "paused" - state = 'p' + state_short = 'p' when "crashed" - state = 'c' + state_short = 'c' else - state = 'd' + state_short = 'd' end return "STATE=#{state_short}" From fd4ce9ebeda30f6c40b3f7b02694377772ef9997 Mon Sep 17 00:00:00 2001 From: "Ruben S.Montero" Date: Sat, 24 Dec 2011 00:37:58 +0100 Subject: [PATCH 25/35] feature #1020: Bug in deploy --- src/vmm_mad/remotes/vmware/deploy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vmm_mad/remotes/vmware/deploy b/src/vmm_mad/remotes/vmware/deploy index 290bd60a74..e7024fe1cb 100755 --- a/src/vmm_mad/remotes/vmware/deploy +++ b/src/vmm_mad/remotes/vmware/deploy @@ -33,8 +33,8 @@ dfile = ARGV[0] host = ARGV[1] id = ARGV[3] -vmware_drv = VMwareDriver.new(host, id) +vmware_drv = VMwareDriver.new(host) -puts vmware_drv.deploy(dfile) +puts vmware_drv.deploy(dfile, id) exit 0 From 0b449e34013387754e94a621341d074b624f90d6 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 24 Dec 2011 03:48:51 +0100 Subject: [PATCH 26/35] feature #1020: Add common lib for tm functions. Fix deploy bug. Fix save bug in tm_mv. Add better linking of image files. --- install.sh | 1 + src/tm_mad/vmware/functions.sh | 61 +++++++++++++++++++++++++++++++ src/tm_mad/vmware/tm_clone.sh | 34 +++-------------- src/tm_mad/vmware/tm_context.sh | 1 + src/tm_mad/vmware/tm_ln.sh | 33 ++++++----------- src/tm_mad/vmware/tm_mv.sh | 9 +++-- src/vmm_mad/remotes/vmware/deploy | 2 +- 7 files changed, 87 insertions(+), 54 deletions(-) create mode 100644 src/tm_mad/vmware/functions.sh diff --git a/install.sh b/install.sh index b0e0421029..1b84ebe73f 100755 --- a/install.sh +++ b/install.sh @@ -728,6 +728,7 @@ LVM_TM_COMMANDS_LIB_FILES="src/tm_mad/lvm/tm_clone.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 \ + src/tm_mad/vmware/functions.sh \ src/tm_mad/vmware/tm_context.sh" #------------------------------------------------------------------------------- diff --git a/src/tm_mad/vmware/functions.sh b/src/tm_mad/vmware/functions.sh new file mode 100644 index 0000000000..d55effbd78 --- /dev/null +++ b/src/tm_mad/vmware/functions.sh @@ -0,0 +1,61 @@ +# ---------------------------------------------------------------------------- # +# 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. # +# ---------------------------------------------------------------------------- # + +#Symlinks the dst_path to dst_path.iso if it is an ISO file +function fix_iso { + dst_path=$1 + + if [ -f $dst_path ]; then + file -b $dst_path | grep "ISO 9660" > /dev/null 2>&1 + + if [ $? -eq 0 ]; then + bname=`basename $dst_path` + exec_and_log "ln -s $bname $dst_path/$bname.iso" \ + "Can not link ISO file." + fi + fi +} + +#Creates the VM dir +function create_vmdir { + dst_path=$1 + + log "Creating directory `basename $dst_path`" + exec_and_log "mkdir -p $dst_path" + exec_and_log "chmod a+rw $dst_path" +} + +#Makes path src ($1) relative to dst ($2) +function make_relative { + src=$1 + dst=$2 + + common=$dst + + while [ -z "`echo $src | grep -E "^$common"`" ]; do + common=`dirname $common` + dots="../$dots" + done + + echo $dots${src#$common/} +} + +#Test if the source file is a disk (and not the image dir for the VM) +function is_disk { + echo $1 | grep -q 'disk\.[0-9]\+$' > /dev/null 2>&1 + echo $? +} + diff --git a/src/tm_mad/vmware/tm_clone.sh b/src/tm_mad/vmware/tm_clone.sh index 09a337fb03..cd9cd874ae 100755 --- a/src/tm_mad/vmware/tm_clone.sh +++ b/src/tm_mad/vmware/tm_clone.sh @@ -26,6 +26,7 @@ else fi . $TMCOMMON +. "`dirname $0`/functions.sh" get_vmdir @@ -37,34 +38,11 @@ fix_paths log_debug "$1 $2" log_debug "DST: $DST_PATH" -DST_DIR=`dirname $DST_PATH` +create_vmdir $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" +log "Cloning $SRC_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" +exec_and_log "cp -r $SRC_PATH/* $DST_PATH" \ + "Error copying $SRC to $DST" +fix_iso_file $DST_PATH diff --git a/src/tm_mad/vmware/tm_context.sh b/src/tm_mad/vmware/tm_context.sh index 6292d391f2..3b26f50627 100755 --- a/src/tm_mad/vmware/tm_context.sh +++ b/src/tm_mad/vmware/tm_context.sh @@ -33,6 +33,7 @@ else fi . $TMCOMMON +. "`dirname $0`/functions.sh" get_vmdir diff --git a/src/tm_mad/vmware/tm_ln.sh b/src/tm_mad/vmware/tm_ln.sh index d815341511..5ae24f0c37 100755 --- a/src/tm_mad/vmware/tm_ln.sh +++ b/src/tm_mad/vmware/tm_ln.sh @@ -26,6 +26,7 @@ else fi . $TMCOMMON +. "`dirname $0`/functions.sh" get_vmdir @@ -34,30 +35,20 @@ DST_PATH=`arg_path $DST` fix_dst_path -DST_DIR=`dirname $DST_PATH` +create_vmdir $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" -exec_and_log "mkdir -p $DST_PATH" -exec_and_log "chmod a+w $DST_PATH" +# ---------------------------------------------------------------------------- # +# Link all files of the disk directory. Note that link paths needs to be # +# relative in order to be accessible from the vSphere Data Store # +# ---------------------------------------------------------------------------- # +REL_SRC_PATH=`make_relative $SRC_PATH $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" +for file in `find $SRC_PATH -type f`; do + FNAME=`basename $file` + exec_and_log "ln -sf $REL_SRC_PATH/$FNAME $DST_PATH/$FNAME" done -# Put the symlink mark for tm_mv -exec_and_log "ln -sf $RELATIVE_SRC_PATH $DST_PATH/.disk" - - - +#Mark this disk persistent with a symlink for tm_mv and repo mv +exec_and_log "ln -sf $REL_SRC_PATH $DST_PATH/.disk" diff --git a/src/tm_mad/vmware/tm_mv.sh b/src/tm_mad/vmware/tm_mv.sh index 8a4b27f875..b60be2862e 100755 --- a/src/tm_mad/vmware/tm_mv.sh +++ b/src/tm_mad/vmware/tm_mv.sh @@ -28,6 +28,7 @@ else fi . $TMCOMMON +. "`dirname $0`/functions.sh" get_vmdir @@ -41,13 +42,13 @@ SRC_PATH=`fix_dir_slashes "$SRC_PATH"` if [ "$SRC_PATH" = "$DST_PATH" ]; then log "Will not move, source and destination are equal" -elif [ -f "$SRC_PATH/.disk" ]; then # This link was set in tm_ln.sh +elif [ -L "$SRC_PATH/.disk" ]; then  exec_and_log "mv $SRC_PATH/.disk $DST_PATH" -elif echo $SRC_PATH | grep -q 'disk\.[0-9]\+$'; then -    log "Moving $SRC_PATH" +elif [ "`is_disk $SRC_PATH`" = "0" ] ; 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" + log "Will not move, is not saving a VM disk image" else log "Moving $SRC_PATH" exec_and_log "mv $SRC_PATH $DST_PATH" diff --git a/src/vmm_mad/remotes/vmware/deploy b/src/vmm_mad/remotes/vmware/deploy index 290bd60a74..cbd4d0c303 100755 --- a/src/vmm_mad/remotes/vmware/deploy +++ b/src/vmm_mad/remotes/vmware/deploy @@ -31,7 +31,7 @@ require 'vmwarelib' dfile = ARGV[0] host = ARGV[1] -id = ARGV[3] +id = ARGV[2] vmware_drv = VMwareDriver.new(host, id) From 96918e58b086dcbf8fa16301545f0bd67c9af069 Mon Sep 17 00:00:00 2001 From: "Ruben S.Montero" Date: Sat, 24 Dec 2011 03:51:44 +0100 Subject: [PATCH 27/35] feature #1020: Fix bug in deploywq --- src/tm_mad/vmware/tm_ln.sh | 35 ++++++++++++------------------- src/tm_mad/vmware/tm_mv.sh | 11 ++++++---- src/vmm_mad/remotes/vmware/deploy | 2 +- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/tm_mad/vmware/tm_ln.sh b/src/tm_mad/vmware/tm_ln.sh index d815341511..cb7f29193a 100755 --- a/src/tm_mad/vmware/tm_ln.sh +++ b/src/tm_mad/vmware/tm_ln.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -xv # ---------------------------------------------------------------------------- # # Copyright 2010-2011, C12G Labs S.L # @@ -26,6 +26,7 @@ else fi . $TMCOMMON +. "`dirname $0`/functions.sh" get_vmdir @@ -34,30 +35,20 @@ DST_PATH=`arg_path $DST` fix_dst_path -DST_DIR=`dirname $DST_PATH` +create_vmdir $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" -exec_and_log "mkdir -p $DST_PATH" -exec_and_log "chmod a+w $DST_PATH" +# ---------------------------------------------------------------------------- # +# Link all files of the disk directory. Note that link paths needs to be # +# relative in order to be accessible from the vSphere Data Store # +# ---------------------------------------------------------------------------- # +REL_SRC_PATH=`make_relative $SRC_PATH $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" +for file in `find $SRC_PATH -type f`; do + FNAME=`basename $file` + exec_and_log "ln -sf $REL_SRC_PATH/$FNAME $DST_PATH/$FNAME" done -# Put the symlink mark for tm_mv -exec_and_log "ln -sf $RELATIVE_SRC_PATH $DST_PATH/.disk" - - - +#Mark this disk persistent with a symlink for tm_mv and repo mv +exec_and_log "ln -sf $REL_SRC_PATH $DST_PATH/.disk" diff --git a/src/tm_mad/vmware/tm_mv.sh b/src/tm_mad/vmware/tm_mv.sh index 8a4b27f875..1d149be3bb 100755 --- a/src/tm_mad/vmware/tm_mv.sh +++ b/src/tm_mad/vmware/tm_mv.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash # ---------------------------------------------------------------------------- # # Copyright 2010-2011, C12G Labs S.L # @@ -39,11 +39,14 @@ fix_paths DST_PATH=`fix_dir_slashes "$DST_PATH"` SRC_PATH=`fix_dir_slashes "$SRC_PATH"` +echo $SRC_PATH | grep -q 'disk\.[0-9]\+$' > /dev/null 2>&1 +IS_DISK=$? + if [ "$SRC_PATH" = "$DST_PATH" ]; then log "Will not move, source and destination are equal" -elif [ -f "$SRC_PATH/.disk" ]; then # This link was set in tm_ln.sh -  exec_and_log "mv $SRC_PATH/.disk $DST_PATH" -elif echo $SRC_PATH | grep -q 'disk\.[0-9]\+$'; then +elif [ -L "$SRC_PATH/.disk" ]; then # This link was set in tm_ln.sh + exec_and_log "mv $SRC_PATH/.disk $DST_PATH" +elif [ IS_DISK -eq 0 ]; then    log "Moving $SRC_PATH"    exec_and_log "mv $SRC_PATH $DST_PATH" elif [ -d $SRC_PATH ]; then diff --git a/src/vmm_mad/remotes/vmware/deploy b/src/vmm_mad/remotes/vmware/deploy index e7024fe1cb..48cbaedd53 100755 --- a/src/vmm_mad/remotes/vmware/deploy +++ b/src/vmm_mad/remotes/vmware/deploy @@ -31,7 +31,7 @@ require 'vmwarelib' dfile = ARGV[0] host = ARGV[1] -id = ARGV[3] +id = ARGV[2] vmware_drv = VMwareDriver.new(host) From 8cf17480588656a19a773b150a464e3d9fca2831 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 24 Dec 2011 03:59:05 +0100 Subject: [PATCH 28/35] feature #1020: Removed debug information from tm script --- src/tm_mad/vmware/tm_ln.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tm_mad/vmware/tm_ln.sh b/src/tm_mad/vmware/tm_ln.sh index cb7f29193a..5ae24f0c37 100755 --- a/src/tm_mad/vmware/tm_ln.sh +++ b/src/tm_mad/vmware/tm_ln.sh @@ -1,4 +1,4 @@ -#!/bin/bash -xv +#!/bin/bash # ---------------------------------------------------------------------------- # # Copyright 2010-2011, C12G Labs S.L # From ea558a993edbf9f933886df8bf54c5ddbe55bbf3 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 24 Dec 2011 04:02:17 +0100 Subject: [PATCH 29/35] feature #1020: Remove chars in script --- src/tm_mad/vmware/tm_mv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tm_mad/vmware/tm_mv.sh b/src/tm_mad/vmware/tm_mv.sh index 7e6f198f94..f52499cd3e 100755 --- a/src/tm_mad/vmware/tm_mv.sh +++ b/src/tm_mad/vmware/tm_mv.sh @@ -43,7 +43,7 @@ SRC_PATH=`fix_dir_slashes "$SRC_PATH"` if [ "$SRC_PATH" = "$DST_PATH" ]; then log "Will not move, source and destination are equal" elif [ -L "$SRC_PATH/.disk" ]; then -  exec_and_log "mv $SRC_PATH/.disk $DST_PATH" + exec_and_log "mv $SRC_PATH/.disk $DST_PATH" elif [ "`is_disk $SRC_PATH`" = "0" ] ; then log "Moving $SRC_PATH"    exec_and_log "mv $SRC_PATH $DST_PATH" From 466766292a61eed89b9f3411cb750c7d8e1b4cb6 Mon Sep 17 00:00:00 2001 From: "Ruben S.Montero" Date: Sat, 24 Dec 2011 04:33:44 +0100 Subject: [PATCH 30/35] feature #1020: Fix bugs when dealing with persistent imageswq --- src/image_mad/remotes/fs/mv | 4 +++- src/tm_mad/vmware/tm_ln.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/image_mad/remotes/fs/mv b/src/image_mad/remotes/fs/mv index 84c845803e..2abcb29fe7 100755 --- a/src/image_mad/remotes/fs/mv +++ b/src/image_mad/remotes/fs/mv @@ -53,7 +53,9 @@ http://*) *) log "Moving local image $SRC to the image repository" - if [ \( -L $SRC \) -a \( "`$READLINK $SRC`" = "$DST" \) ] ; then + + if [ \( -L $SRC \) -a \ + \( "`$READLINK -f $SRC`" = "`$READLINK -f $DST`" \) ] ; then log "Not moving files to image repo, they are the same" else exec_and_log "mv -f $SRC $DST" "Could not move $SRC to $DST" diff --git a/src/tm_mad/vmware/tm_ln.sh b/src/tm_mad/vmware/tm_ln.sh index 5ae24f0c37..87dd227bb0 100755 --- a/src/tm_mad/vmware/tm_ln.sh +++ b/src/tm_mad/vmware/tm_ln.sh @@ -51,4 +51,4 @@ for file in `find $SRC_PATH -type f`; do done #Mark this disk persistent with a symlink for tm_mv and repo mv -exec_and_log "ln -sf $REL_SRC_PATH $DST_PATH/.disk" +exec_and_log "ln -sf ${REL_SRC_PATH#../../} $DST_PATH/.disk" From eafea8edbe4b805ab87f3877c55886f8f11f4ddd Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 26 Dec 2011 00:22:52 +0100 Subject: [PATCH 31/35] feature #132, #1020: Reboot for VMWare Hypervisor --- install.sh | 1 + src/mad/ruby/vmwarelib.rb | 13 +++++++++++ src/vmm_mad/remotes/vmware/reboot | 37 +++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100755 src/vmm_mad/remotes/vmware/reboot diff --git a/install.sh b/install.sh index 1b84ebe73f..f2c4022b05 100755 --- a/install.sh +++ b/install.sh @@ -614,6 +614,7 @@ 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/reboot \ src/vmm_mad/remotes/vmware/save \ src/vmm_mad/remotes/vmware/poll \ src/vmm_mad/remotes/vmware/checkpoint \ diff --git a/src/mad/ruby/vmwarelib.rb b/src/mad/ruby/vmwarelib.rb index 565cdf3d2d..908e5588f6 100644 --- a/src/mad/ruby/vmwarelib.rb +++ b/src/mad/ruby/vmwarelib.rb @@ -101,6 +101,19 @@ class VMwareDriver undefine_domain(deploy_id) end + # ------------------------------------------------------------------------ # + # Reboots a running VM # + # ------------------------------------------------------------------------ # + def reboot(deploy_id) + # Destroy the VM + rc, info = perform_action("virsh -c #{@uri} reboot #{deploy_id}") + + if rc == false + exit info + end + + OpenNebula.log_debug("Domain #{deploy_id} successfully rebooted.") + end # ------------------------------------------------------------------------ # # Migrate # # ------------------------------------------------------------------------ # diff --git a/src/vmm_mad/remotes/vmware/reboot b/src/vmm_mad/remotes/vmware/reboot new file mode 100755 index 0000000000..3d2c40b383 --- /dev/null +++ b/src/vmm_mad/remotes/vmware/reboot @@ -0,0 +1,37 @@ +#!/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 + RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION) +else + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION) +end + +$: << RUBY_LIB_LOCATION +$: << File.dirname(__FILE__) + +require 'vmwarelib' + +deploy_id = ARGV[0] +host = ARGV[1] + +vmware_drv = VMwareDriver.new(host) + +vmware_drv.reboot(deploy_id) From 9270b57ebb6fccca8e56153a6f01bfdacede9e43 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 26 Dec 2011 00:33:01 +0100 Subject: [PATCH 32/35] feature #1020: Moved and renamed vmwarelib to driver folder and name vmware_driver --- install.sh | 4 ++-- src/vmm_mad/remotes/vmware/cancel | 8 ++++---- src/vmm_mad/remotes/vmware/deploy | 2 +- src/vmm_mad/remotes/vmware/poll | 2 +- src/vmm_mad/remotes/vmware/reboot | 2 +- src/vmm_mad/remotes/vmware/restore | 2 +- src/vmm_mad/remotes/vmware/save | 8 ++++---- src/vmm_mad/remotes/vmware/shutdown | 4 ++-- .../remotes/vmware/vmware_driver.rb} | 13 +++---------- 9 files changed, 19 insertions(+), 26 deletions(-) rename src/{mad/ruby/vmwarelib.rb => vmm_mad/remotes/vmware/vmware_driver.rb} (98%) diff --git a/install.sh b/install.sh index f2c4022b05..8d570c86c3 100755 --- a/install.sh +++ b/install.sh @@ -528,7 +528,6 @@ RUBY_LIB_FILES="src/mad/ruby/ActionManager.rb \ src/mad/ruby/ssh_stream.rb \ src/vnm_mad/one_vnm.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 \ @@ -618,7 +617,8 @@ VMM_EXEC_VMWARE_SCRIPTS="src/vmm_mad/remotes/vmware/cancel \ src/vmm_mad/remotes/vmware/save \ src/vmm_mad/remotes/vmware/poll \ src/vmm_mad/remotes/vmware/checkpoint \ - src/vmm_mad/remotes/vmware/shutdown" + src/vmm_mad/remotes/vmware/shutdown \ + src/vmm_mad/remotes/vmware/vmware_driver.rb" #------------------------------------------------------------------------------- # Information Manager Probes, to be installed under $REMOTES_LOCATION/im diff --git a/src/vmm_mad/remotes/vmware/cancel b/src/vmm_mad/remotes/vmware/cancel index e5567189bf..7352a66720 100755 --- a/src/vmm_mad/remotes/vmware/cancel +++ b/src/vmm_mad/remotes/vmware/cancel @@ -27,11 +27,11 @@ end $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) -require 'vmwarelib' +require 'vmware_driver' -dfile = ARGV[0] -host = ARGV[1] +deploy_id = ARGV[0] +host = ARGV[1] vmware_drv = VMwareDriver.new(host) -vmware_drv.cancel(dfile) +vmware_drv.cancel(deploy_id) diff --git a/src/vmm_mad/remotes/vmware/deploy b/src/vmm_mad/remotes/vmware/deploy index 48cbaedd53..05e89cc98e 100755 --- a/src/vmm_mad/remotes/vmware/deploy +++ b/src/vmm_mad/remotes/vmware/deploy @@ -27,7 +27,7 @@ end $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) -require 'vmwarelib' +require 'vmware_driver' dfile = ARGV[0] host = ARGV[1] diff --git a/src/vmm_mad/remotes/vmware/poll b/src/vmm_mad/remotes/vmware/poll index c4454bec60..f4fa915cb2 100755 --- a/src/vmm_mad/remotes/vmware/poll +++ b/src/vmm_mad/remotes/vmware/poll @@ -28,7 +28,7 @@ end $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) -require 'vmwarelib' +require 'vmware_driver' deploy_id = ARGV[0] host = ARGV[1] diff --git a/src/vmm_mad/remotes/vmware/reboot b/src/vmm_mad/remotes/vmware/reboot index 3d2c40b383..3c61f64e3b 100755 --- a/src/vmm_mad/remotes/vmware/reboot +++ b/src/vmm_mad/remotes/vmware/reboot @@ -27,7 +27,7 @@ end $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) -require 'vmwarelib' +require 'vmware_driver' deploy_id = ARGV[0] host = ARGV[1] diff --git a/src/vmm_mad/remotes/vmware/restore b/src/vmm_mad/remotes/vmware/restore index 7f8702dfbc..feced12ea8 100755 --- a/src/vmm_mad/remotes/vmware/restore +++ b/src/vmm_mad/remotes/vmware/restore @@ -27,7 +27,7 @@ end $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) -require 'vmwarelib' +require 'vmware_driver' checkpoint_file = ARGV[0] host = ARGV[1] diff --git a/src/vmm_mad/remotes/vmware/save b/src/vmm_mad/remotes/vmware/save index a8dbf6e35d..60f7eb87eb 100755 --- a/src/vmm_mad/remotes/vmware/save +++ b/src/vmm_mad/remotes/vmware/save @@ -27,11 +27,11 @@ end $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) -require 'vmwarelib' +require 'vmware_driver' -deploy_id = ARGV[0] -file = ARGV[1] -host = ARGV[2] +deploy_id = ARGV[0] +file = ARGV[1] +host = ARGV[2] vmware_drv = VMwareDriver.new(host) diff --git a/src/vmm_mad/remotes/vmware/shutdown b/src/vmm_mad/remotes/vmware/shutdown index a32849172e..b154da7dd9 100755 --- a/src/vmm_mad/remotes/vmware/shutdown +++ b/src/vmm_mad/remotes/vmware/shutdown @@ -27,10 +27,10 @@ end $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) -require 'vmwarelib' +require 'vmware_driver' deploy_id = ARGV[0] -host = ARGV[1] +host = ARGV[1] vmware_drv = VMwareDriver.new(host) diff --git a/src/mad/ruby/vmwarelib.rb b/src/vmm_mad/remotes/vmware/vmware_driver.rb similarity index 98% rename from src/mad/ruby/vmwarelib.rb rename to src/vmm_mad/remotes/vmware/vmware_driver.rb index 908e5588f6..1531ad4958 100644 --- a/src/mad/ruby/vmwarelib.rb +++ b/src/vmm_mad/remotes/vmware/vmware_driver.rb @@ -91,9 +91,7 @@ class VMwareDriver # Destroy the VM rc, info = perform_action("virsh -c #{@uri} destroy #{deploy_id}") - if rc == false - exit info - end + exit info if rc == false OpenNebula.log_debug("Successfully canceled domain #{deploy_id}.") @@ -105,12 +103,9 @@ class VMwareDriver # Reboots a running VM # # ------------------------------------------------------------------------ # def reboot(deploy_id) - # Destroy the VM rc, info = perform_action("virsh -c #{@uri} reboot #{deploy_id}") - if rc == false - exit info - end + exit info if rc == false OpenNebula.log_debug("Domain #{deploy_id} successfully rebooted.") end @@ -128,9 +123,7 @@ class VMwareDriver def poll(deploy_id) rc, info = do_action("virsh -c #{@uri} --readonly dominfo #{deploy_id}") - if rc == false - return "STATE=d" - end + return "STATE=d" if rc == false state = "" From a5996c514fe7385d44705f8e66aa60278d651d15 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 26 Dec 2011 13:28:24 +0100 Subject: [PATCH 33/35] feature #132: Use again deploy_id from drv_message for actions. (cherry picked from commit 4f242f4df9ec31b1668abde9c41b96010a024205) --- src/vmm_mad/exec/one_vmm_exec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 107ddcdd5f..6f44895e0e 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -450,20 +450,22 @@ class ExecDriver < VirtualMachineDriver # POLL action, gets information of a VM # def poll(id, drv_message) - data = decode(drv_message) - host = data.elements['HOST'].text + data = decode(drv_message) + host = data.elements['HOST'].text + deploy_id = data.elements['DEPLOY_ID'].text - do_action("#{id} #{host}", id, host, ACTION[:poll]) + do_action("#{deploy_id} #{host}", id, host, ACTION[:poll]) end # # REBOOT action, reboots a running VM # def reboot(id, drv_message) - data = decode(drv_message) - host = data.elements['HOST'].text + data = decode(drv_message) + host = data.elements['HOST'].text + deploy_id = data.elements['DEPLOY_ID'].text - do_action("#{id} #{host}", id, host, ACTION[:reboot]) + do_action("#{deploy_id} #{host}", id, host, ACTION[:reboot]) end end From d736284dfb8727c4dd3a24916fe4a89cd464c2e0 Mon Sep 17 00:00:00 2001 From: "Ruben S.Montero" Date: Mon, 26 Dec 2011 13:33:14 +0100 Subject: [PATCH 34/35] feature #1020: Fix bug in cancel and reboot methods. (was calling wrong method) --- src/vmm_mad/remotes/vmware/vmware_driver.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vmm_mad/remotes/vmware/vmware_driver.rb b/src/vmm_mad/remotes/vmware/vmware_driver.rb index 1531ad4958..6841906fe2 100644 --- a/src/vmm_mad/remotes/vmware/vmware_driver.rb +++ b/src/vmm_mad/remotes/vmware/vmware_driver.rb @@ -89,7 +89,7 @@ class VMwareDriver # ------------------------------------------------------------------------ # def cancel(deploy_id) # Destroy the VM - rc, info = perform_action("virsh -c #{@uri} destroy #{deploy_id}") + rc, info = do_action("virsh -c #{@uri} destroy #{deploy_id}") exit info if rc == false @@ -103,7 +103,7 @@ class VMwareDriver # Reboots a running VM # # ------------------------------------------------------------------------ # def reboot(deploy_id) - rc, info = perform_action("virsh -c #{@uri} reboot #{deploy_id}") + rc, info = do_action("virsh -c #{@uri} reboot #{deploy_id}") exit info if rc == false From 2bbc1cc1181bc4674c2db4365329c686d6793aad Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 27 Dec 2011 23:56:14 +0100 Subject: [PATCH 35/35] feature #1020: Removed uneeded permissions update. Removed wrong chars --- src/image_mad/remotes/fs/fsrc | 9 --------- src/image_mad/remotes/fs/mv | 1 - src/tm_mad/vmware/tm_clone.sh | 2 +- src/tm_mad/vmware/tm_mv.sh | 2 +- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/image_mad/remotes/fs/fsrc b/src/image_mad/remotes/fs/fsrc index 8cec0f0b05..4df7a005a3 100644 --- a/src/image_mad/remotes/fs/fsrc +++ b/src/image_mad/remotes/fs/fsrc @@ -92,12 +92,3 @@ 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 '{}' \; -} \ No newline at end of file diff --git a/src/image_mad/remotes/fs/mv b/src/image_mad/remotes/fs/mv index 2abcb29fe7..02290af989 100755 --- a/src/image_mad/remotes/fs/mv +++ b/src/image_mad/remotes/fs/mv @@ -65,7 +65,6 @@ esac if [ -d $DST ]; then exec_and_log "chmod 0770 $DST" - fix_owner_perms else exec_and_log "chmod 0660 $DST" fi diff --git a/src/tm_mad/vmware/tm_clone.sh b/src/tm_mad/vmware/tm_clone.sh index cd9cd874ae..aacc251c71 100755 --- a/src/tm_mad/vmware/tm_clone.sh +++ b/src/tm_mad/vmware/tm_clone.sh @@ -45,4 +45,4 @@ log "Cloning $SRC_PATH" exec_and_log "cp -r $SRC_PATH/* $DST_PATH" \ "Error copying $SRC to $DST" -fix_iso_file $DST_PATH +fix_iso $DST_PATH diff --git a/src/tm_mad/vmware/tm_mv.sh b/src/tm_mad/vmware/tm_mv.sh index 990abfca40..a03071bf0e 100755 --- a/src/tm_mad/vmware/tm_mv.sh +++ b/src/tm_mad/vmware/tm_mv.sh @@ -46,7 +46,7 @@ elif [ -L "$SRC_PATH/.disk" ]; then exec_and_log "mv $SRC_PATH/.disk $DST_PATH" elif [ "`is_disk $SRC_PATH`" = "0" ] ; then log "Moving $SRC_PATH" -    exec_and_log "mv $SRC_PATH $DST_PATH" + exec_and_log "mv $SRC_PATH $DST_PATH" elif [ -d $SRC_PATH ]; then log "Will not move, it is not saving a VM disk image" else