from typing import Optional from frostfs_testlib.cli.cli_command import CliCommand from frostfs_testlib.shell import CommandResult class FrostfsCliShards(CliCommand): def flush_cache( self, endpoint: str, wallet: str, wallet_password: str, id: Optional[list[str]], address: Optional[str] = None, all: bool = False, timeout: Optional[str] = None, ) -> CommandResult: """ Flush objects from the write-cache to the main storage. Args: address: Address of wallet account. id: List of shard IDs in base58 encoding. all: Process all shards. endpoint: Remote node address (as 'multiaddr' or ':'). wallet: WIF (NEP-2) string or path to the wallet or binary key. wallet_password: Wallet password. timeout: Timeout for an operation (default 15s). Returns: Command's result. """ return self._execute_with_password( f"control shards flush-cache", wallet_password, **{param: value for param, value in locals().items() if param not in ["self"]}, ) def set_mode( self, endpoint: str, mode: str, id: Optional[list[str]] = None, wallet: Optional[str] = None, wallet_password: Optional[str] = None, address: Optional[str] = None, all: bool = False, clear_errors: bool = False, timeout: Optional[str] = None, ) -> CommandResult: """ Set work mode of the shard. Args: address: Address of wallet account. id: List of shard IDs in base58 encoding. mode: New shard mode ('degraded-read-only', 'read-only', 'read-write'). all: Process all shards. clear_errors: Set shard error count to 0. endpoint: Remote node address (as 'multiaddr' or ':'). wallet: WIF (NEP-2) string or path to the wallet or binary key. wallet_password: Wallet password. timeout: Timeout for an operation (default 15s). Returns: Command's result. """ if not wallet_password: return self._execute( "control shards set-mode", **{param: value for param, value in locals().items() if param not in ["self"]}, ) return self._execute_with_password( "control shards set-mode", wallet_password, **{param: value for param, value in locals().items() if param not in ["self", "wallet_password"]}, ) def dump( self, endpoint: str, wallet: str, wallet_password: str, id: str, path: str, address: Optional[str] = None, no_errors: bool = False, timeout: Optional[str] = None, ) -> CommandResult: """ Dump objects from shard to a file. Args: address: Address of wallet account. no_errors: Skip invalid/unreadable objects. id: Shard ID in base58 encoding. path: File to write objects to. endpoint: Remote node address (as 'multiaddr' or ':'). wallet: WIF (NEP-2) string or path to the wallet or binary key. wallet_password: Wallet password. timeout: Timeout for an operation (default 15s). Returns: Command's result. """ return self._execute_with_password( "control shards dump", wallet_password, **{param: value for param, value in locals().items() if param not in ["self", "wallet_password"]}, ) def list( self, endpoint: str, wallet: Optional[str] = None, wallet_password: Optional[str] = None, address: Optional[str] = None, json_mode: bool = False, timeout: Optional[str] = None, ) -> CommandResult: """ List shards of the storage node. Args: address: Address of wallet account. json_mode: Print shard info as a JSON array. endpoint: Remote node address (as 'multiaddr' or ':'). wallet: WIF (NEP-2) string or path to the wallet or binary key. wallet_password: Wallet password. timeout: Timeout for an operation (default 15s). Returns: Command's result. """ if not wallet_password: return self._execute( "control shards list", **{param: value for param, value in locals().items() if param not in ["self"]}, ) return self._execute_with_password( "control shards list", wallet_password, **{param: value for param, value in locals().items() if param not in ["self", "wallet_password"]}, ) def evacuation_start( self, endpoint: str, id: Optional[str] = None, scope: Optional[str] = None, all: bool = False, no_errors: bool = True, await_mode: bool = False, address: Optional[str] = None, timeout: Optional[str] = None, no_progress: bool = False, ) -> CommandResult: """ Objects evacuation from shard to other shards. Args: address: Address of wallet account all: Process all shards await: Block execution until evacuation is completed endpoint: Remote node control address (as 'multiaddr' or ':') id: List of shard IDs in base58 encoding no_errors: Skip invalid/unreadable objects (default true) no_progress: Print progress if await provided scope: Evacuation scope; possible values: trees, objects, all (default "all") timeout: Timeout for an operation (default 15s) Returns: Command's result. """ return self._execute( "control shards evacuation start", **{param: value for param, value in locals().items() if param not in ["self"]}, ) def evacuation_reset( self, endpoint: str, address: Optional[str] = None, timeout: Optional[str] = None, ) -> CommandResult: """ Reset evacuate objects from shard to other shards status. Args: address: Address of wallet account endpoint: Remote node control address (as 'multiaddr' or ':') timeout: Timeout for an operation (default 15s) Returns: Command's result. """ return self._execute( "control shards evacuation reset", **{param: value for param, value in locals().items() if param not in ["self"]}, ) def evacuation_stop( self, endpoint: str, address: Optional[str] = None, timeout: Optional[str] = None, ) -> CommandResult: """ Stop running evacuate process from shard to other shards. Args: address: Address of wallet account endpoint: Remote node control address (as 'multiaddr' or ':') timeout: Timeout for an operation (default 15s) Returns: Command's result. """ return self._execute( "control shards evacuation stop", **{param: value for param, value in locals().items() if param not in ["self"]}, ) def evacuation_status( self, endpoint: str, address: Optional[str] = None, timeout: Optional[str] = None, ) -> CommandResult: """ Get evacuate objects from shard to other shards status. Args: address: Address of wallet account endpoint: Remote node control address (as 'multiaddr' or ':') timeout: Timeout for an operation (default 15s) Returns: Command's result. """ return self._execute( "control shards evacuation status", **{param: value for param, value in locals().items() if param not in ["self"]}, ) def detach(self, endpoint: str, address: Optional[str] = None, id: Optional[str] = None, timeout: Optional[str] = None): """ Detach and close the shards Args: address: Address of wallet account endpoint: Remote node control address (as 'multiaddr' or ':') id: List of shard IDs in base58 encoding timeout: Timeout for an operation (default 15s) Returns: Command's result. """ return self._execute( "control shards detach", **{param: value for param, value in locals().items() if param not in ["self"]}, )