Class: HammerCLICsv::CsvCommand::OrganizationsCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLICsv::CsvCommand::OrganizationsCommand
- Defined in:
- lib/hammer_cli_csv/organizations.rb
Constant Summary collapse
- LABEL =
'Label'
- DESCRIPTION =
'Description'
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_organizations_from_csv(line) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hammer_cli_csv/organizations.rb', line 37 def create_organizations_from_csv(line) count(line[COUNT]).times do |number| name = namify(line[NAME], number) return if option_organization && name != option_organization label = namify(line[LABEL], number) organization_id = @existing[name] if organization_id.nil? print "Creating organization '#{name}'... " if option_verbose? @api.resource(:organizations).call(:create, { 'name' => name, 'organization' => { 'name' => name, 'label' => label, 'description' => line[DESCRIPTION] } }) else print "Updating organization '#{name}'... " if option_verbose? organization = @api.resource(:organizations).call(:show, {'id' => organization_id}) @api.resource(:organizations).call(:update, { 'id' => organization_id, 'organization' => { 'id' => organization_id, 'description' => line[DESCRIPTION] } }) end print "done\n" if option_verbose? end end |
#export(csv) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hammer_cli_csv/organizations.rb', line 10 def export(csv) csv << [NAME, LABEL, DESCRIPTION] if @server_status['release'] == 'Headpin' @headpin.get(:organizations).each do |organization| next if option_organization && organization['name'] != option_organization csv << [organization['name'], organization['label'], organization['description']] end else @api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization| next if option_organization && organization['name'] != option_organization csv << [organization['name'], organization['label'], organization['description']] end end end |
#import ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hammer_cli_csv/organizations.rb', line 26 def import @existing = {} @api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization| @existing[organization['name']] = organization['id'] if organization end thread_import do |line| create_organizations_from_csv(line) end end |