Squashed commit of the following:

commit 8171c6ea27982c736c30c0db69a7fdde07ee10ce
Author: Uwe Seimet <Uwe.Seimet@seimet.de>
Date:   Sat Dec 18 12:43:14 2021 +0100

    The data type is implicit

commit fb01dc9d82e8ff7456b05a0cb9d08069adacc64c
Author: Uwe Seimet <Uwe.Seimet@seimet.de>
Date:   Sat Dec 18 12:37:49 2021 +0100

    Renaming

commit 057dbf1aca7be3f7e76a5ff89a582a276b6d3089
Author: Uwe Seimet <Uwe.Seimet@seimet.de>
Date:   Sat Dec 18 12:29:54 2021 +0100

    Comment update

commit 5f699aad2f835f72accdb445d1e59f094aeb108f
Author: Uwe Seimet <Uwe.Seimet@seimet.de>
Date:   Sat Dec 18 12:24:25 2021 +0100

    Signature update

commit cbcf8b09f9d1ba7b82f816269bcfe91d9f00eb6e
Author: Uwe Seimet <Uwe.Seimet@seimet.de>
Date:   Sat Dec 18 12:22:45 2021 +0100

    Signature update

commit a8148ef802ca809e5a305d2caa69856c9033d932
Author: Uwe Seimet <Uwe.Seimet@seimet.de>
Date:   Sat Dec 18 12:16:46 2021 +0100

    Comment update

commit ce685a92d4827e131d80d10ecd56e2b3baf173f8
Author: Uwe Seimet <Uwe.Seimet@seimet.de>
Date:   Sat Dec 18 12:15:46 2021 +0100

    Use map instead of list

commit 454c0438f3589904f5dbe5253963dd200ea416dd
Author: Uwe Seimet <Uwe.Seimet@seimet.de>
Date:   Sat Dec 18 10:47:36 2021 +0100

    Updated size check

commit b386dbba4b0262f4f6f02aecb2a1daeffd41f4a2
Author: Uwe Seimet <Uwe.Seimet@seimet.de>
Date:   Sat Dec 18 01:23:43 2021 +0100

    Initial improvements
This commit is contained in:
Uwe Seimet 2021-12-18 12:47:36 +01:00
parent 5d6862b6b0
commit d9dbbc0bb3
4 changed files with 120 additions and 100 deletions

View File

@ -159,31 +159,29 @@ enum PbOperation {
OPERATION_INFO = 30;
}
// The operation parameter meta data
// The operation parameter meta data. The parameter data type is provided by the protobuf API.
message PbOperationParameter {
string name = 1;
// Optional short localized description, key is the lower case locale (e.g. en, de).
// Falling back to "en" is recommended if a description for a different language is missing.
// Falling back to "en" is recommended if a description for a particular language is missing.
map<string, string> description = 2;
// "string", "int", or "boolean". Parameters are always strings but must be convertible to these types.
string type = 3;
// There is no specific set of values if empty
repeated string values = 4;
// There is no specific set of permitted values if empty
repeated string permitted_values = 3;
// Optional default value. If there is no default the value is mandatory.
string default_value = 5;
string default_value = 4;
}
// The list of parameters supported by an operation
message PbOperationParameters {
string name = 1;
message PbOperationMetaData {
// Optional short localized description, key is the lower case locale (e.g. en, de).
// Falling back to "en" is recommended if a description for a different language is missing.
map<string, string> description = 2;
repeated PbOperationParameter parameters = 3;
// Falling back to "en" is recommended if a description for a particular language is missing.
map<string, string> description = 1;
repeated PbOperationParameter parameters = 2;
}
// Mapping of operation names to their meta data
message PbOperationInfo {
repeated PbOperationParameters operations = 1;
map<string, PbOperationMetaData> operations = 1;
}
// The supported file extensions mapped to their respective device types

View File

@ -340,120 +340,143 @@ PbOperationInfo *RascsiResponse::GetOperationInfo(PbResult& result)
{
PbOperationInfo *operation_info = new PbOperationInfo();
PbOperationParameters *parameters;
PbOperationParameter *parameter;
PbOperationMetaData *meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "name", "Image file name in case of a mass storage device", "string");
AddOperationParameter(meta_data, "interfaces", "Comma-separated prioritized network interface list", "string");
CreateOperation(operation_info, meta_data, ATTACH, "Attach device, one of the device-specific parameters is required");
parameters = AddOperation(*operation_info, ATTACH, "Attach device, one of the device-specific parameters is required");
AddOperationParameter(*parameters, "name", "Image file name in case of a mass storage device", "string");
AddOperationParameter(*parameters, "interfaces", "Comma-separated prioritized network interface list", "string");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, DETACH, "Detach device");
AddOperation(*operation_info, DETACH, "Detach device");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, DETACH_ALL, "Detach all devices");
AddOperation(*operation_info, DETACH_ALL, "Detach all devices");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, START, "Start device");
AddOperation(*operation_info, START, "Start device");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, STOP, "Stop device");
AddOperation(*operation_info,STOP, "Stop device");
meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "file", "Image file name");
CreateOperation(operation_info, meta_data, INSERT, "Insert medium");
parameters = AddOperation(*operation_info, INSERT, "Insert medium");
AddOperationParameter(*parameters, "file", "Image file name");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, EJECT, "Eject medium");
AddOperation(*operation_info, EJECT, "Eject medium");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, PROTECT, "Protect medium");
AddOperation(*operation_info, PROTECT, "Protect medium");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, UNPROTECT, "Unprotect medium");
AddOperation(*operation_info, UNPROTECT, "Unprotect medium");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, SERVER_INFO, "Get rascsi server information");
AddOperation(*operation_info, SERVER_INFO, "Get rascsi server information");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, VERSION_INFO, "Get rascsi server version");
AddOperation(*operation_info, VERSION_INFO, "Get rascsi server version");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, DEVICES_INFO, "Get information on attached devices");
AddOperation(*operation_info, DEVICES_INFO, "Get information on attached devices");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, DEVICE_TYPES_INFO, "Get device properties by device type");
AddOperation(*operation_info, DEVICE_TYPES_INFO, "Get device properties by device type");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, DEFAULT_IMAGE_FILES_INFO, "Get information on available image files");
AddOperation(*operation_info, DEFAULT_IMAGE_FILES_INFO, "Get information on available image files");
meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "file", "Image file name");
CreateOperation(operation_info, meta_data, IMAGE_FILE_INFO, "Get information on image file");
parameters = AddOperation(*operation_info, IMAGE_FILE_INFO, "Get information on image file");
AddOperationParameter(*parameters, "file", "Image file name");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, LOG_LEVEL_INFO, "Get log level information");
AddOperation(*operation_info, LOG_LEVEL_INFO, "Get log level information");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, NETWORK_INTERFACES_INFO, "Get the available network interfaces");
AddOperation(*operation_info, NETWORK_INTERFACES_INFO, "Get the available network interfaces");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, MAPPING_INFO, "Get mapping of extensions to device types");
parameters = AddOperation(*operation_info, MAPPING_INFO, "Get mapping of extensions to device types");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, RESERVED_IDS_INFO, "Get list of reserved device IDs");
AddOperation(*operation_info, RESERVED_IDS_INFO, "Get list of reserved device IDs");
meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "folder", "Default image file folder name");
CreateOperation(operation_info, meta_data, DEFAULT_FOLDER, "Set default image file folder");
parameters = AddOperation(*operation_info,DEFAULT_FOLDER, "Set default image file folder");
AddOperationParameter(*parameters, "folder", "Default image file folder name");
meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "level", "The log level");
CreateOperation(operation_info, meta_data, LOG_LEVEL, "Set log level");
parameters = AddOperation(*operation_info, LOG_LEVEL, "Set log level");
AddOperationParameter(*parameters, "level", "The log level");
meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "ids", "Comma-separated device ID list");
CreateOperation(operation_info, meta_data, RESERVE_IDS, "Reserve device IDs");
parameters = AddOperation(*operation_info,RESERVE_IDS, "Reserve device IDs");
AddOperationParameter(*parameters, "ids", "Comma-separated device ID list");
meta_data = new PbOperationMetaData();
PbOperationParameter *parameter = AddOperationParameter(meta_data, "mode", "Shutdown mode");
parameter->add_permitted_values("rascsi");
parameter->add_permitted_values("system");
parameter->add_permitted_values("reboot");
CreateOperation(operation_info, meta_data, SHUT_DOWN, "Shut down or reboot");
parameters = AddOperation(*operation_info, SHUT_DOWN, "Shut down or reboot");
parameter = AddOperationParameter(*parameters, "mode", "Shutdown mode");
parameter->add_values("rascsi");
parameter->add_values("system");
parameter->add_values("reboot");
meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "file", "Image file name");
AddOperationParameter(meta_data, "size", "Image file size in bytes", "int");
parameter = AddOperationParameter(meta_data, "read_only", "Read-only flag", "false");
parameter->add_permitted_values("true");
parameter->add_permitted_values("false");
CreateOperation(operation_info, meta_data, CREATE_IMAGE, "Create an image file");
parameters = AddOperation(*operation_info, CREATE_IMAGE, "Create an image file");
AddOperationParameter(*parameters, "file", "Image file name");
AddOperationParameter(*parameters, "size", "Image file size in bytes", "int");
parameter = AddOperationParameter(*parameters, "read_only", "Read-only flag", "boolean", "false");
parameter->add_values("true");
parameter->add_values("false");
meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "file", "Image file name");
CreateOperation(operation_info, meta_data, DELETE_IMAGE, "Delete image file");
parameters = AddOperation(*operation_info, DELETE_IMAGE, "Delete image file");
AddOperationParameter(*parameters, "file", "Image file name");
meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "from", "Source image file name");
AddOperationParameter(meta_data, "to", "Destination image file name");
CreateOperation(operation_info, meta_data, RENAME_IMAGE, "Rename image file");
parameters = AddOperation(*operation_info, RENAME_IMAGE, "Rename image file");
AddOperationParameter(*parameters, "from", "Source image file name");
AddOperationParameter(*parameters, "to", "Destination image file name");
meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "from", "Source image file name image file name");
AddOperationParameter(meta_data, "to", "Destination image file name");
parameter = AddOperationParameter(meta_data, "read_only", "Read-only flag", "false");
parameter->add_permitted_values("true");
parameter->add_permitted_values("false");
CreateOperation(operation_info, meta_data, COPY_IMAGE, "Copy image file");
parameters = AddOperation(*operation_info, COPY_IMAGE, "Copy image file");
AddOperationParameter(*parameters, "from", "Source image file name image file name");
AddOperationParameter(*parameters, "to", "Destination image file name");
parameter = AddOperationParameter(*parameters, "read_only", "Read-only flag", "boolean", "false");
parameter->add_values("true");
parameter->add_values("false");
meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "file", "Image file name");
CreateOperation(operation_info, meta_data, PROTECT_IMAGE, "Write-protect image file");
parameters = AddOperation(*operation_info, PROTECT_IMAGE, "Write-protect an image file");
AddOperationParameter(*parameters, "file", "Image file name");
meta_data = new PbOperationMetaData();
AddOperationParameter(meta_data, "file", "Image file name");
CreateOperation(operation_info, meta_data, UNPROTECT_IMAGE, "Make image file writable");
parameters = AddOperation(*operation_info, UNPROTECT_IMAGE, "Make image file writable");
AddOperationParameter(*parameters, "file", "Image file name");
meta_data = new PbOperationMetaData();
CreateOperation(operation_info, meta_data, OPERATION_INFO, "Get operation meta data");
AddOperation(*operation_info, OPERATION_INFO, "Get operation meta data");
// Ensure that all operations are covered
assert(operation_info->operations_size() == 30);
// Ensure that the complete set of operations is covered
assert(operation_info->operations_size() == PbOperation_ARRAYSIZE - 1);
result.set_status(true);
return operation_info;
}
PbOperationParameters *RascsiResponse::AddOperation(PbOperationInfo& operation_info, const PbOperation& operation,
const string& description)
void RascsiResponse::CreateOperation(PbOperationInfo *operation_info, PbOperationMetaData *meta_data,
const PbOperation& operation, const string& description)
{
PbOperationParameters *parameters = operation_info.add_operations();
parameters->set_name(PbOperation_Name(operation));
(*parameters->mutable_description())["en"] = description;
return parameters;
(*meta_data->mutable_description())["en"] = description;
(*operation_info->mutable_operations())[PbOperation_Name(operation)] = *meta_data;
}
PbOperationParameter *RascsiResponse::AddOperationParameter(PbOperationParameters& parameters, const string& name,
const string& description, const string& type, const string& default_value)
PbOperationParameter *RascsiResponse::AddOperationParameter(PbOperationMetaData *meta_data, const string& name,
const string& description, const string& default_value)
{
PbOperationParameter *parameter = parameters.add_parameters();
PbOperationParameter *parameter = meta_data->add_parameters();
parameter->set_name(name);
(*parameter->mutable_description())["en"] = description;
parameter->set_type(type);
if (!default_value.empty()) {
parameter->set_default_value(default_value);
}

View File

@ -53,7 +53,7 @@ private:
void GetAllDeviceTypeProperties(PbDeviceTypesInfo&);
void GetDeviceTypeProperties(PbDeviceTypesInfo&, PbDeviceType);
void GetAvailableImages(PbResult& result, PbServerInfo&);
PbOperationParameters *AddOperation(PbOperationInfo&, const PbOperation&, const string&);
PbOperationParameter *AddOperationParameter(PbOperationParameters&, const string&, const string&,
const string& = "string", const string& = "");
void CreateOperation(PbOperationInfo *, PbOperationMetaData *, const PbOperation&, const string&);
PbOperationParameter *AddOperationParameter(PbOperationMetaData *, const string&, const string&,
const string& = "");
};

View File

@ -276,35 +276,34 @@ void RasctlDisplay::DisplayMappingInfo(const PbMappingInfo& mapping_info)
void RasctlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info)
{
// Creates a sorted list
list<PbOperationParameters> operations = { operation_info.operations().begin(), operation_info.operations().end() };
operations.sort([](const auto& a, const auto& b) { return a.name() < b.name(); });
// Creates a sorted map
const map<string, PbOperationMetaData> operations = { operation_info.operations().begin(), operation_info.operations().end() };
cout << "Remote operations supported by rascsi and their parameters:" << endl;
for (const auto& operation : operations) {
cout << " " << operation.name();
if (!operation.description().empty()) {
cout << " (" << operation.description().at("en") << ")";
cout << " " << operation.first;
if (!operation.second.description().empty()) {
cout << " (" << operation.second.description().at("en") << ")";
}
cout << endl;
for (const auto& parameter : operation.parameters()) {
cout << " " << parameter.name() << ": " << parameter.type()
<< (parameter.default_value().empty() ? ", mandatory" : ", optional");
for (const auto& parameter : operation.second.parameters()) {
cout << " " << parameter.name() << ": "
<< (parameter.default_value().empty() ? "mandatory" : "optional");
if (!parameter.description().empty()) {
cout << " (" << parameter.description().at("en") << ")";
}
cout << endl;
if (parameter.values_size()) {
if (parameter.permitted_values_size()) {
cout << " Permitted values: ";
bool isFirst = true;
for (const auto& value : parameter.values()) {
for (const auto& permitted_value : parameter.permitted_values()) {
if (!isFirst) {
cout << ", ";
}
isFirst = false;
cout << value;
cout << permitted_value;
}
cout << endl;
}