Skip to content

Commit

Permalink
cv-updates - a lot of updates and clean up
Browse files Browse the repository at this point in the history
+ GPLv2 in files
+ updated to new dynamic apipie bindings
+ fixed domain and puppet environments associating to organizations
  • Loading branch information
Tom McKay committed Mar 20, 2014
1 parent 6130dbe commit 587327f
Show file tree
Hide file tree
Showing 32 changed files with 781 additions and 1,368 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ pickle-email-*.html
.project
config/initializers/secret_token.rb
test/data/*.zip
test/config.yml
test/config.yml
.ruby-version
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ source "https://rubygems.org"

gemspec


gem 'hammer_cli', :path => "../hammer-cli"
gem 'foreman_api', :path => "../foreman_api"
gem 'katello_api', :path => "../katello_api"
gem 'hammer_cli_foreman', :path => "../hammer-cli-foreman"
gem 'hammer_cli_katello', :path => "../hammer-cli-katello"
gem 'hammer_cli_foreman_tasks', :path => "../hammer-cli-foreman-tasks"
Expand Down
899 changes: 282 additions & 617 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions hammer_cli_csv.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ Gem::Specification.new do |spec|
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")

spec.add_dependency("hammer_cli")
spec.add_dependency("katello_api")
spec.add_dependency("foreman_api")
end
11 changes: 11 additions & 0 deletions lib/hammer_cli_csv.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 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
81 changes: 34 additions & 47 deletions lib/hammer_cli_csv/activation_keys.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
# Copyright (c) 2013-2014 Red Hat
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# 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.

#
# -= Activation Key CSV =-
#
Expand All @@ -37,7 +25,6 @@
#

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

Expand All @@ -56,10 +43,10 @@ def export
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
csv << [NAME, COUNT, ORGANIZATION, DESCRIPTION, LIMIT, ENVIRONMENT, CONTENTVIEW,
SYSTEMGROUPS, SUBSCRIPTIONS]
@k_organization_api.index({:per_page => 999999})[0]['results'].each do |organization|
@k_activationkey_api.index({'per_page' => 999999,
@api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization|
@api.resource(:activationkeys).call(:index, {'per_page' => 999999,
'organization_id' => organization['label']
})[0]['results'].each do |activationkey|
})['results'].each do |activationkey|
puts "Writing activation key '#{activationkey['name']}'" if option_verbose?
name = namify(activationkey['name'])
count = 1
Expand All @@ -73,9 +60,9 @@ def export
end
end.delete!("\n") if activationkey['systemGroups']
subscriptions = CSV.generate do |column|
column << @k_subscription_api.index({
column << @api.resource(:subscriptions).call(:index, {
'activation_key_id' => activationkey['id']
})[0]['results'].collect do |subscription|
})['results'].collect do |subscription|
amount = subscription['amount'] == 0 ? 'Automatic' : subscription['amount']
"#{amount}|#{subscription['product_name']}"
end
Expand All @@ -98,10 +85,10 @@ def import
def create_activationkeys_from_csv(line)
if !@existing[line[ORGANIZATION]]
@existing[line[ORGANIZATION]] = {}
@k_activationkey_api.index({
@api.resource(:activationkeys).call(:index, {
'per_page' => 999999,
'organization_id' => katello_organization(:name => line[ORGANIZATION])
})[0]['results'].each do |activationkey|
})['results'].each do |activationkey|
@existing[line[ORGANIZATION]][activationkey['name']] = activationkey['id'] if activationkey
end
end
Expand All @@ -111,26 +98,26 @@ def create_activationkeys_from_csv(line)

if !@existing[line[ORGANIZATION]].include? name
print "Creating activation key '#{name}'..." if option_verbose?
activationkey = @k_activationkey_api.create({
activationkey = @api.resource(:activationkeys).call(:create, {
'name' => name,
'environment_id' => katello_environment(line[ORGANIZATION],
:name => line[ENVIRONMENT]),
'content_view_id' => katello_contentview(line[ORGANIZATION],
:name => line[CONTENTVIEW]),
'description' => line[DESCRIPTION]
})[0]
})
@existing[line[ORGANIZATION]][activationkey['name']] = activationkey['id']
else
print "Updating activation key '#{name}'..." if option_verbose?
activationkey = @k_activationkey_api.update({
activationkey = @api.resource(:activationkeys).call(:update, {
'id' => @existing[line[ORGANIZATION]][name],
'name' => name,
'environment_id' => katello_environment(line[ORGANIZATION],
:name => line[ENVIRONMENT]),
'content_view_id' => katello_contentview(line[ORGANIZATION],
:name => line[CONTENTVIEW]),
'description' => line[DESCRIPTION]
})[0]
})
end

update_subscriptions(activationkey, line)
Expand All @@ -144,7 +131,7 @@ def update_groups(activationkey, line)
if line[SYSTEMGROUPS] && line[SYSTEMGROUPS] != ''
# TODO: note that existing system groups are not removed
CSV.parse_line(line[SYSTEMGROUPS], {:skip_blanks => true}).each do |name|
@k_systemgroup_api.add_activation_keys({
@api.resource(:systemgroups).call(:add_activation_keys, {
'id' => katello_systemgroup(line[ORGANIZATION], :name => name),
'activation_key_ids' => [activationkey['id']]
})
Expand All @@ -166,20 +153,20 @@ def update_subscriptions(activationkey, line)
end

# TODO: should there be a destroy_all similar to systems?
@k_subscription_api.index({
'per_page' => 999999,
'activation_key_id' => activationkey['id']
})[0]['results'].each do |subscription|
@k_subscription_api.destroy({
'id' => subscription['id'],
'activation_key_id' => activationkey['id']
})
@api.resource(:subscriptions).call(:index, {
'per_page' => 999999,
'activation_key_id' => activationkey['id']
})['results'].each do |subscription|
@api.resource(:subscriptions).call(:destroy, {
'id' => subscription['id'],
'activation_key_id' => activationkey['id']
})
end

@k_subscription_api.create({
'activation_key_id' => activationkey['id'],
'subscriptions' => subscriptions
})
@api.resource(:subscriptions).call(:create, {
'activation_key_id' => activationkey['id'],
'subscriptions' => subscriptions
})
end
end

Expand Down
41 changes: 14 additions & 27 deletions lib/hammer_cli_csv/architectures.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
# Copyright (c) 2013-2014 Red Hat
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# 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 =-
#
Expand All @@ -34,7 +22,6 @@
#

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

Expand All @@ -46,7 +33,7 @@ class ArchitecturesCommand < BaseCommand
def export
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
csv << [NAME, COUNT, ORGANIZATIONS, OPERATINGSYSTEMS]
@f_architecture_api.index({:per_page => 999999})[0]['results'].each do |architecture|
@api.resource(:architectures).call(:index, {:per_page => 999999})['results'].each do |architecture|
name = architecture['name']
count = 1
# TODO: http://projects.theforeman.org/issues/4198
Expand All @@ -61,7 +48,7 @@ def export

def import
@existing = {}
@f_architecture_api.index({:per_page => 999999})[0]['results'].each do |architecture|
@api.resource(:architectures).call(:index, {:per_page => 999999})['results'].each do |architecture|
@existing[architecture['name']] = architecture['id'] if architecture
end

Expand All @@ -79,15 +66,15 @@ def create_architectures_from_csv(line)
end
if !architecture_id
print "Creating architecture '#{name}'..." if option_verbose?
architecture_id = @f_architecture_api.create({
architecture_id = @api.resource(:architectures).call(:create, {
'architecture' => {
'name' => name,
'operatingsystem_ids' => operatingsystem_ids
}
})
else
print "Updating architecture '#{name}'..." if option_verbose?
@f_architecture_api.update({
@api.resource(:architectures).call(:update, {
'id' => architecture_id,
'architecture' => {
'name' => name,
Expand Down
Loading

0 comments on commit 587327f

Please sign in to comment.