Rebrand project to PiSCSI (#1016)

* Rebrand project to PiSCSI
- rascsi ->piscsi
- rasctl -> scsictl
- rasdump -> scsidump
- ras* -> piscsi* (rasutil -> piscsi_util, etc.)

* Refined the formatting and wording of the app startup banner
* Kept some references to rascsi and rasctl where backwards compatibility is concerned
* Point to the new github repo URL

Co-authored-by: nucleogenic <nr@nucleogenic.com>
Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
This commit is contained in:
Daniel Markstedt
2022-12-05 09:58:23 -08:00
committed by GitHub
parent 12068cafb8
commit 52c2aa474f
274 changed files with 2341 additions and 2380 deletions
+8 -8
View File
@@ -1,13 +1,13 @@
# RaSCSI Common Python Module
# PiSCSI Common Python Module
The common module contains python modules that are shared among multiple Python
applications such as the OLED or the Web application. It contains shared functionality.
For example, the rascsi python module provides functionality for accessing rascsi through its
For example, the piscsi python module provides functionality for accessing piscsi through its
protobuf interface and provides convenient classes for that purpose.
### Usage
To make use of the rascsi python module, it needs to be found by the Python scripts using it.
To make use of the piscsi python module, it needs to be found by the Python scripts using it.
This can be achieved in multiple ways. One way is to simply adapt the PYTHONPATH environment
variable to include the common/src directory:
@@ -17,14 +17,14 @@ export PYTHONPATH=$PWD:${PYTHON_COMMON_PATH}
python3 myapp.py
```
The most interesting functions are likely found in the classes RaCtlCmds and FileCmds. Classes
The most interesting functions are likely found in the classes PiscsiCmds and FileCmds. Classes
can be instantiated, for example, as follows
(assuming that rascsi host, rascsi port and token are somehow retrieved from a command line
(assuming that piscsi host, piscsi port and token are somehow retrieved from a command line
argument):
```
sock_cmd = SocketCmds(host=args.rascsi_host, port=args.rascsi_port)
ractl_cmd = RaCtlCmds(sock_cmd=sock_cmd, token=args.token)
sock_cmd = SocketCmds(host=args.piscsi_host, port=args.piscsi_port)
piscsi_cmd = PiscsiCmds(sock_cmd=sock_cmd, token=args.token)
```
Usage examples can be found in the existing RaSCSI Python applications.
Usage examples can be found in the existing PiSCSI Python applications.
@@ -1,12 +1,12 @@
"""
Module for general settings used in the rascsi module
Module for general settings used in the piscsi module
"""
from os import getcwd
# There may be a more elegant way to get the HOME dir of the user that installed RaSCSI
# There may be a more elegant way to get the HOME dir of the user that installed PiSCSI
HOME_DIR = "/".join(getcwd().split("/")[0:3])
CFG_DIR = f"{HOME_DIR}/.config/rascsi"
CFG_DIR = f"{HOME_DIR}/.config/piscsi"
CONFIG_FILE_SUFFIX = "json"
# File ending used for drive properties files
@@ -1,10 +1,10 @@
"""
Module for custom exceptions raised by the rascsi module
Module for custom exceptions raised by the piscsi module
"""
class FailedSocketConnectionException(Exception):
"""Raise when a rascsi protobuf socket connection cannot be established after multiple tries."""
"""Raise when a piscsi protobuf socket connection cannot be established after multiple tries."""
class EmptySocketChunkException(Exception):
@@ -12,4 +12,4 @@ class EmptySocketChunkException(Exception):
class InvalidProtobufResponse(Exception):
"""Raise when a rascsi socket payload contains unpexpected data."""
"""Raise when a piscsi socket payload contains unpexpected data."""
@@ -17,8 +17,8 @@ from re import search
import requests
import rascsi_interface_pb2 as proto
from rascsi.common_settings import (
import piscsi_interface_pb2 as proto
from piscsi.common_settings import (
CFG_DIR,
CONFIG_FILE_SUFFIX,
PROPERTIES_SUFFIX,
@@ -26,9 +26,9 @@ from rascsi.common_settings import (
RESERVATIONS,
SHELL_ERROR,
)
from rascsi.ractl_cmds import RaCtlCmds
from rascsi.return_codes import ReturnCodes
from rascsi.socket_cmds import SocketCmds
from piscsi.piscsi_cmds import PiscsiCmds
from piscsi.return_codes import ReturnCodes
from piscsi.socket_cmds import SocketCmds
from util import unarchiver
FILE_READ_ERROR = "Unhandled exception when reading file: %s"
@@ -41,16 +41,16 @@ class FileCmds:
class for methods reading from and writing to the file system
"""
def __init__(self, sock_cmd: SocketCmds, ractl: RaCtlCmds, token=None, locale=None):
def __init__(self, sock_cmd: SocketCmds, piscsi: PiscsiCmds, token=None, locale=None):
self.sock_cmd = sock_cmd
self.ractl = ractl
self.piscsi = piscsi
self.token = token
self.locale = locale
def send_pb_command(self, command):
if logging.getLogger().isEnabledFor(logging.DEBUG):
# TODO: Uncouple/move to common dependency
logging.debug(self.ractl.format_pb_command(command))
logging.debug(self.piscsi.format_pb_command(command))
return self.sock_cmd.send_pb_command(command.SerializeToString())
@@ -104,7 +104,7 @@ class FileCmds:
prop_data = self.list_files(PROPERTIES_SUFFIX, CFG_DIR)
prop_files = [PurePath(x[0]).stem for x in prop_data]
server_info = self.ractl.get_server_info()
server_info = self.piscsi.get_server_info()
files = []
for file in result.image_files_info.image_files:
# Add properties meta data for the image, if applicable
@@ -188,8 +188,8 @@ class FileCmds:
"""
command = proto.PbCommand()
command.operation = proto.PbOperation.DELETE_IMAGE
command.params["token"] = self.ractl.token
command.params["locale"] = self.ractl.locale
command.params["token"] = self.piscsi.token
command.params["locale"] = self.piscsi.locale
command.params["file"] = file_name
@@ -206,8 +206,8 @@ class FileCmds:
"""
command = proto.PbCommand()
command.operation = proto.PbOperation.RENAME_IMAGE
command.params["token"] = self.ractl.token
command.params["locale"] = self.ractl.locale
command.params["token"] = self.piscsi.token
command.params["locale"] = self.piscsi.locale
command.params["from"] = file_name
command.params["to"] = new_file_name
@@ -225,8 +225,8 @@ class FileCmds:
"""
command = proto.PbCommand()
command.operation = proto.PbOperation.COPY_IMAGE
command.params["token"] = self.ractl.token
command.params["locale"] = self.ractl.locale
command.params["token"] = self.piscsi.token
command.params["locale"] = self.piscsi.locale
command.params["from"] = file_name
command.params["to"] = new_file_name
@@ -309,7 +309,7 @@ class FileCmds:
move_properties_files_to_config controls if .properties files are auto-moved to CFG_DIR
Returns (dict) result
"""
server_info = self.ractl.get_server_info()
server_info = self.piscsi.get_server_info()
if not members:
return {
@@ -384,7 +384,7 @@ class FileCmds:
disk_format is either HFS or FAT
Returns (dict) with (bool) status, (str) msg
"""
server_info = self.ractl.get_server_info()
server_info = self.piscsi.get_server_info()
full_file_path = Path(server_info["image_dir"]) / file_name
# Inject hfdisk commands to create Drive with correct partitions
@@ -480,7 +480,7 @@ class FileCmds:
Takes (str) file_name, (str) volume_name and (Path) driver_path as arguments.
Returns (dict) with (bool) status, (str) msg
"""
server_info = self.ractl.get_server_info()
server_info = self.piscsi.get_server_info()
full_file_path = Path(server_info["image_dir"]) / file_name
try:
@@ -529,7 +529,7 @@ class FileCmds:
Takes (str) file_name, (str) volume_name and (str) FAT size (12|16|32) as arguments.
Returns (dict) with (bool) status, (str) msg
"""
server_info = self.ractl.get_server_info()
server_info = self.piscsi.get_server_info()
full_file_path = Path(server_info["image_dir"]) / file_name
loopback_device = ""
@@ -595,7 +595,7 @@ class FileCmds:
Returns (dict) with (bool) status and (str) msg
"""
server_info = self.ractl.get_server_info()
server_info = self.piscsi.get_server_info()
file_name = PurePath(url).name
iso_filename = Path(server_info["image_dir"]) / f"{file_name}.iso"
@@ -703,8 +703,8 @@ class FileCmds:
file_path = f"{CFG_DIR}/{file_name}"
try:
with open(file_path, "w", encoding="ISO-8859-1") as json_file:
version = self.ractl.get_server_info()["version"]
devices = self.ractl.list_devices()["device_list"]
version = self.piscsi.get_server_info()["version"]
devices = self.piscsi.list_devices()["device_list"]
for device in devices:
# Remove keys that we don't want to store in the file
del device["status"]
@@ -712,16 +712,16 @@ class FileCmds:
# It's cleaner not to store an empty parameter for every device without media
if device["image"] == "":
device["image"] = None
# RaSCSI product names will be generated on the fly by RaSCSI
if device["vendor"] == "RaSCSI":
# PiSCSI product names will be generated on the fly by PiSCSI
if device["vendor"] == "PiSCSI":
device["vendor"] = device["product"] = device["revision"] = None
# A block size of 0 is how RaSCSI indicates N/A for block size
# A block size of 0 is how PiSCSI indicates N/A for block size
if device["block_size"] == 0:
device["block_size"] = None
# Convert to a data type that can be serialized
device["params"] = dict(device["params"])
reserved_ids_and_memos = []
reserved_ids = self.ractl.get_reserved_ids()["ids"]
reserved_ids = self.piscsi.get_reserved_ids()["ids"]
for scsi_id in reserved_ids:
reserved_ids_and_memos.append(
{"id": scsi_id, "memo": RESERVATIONS[int(scsi_id)]}
@@ -762,14 +762,14 @@ class FileCmds:
# If the config file format changes again in the future,
# introduce more sophisticated format detection logic here.
if isinstance(config, dict):
self.ractl.detach_all()
self.piscsi.detach_all()
for scsi_id in range(0, 8):
RESERVATIONS[scsi_id] = ""
ids_to_reserve = []
for item in config["reserved_ids"]:
ids_to_reserve.append(item["id"])
RESERVATIONS[int(item["id"])] = item["memo"]
self.ractl.reserve_scsi_ids(ids_to_reserve)
self.piscsi.reserve_scsi_ids(ids_to_reserve)
for row in config["devices"]:
kwargs = {
"device_type": row["device_type"],
@@ -782,12 +782,12 @@ class FileCmds:
}
if row["image"]:
kwargs["params"]["file"] = row["image"]
self.ractl.attach_device(row["id"], **kwargs)
self.piscsi.attach_device(row["id"], **kwargs)
# The config file format in RaSCSI 21.10 is using a list data type at the top level.
# If future config file formats return to the list data type,
# introduce more sophisticated format detection logic here.
elif isinstance(config, list):
self.ractl.detach_all()
self.piscsi.detach_all()
for row in config:
kwargs = {
"device_type": row["device_type"],
@@ -801,7 +801,7 @@ class FileCmds:
}
if row["image"]:
kwargs["params"]["file"] = row["image"]
self.ractl.attach_device(row["id"], **kwargs)
self.piscsi.attach_device(row["id"], **kwargs)
logging.warning("%s is in an obsolete config file format", file_name)
else:
return {
@@ -1,16 +1,16 @@
"""
Module for commands sent to the RaSCSI backend service.
Module for commands sent to the PiSCSI backend service.
"""
import rascsi_interface_pb2 as proto
from rascsi.return_codes import ReturnCodes
from rascsi.socket_cmds import SocketCmds
import piscsi_interface_pb2 as proto
from piscsi.return_codes import ReturnCodes
from piscsi.socket_cmds import SocketCmds
import logging
class RaCtlCmds:
class PiscsiCmds:
"""
Class for commands sent to the RaSCSI backend service.
Class for commands sent to the PiSCSI backend service.
"""
def __init__(self, sock_cmd: SocketCmds, token=None, locale="en"):
@@ -29,13 +29,13 @@ class RaCtlCmds:
Sends a SERVER_INFO command to the server.
Returns a dict with:
- (bool) status
- (str) version (RaSCSI version number)
- (list) of (str) log_levels (the log levels RaSCSI supports)
- (str) version (PiSCSI version number)
- (list) of (str) log_levels (the log levels PiSCSI supports)
- (str) current_log_level
- (list) of (int) reserved_ids
- (str) image_dir, path to the default images directory
- (int) scan_depth, the current images directory scan depth
- 5 distinct (list)s of (str)s with file endings recognized by RaSCSI
- 5 distinct (list)s of (str)s with file endings recognized by PiSCSI
"""
command = proto.PbCommand()
command.operation = proto.PbOperation.SERVER_INFO
@@ -58,7 +58,7 @@ class RaCtlCmds:
image_dir = result.server_info.image_files_info.default_image_folder
scan_depth = result.server_info.image_files_info.depth
# Creates lists of file endings recognized by RaSCSI
# Creates lists of file endings recognized by PiSCSI
mappings = result.server_info.mapping_info.mapping
schd = []
scrm = []
@@ -114,7 +114,7 @@ class RaCtlCmds:
Sends a NETWORK_INTERFACES_INFO command to the server.
Returns a dict with:
- (bool) status
- (list) of (str) ifs (network interfaces detected by RaSCSI)
- (list) of (str) ifs (network interfaces detected by PiSCSI)
"""
command = proto.PbCommand()
command.operation = proto.PbOperation.NETWORK_INTERFACES_INFO
@@ -481,7 +481,7 @@ class RaCtlCmds:
def is_token_auth(self):
"""
Sends a CHECK_AUTHENTICATION command to the server.
Tells you whether RaSCSI backend is protected by a token password or not.
Tells you whether PiSCSI backend is protected by a token password or not.
Returns (bool) status and (str) msg.
"""
command = proto.PbCommand()
@@ -1,11 +1,11 @@
"""
Module for return codes that are refrenced in the return payloads of the rascsi module.
Module for return codes that are refrenced in the return payloads of the piscsi module.
"""
# pylint: disable=too-few-public-methods
class ReturnCodes:
"""Class for the return codes used within the rascsi module."""
"""Class for the return codes used within the piscsi module."""
DELETEFILE_SUCCESS = 0
DELETEFILE_FILE_NOT_FOUND = 1
@@ -1,5 +1,5 @@
"""
Module for sending and receiving data over a socket connection with the RaSCSI backend
Module for sending and receiving data over a socket connection with the PiSCSI backend
"""
import logging
@@ -7,7 +7,7 @@ import socket
from time import sleep
from struct import pack, unpack
from rascsi.exceptions import (
from piscsi.exceptions import (
EmptySocketChunkException,
InvalidProtobufResponse,
FailedSocketConnectionException,
@@ -16,7 +16,7 @@ from rascsi.exceptions import (
class SocketCmds:
"""
Class for sending and receiving data over a socket connection with the RaSCSI backend
Class for sending and receiving data over a socket connection with the PiSCSI backend
"""
def __init__(self, host="localhost", port=6868):
@@ -26,7 +26,7 @@ class SocketCmds:
def send_pb_command(self, payload):
"""
Takes a (str) containing a serialized protobuf as argument.
Establishes a socket connection with RaSCSI.
Establishes a socket connection with PiSCSI.
"""
counter = 0
@@ -42,7 +42,7 @@ class SocketCmds:
except socket.error as error:
counter += 1
logging.warning(
"The RaSCSI service is not responding - attempt %s/%s",
"The PiSCSI service is not responding - attempt %s/%s",
str(counter),
str(tries),
)
@@ -60,7 +60,7 @@ class SocketCmds:
def send_over_socket(self, sock, payload):
"""
Takes a socket object and (str) payload with serialized protobuf.
Sends payload to RaSCSI over socket and captures the response.
Sends payload to PiSCSI over socket and captures the response.
Tries to extract and interpret the protobuf header to get response size.
Reads data from socket in 2048 bytes chunks until all data is received.
"""
@@ -84,7 +84,7 @@ class SocketCmds:
if chunk == b"":
error_message = (
"Read an empty chunk from the socket. Socket connection has "
"dropped unexpectedly. RaSCSI may have crashed."
"dropped unexpectedly. PiSCSI may have crashed."
)
logging.error(error_message)
raise EmptySocketChunkException(error_message)
@@ -94,8 +94,8 @@ class SocketCmds:
return response_message
error_message = (
"The response from RaSCSI did not contain a protobuf header. "
"RaSCSI may have crashed."
"The response from PiSCSI did not contain a protobuf header. "
"PiSCSI may have crashed."
)
logging.error(error_message)
@@ -10,7 +10,7 @@ from socket import socket, gethostname, AF_INET, SOCK_DGRAM
from pathlib import Path
from platform import uname
from rascsi.common_settings import SHELL_ERROR
from piscsi.common_settings import SHELL_ERROR
class SysCmds:
@@ -97,7 +97,7 @@ class SysCmds:
@staticmethod
def is_bridge_setup():
"""
Returns (bool) True if the rascsi_bridge network interface exists
Returns (bool) True if the piscsi_bridge network interface exists
"""
try:
bridges = (
@@ -113,7 +113,7 @@ class SysCmds:
logging.warning(SHELL_ERROR, error.cmd, error.stderr.decode("utf-8"))
bridges = ""
if "rascsi_bridge" in bridges:
if "piscsi_bridge" in bridges:
return True
return False