diff --git a/Management-Utilities/Workload-Factory-API-Samples/volume_cifs_share_create b/Management-Utilities/Workload-Factory-API-Samples/volume_cifs_share_create new file mode 100755 index 0000000..6a72245 --- /dev/null +++ b/Management-Utilities/Workload-Factory-API-Samples/volume_cifs_share_create @@ -0,0 +1,128 @@ +#!/bin/bash +# +################################################################################ +# This script is used to create a cifs share in a volume in a FSx for ONTAP +# file system. It will assume that the path is /cifs_share_name and will give +# it full control permissions for everyone. +# +# It is dependent on the 'wf_utils' file that is included in this repo. That +# file contains the 'get_token' function that is used to obtain a valid +# access token that is needed to run the Workload Factory APIs. The file needs +# to either be in the command search path or in the current directory. +################################################################################ + +################################################################################ +# This function just prints the usage of this script and exits the program. +################################################################################ +usage() { + cat >&2 < + export BLUEXP_ACCOUNT_ID= + export CREDENTIALS_ID= + export AWS_REGION= +EOF + exit 1 +} + +################################################################################ +# Main logic starts here. +################################################################################ +tmpout=$(mktemp /tmp/create_share-out.XXXXXX) +tmperr=$(mktemp /tmp/create_share-err.XXXXXX) +trap 'rm -f $tmpout $tmperr' exit +# +# Source the wf_utils file. +wf_utils=$(command -v wf_utils) +if [ -z "$wf_utils" ]; then + if [ ! -x "./wf_utils" ]; then + cat >&2 < /dev/null; then + echo "Error: The required command '$cmd' was not found. Please install it." >&2 + exit 1 + fi +done + +token=$(get_token) +if [ -z "$token" ]; then + echo "Error: Failed to obtain an access token. Exiting." >&2 + exit 1 +fi +# +# Get the existing shares. +run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/volumes/${VOLUME_ID}?include=cifsShares" $tmpout $tmperr +cifsShares=$(jq -r '.cifsShares' $tmpout) +# +# Create a new share definition. +newShare='{"name":"'$CIFS_SHARE_NAME'","path":"'/$CIFS_SHARE_NAME'","acls":[{"userOrGroup":"Everyone","permission":"full_control","type":"windows"}]}' +# +# Add the new share to the existing ones. +cifsShares=$(echo "$cifsShares" | jq -r '. += ['$newShare']') +cifsShares="{\"cifsShares\": $cifsShares}" +run_curl PATCH "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/volumes/${VOLUME_ID}" $tmpout $tmperr "$cifsShares" diff --git a/Management-Utilities/Workload-Factory-API-Samples/wf_utils b/Management-Utilities/Workload-Factory-API-Samples/wf_utils index c4de022..b477375 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/wf_utils +++ b/Management-Utilities/Workload-Factory-API-Samples/wf_utils @@ -129,7 +129,7 @@ run_curl () { -H "Authorization: Bearer $token" -o $output > $errorOutput exitCode=$? ;; - POST|PUT) + POST|PUT|PATCH) curl -X "$method" -sw "%{http_code},%{errormsg}" "$url" \ -H "Accept: $accept" "${extraHeaders[@]}" \ -H "Content-Type:application/json" \