-
Notifications
You must be signed in to change notification settings - Fork 7
Added volume_cifs_share_create #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kcantrel
wants to merge
5
commits into
main
Choose a base branch
from
add_create_cifs_share
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e49930a
Added volume_cifs_share_create
kcantrel 66beab2
Merge branch 'main' into add_create_cifs_share
kcantrel d3c9ec8
Merge branch 'main' into add_create_cifs_share
kcantrel e96010e
Merge branch 'main' into add_create_cifs_share
kcantrel 395f459
Fixes some typos in some messages.
kcantrel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
Management-Utilities/Workload-Factory-API-Samples/volume_cifs_share_create
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| #!/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 <<EOF | ||
| 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. | ||
|
|
||
| Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_ID -r aws_region -f filesystem_ID -v volume_ID -s cifs_share_name | ||
|
|
||
| Where: refresh_token - Is a refresh token used to obtain an access token needed | ||
| to run the Workload Factory APIs. You can obtain a refresh | ||
| token by going to https://services.cloud.netapp.com/refresh-token | ||
| blueXP_account_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a | ||
| list of accounts you have access to | ||
| credentials_ID - is the Workload Factory credentials ID for the AWS account. Run | ||
| 'list_credentials' to get a list of credentials you have access to | ||
| aws_region - is the AWS region where the FSx file systems are located | ||
| filesystem_id - is the AWS file system ID of the FSx file system where the volume resides | ||
| volume_ID - is the AWS volume ID of the volume where you want to create the cifs share. | ||
| cifs_share_name - is the name of the share to create. Only alphanumeric characters, underscores and dashes are allowed. | ||
|
|
||
| Instead of passing parameters on the command line, you can set the | ||
| following environment variables: | ||
|
|
||
| export REFRESH_TOKEN=<refresh_token> | ||
| export BLUEXP_ACCOUNT_ID=<blueXP_account_ID> | ||
| export CREDENTIALS_ID=<credentials_ID> | ||
| export AWS_REGION=<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 <<EOF | ||
| Error: The 'wf_utils' script was not found in the current directory or in the command search path. | ||
| It is required to run this script. You can download it from: | ||
| https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples | ||
| EOF | ||
| exit 1 | ||
| else | ||
| wf_utils=./wf_utils | ||
| fi | ||
| fi | ||
| . "$wf_utils" | ||
| # | ||
| # Process command line options. | ||
| while getopts "ht:a:c:r:f:v:s:" opt; do | ||
| case $opt in | ||
| t) REFRESH_TOKEN="$OPTARG" ;; | ||
| a) BLUEXP_ACCOUNT_ID="$OPTARG" ;; | ||
| c) CREDENTIALS_ID="$OPTARG" ;; | ||
| r) AWS_REGION="$OPTARG" ;; | ||
| f) FILESYSTEM_ID="$OPTARG" ;; | ||
| v) VOLUME_ID="$OPTARG" ;; | ||
| s) CIFS_SHARE_NAME="$OPTARG" ;; | ||
| *) usage ;; | ||
| esac | ||
| done | ||
| # | ||
| # Declare an array of required options and the error message to display if they are not set. | ||
| declare -A required_options | ||
| required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh token is required to run this script. It can be obtain from this web page: | ||
| https://services.cloud.netapp.com/refresh-token\n\n' | ||
| required_options["BLUEXP_ACCOUNT_ID"]='Error: A BlueXP account ID is required to run this script. | ||
| You can get the list of accounts you have access to by running the "list_bluexp_accts" script | ||
| found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n' | ||
| required_options["CREDENTIALS_ID"]='Error: A Worload Factory Credential ID is required to run this script. | ||
| You can get a list of credentials by running the "list_credentials" script | ||
| found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n' | ||
| required_options["AWS_REGION"]='Error: The AWS region where the file system is located is required.\n\n' | ||
| required_options["FILESYSTEM_ID"]='Error: The ID of the FSxN file system is required.\n\n' | ||
| required_options["VOLUME_ID"]='Error: An AWS Volume ID is required to run this script. | ||
| You can get the list of file systems you have access to by running the "list_volumes" script | ||
| found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n' | ||
| required_options["CIFS_SHARE_NAME"]='Error: The name of the cifs share is required.\n\n' | ||
|
|
||
| check_required_options | ||
| # | ||
| # Check if the required commands are available. | ||
| for cmd in jq curl; do | ||
| if ! command -v $cmd &> /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. | ||
| # Check that the CIFS_SHARE_NAME only contains allowed characters (alphanumeric, underscores and dashes). | ||
| if [[ ! "$CIFS_SHARE_NAME" =~ ^[a-zA-Z0-9_-]+$ ]]; then | ||
| echo "Error: The CIFS share name can only contain alphanumeric characters, underscores and dashes." >&2 | ||
| exit 1 | ||
| fi | ||
| 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" | ||
kcantrel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.