# File transport plugin for vcbMounter/vcbRestore
# This is a dummy plugin for handling backing up to/restoring from
# local files, hence no additional transfer step is required.
# Comments in this file describe what the various plugin
# functions are supposed to do. Use this to write your own
# transport plugin.
#
# (C) 2005 VMware, Inc. All rights reserved.function 



#
# Descrption:
# Get operations for plugins are supposed to make data available
# for vcbRestore in a local directory.
#
# Arguments:
# $1: Path to retrieve the data from (must only make sense to
#     the plugin itself.
# $2: "fullvm" when an entire VM is restored; "disk", if just
#     a virtual disk image is restored.
#
# Result:
# Returns 0 on success != 0 on failure. On success, it also
# writes the name of a local directory to which the file set
# has been transferred to stdout.
#
function file_get
{
    echo "$1"
    return 0
}



#
# Description:
# Must undo the operation performed by the get operation. (i.e:
# unmount file systems or delete a local copy.
#
# Arguments:
# $1: The path the data has been retrieved from (i.e: the
#     argument to get_done is the resulting local path as returned
#     by the get function
#
# Results:
# None. 
#
function file_get_done
{
    return 0
}



#
# Description:
# Provides a local directory point to which data can be exported to.
# This can either be a mount point onto which "put" has mounted a
# remote directory or some temporary local directory.
# Please note that the directory itself must not exist, since 
# "vcbMounter" will create it. (i.e: In foo://mountpoint/vmname,
# make sure that "mountpoint" is present, but not "vmname").
#
# Arguments:
# $1: Destination path. Must only make sense to the plugin itself.
#
# Results:
# Returns 0 on success != 0 on failure. On success, it prints the name
# of a local directory to stdout to which the files should be exported.
#
function file_put
{
    echo "$1"
    return 0
}



#
# Description:
# Undoes the "put" operation: This will unmount any file systems that
# "put" might have mounted, or if "put" just specified a temporary
# directory, this will take care of moving the files to their final
# destination and of removing the local directory.
#
# Arguments
# $1: The path argument returned by the corresponding "put" call
# $2: Destination path (i.e: the argument with which the corresponding
#     "put" command was called).
# $3: 0 if the export operation was successful.
#
# Results
# Returns 0 on success != 0 on failure. 
#
function file_put_done
{
    return 0
}



#
# Description:
# Lists all subdirectories that potentially contain virtual machine
# backups found in a given directory. Prints all the directories that
# are candidates for virtual machine backups to stdout.
#
# Arguments
# $1: Directory containing virtual machine backups
#
# Results
# Returns 0 if a list of directories could be retrieved (list could be
# empty, tho..). 1 If there was a problem retrieving the list, 2 if
# the operation is not supported by a transport plugin.
#
function file_listvms
{
    local sourcedir="$1"

    find "${sourcedir}" -type d -mindepth 1 -maxdepth 1 | sed s@.\*/@@g
    rv=$?
    if [ $rv != 0 ] ; then
	return 1
    fi
    return 0
}
