Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

fixes #15743 - import and export of subscriptions one-per-line #117

Merged
merged 1 commit into from
Aug 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ def clear_cassettes
print "Cassettes cleared\n"
end

# Rake::TestTask.new do |t|
# t.libs << "lib"
# t.test_files = Dir['test/setup_test.rb'] + Dir.glob('test/**/*_test.rb')
# t.verbose = true
# end

namespace :test do
[:resources].each do |task_name|
%w(setup resources).each do |task_name|
desc "Runs the #{task_name} tests"
task task_name do
options = {}
Expand Down Expand Up @@ -73,6 +67,7 @@ end

desc 'Runs all tests'
task :test do
Rake::Task['test:setup'].invoke
Rake::Task['test:resources'].invoke
end

Expand Down
68 changes: 33 additions & 35 deletions lib/hammer_cli_csv/activation_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,41 @@ class ActivationKeysCommand < BaseCommand
AUTOATTACH = "Auto-Attach"
SUBSCRIPTIONS = 'Subscriptions'

def export
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
csv << [NAME, ORGANIZATION, DESCRIPTION, LIMIT, ENVIRONMENT, CONTENTVIEW,
HOSTCOLLECTIONS, AUTOATTACH, SERVICELEVEL, RELEASEVER, SUBSCRIPTIONS]
@api.resource(:organizations).call(:index, {
:per_page => 999999
})['results'].each do |organization|
next if option_organization && organization['name'] != option_organization

@api.resource(:activation_keys).call(:index, {
'per_page' => 999999,
'organization_id' => organization['id']
})['results'].each do |activationkey|
name = namify(activationkey['name'])
count = 1
description = activationkey['description']
limit = activationkey['unlimited_content_hosts'] ? 'Unlimited' : activationkey['max_content_hosts']
environment = activationkey['environment']['label']
contentview = activationkey['content_view']['name']
hostcollections = export_column(activationkey, 'host_collections', 'name')
autoattach = activationkey['auto_attach'] ? 'Yes' : 'No'
servicelevel = activationkey['service_level']
releasever = activationkey['release_version']
subscriptions = CSV.generate do |column|
column << @api.resource(:subscriptions).call(:index, {
'organization_id' => organization['id'],
'activation_key_id' => activationkey['id']
})['results'].collect do |subscription|
amount = subscription['amount'] == 0 ? 'Automatic' : subscription['amount']
sku = subscription['product_id'].match(/\A[0-9]/) ? 'Custom' : subscription['product_id']
"#{amount}|#{sku}|#{subscription['product_name']}"
end
def export(csv)
csv << [NAME, ORGANIZATION, DESCRIPTION, LIMIT, ENVIRONMENT, CONTENTVIEW,
HOSTCOLLECTIONS, AUTOATTACH, SERVICELEVEL, RELEASEVER, SUBSCRIPTIONS]
@api.resource(:organizations).call(:index, {
:per_page => 999999
})['results'].each do |organization|
next if option_organization && organization['name'] != option_organization

@api.resource(:activation_keys).call(:index, {
'per_page' => 999999,
'organization_id' => organization['id']
})['results'].each do |activationkey|
name = namify(activationkey['name'])
count = 1
description = activationkey['description']
limit = activationkey['unlimited_content_hosts'] ? 'Unlimited' : activationkey['max_content_hosts']
environment = activationkey['environment']['label']
contentview = activationkey['content_view']['name']
hostcollections = export_column(activationkey, 'host_collections', 'name')
autoattach = activationkey['auto_attach'] ? 'Yes' : 'No'
servicelevel = activationkey['service_level']
releasever = activationkey['release_version']
subscriptions = CSV.generate do |column|
column << @api.resource(:subscriptions).call(:index, {
'organization_id' => organization['id'],
'activation_key_id' => activationkey['id']
})['results'].collect do |subscription|
amount = subscription['amount'] == 0 ? 'Automatic' : subscription['amount']
sku = subscription['product_id'].match(/\A[0-9]/) ? 'Custom' : subscription['product_id']
"#{amount}|#{sku}|#{subscription['product_name']}"
end
subscriptions.delete!("\n")
csv << [name, count, organization['name'], description, limit, environment, contentview,
hostcollections, servicelevel, releasever, autoattach, subscriptions]
end
subscriptions.delete!("\n")
csv << [name, count, organization['name'], description, limit, environment, contentview,
hostcollections, servicelevel, releasever, autoattach, subscriptions]
end
end
end
Expand Down
16 changes: 7 additions & 9 deletions lib/hammer_cli_csv/architectures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ class ArchitecturesCommand < BaseCommand

OPERATINGSYSTEMS = 'Operating Systems'

def export
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
csv << [NAME, 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']
operatingsystems = export_column(architecture, 'operatingsystems', 'title')
csv << [name, operatingsystems]
end
def export(csv)
csv << [NAME, 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']
operatingsystems = export_column(architecture, 'operatingsystems', 'title')
csv << [name, operatingsystems]
end
end

Expand Down
14 changes: 13 additions & 1 deletion lib/hammer_cli_csv/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,19 @@ def execute
})
end

option_export? ? export : import
if option_export?
if option_file
CSV.open(option_file, 'wb', {:force_quotes => false}) do |csv|
export csv
end
else
CSV do |csv|
export csv
end
end
else
import
end
HammerCLI::EX_OK
end

Expand Down
24 changes: 11 additions & 13 deletions lib/hammer_cli_csv/compute_profiles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ class ComputeProfilesCommand < BaseCommand
URL = 'URL'

def export
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
csv << [NAME, ORGANIZATIONS, LOCATIONS, DESCRIPTION, PROVIDER, URL]
@api.resource(:compute_profiles).call(:index, {:per_page => 999999})['results'].each do |compute_profile|
puts compute_profile
compute_profile = @api.resource(:compute_profiles).call(:show, {'id' => compute_profile['id']})
name = compute_profile['name']
organizations = export_column(compute_profile, 'organizations', 'name')
locations = export_column(compute_profile, 'locations', 'name')
description = compute_profile['description']
provider = compute_profile['provider']
url = compute_profile['url']
csv << [name, organizations, locations, description, provider, url]
end
csv << [NAME, ORGANIZATIONS, LOCATIONS, DESCRIPTION, PROVIDER, URL]
@api.resource(:compute_profiles).call(:index, {:per_page => 999999})['results'].each do |compute_profile|
puts compute_profile
compute_profile = @api.resource(:compute_profiles).call(:show, {'id' => compute_profile['id']})
name = compute_profile['name']
organizations = export_column(compute_profile, 'organizations', 'name')
locations = export_column(compute_profile, 'locations', 'name')
description = compute_profile['description']
provider = compute_profile['provider']
url = compute_profile['url']
csv << [name, organizations, locations, description, provider, url]
end
end

Expand Down
24 changes: 11 additions & 13 deletions lib/hammer_cli_csv/compute_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ class ComputeResourcesCommand < BaseCommand
PROVIDER = 'Provider'
URL = 'URL'

def export
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
csv << [NAME, 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']})
def export(csv)
csv << [NAME, 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']})

name = compute_resource['name']
organizations = export_column(compute_resource, 'organizations', 'name')
locations = export_column(compute_resource, 'locations', 'name')
description = compute_resource['description']
provider = compute_resource['provider']
url = compute_resource['url']
csv << [name, organizations, locations, description, provider, url]
end
name = compute_resource['name']
organizations = export_column(compute_resource, 'organizations', 'name')
locations = export_column(compute_resource, 'locations', 'name')
description = compute_resource['description']
provider = compute_resource['provider']
url = compute_resource['url']
csv << [name, organizations, locations, description, provider, url]
end
end

Expand Down
22 changes: 10 additions & 12 deletions lib/hammer_cli_csv/containers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ class ContainersCommand < BaseCommand
ENTRYPOINT = 'Entry Point'
COMMAND = 'Command'

def export
CSV.open(option_file || '/dev/stdout', 'wb') do |csv|
csv << [NAME, REGISTRY, REPOSITORY, COMPUTERESOURCE, ATTACH, ENTRYPOINT, COMMAND]
@api.resource(:containers).call(:index, {'per_page' => 999999})['results'].each do |container|
csv << [container['name'],
container['registry_name'],
"#{container['repository_name']}:#{container['tag']}",
container['compute_resource_name'],
export_attach_types(container),
container['entrypoint'],
container['command']]
end
def export(csv)
csv << [NAME, REGISTRY, REPOSITORY, COMPUTERESOURCE, ATTACH, ENTRYPOINT, COMMAND]
@api.resource(:containers).call(:index, {'per_page' => 999999})['results'].each do |container|
csv << [container['name'],
container['registry_name'],
"#{container['repository_name']}:#{container['tag']}",
container['compute_resource_name'],
export_attach_types(container),
container['entrypoint'],
container['command']]
end
end

Expand Down
Loading