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 5a8b646c35..2ecd2bb076 100644 --- a/src/mad/ruby/vmwarelib.rb +++ b/src/mad/ruby/vmwarelib.rb @@ -89,7 +89,7 @@ class VmWareDriver end # Undefine the VM - exit undefine_domain(deploy_id) + undefine_domain(deploy_id) end # ------------------------------------------------------------------------ # @@ -217,6 +217,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/tm_mad/vmware/tm_ln.sh b/src/tm_mad/vmware/tm_ln.sh index 878b0785f7..d815341511 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" @@ -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 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 8192ce7127..1171e3fa6c 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