diff --git a/src/tm_mad/vmware/clone b/src/tm_mad/vmware/clone
index c5a33e933e..e232fe245d 100755
--- a/src/tm_mad/vmware/clone
+++ b/src/tm_mad/vmware/clone
@@ -52,22 +52,21 @@ DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
-
-IMAGE_DS_NAME=`basename $(dirname $SRC_PATH)`
-SYSTEM_DS_NAME=`basename $(dirname $(dirname $DST_PATH))`
-USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)`
-PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)`
-
-
-DST_DIR_WITHOUT_DS_PATH="[$SYSTEM_DS_NAME] ${DST_PATH##"$DS_DIR/$SYSTEM_DS_NAME/"}"
-
+if [ "$SSH" != "yes" ]; then
+ USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)`
+ PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)`
+ IMAGE_DS_NAME=`basename $(dirname $SRC_PATH)`
+ SYSTEM_DS_NAME=`basename $(dirname $(dirname $DST_PATH))`
+ DST_DIR_WITHOUT_DS_PATH="[$SYSTEM_DS_NAME] ${DST_PATH##"$DS_DIR/$SYSTEM_DS_NAME/"}"
+ VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD"
+fi
if [ "$SSH" == "yes" ]; then
ssh_make_path $DST_HOST $DST_PATH
else
# Two calls needed since vifs cannot do a mkdir -p
- vifs --server $DST_HOST --username $USERNAME --password $PASSWORD --mkdir "[$SYSTEM_DS_NAME] $VMID"
- vifs --server $DST_HOST --username $USERNAME --password $PASSWORD --mkdir "$DST_DIR_WITHOUT_DS_PATH"
+ exec_and_log 'vifs $VI_PARAMS --mkdir "[$SYSTEM_DS_NAME] $VMID"' "Cannot create [$SYSTEM_DS_NAME] $VMID in $DST_HOST"
+ exec_and_log 'vifs $VI_PARAMS --mkdir "$DST_DIR_WITHOUT_DS_PATH"' "Cannot create $DST_DIR_WITHOUT_DS_PATH in $DST_HOST"
fi
#-------------------------------------------------------------------------------
@@ -92,7 +91,7 @@ EOF
)
ssh_exec_and_log $DST_HOST "$CLONESCRIPT" "Error cloning $SRC to $DST"
else
- $VMKFSTOOLS --server $DST_HOST --username $USERNAME --password $PASSWORD -i "$SRC_DIR_WITHOUT_DS_PATH/disk.vmdk" -d thin "$DST_DIR_WITHOUT_DS_PATH/disk.vmdk"
+ exec_and_log '$VMKFSTOOLS $VI_PARAMS -i "$SRC_DIR_WITHOUT_DS_PATH/disk.vmdk" -d thin "$DST_DIR_WITHOUT_DS_PATH/disk.vmdk"' "Error cloning $SRC to $DST"
fi
exit 0
diff --git a/src/tm_mad/vmware/context b/src/tm_mad/vmware/context
deleted file mode 120000
index 921312e950..0000000000
--- a/src/tm_mad/vmware/context
+++ /dev/null
@@ -1 +0,0 @@
-../common/context
\ No newline at end of file
diff --git a/src/tm_mad/vmware/context b/src/tm_mad/vmware/context
new file mode 100755
index 0000000000..9ccfb58224
--- /dev/null
+++ b/src/tm_mad/vmware/context
@@ -0,0 +1,97 @@
+#!/bin/bash
+
+# -------------------------------------------------------------------------- #
+# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
+# #
+# 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. #
+#--------------------------------------------------------------------------- #
+
+# context context.sh file1 file2 ... fileN host:remote_system_ds/disk.i vmid 0
+# - context.sh file are the contents of the context ISO
+# - host is the target host to deploy the VM
+# - remote_system_ds is the path for the system datastore in the host
+# - vmid is the id of the VM
+# - 0 is the target datastore (system)
+
+ARGV=("$@")
+
+DS_ID="${ARGV[$(($#-1))]}"
+VM_ID="${ARGV[$(($#-2))]}"
+DST="${ARGV[$(($#-3))]}"
+SRC="${ARGV[@]:0:$(($#-3))}"
+
+if [ -z "${ONE_LOCATION}" ]; then
+ TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
+ VMWARERC=/etc/one/vmwarerc
+else
+ TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
+ VMWARERC=$ONE_LOCATION/etc/vmwarerc
+fi
+
+. $TMCOMMON
+
+source $(dirname $0)/tm_vmwarerc
+
+#-------------------------------------------------------------------------------
+# Set dst path and dirs
+#-------------------------------------------------------------------------------
+DST_PATH=`arg_path $DST`
+DST_HOST=`arg_host $DST`
+DST_DIR=`dirname $DST_PATH`
+
+if [ "$SSH" != "yes" ]; then
+ USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)`
+ PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)`
+ VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD"
+fi
+
+if [ "$SSH" == "yes" ]; then
+ ssh_make_path $DST_HOST $DST_DIR
+else
+ exec_and_log 'vifs $VI_PARAMS --mkdir "$DST_DIR"' "Cannot create $DST_DIR on %DST_HOST"
+fi
+
+#-------------------------------------------------------------------------------
+# Build the Context Block device (locally) and copy it remotely
+#-------------------------------------------------------------------------------
+log "Generating context block device at $DST"
+
+VM_ID=`basename $DST_DIR`
+ISO_DIR="$DS_DIR/.isofiles/$VM_ID"
+ISO_FILE="$ISO_DIR/$VM_ID.iso"
+
+exec_and_log "mkdir -p $ISO_DIR" "Could not create tmp dir to make context dev"
+
+for f in $SRC; do
+ case $f in
+ http://*)
+ exec_and_log "$WGET -P $ISO_DIR $f" "Error downloading $f"
+ ;;
+ *)
+ exec_and_log "cp -R $f $ISO_DIR" "Error copying $f to $ISO_DIR"
+ ;;
+ esac
+done
+
+exec_and_log "$MKISOFS -o $ISO_FILE -J -R $ISO_DIR" "Error creating iso fs"
+
+if [ "$SSH" == "yes" ]; then
+ exec_and_log "$SCP $ISO_FILE $DST" "Error copying context ISO to $DST"
+else
+ # Copies the iso file with .iso suffix, needed for VMware CDROMs
+ exec_and_log 'vifs $VI_PARAMS -p $ISO_FILE $DST_PATH.iso' "Error copying context ISO to $DST"
+fi
+
+rm -rf $ISO_DIR > /dev/null 2>&1
+
+exit 0
diff --git a/src/tm_mad/vmware/delete b/src/tm_mad/vmware/delete
deleted file mode 120000
index 230e56774f..0000000000
--- a/src/tm_mad/vmware/delete
+++ /dev/null
@@ -1 +0,0 @@
-../common/delete
\ No newline at end of file
diff --git a/src/tm_mad/vmware/delete b/src/tm_mad/vmware/delete
new file mode 100755
index 0000000000..29043ae8c0
--- /dev/null
+++ b/src/tm_mad/vmware/delete
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+# -------------------------------------------------------------------------- #
+# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
+# #
+# 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. #
+#--------------------------------------------------------------------------- #
+
+# DELETE vmid dsid
+# - host is the target host to deploy the VM
+# - remote_system_ds is the path for the system datastore in the host
+# - vmid is the id of the VM
+# - dsid is the target datastore (0 is the system datastore)
+
+DST=$1
+
+VMID=$2
+DSID=$3
+
+if [ -z "${ONE_LOCATION}" ]; then
+ TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
+ VMWARERC=/etc/one/vmwarerc
+else
+ TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
+ VMWARERC=$ONE_LOCATION/etc/vmwarerc
+fi
+
+. $TMCOMMON
+
+source $(dirname $0)/tm_vmwarerc
+
+#-------------------------------------------------------------------------------
+# Return if deleting a disk, we will delete them when removing the
+# remote_system_ds directory for the VM (remotely)
+#-------------------------------------------------------------------------------
+DST_PATH=`arg_path $DST`
+DST_HOST=`arg_host $DST`
+
+if [ `is_disk $DST_PATH` -eq 1 ]; then
+ exit 0
+fi
+
+log "Deleting $DST_PATH"
+
+if [ "$SSH" == "yes" ]; then
+ ssh_exec_and_log $DST_HOST "rm -rf $DST_PATH" "Error deleting $DST_PATH"
+else
+ USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)`
+ PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)`
+ exec_and_log '$VMKFSTOOLS --server $DST_HOST --username $USERNAME --password $PASSWORD -U $DST_PATH' "Cannot delelete $DST"
+fi
+
+exit 0
diff --git a/src/tm_mad/vmware/ln b/src/tm_mad/vmware/ln
deleted file mode 120000
index 2926cd697b..0000000000
--- a/src/tm_mad/vmware/ln
+++ /dev/null
@@ -1 +0,0 @@
-../shared/ln
\ No newline at end of file
diff --git a/src/tm_mad/vmware/ln b/src/tm_mad/vmware/ln
new file mode 100755
index 0000000000..ff534b58b9
--- /dev/null
+++ b/src/tm_mad/vmware/ln
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+# -------------------------------------------------------------------------- #
+# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
+# #
+# 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. #
+#--------------------------------------------------------------------------- #
+
+# ln fe:SOURCE host:remote_system_ds/disk.i vmid dsid
+# - fe is the front-end hostname
+# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk
+# - host is the target host to deploy the VM
+# - remote_system_ds is the path for the system datastore in the host
+# - vmid is the id of the VM
+# - dsid is the target datastore (0 is the system datastore)
+
+SRC=$1
+DST=$2
+
+VMID=$3
+DSID=$4
+
+if [ -z "${ONE_LOCATION}" ]; then
+ TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
+else
+ TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
+fi
+
+. $TMCOMMON
+
+#-------------------------------------------------------------------------------
+# Set dst path and dir
+#-------------------------------------------------------------------------------
+SRC_PATH=`arg_path $SRC`
+SRC_PATH="../../${SRC_PATH##"$DS_DIR/"}"
+
+DST_PATH=`arg_path $DST`
+DST_HOST=`arg_host $DST`
+DST_DIR=`dirname $DST_PATH`
+
+#-------------------------------------------------------------------------------
+# Link (ln) SRC into DST
+#-------------------------------------------------------------------------------
+
+if [ "$SSH" == "yes" ]; then
+ ssh_make_path $DST_HOST $DST_PATH
+
+ # It's a folder, make links for all elements
+ SRC_FOLDER_NAME=`basename $SRC_PATH`
+ SRC_WITH_NO_FOLDER=`dirname $SRC_PATH`
+ SRC_DS_NAME=`basename $SRC_WITH_NO_FOLDER`
+ REL_SRC_PATH="../../../$SRC_DS_NAME/$SRC_FOLDER_NAME"
+
+ log "Link all files in $SRC_PATH to $DST_PATH"
+
+LINK_SCRIPT=$(cat <