Skip to content

Commit

Permalink
+ removed copyright and old comments that had been moved to README
Browse files Browse the repository at this point in the history
+ updated api call to add host collections to activation key

+ adding import/export settings

+ clean up options --organization and --file

+ added deprecation for --csv-file and --csv-export

+ hosts create/update API fixed

+ corrected export of architectures

+ export puppet-environments

+ export partition-tables

+ import partition-tables

+ import/export puppet-environments w/ locations

+ subscription import/export

+ check existence of parameters on partition-tables for Sat-6.1.1 vs. upstream

+ import / export operating-systems corrected

+ updated .gitignore for local config yml
  • Loading branch information
Tom McKay committed Aug 19, 2015
1 parent 2004189 commit 088e085
Show file tree
Hide file tree
Showing 45 changed files with 318 additions and 808 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pickle-email-*.html
.project
config/initializers/secret_token.rb
config/cli.modules.d/*.yml
config/cli_config.yml
!config/*.template.yml
!config/cli.modules.d/*.template.yml
test/data/*.zip
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Creating organization 'abcMega Corporation'... done
## Puppet Environments

**Overview**
* Due to the implications of removing a puppet environment from an organization or location, this column only adds to what is present already.
* [Open Issues](https://github.com/Katello/hammer-cli-csv/issues?labels=puppet-environments&state=open)
* [Tests](https://github.com/Katello/hammer-cli-csv/blob/master/test/puppet_environments_test.rb)
* Sample data
Expand Down Expand Up @@ -226,6 +227,8 @@ Creating organization 'abcMega Corporation'... done
## Partition Tables

**Overview**
* Import and export of the Organizations and Locations columns does not apply to all versions and will be silently ignored when unsupported.
* Importing Operating Systems column does not apply to all versions and will be silently ignored when unsupported.
* [Open Issues](https://github.com/Katello/hammer-cli-csv/issues?labels=partition-tables&state=open)
* [Tests](https://github.com/Katello/hammer-cli-csv/blob/master/test/partition_tables_test.rb)
* Sample data
Expand Down Expand Up @@ -306,10 +309,10 @@ Creating organization 'abcMega Corporation'... done
| Additional arguments | Description |
| ---------------:| :--------------|
| --organization | Only process organization matching this name |
| --sync | Sync product repositories (default true) |
| --[no-]sync | Sync product repositories (default true) |

**Overview**
* Due to the length of time that syncing repositories can take, the --sync=false option may be used to skip this step. To always disable syncing, ':products_sync: false' may be specified in configuration file.
* Due to the length of time that syncing repositories can take, the --no-sync option may be used to skip this step. To always disable syncing, ':products_sync: false' may be specified in configuration file.
* [Open Issues](https://github.com/Katello/hammer-cli-csv/issues?labels=products&state=open)
* [Tests](https://github.com/Katello/hammer-cli-csv/blob/master/test/products_test.rb)
* Sample data
Expand Down
12 changes: 1 addition & 11 deletions lib/hammer_cli_csv.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# Copyright 2013-2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require 'hammer_cli'
require 'hammer_cli/exit_codes'

Expand Down Expand Up @@ -45,6 +34,7 @@ module HammerCLICsv
require 'hammer_cli_csv/puppet_reports'
require 'hammer_cli_csv/reports'
require 'hammer_cli_csv/roles'
require 'hammer_cli_csv/settings'
require 'hammer_cli_csv/smart_proxies'
require 'hammer_cli_csv/splice'
require 'hammer_cli_csv/subnets'
Expand Down
21 changes: 4 additions & 17 deletions lib/hammer_cli_csv/activation_keys.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
# Copyright 2013-2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

module HammerCLICsv
class CsvCommand
class ActivationKeysCommand < BaseCommand
command_name 'activation-keys'
desc _('import or export activation keys')

option %w(--organization), 'ORGANIZATION', _('Only process organization matching this name')

ORGANIZATION = 'Organization'
DESCRIPTION = 'Description'
LIMIT = 'Limit'
Expand All @@ -26,7 +13,7 @@ class ActivationKeysCommand < BaseCommand
SUBSCRIPTIONS = 'Subscriptions'

def export
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
csv << [NAME, COUNT, ORGANIZATION, DESCRIPTION, LIMIT, ENVIRONMENT, CONTENTVIEW,
HOSTCOLLECTIONS, SUBSCRIPTIONS]
if @server_status['release'] == 'Headpin'
Expand Down Expand Up @@ -146,9 +133,9 @@ def update_groups(activationkey, line)
if line[HOSTCOLLECTIONS] && line[HOSTCOLLECTIONS] != ''
# TODO: note that existing system groups are not removed
CSV.parse_line(line[HOSTCOLLECTIONS], {:skip_blanks => true}).each do |name|
@api.resource(:host_collections).call(:add_activation_keys, {
'id' => katello_hostcollection(line[ORGANIZATION], :name => name),
'activation_key_ids' => [activationkey['id']]
@api.resource(:activation_keys).call(:add_host_collections, {
'id' => activationkey['id'],
'host_collection_ids' => [katello_hostcollection(line[ORGANIZATION], :name => name)]
})
end
end
Expand Down
38 changes: 4 additions & 34 deletions lib/hammer_cli_csv/architectures.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
# Copyright 2013-2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

#
# -= Architectures CSV =-
#
# Columns
# Name
# - Architecture name
# - May contain '%d' which will be replaced with current iteration number of Count
# - eg. "os%d" -> "os1"
# Count
# - Number of times to iterate on this line of the CSV file
#

require 'hammer_cli'
require 'json'
require 'csv'

module HammerCLICsv
class CsvCommand
class ArchitecturesCommand < BaseCommand
Expand All @@ -34,16 +7,13 @@ class ArchitecturesCommand < BaseCommand
OPERATINGSYSTEMS = 'Operating Systems'

def export
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
csv << [NAME, COUNT, ORGANIZATIONS, OPERATINGSYSTEMS]
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
csv << [NAME, COUNT, OPERATINGSYSTEMS]
@api.resource(:architectures).call(:index, {:per_page => 999999})['results'].each do |architecture|
architecture = @api.resource(:architectures).call(:show, {:id => architecture['id']})
name = architecture['name']
count = 1
# TODO: http://projects.theforeman.org/issues/4198
#operatingsystems = architecture['operatingsystem_ids'].collect do |operatingsystem_id|
# foreman_operatingsystem(:id => operatingsystem_id)
#end.join(',')
operatingsystems = ''
operatingsystems = export_column(architecture, 'operatingsystems', 'title')
csv << [name, count, operatingsystems]
end
end
Expand Down
50 changes: 35 additions & 15 deletions lib/hammer_cli_csv/base.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# Copyright 2013-2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require 'apipie-bindings'
require 'hammer_cli'
require 'json'
Expand All @@ -20,9 +9,18 @@ module HammerCLICsv
class BaseCommand < HammerCLI::Apipie::Command
option %w(-v --verbose), :flag, 'be verbose'
option %w(--threads), 'THREAD_COUNT', 'Number of threads to hammer with', :default => 1
option %w(--csv-export), :flag, 'Export current data instead of importing'
option %w(--csv-file), 'FILE_NAME', 'CSV file (default to /dev/stdout with --csv-export, otherwise required)'
option %w(--export), :flag, 'Export current data instead of importing'
option %w(--file), 'FILE_NAME', 'CSV file (default to /dev/stdout with --csv-export, otherwise required)'
option %w(--prefix), 'PREFIX', 'Prefix for all name columns'
option %w(--organization), 'ORGANIZATION', _('Only process organization matching this name')

option %w(--csv-file), 'FILE_NAME', 'Option --csv-file is deprecated. Use --file',
:deprecated => "Use --file", :hidden => true,
:attribute_name => :option_file
option %w(--csv-export), :flag, 'Option --csv-export is deprecated. Use --export',
:deprecated => "Use --export", :hidden => true,
:attribute_name => :option_export


NAME = 'Name'
COUNT = 'Count'
Expand Down Expand Up @@ -58,7 +56,7 @@ def execute
})
end

option_csv_export? ? export : import
option_export? ? export : import
HammerCLI::EX_OK
end

Expand Down Expand Up @@ -105,7 +103,7 @@ def labelize(name)
end

def thread_import(return_headers = false, filename=nil, name_column=nil)
filename ||= option_csv_file || '/dev/stdin'
filename ||= option_file || '/dev/stdin'
csv = []
CSV.foreach(filename, {
:skip_blanks => true,
Expand Down Expand Up @@ -804,6 +802,28 @@ def associate_locations(id, locations, name)
end if locations && !locations.empty?
end

def apipie_check_param(resource, action, name)
method = @api.resource(pluralize(resource).to_sym).apidoc[:methods].detect do |api_method|
api_method[:name] == action.to_s
end
return false unless method

found = method[:params].detect do |param|
param[:full_name] == name
end
if !found
nested = method[:params].detect do |param|
param[:name] == resource.to_s
end
if nested
found = nested[:params].detect do |param|
param[:full_name] == name
end
end
end
found
end

private

def search_string(resource, name)
Expand Down
18 changes: 1 addition & 17 deletions lib/hammer_cli_csv/compute_profiles.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
# Copyright 2013-2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require 'hammer_cli'
require 'json'
require 'csv'

# TODO: waiting for https://github.com/theforeman/foreman/pull/1326

module HammerCLICsv
class CsvCommand
class ComputeProfilesCommand < BaseCommand
Expand All @@ -28,7 +12,7 @@ class ComputeProfilesCommand < BaseCommand
URL = 'URL'

def export
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
csv << [NAME, COUNT, ORGANIZATIONS, LOCATIONS, DESCRIPTION, PROVIDER, URL]
@api.resource(:compute_profiles).call(:index, {:per_page => 999999})['results'].each do |compute_profile|
puts compute_profile
Expand Down
13 changes: 1 addition & 12 deletions lib/hammer_cli_csv/compute_resources.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# Copyright 2013-2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require 'hammer_cli'
require 'json'
require 'csv'
Expand All @@ -26,7 +15,7 @@ class ComputeResourcesCommand < BaseCommand
URL = 'URL'

def export
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
csv << [NAME, COUNT, ORGANIZATIONS, LOCATIONS, DESCRIPTION, PROVIDER, URL]
@api.resource(:compute_resources).call(:index, {:per_page => 999999})['results'].each do |compute_resource|
compute_resource = @api.resource(:compute_resources).call(:show, {'id' => compute_resource['id']})
Expand Down
17 changes: 2 additions & 15 deletions lib/hammer_cli_csv/content_hosts.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# Copyright 2013-2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

module HammerCLICsv
class CsvCommand
class ContentHostsCommand < BaseCommand
Expand All @@ -17,8 +6,6 @@ class ContentHostsCommand < BaseCommand
command_name 'content-hosts'
desc 'import or export content hosts'

option %w(--organization), 'ORGANIZATION', 'Only process organization matching this name'

ORGANIZATION = 'Organization'
ENVIRONMENT = 'Environment'
CONTENTVIEW = 'Content View'
Expand All @@ -35,7 +22,7 @@ class ContentHostsCommand < BaseCommand
SUBSCRIPTIONS = 'Subscriptions'

def export
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
csv << [NAME, COUNT, ORGANIZATION, ENVIRONMENT, CONTENTVIEW, HOSTCOLLECTIONS, VIRTUAL, HOST,
OPERATINGSYSTEM, ARCHITECTURE, SOCKETS, RAM, CORES, SLA, PRODUCTS, SUBSCRIPTIONS]
if @server_status['release'] == 'Headpin'
Expand Down Expand Up @@ -164,7 +151,7 @@ def import
end

def import_remotely
params = {'content' => ::File.new(::File.expand_path(option_csv_file), 'rb')}
params = {'content' => ::File.new(::File.expand_path(option_file), 'rb')}
headers = {:content_type => 'multipart/form-data', :multipart => true}
task_progress(@api.resource(:csv).call(:import_content_hosts, params, headers))
end
Expand Down
15 changes: 1 addition & 14 deletions lib/hammer_cli_csv/content_view_filters.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# Copyright 2013-2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

# NOTE:
# rpm -qa --queryformat "%{NAME}|=|%{VERSION}-%{RELEASE},"

Expand All @@ -18,8 +7,6 @@ class ContentViewFiltersCommand < BaseCommand
command_name 'content-view-filters'
desc 'import or export content-view-filters'

option %w(--organization), 'ORGANIZATION', 'Only process organization matching this name'

CONTENTVIEW = 'Content View'
ORGANIZATION = 'Organization'
DESCRIPTION = 'Description'
Expand All @@ -28,7 +15,7 @@ class ContentViewFiltersCommand < BaseCommand
RULES = 'Rules'

def export
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
csv << [NAME, COUNT, CONTENTVIEW, ORGANIZATION, TYPE, DESCRIPTION, REPOSITORIES, RULES]
@api.resource(:organizations).call(:index, {
:per_page => 999999
Expand Down
Loading

0 comments on commit 088e085

Please sign in to comment.