mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #1112: Implement clone, delete, ln, mv, mvds for tm_iscsi
This commit is contained in:
parent
5ec865cb3c
commit
41d3bbe200
@ -79,8 +79,9 @@ let TID=ID+BASE_TID
|
||||
REGISTER_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$SUDO $LVCREATE -L${SIZE}M ${VG_NAME} -n ${LV_NAME}
|
||||
$SUDO $(iscsi_target_new "$TID" "$IQN")
|
||||
$SUDO $(iscsi_logicalunit_new "$TID" "$DEV")
|
||||
$SUDO $(tgtadm_target_new "$TID" "$IQN")
|
||||
$SUDO $(tgtadm_target_bind_all "$TID")
|
||||
$SUDO $(tgtadm_logicalunit_new "$TID" "$DEV")
|
||||
EOF
|
||||
)
|
||||
|
||||
|
@ -80,8 +80,9 @@ let TID=ID+BASE_TID
|
||||
REGISTER_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$SUDO $LVCREATE -L${SIZE}M ${VG_NAME} -n ${LV_NAME}
|
||||
$SUDO $(iscsi_target_new "$TID" "$IQN")
|
||||
$SUDO $(iscsi_logicalunit_new "$TID" "$DEV")
|
||||
$SUDO $(tgtadm_target_new "$TID" "$IQN")
|
||||
$SUDO $(tgtadm_target_bind_all "$TID")
|
||||
$SUDO $(tgtadm_logicalunit_new "$TID" "$DEV")
|
||||
$SUDO $(mkfs_command "$DEV" "$FSTYPE")
|
||||
EOF
|
||||
)
|
||||
|
@ -61,15 +61,8 @@ DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
let TID=ID+BASE_TID
|
||||
|
||||
RM_COMMAND=$(cat <<EOF
|
||||
n_snapshots=\$($SUDO $LVS --noheadings -o name,origin $VG_NAME | \
|
||||
$AWK '{if(\$2 == "$LV_NAME"){print \$1}}'|wc -l)
|
||||
if [ "\$n_snapshots" = "0" ]; then
|
||||
$SUDO $(iscsi_target_delete "$TID")
|
||||
$SUDO $LVREMOVE -f $VG_NAME/$LV_NAME
|
||||
else
|
||||
echo "Error: \$n_snapshots active snapshots for $VG_NAME/$LV_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
$SUDO $(tgtadm_target_delete "$TID")
|
||||
$SUDO $LVREMOVE -f $VG_NAME/$LV_NAME
|
||||
EOF
|
||||
)
|
||||
|
||||
|
@ -136,37 +136,3 @@ function check_restricted {
|
||||
|
||||
echo 0
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# iSCSI functions
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Returns the command to create a new target
|
||||
# @param $1 - ID of the image
|
||||
# @param $2 - Target Host
|
||||
# @param $3 - Device
|
||||
# @return the command to create a new target
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function iscsi_target_new {
|
||||
ID="$1"
|
||||
IQN="$2"
|
||||
|
||||
echo "$TGTADM --lld iscsi --op new --mode target --tid $ID "\
|
||||
"--targetname $IQN"
|
||||
}
|
||||
|
||||
function iscsi_logicalunit_new {
|
||||
ID="$1"
|
||||
DEV="$2"
|
||||
|
||||
echo "$TGTADM --lld iscsi --op new --mode logicalunit --tid $ID "\
|
||||
"--lun 1 --backing-store $DEV"
|
||||
}
|
||||
|
||||
function iscsi_target_delete {
|
||||
ID="$1"
|
||||
echo "$TGTADM --lld iscsi --op delete --mode target --tid $ID"
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ DATE=date
|
||||
DD=dd
|
||||
DU=du
|
||||
GREP=grep
|
||||
ISCSIADM=iscsiadm
|
||||
LVCREATE=lvcreate
|
||||
LVREMOVE=lvremove
|
||||
LVS=lvs
|
||||
@ -244,3 +245,61 @@ EOF`
|
||||
exit $SSH_EXEC_RC
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# iSCSI functions
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Returns the command to create a new target
|
||||
# @param $1 - ID of the image
|
||||
# @param $2 - Target Host
|
||||
# @param $3 - Device
|
||||
# @return the command to create a new target
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function tgtadm_target_new {
|
||||
ID="$1"
|
||||
IQN="$2"
|
||||
|
||||
echo "$TGTADM --lld iscsi --op new --mode target --tid $ID "\
|
||||
"--targetname $IQN;"
|
||||
}
|
||||
|
||||
function tgtadm_target_bind_all {
|
||||
ID="$1"
|
||||
echo "$TGTADM --lld iscsi --op bind --mode target --tid $ID -I ALL"
|
||||
}
|
||||
|
||||
function tgtadm_logicalunit_new {
|
||||
ID="$1"
|
||||
DEV="$2"
|
||||
|
||||
echo "$TGTADM --lld iscsi --op new --mode logicalunit --tid $ID "\
|
||||
"--lun 1 --backing-store $DEV"
|
||||
}
|
||||
|
||||
function tgtadm_target_delete {
|
||||
ID="$1"
|
||||
echo "$TGTADM --lld iscsi --op delete --mode target --tid $ID"
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
function iscsiadm_discovery {
|
||||
TARGET_HOST="$1"
|
||||
echo "$ISCSIADM -m discovery -t st -p $TARGET_HOST"
|
||||
}
|
||||
|
||||
function iscsiadm_login {
|
||||
IQN="$1"
|
||||
TARGET_HOST="$2"
|
||||
echo "$ISCSIADM -m node --targetname $IQN -p $TARGET_HOST --login"
|
||||
}
|
||||
|
||||
function iscsiadm_logout {
|
||||
IQN="$1"
|
||||
echo "$ISCSIADM -m node --targetname $IQN --logout"
|
||||
}
|
||||
|
||||
|
68
src/tm_mad/iscsi/clone
Executable file
68
src/tm_mad/iscsi/clone
Executable file
@ -0,0 +1,68 @@
|
||||
#!/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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# clone fe:SOURCE host:remote_system_ds/disk.i size
|
||||
# - 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
|
||||
|
||||
SRC=$1 # iqn.2012-02.org.opennebula:o200.vg-one.lv-one-0
|
||||
DST=$2 # o202:/var/lib/one//datastores/0/0/disk.0
|
||||
|
||||
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
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
TARGET=`arg_path $SRC` # o200.vg-one.lv-one-0
|
||||
DST_PATH=`arg_path $DST` # /var/lib/one/datastores/0/0/disk.0
|
||||
DST_HOST=`arg_host $DST` # o202
|
||||
DST_DIR=`dirname $DST_PATH` # /var/lib/one/datastores/0/0
|
||||
|
||||
BASE_IQN=`echo $SRC|$CUT -d: -f1`
|
||||
TARGET=`echo $SRC|$CUT -d: -f2`
|
||||
LV_NAME=`echo $TARGET|$AWK -F. '{print $(NF)}'`
|
||||
VG_NAME=`echo $TARGET|$AWK -F. '{print $(NF-1)}'`
|
||||
DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
|
||||
exit
|
||||
ssh_make_path $DST_HOST $DST_DIR
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copy files to the remote host
|
||||
#-------------------------------------------------------------------------------
|
||||
case $SRC in
|
||||
http://*)
|
||||
log "Downloading $SRC"
|
||||
RMT_CMD="$WGET -O $DST_PATH $SRC"
|
||||
ssh_exec_and_log "$DST_HOST" "$RMT_CMD" "Error downloading $SRC"
|
||||
;;
|
||||
|
||||
*)
|
||||
log "Cloning $SRC in $DST_PATH"
|
||||
exec_and_log "$SCP $SRC $DST" "Error copying $SRC to $DST"
|
||||
;;
|
||||
esac
|
59
src/tm_mad/iscsi/delete
Executable file
59
src/tm_mad/iscsi/delete
Executable file
@ -0,0 +1,59 @@
|
||||
#!/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 <host:remote_system_ds/disk.i|host:remote_system_ds/>
|
||||
# - host is the target host to deploy the VM
|
||||
# - remote_system_ds is the path for the system datastore in the host
|
||||
|
||||
DST=$1 # o202:/var/lib/one//datastores/0/0/disk.0
|
||||
|
||||
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
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# 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
|
||||
# Disk
|
||||
LOGOUT_CMD=$(cat <<EOF
|
||||
set -e
|
||||
IQN=\$(readlink $DST_PATH |grep -o 'iqn.*$')
|
||||
IQN=\${IQN%-lun-1}
|
||||
$SUDO $(iscsiadm_logout "\$IQN")
|
||||
EOF
|
||||
)
|
||||
ssh_exec_and_log "$DST_HOST" "$LOGOUT_CMD" \
|
||||
"Error logging out $IQN"
|
||||
else
|
||||
# Directory
|
||||
log "Deleting $DST_PATH"
|
||||
ssh_exec_and_log "$DST_HOST" "rm -rf $DST_PATH" "Error deleting $DST_PATH"
|
||||
fi
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$DISCOVER_CMD" \
|
||||
"Error registering $DST_HOST:$DEV"
|
||||
exit 0
|
80
src/tm_mad/iscsi/ln
Executable file
80
src/tm_mad/iscsi/ln
Executable file
@ -0,0 +1,80 @@
|
||||
#!/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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# clone fe:SOURCE host:remote_system_ds/disk.i size
|
||||
# - 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
|
||||
|
||||
SRC=$1 # iqn.2012-02.org.opennebula:o200.vg-one.lv-one-0
|
||||
DST=$2 # o202:/var/lib/one//datastores/0/0/disk.0
|
||||
|
||||
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
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
IQN=$SRC
|
||||
TARGET=`arg_path $SRC` # o200.vg-one.lv-one-0
|
||||
DST_PATH=`arg_path $DST` # /var/lib/one/datastores/0/0/disk.0
|
||||
DST_HOST=`arg_host $DST` # o202
|
||||
DST_DIR=`dirname $DST_PATH` # /var/lib/one/datastores/0/0
|
||||
|
||||
BASE_IQN=`echo $IQN|$CUT -d: -f1`
|
||||
TARGET=`echo $IQN|$CUT -d: -f2`
|
||||
LV_NAME=`echo $TARGET|$AWK -F. '{print $(NF)}'`
|
||||
VG_NAME=`echo $TARGET|$AWK -F. '{print $(NF-1)}'`
|
||||
TARGET_DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
TARGET_HOST=${TARGET%.$VG_NAME.$LV_NAME}
|
||||
|
||||
DISCOVER_CMD=$(cat <<EOF
|
||||
set -e
|
||||
mkdir -p $DST_DIR
|
||||
$SUDO $(iscsiadm_discovery "$TARGET_HOST")
|
||||
$SUDO $(iscsiadm_login "$IQN" "$TARGET_HOST")
|
||||
sleep 1
|
||||
DISK_BY_PATH=\$(ls /dev/disk/by-path/*$IQN-lun-1)
|
||||
ln -s "\$DISK_BY_PATH" "$DST_PATH"
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$DISCOVER_CMD" \
|
||||
"Error registering $DST_HOST:$DEV"
|
||||
exit 0
|
||||
|
||||
|
||||
# case $SRC in
|
||||
# http://*)
|
||||
# log "Downloading $SRC"
|
||||
# RMT_CMD="$WGET -O $DST_PATH $SRC"
|
||||
# ssh_exec_and_log "$DST_HOST" "$RMT_CMD" "Error downloading $SRC"
|
||||
# ;;
|
||||
|
||||
# *)
|
||||
# log "Cloning $SRC in $DST_PATH"
|
||||
# exec_and_log "$SCP $SRC $DST" "Error copying $SRC to $DST"
|
||||
# ;;
|
||||
# esac
|
74
src/tm_mad/iscsi/mv
Executable file
74
src/tm_mad/iscsi/mv
Executable file
@ -0,0 +1,74 @@
|
||||
#!/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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# MV <hostA:system_ds/disk.i|hostB:system_ds/disk.i>
|
||||
# <hostA:system_ds/|hostB:system_ds/>
|
||||
# - hostX is the target host to deploy the VM
|
||||
# - system_ds is the path for the system datastore in the host
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
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
|
||||
|
||||
# {:path=>
|
||||
# "/var/lib/one/remotes/tm/iscsi/mv o202:/var/lib/one//datastores/0/3/disk.0 rama:/var/lib/one/datastores/0/3/disk.0",
|
||||
# :result=>"SUCCESS",
|
||||
# :info=>"-"}
|
||||
|
||||
# {:path=>
|
||||
# "/var/lib/one/remotes/tm/shared/mv o202:/var/lib/one//datastores/0/3 rama:/var/lib/one/datastores/0/3",
|
||||
# :result=>"SUCCESS",
|
||||
# :info=>"-"}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Return if moving a disk, we will move them when moving the whole system_ds
|
||||
# directory for the VM
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
|
||||
if [ `is_disk $SRC_PATH` -eq 0 ]; then
|
||||
log "Removing directory"
|
||||
ssh_exec_and_log "$SRC_HOST" "rm -rf $SRC_PATH"
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$SRC" == "$DST" ]; then
|
||||
log "Not moving $SRC to $DST, they are the same path"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log "Logging out $IQN"
|
||||
|
||||
LOGOUT_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$SUDO $(iscsiadm_logout "$IQN")
|
||||
EOF
|
||||
)
|
||||
ssh_exec_and_log "$SRC_HOST" "$LOGOUT_CMD" \
|
||||
"Error logging out $IQN"
|
||||
|
||||
exit 0
|
50
src/tm_mad/iscsi/mvds
Executable file
50
src/tm_mad/iscsi/mvds
Executable file
@ -0,0 +1,50 @@
|
||||
#!/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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# mvds host:remote_system_ds/disk.i fe:SOURCE
|
||||
# - 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
|
||||
|
||||
SRC=$1 # o202:/var/lib/one//datastores/0/1/disk.0
|
||||
DST=$2 # iqn.2012-02.org.opennebula:o200.vg-one.lv-one-0
|
||||
|
||||
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
|
||||
|
||||
SRC_HOST=`arg_host $SRC` # o202
|
||||
IQN=$DST
|
||||
|
||||
log "Logging out $IQN"
|
||||
|
||||
LOGOUT_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$SUDO $(iscsiadm_logout "$IQN")
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "$LOGOUT_CMD" \
|
||||
"Error logging out $IQN"
|
||||
|
||||
exit 0
|
Loading…
x
Reference in New Issue
Block a user