Class: HammerCLICsv::CsvCommand::SyncPlansCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLICsv::CsvCommand::SyncPlansCommand
- Defined in:
- lib/hammer_cli_csv/sync_plans.rb
Constant Summary collapse
- ORGANIZATION =
'Organization'
- DESCRIPTION =
'Description'
- ENABLED =
'Enabled'
- STARTDATE =
'Start Date'
- INTERVAL =
'Interval'
- PRODUCTS =
'Products'
Constants inherited from BaseCommand
BaseCommand::COUNT, BaseCommand::NAME
Instance Method Summary collapse
Methods inherited from BaseCommand
#apipie_check_param, #associate_locations, #associate_organizations, #build_os_name, #check_server_status, #collect_column, #count, #execute, #export_column, #foreman_architecture, #foreman_container, #foreman_domain, #foreman_environment, #foreman_filter, #foreman_host, #foreman_hostgroup, #foreman_location, #foreman_medium, #foreman_operatingsystem, #foreman_organization, #foreman_partitiontable, #foreman_permission, #foreman_provisioning_template, #foreman_role, #foreman_smart_proxy, #foreman_template_kind, #hammer, #hammer_context, #help, #katello_contentview, #katello_contentviewversion, #katello_hostcollection, #katello_product, #katello_repository, #labelize, #lifecycle_environment, #namify, #pluralize, #split_os_name, #supported?, supported?, #thread_import
Methods included from Utils::Config
#api_connection, #credentials, #resource_config
Instance Method Details
#create_content_hosts_from_csv(line) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/hammer_cli_csv/sync_plans.rb', line 50 def create_content_hosts_from_csv(line) return if option_organization && line[ORGANIZATION] != option_organization if !@existing[line[ORGANIZATION]] @existing[line[ORGANIZATION]] = {} @api.resource(:sync_plans).call(:index, { 'per_page' => 999999, 'organization_id' => foreman_organization(:name => line[ORGANIZATION]) })['results'].each do |sync_plan| @existing[line[ORGANIZATION]][sync_plan['name']] = sync_plan['id'] end end count(line[COUNT]).times do |number| name = namify(line[NAME], number) if !@existing[line[ORGANIZATION]].include? name print "Creating sync plan '#{name}'..." if option_verbose? @api.resource(:sync_plans).call(:create, { 'organization_id' => foreman_organization(:name => line[ORGANIZATION]), 'name' => name, 'description' => line[DESCRIPTION], 'enabled' => line[ENABLED] == 'Yes' ? true : false, 'sync_date' => line[STARTDATE], 'interval' => line[INTERVAL], 'products' => products(line) }) else print "Updating sync plan '#{name}'..." if option_verbose? # TODO # @api.resource(:host_collections).call(:update, { # 'organization_id' => line[ORGANIZATION], # 'id' => @existing[line[ORGANIZATION]][name], # 'name' => name, # 'max_systems' => (line[LIMIT] == 'Unlimited') ? -1 : line[LIMIT], # 'description' => line[DESCRIPTION] # }) end puts "done" if option_verbose? end end |
#export(csv) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hammer_cli_csv/sync_plans.rb', line 14 def export(csv) csv << [NAME, ORGANIZATION, DESCRIPTION, ENABLED, STARTDATE, INTERVAL, PRODUCTS] @api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization| next if option_organization && organization['name'] != option_organization @api.resource(:sync_plans).call(:index, { 'per_page' => 999999, 'organization_id' => foreman_organization(:name => organization['name']) })['results'].each do |sync_plan| name = sync_plan['name'] organization_name = organization['name'] description = sync_plan['description'] enabled = sync_plan['enabled'] ? 'Yes' : 'No' start_date = sync_plan['sync_date'] interval = sync_plan['interval'] products = CSV.generate do |column| column << sync_plan['products'].collect do |product| product['name'] end end products.delete!("\n") csv << [name, organization_name, description, enabled, start_date, interval, products] end end end |
#import ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/hammer_cli_csv/sync_plans.rb', line 42 def import @existing = {} thread_import do |line| create_content_hosts_from_csv(line) end end |