Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/recipes/examples/scripts/check_config_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# Usage: ./check_config_status.sh

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Usage: ./check_config_status.sh
# Usage: ./check_copy_status.sh
# The status indicates the status of current copy operation.
# none(0) means no copy operation.
# success(1) means copy operation is successful.
# inProgress(2) means current copy operation is in progress.
# errOtherInProcessing(3) means copy operation is failed due to other in processing.
# errNoSuchFile(4) means copy operation is failed due to file not existing.
# errSameSrcDst(5) means copy operation is failed due to the source and destination are the same.
# errPermissionDenied(6) means copy operation is failed due to the destination is not permitted to modify.
# errLoadSrc(7) means copy operation is failed due to the error to load source file.
# errSaveDst(8) means copy operation is failed due to the error to save or commit destination."

Copy link
Copy Markdown
Collaborator

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.


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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify a little with post -d to just inline the request so we don't have to generate (or overwrite) request.jsonl.
If the id isn't important, one will be filled in by gs-rpc if omitted.
Could also simplify to:
gs-rpc call icfg.status.copy.get


gs-rpc post -f $fname
21 changes: 21 additions & 0 deletions docs/recipes/examples/scripts/get_running_config.sh
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# just the filename (file must be in the tftp dir
# just the filename (file must be in the top tftp dir)

CONFIG=$(basename "$2")

# Output file name

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"
gr-rpc post -d '{ "method": "icfg.control.copy.set", "params": [{ "Copy": true, "SourceConfigType": "runningConfig", "SourceConfigFile": "", "DestinationConfigType": "configFile", "DestinationConfigFile": "tftp://'"$TFTP_SERVER_IP"'/'"$CONFIG"'", "Merge": false }], "id": 1 }'

gs-rpc post -f $fname

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gs-rpc post -f $fname

82 changes: 82 additions & 0 deletions docs/recipes/examples/scripts/port_power.sh
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>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Usage: ./make_port_file.sh <port_number 1-29> <power_mode 0|1>
# Usage: ./set_port_power.sh <port_number 1-29> <power_mode 0|1>
# For specified port, 0 powers off port and 1 turns it back on.


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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Shutdown true if power_mode=1, false if 0
# Shutdown false if power_mode=1, true if 0

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:"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "If you really want to turn of the management port, type:"
echo "If you really want to alter the management port, type:"

echo " gs-rpc post -f $fname"
else
gs-rpc post -f $fname
fi
19 changes: 19 additions & 0 deletions docs/recipes/examples/scripts/set_running_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Usage: ./set_running_config <tftp_server_ip> <config>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Usage: ./set_running_config <tftp_server_ip> <config>
# Usage: ./set_running_config <tftp_server_ip> <config>
# Update running-config by copying <config> file from tftp server.


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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"
gs-rpc post -d '{ "method": "icfg.control.copy.set", "params": [{ "Copy": true, "DestinationConfigType": "runningConfig", "DestinationConfigFile": "", "SourceConfigType": "configFile", "SourceConfigFile": "tftp://'"$TFTP_SERVER_IP"'/'"$CONFIG"'", "Merge": false }], "id": 1 }'

gs-rpc post -f $fname

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gs-rpc post -f $fname