Add binary output file

This commit is contained in:
Uwe Seimet 2023-11-14 09:52:58 +01:00
parent b04a96a782
commit 06ab3faa33
4 changed files with 47 additions and 13 deletions

View File

@ -81,13 +81,14 @@ int ScsiCtl::run(const vector<char *>& args) const
string token;
bool list = false;
bool to_json = false;
bool to_binary = false;
string locale = GetLocale();
opterr = 1;
int opt;
while ((opt = getopt(static_cast<int>(args.size()), args.data(),
"e::lmos::vDINOSTVXa:b:c:d:f:h:i:j:n:p:r:t:x:z:C:E:F:L:P::R:")) != -1) {
"e::lmos::vDINOSTVXa:b:c:d:f:h:i:n:p:r:t:x:z:B:C:E:F:J:L:P::R:")) != -1) {
switch (opt) {
case 'i':
if (const string error = SetIdAndLun(*device, optarg); !error.empty()) {
@ -152,11 +153,16 @@ int ScsiCtl::run(const vector<char *>& args) const
hostname = optarg;
break;
case 'j':
case 'J':
filename = optarg;
to_json = true;
break;
case 'B':
filename = optarg;
to_binary = true;
break;
case 'I':
command.set_operation(RESERVED_IDS_INFO);
break;
@ -276,6 +282,9 @@ int ScsiCtl::run(const vector<char *>& args) const
if (to_json) {
return ExportAsJson(command, filename);
}
if (to_binary) {
return ExportAsBinary(command, filename);
}
ScsictlCommands scsictl_commands(command, hostname, port);
@ -321,3 +330,18 @@ int ScsiCtl::ExportAsJson(const PbCommand &command, const string &filename) cons
return EXIT_SUCCESS;
}
int ScsiCtl::ExportAsBinary(const PbCommand &command, const string &filename) const
{
const string binary = command.SerializeAsString();
ofstream out;
out.open(filename, ios::binary);
out << binary;
if (out.fail()) {
cerr << "Error: Can't create JSON file '" << filename << "'" << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

View File

@ -30,4 +30,5 @@ private:
void Banner(const vector<char *>&) const;
int ExportAsJson(const PbCommand&, const string&) const;
int ExportAsBinary(const PbCommand&, const string&) const;
};

View File

@ -18,7 +18,8 @@ scsictl \- Sends management commands to the piscsi process
\fB\-V\fR |
\fB\-X\fR |
[\fB\-d\fR \fIFILENAME\fR] |
[\fB\-j\fR \fIFILENAME\fR] |
[\fB\-B\fR \fIFILENAME\fR] |
[\fB\-J\fR \fIFILENAME\fR] |
[\fB\-C\fR \fIFILENAME:FILESIZE\fR] |
[\fB\-E\fR \fIFILENAME\fR] |
[\fB\-F\fR \fIIMAGE_FOLDER\fR] |
@ -119,8 +120,11 @@ Shut down the piscsi process.
.BR \-d\fI " "\fIFILENAME
Delete an image file in the default image folder.
.TP
.BR \-j\fI " "\fIFILENAME
Do not send command to piscsi but write it to a JSON file.
.BR \-B\fI " "\fIFILENAME
Do not send command to piscsi but write it to a binary protobuf file.
.TP
.BR \-J\fI " "\fIFILENAME
Do not send command to piscsi but write it to a JSON protobuf file.
.TP
.BR \-x\fI " "\fICURRENT_NAME:NEW_NAME
Copy an image file in the default image folder.

View File

@ -7,12 +7,12 @@ NAME
SYNOPSIS
scsictl -e | -l | -m | -o | -v | -D | -I | -L | -O | -P | -S | -T | -V
| -X | [-d FILENAME] | [-j FILENAME] | [-C FILENAME:FILESIZE] | [-E
FILENAME] | [-F IMAGE_FOLDER] | [-R CURRENT_NAME:NEW_NAME] | [-c CMD] |
[-f FILE|PARAM] | [-g LOG_LEVEL] | [-h HOST] | [-i ID[:LUN]] | [-n
NAME] | [-p PORT] | [-r RESERVED_IDS] | [-s [FOLDER_PATTERN:FILE_PAT
TERN:OPERATIONS]] | [-t TYPE] | [-x CURRENT_NAME:NEW_NAME] | [-z LO
CALE]
| -X | [-d FILENAME] | [-B FILENAME] | [-J FILENAME] | [-C FILE
NAME:FILESIZE] | [-E FILENAME] | [-F IMAGE_FOLDER] | [-R CUR
RENT_NAME:NEW_NAME] | [-c CMD] | [-f FILE|PARAM] | [-g LOG_LEVEL] | [-h
HOST] | [-i ID[:LUN]] | [-n NAME] | [-p PORT] | [-r RESERVED_IDS] | [-s
[FOLDER_PATTERN:FILE_PATTERN:OPERATIONS]] | [-t TYPE] | [-x CUR
RENT_NAME:NEW_NAME] | [-z LOCALE]
DESCRIPTION
scsictl sends commands to the piscsi process to make configuration ad
@ -94,8 +94,13 @@ OPTIONS
-d FILENAME
Delete an image file in the default image folder.
-j FILENAME
Do not send command to piscsi but write it to a JSON file.
-B FILENAME
Do not send command to piscsi but write it to a binary protobuf
file.
-J FILENAME
Do not send command to piscsi but write it to a JSON protobuf
file.
-x CURRENT_NAME:NEW_NAME
Copy an image file in the default image folder.