Skip to content

Commit

Permalink
Set SRD ratio tools (#121)
Browse files Browse the repository at this point in the history
* set srd ratio

* fix error

* fix error
  • Loading branch information
LowEntropyBody authored Feb 1, 2021
1 parent 19bfef4 commit dcc0e81
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
39 changes: 38 additions & 1 deletion scripts/crust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,8 @@ Crust tools usage:
workload show workload information
file-info {cid} show all files information or one file details
upgrade-image {chain|api|smanager|ipfs|c-gen|sworker} upgrade one docker image
change-srd {number} change sworker's srd capacity(GB), for example: 'crust tools change-srd 100', 'crust tools change-srd -50'
set-srd-ratio {ratio} set SRD raito, default is 70%, range is 0% - 95%, for example 'set-srd-ratio 75'
change-srd {number} change sworker's srd capacity(GB), for example: 'change-srd 100', 'change-srd -50'
ipfs {...} ipfs command, for example 'ipfs pin ls', 'ipfs swarm peers'
EOF
}
Expand Down Expand Up @@ -839,6 +840,39 @@ change_srd()
curl -XPOST ''$base_url'/srd/change' -H 'backup: '$backup'' --data-raw '{"change" : '$1'}'
}

set_srd_ratio()
{
if [ x"$1" == x"" ] || [[ ! $1 =~ ^[1-9][0-9]*$|^[-][1-9][0-9]*$|^0$ ]]; then
log_err "The input of set srd ratio must be integer number"
tools_help
return 1
fi

if [ $1 -lt 0 ] || [ $1 -gt 95 ]; then
log_err "The range of set srd ratio is 0 ~ 95"
tools_help
return 1
fi

local a_or_b=`cat $basedir/etc/sWorker.ab`
check_docker_status crust-sworker-$a_or_b
if [ $? -ne 0 ]; then
log_info "Service crust sworker is not started or exited now"
return 0
fi

if [ ! -f "$builddir/sworker/sworker_config.json" ]; then
log_err "No sworker configuration file"
return 1
fi

local base_url=`cat $builddir/sworker/sworker_config.json | jq .base_url`
base_url=${base_url%?}
base_url=${base_url:1}

curl -XPOST ''$base_url'/srd/ratio' -H 'backup: '$backup'' --data-raw '{"ratio" : '$1'}'
}

workload()
{
local a_or_b=`cat $basedir/etc/sWorker.ab`
Expand Down Expand Up @@ -931,6 +965,9 @@ tools()
change-srd)
change_srd $2
;;
set-srd-ratio)
set_srd_ratio $2
;;
rotate-keys)
rotate_keys
;;
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function log_success()

function log_err()
{
echo_c 35 "$1"
echo_c 35 "ERROR: $1"
}

function upgrade_docker_image()
Expand Down

0 comments on commit dcc0e81

Please sign in to comment.