-
Notifications
You must be signed in to change notification settings - Fork 2
feat(scripts): created convenience shell scripts #4
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/bash | ||
| # Usage: ./check_config_status.sh | ||
|
|
||
| if [[ $# -ne 0 ]]; then | ||
| echo "Usage: $0" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Output file name | ||
| fname="request.jsonl" | ||
|
|
||
| echo '{ "method": "icfg.status.copy.get", "params": [], "id": 99 }' > "$fname" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can simplify a little with |
||
|
|
||
| gs-rpc post -f $fname | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||
| #!/bin/bash | ||||||
| # Usage: ./get_running_config <tftp_server_ip> <config> | ||||||
|
|
||||||
| if [[ $# -ne 2 ]]; then | ||||||
| echo "Usage: $0 <tftp_server_ip> <config>" | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| # Create JSON | ||||||
| TFTP_SERVER_IP=$1 | ||||||
|
|
||||||
| # strip leading "/" from CONFIG if present | ||||||
| # CONFIG=${2#/} | ||||||
| # just the filename (file must be in the tftp dir | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| CONFIG=$(basename "$2") | ||||||
|
|
||||||
| # Output file name | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't need to create a file artifact. |
||||||
| fname="request.jsonl" | ||||||
|
|
||||||
| echo '{ "method": "icfg.control.copy.set", "params": [{ "Copy": true, "SourceConfigType": "runningConfig", "SourceConfigFile": "", "DestinationConfigType": "configFile", "DestinationConfigFile": "tftp://'"$TFTP_SERVER_IP"'/'"$CONFIG"'", "Merge": false }], "id": 1 }' > "$fname" | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| gs-rpc post -f $fname | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||||
| #!/bin/bash | ||||||||
| # Usage: ./make_port_file.sh <port_number 1-29> <power_mode 0|1> | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| MANAGEMENT_PORT=29 | ||||||||
|
|
||||||||
| if [[ $# -ne 2 ]]; then | ||||||||
| echo "Usage: $0 <port_number 1-29> <power_mode 0|1>" | ||||||||
| exit 1 | ||||||||
| fi | ||||||||
|
|
||||||||
| port_num=$1 | ||||||||
| power_mode=$2 | ||||||||
|
|
||||||||
| # Validate input | ||||||||
| if ! [[ "$port_num" =~ ^[0-9]+$ ]] || (( port_num < 1 || port_num > 29 )); then | ||||||||
| echo "Error: port number must be between 1 and 29" | ||||||||
| exit 1 | ||||||||
| fi | ||||||||
|
|
||||||||
| if [[ "$power_mode" != "0" && "$power_mode" != "1" ]]; then | ||||||||
| echo "Error: power mode must be 0 or 1" | ||||||||
| exit 1 | ||||||||
| fi | ||||||||
|
|
||||||||
| # List of ports | ||||||||
| ports=( | ||||||||
| "Gi 1/1" | ||||||||
| "Gi 1/2" | ||||||||
| "Gi 1/3" | ||||||||
| "Gi 1/4" | ||||||||
| "Gi 1/5" | ||||||||
| "Gi 1/6" | ||||||||
| "Gi 1/7" | ||||||||
| "Gi 1/8" | ||||||||
| "Gi 1/9" | ||||||||
| "Gi 1/10" | ||||||||
| "Gi 1/11" | ||||||||
| "Gi 1/12" | ||||||||
| "Gi 1/13" | ||||||||
| "Gi 1/14" | ||||||||
| "Gi 1/15" | ||||||||
| "Gi 1/16" | ||||||||
| "Gi 1/17" | ||||||||
| "Gi 1/18" | ||||||||
| "Gi 1/19" | ||||||||
| "Gi 1/20" | ||||||||
| "Gi 1/21" | ||||||||
| "Gi 1/22" | ||||||||
| "Gi 1/23" | ||||||||
| "Gi 1/24" | ||||||||
| "10G 1/1" | ||||||||
| "10G 1/2" | ||||||||
| "10G 1/3" | ||||||||
| "10G 1/4" | ||||||||
| "Gi 1/25" | ||||||||
| ) | ||||||||
|
|
||||||||
| # Pick correct port (subtract 1 because arrays are 0-based) | ||||||||
| port_name="${ports[$((port_num-1))]}" | ||||||||
|
|
||||||||
| # Output file name | ||||||||
| fname="request.jsonl" | ||||||||
|
|
||||||||
| # Shutdown true if power_mode=1, false if 0 | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| if [[ "$power_mode" == "1" ]]; then | ||||||||
| shutdown="false" | ||||||||
| else | ||||||||
| shutdown="true" | ||||||||
| fi | ||||||||
|
|
||||||||
| # Create JSON | ||||||||
| jq -n --arg port "$port_name" --argjson shutdown "$shutdown" \ | ||||||||
| '{method:"port.config.set", params:[$port, {Shutdown:$shutdown}], id:1}' \ | ||||||||
| > "$fname" | ||||||||
|
|
||||||||
| if [[ "$port_num" == $MANAGEMENT_PORT ]]; then | ||||||||
| echo "Warning, do not modify the management port power mode" | ||||||||
| echo "If you really want to turn of the management port, type:" | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| echo " gs-rpc post -f $fname" | ||||||||
| else | ||||||||
| gs-rpc post -f $fname | ||||||||
| fi | ||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,19 @@ | ||||||||
| #!/bin/bash | ||||||||
| # Usage: ./set_running_config <tftp_server_ip> <config> | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| if [[ $# -ne 2 ]]; then | ||||||||
| echo "Usage: $0 <tftp_server_ip> <config>" | ||||||||
| exit 1 | ||||||||
| fi | ||||||||
|
|
||||||||
| # Create JSON | ||||||||
| TFTP_SERVER_IP=$1 | ||||||||
|
|
||||||||
| # just the filename (file must be in the tftp dir) | ||||||||
| CONFIG=$(basename "$2") | ||||||||
|
|
||||||||
| # Output file name | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can remove saving to output file. |
||||||||
| fname="request.jsonl" | ||||||||
|
|
||||||||
| echo '{ "method": "icfg.control.copy.set", "params": [{ "Copy": true, "DestinationConfigType": "runningConfig", "DestinationConfigFile": "", "SourceConfigType": "configFile", "SourceConfigFile": "tftp://'"$TFTP_SERVER_IP"'/'"$CONFIG"'", "Merge": false }], "id": 1 }' > "$fname" | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| gs-rpc post -f $fname | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ This is just inlined from the json-rpc spec comments.