-
Notifications
You must be signed in to change notification settings - Fork 7
Add more wf scripts #281
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
Merged
Merged
Add more wf scripts #281
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
48999e1
Added scripts that will add and remove members from a BlueXP organiza…
kcantrel 333a2f5
Fixed a bug where if someone provided a different refresh token and t…
kcantrel 08d9400
Added an option to provide a different endpoint for the API and provi…
kcantrel cfa16a7
Added an option to provide a different endpoint for the API and provi…
kcantrel 6918379
Updated it to use the publised API.
kcantrel 56f0ff1
Corrected the logic for the required parameters.
kcantrel 45b26cd
Added an option to provide a different endpoint for the API and provi…
kcantrel 8b3625b
Updated the calculation of days left.
kcantrel b959df1
Added an option to provide a different endpoint for the API and provi…
kcantrel c385b86
Fixed a typo in the usage statement.
kcantrel 0826064
Effectively renamed to list_bluexp_organization_members
kcantrel d131658
Added an option to provide a different endpoint for the API and provi…
kcantrel a1d7767
Added a message if no latency events were found.
kcantrel 7736565
Made it where the -j option would at least 'pretty print' the json ou…
kcantrel 6bba284
Added new scripts.
kcantrel de82d12
Updated for the new programs
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
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
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
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
108 changes: 108 additions & 0 deletions
108
Management-Utilities/Workload-Factory-API-Samples/bluexp_organization_member_add
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,108 @@ | ||
| #!/bin/bash | ||
| # | ||
| # This script adds a user to an BlueXP organization. | ||
| # | ||
| ################################################################################ | ||
| # Display usage information then exits the script. | ||
| ################################################################################ | ||
| usage () { | ||
| cat 1>&2 <<EOF | ||
| This script adds a user to an BlueXP organization. | ||
|
|
||
| Usage: $(basename $0) -t REFRESH_TOKEN -o ORGANIZATION_ID -r ROLE_ID -E email_address [-e ENDPOINT] [-b BEARER_TOKEN] | ||
|
|
||
| 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 | ||
| ORGANIZATION_ID - Is the ID of the organization to add the user to. You can get | ||
| a list of organizations by running the list_bluexp_acct script. | ||
| ROLE_ID - Is the ID of the role to assign to the user. You can get a list of | ||
| roles by running the list_bluexp_roles script. | ||
| email_address - Is the email address of the user to add to the organization. | ||
| ENDPOINT - Is the BlueXP API endpoint to use. The default is api.bluexp.netapp.com. | ||
| BEARER_TOKEN - Is an access token that can be used instead of a refresh token. If you | ||
| provide a bearer token, the script will not attempt to obtain a new | ||
| access token using the refresh token. | ||
|
|
||
| Instead of passing parameters on the command line, you can set the following | ||
| environment variables: | ||
|
|
||
| export REFRESH_TOKEN=<REFRESH_TOKEN> | ||
| ORGANIZATION_ID=<ORGANIZATION_ID> | ||
| EOF | ||
| exit 1 | ||
| } | ||
|
|
||
| ################################################################################ | ||
| # Main logic starts here. | ||
| ################################################################################ | ||
| tmpout=$(mktemp /tmp/add_organization_to_bluexp-out.XXXXXX) | ||
| tmperr=$(mktemp /tmp/add_organization_to_bluexp-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" | ||
| # | ||
| # Parse the command line options. | ||
| : "${ENDPOINT:=api.bluexp.netapp.com}" | ||
| while getopts "ht:o:e:b:r:E:" opt; do | ||
| case ${opt} in | ||
| t) REFRESH_TOKEN=$OPTARG ;; | ||
| o) ORGANIZATION_ID=$OPTARG ;; | ||
| r) ROLE_ID=$OPTARG ;; | ||
| E) emailAddress=$OPTARG ;; | ||
| e) ENDPOINT="$OPTARG" ;; | ||
| b) BEARER_TOKEN="$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["ORGANIZATION_ID"]='Error: You must provide the ID of the organization you want to add the user to.\n\n' | ||
| required_options["ROLE_ID"]='Error: You must provide the ID of the role you want to assign to the user.\n\n' | ||
| required_options["emailAddress"]='Error: You must provide the email address of the user you want to add.\n\n' | ||
|
|
||
| check_required_options | ||
|
|
||
| if [ -z "$REFRESH_TOKEN" -a -z "$BEATER_TOKEN" ]; then | ||
| echo "Error: You must provide either a refresh token or a bearer token." >&2 | ||
| usage | ||
| fi | ||
|
kcantrel marked this conversation as resolved.
Outdated
|
||
| # | ||
| # Check that 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 | ||
| # | ||
| # Get an access token. | ||
| if [ -z "$BEARER_TOKEN" ]; then | ||
| token=$(get_token) | ||
| else | ||
| token=$BEARER_TOKEN | ||
| fi | ||
|
|
||
| if [ -z "$token" ]; then | ||
| echo "Failed to get a token." | ||
| exit 1 | ||
| fi | ||
| # | ||
| # This uses the same API that the console uses. | ||
| run_curl "POST" "$token" "https://$ENDPOINT/v1/management/organizations/$ORGANIZATION_ID/roles/$ROLE_ID/users" $tmpout $tmperr '{"type":"application/vnd.netapp.bxp.userbulk","users":[{"emailId": "'$emailAddress'"}], "version":"1.0"}' 'application/json' | ||
| echo "Done." | ||
Oops, something went wrong.
Oops, something went wrong.
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.