Description of problem: Customer wanted to pull out a CSV list of hosts registered to the Satellite with their subscriptions, and separate the fields with ";" as some product names include "," and make things hard to read/parse. We found out that the --csv-separator option doesn't work when "hammer csv" is used and that "hammer" options do not offer the possibility to extract subscriptions. Following works but no custom seperator: # hammer csv content-hosts --export --file content-hosts-export_29052017.csv --itemized-subscriptions --verbose --organization "Default Organization" Following fails with custom seperator: # hammer --csv --csv-separator ";" content-hosts --export --file content-hosts-export_29052017.csv --itemized-subscriptions --verbose --organization "Default Organization" ~~~ Error: No such sub-command 'content-hosts' ~~~ Following works with csv-seperator: # hammer --csv --csv-separator ";" content-host list --organization "Default Organization" ~~~ ID;Name;Installable Errata 8b7aa6dc-79f1-45cf-8866-6ae053d75ed6;00-satha-test-vm.sysmgmt.lan;12 d80054a0-5bb7-4af0-b527-78ce878a6a82;virt-who-satotest.gsslab.brq.redhat.com-1; ~~~ # hammer --help | egrep "content-host|csv" ~~~ content-host Manipulate content hosts on the server csv import to or export from a running foreman server --csv Output as CSV (same as --output=csv) --csv-separator SEPARATOR Character to separate the values --output ADAPTER Set output format. One of [base, table, silent, csv, yaml, json] ~~~ +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hammer csv does not have the --csv-separator available +++++++++++++++++++++++++++++++++++++++++++++++++++++++ # hammer csv --help ~~~ Usage: hammer csv [OPTIONS] SUBCOMMAND [ARG] ... Parameters: SUBCOMMAND subcommand [ARG] ... subcommand arguments Subcommands: activation-keys import or export activation keys content-hosts import or export content hosts export export into directory import import by directory settings import or export settings subscriptions import or export subscriptions Options: -h, --help print help [root@satha ~]# hammer csv content-hosts --help Usage: hammer csv content-hosts [OPTIONS] Options: --columns COLUMN_NAMES Comma separated list of column names to export --continue-on-error Continue processing even if individual resource error --export Export current data instead of importing --file FILE_NAME CSV file (default to /dev/stdout with --export, otherwise required) --itemized-subscriptions Export one subscription per row, only process update subscriptions on import --organization ORGANIZATION Only process organization matching this name --search SEARCH Only export search results -h, --help print help -v, --verbose be verbose Columns: Name - Name of resource Search - Search for matching names during import (overrides 'Name' column) Organization - Organization name Environment - Lifecycle environment name Content View - Content view name Host Collections - Comma separated list of host collection names Virtual - Is a virtual host, Yes or No Guest of Host - Hypervisor host name for virtual hosts OS - Operating system Arch - Architecture Sockets - Number of sockets RAM - Quantity of RAM in bytes Cores - Number of cores SLA - Service Level Agreement value Products - Comma separated list of products, each of the format "<sku>|<name>" Subscriptions - Comma separated list of subscriptions, each of the format "<quantity>|<sku>|<name>|<contract>|<account>" Subscription Name - Subscription name (only applicable for --itemized-subscriptions) Subscription Type - Subscription type (only applicable for --itemized-subscriptions) Subscription Quantity - Subscription quantity (only applicable for --itemized-subscriptions) Subscription SKU - Subscription SKU (only applicable for --itemized-subscriptions) Subscription Contract - Subscription contract number (only applicable for --itemized-subscriptions) Subscription Account - Subscription account number (only applicable for --itemized-subscriptions) Subscription Start - Subscription start date (only applicable for --itemized-subscriptions) Subscription End - Subscription end date (only applicable for --itemized-subscriptions) ~~~ Version-Release number of selected component (if applicable): How reproducible: 100% Steps to Reproduce: 1. Use "hammer csv" 2. Specify a custom separator with --csv-separator 3. Option doesn't exist Actual results: We are unable to produce a CSV containing the list of hosts registered to the Satellite and their subscriptions, separated by a custom separator Expected results: Ability to produce a CSV containing the list of hosts registered to the Satellite and their subscriptions, separated by a custom separator
Daniele, I would expect the Ruby CSV module to properly quote the strings if they contain the delimiter char. If you want, you can even force this: /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.2.1.1/lib/hammer_cli_csv/base.rb, line 57, change CSV.open(option_file, 'wb', {:force_quotes => false}) do |csv| to CSV.open(option_file, 'wb', {:force_quotes => true}) do |csv| You can also add ":col_sep => ';'" to the option hash, to make it use ; as the delimiter. Does that help as a quick-fix?
(In reply to Evgeni Golov from comment #3) > Daniele, > > I would expect the Ruby CSV module to properly quote the strings if they > contain the delimiter char. > > If you want, you can even force this: > /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.2.1.1/lib/ > hammer_cli_csv/base.rb, line 57, change > CSV.open(option_file, 'wb', {:force_quotes => false}) do |csv| > to > CSV.open(option_file, 'wb', {:force_quotes => true}) do |csv| > > You can also add ":col_sep => ';'" to the option hash, to make it use ; as > the delimiter. > > Does that help as a quick-fix? Hello Evgeni, Thanks a lot for this. Could you tell me exactly what line has to be modified to add the :col_sep => ';' option?
- CSV.open(option_file, 'wb', {:force_quotes => false}) do |csv| + CSV.open(option_file, 'wb', {:force_quotes => false, :col_sep => ';'}) do |csv|
The Satellite Team is attempting to provide an accurate backlog of bugzilla requests which we feel will be resolved in the next few releases. We do not believe this bugzilla will meet that criteria, and have plans to close it out in 1 month. This is not a reflection on the validity of the request, but a reflection of the many priorities for the product. If you have any concerns about this, feel free to contact Red Hat Technical Support or your account team. If we do not hear from you, we will close this bug out. Thank you.
Thank you for your interest in Satellite 6. We have evaluated this request, and while we recognize that it is a valid request, we do not expect this to be implemented in the product in the foreseeable future. This is due to other priorities for the product, and not a reflection on the request itself. We are therefore closing this out as WONTFIX. If you have any concerns about this, please do not reopen. Instead, feel free to contact Red Hat Technical Support. Thank you.