forked from TrueCloudLab/frostfs-node
[#1916] cli/control: Pre-check maintenance mode in set-status
Node's maintenance state can be set only if the network allows it. Make `neofs-cli control set-status` to read current network settings and check is maintenance state is allowed. Fail the execution if the mode is not allowed. Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
This commit is contained in:
parent
e1be0180f6
commit
c50603494b
1 changed files with 29 additions and 0 deletions
|
@ -4,10 +4,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
||||||
|
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
||||||
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -54,6 +57,32 @@ func setNetmapStatus(cmd *cobra.Command, _ []string) {
|
||||||
status = control.NetmapStatus_OFFLINE
|
status = control.NetmapStatus_OFFLINE
|
||||||
case netmapStatusMaintenance:
|
case netmapStatusMaintenance:
|
||||||
status = control.NetmapStatus_MAINTENANCE
|
status = control.NetmapStatus_MAINTENANCE
|
||||||
|
|
||||||
|
common.PrintVerbose("Reading network settings to check allowance of \"%s\" mode...", st)
|
||||||
|
|
||||||
|
if !viper.IsSet(commonflags.RPC) {
|
||||||
|
common.ExitOnErr(cmd, "",
|
||||||
|
fmt.Errorf("flag --%s (-%s) is not set, you must specify it for \"%s\" mode",
|
||||||
|
commonflags.RPC,
|
||||||
|
commonflags.RPCShorthand,
|
||||||
|
st,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
|
||||||
|
|
||||||
|
var prm internalclient.NetworkInfoPrm
|
||||||
|
prm.SetClient(cli)
|
||||||
|
|
||||||
|
res, err := internalclient.NetworkInfo(prm)
|
||||||
|
common.ExitOnErr(cmd, "receive network info: %v", err)
|
||||||
|
|
||||||
|
if !res.NetworkInfo().MaintenanceModeAllowed() {
|
||||||
|
common.ExitOnErr(cmd, "", fmt.Errorf("\"%s\" mode is not allowed by the network", st))
|
||||||
|
}
|
||||||
|
|
||||||
|
common.PrintVerbose("\"%s\" mode is allowed, continue processing...", st)
|
||||||
}
|
}
|
||||||
|
|
||||||
body := new(control.SetNetmapStatusRequest_Body)
|
body := new(control.SetNetmapStatusRequest_Body)
|
||||||
|
|
Loading…
Reference in a new issue