{"action":"created","comment":{"url":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/comments/59249522","id":59249522,"diff_hunk":"@@ -45,66 +47,76 @@ def export\n             realm = hostgroup['realm_name']\n             puppet_proxy = hostgroup['puppet_proxy_id'] ? foreman_host(:id => hostgroup['puppet_proxy_id']) : nil\n             puppet_ca_proxy = hostgroup['puppet_ca_proxy_id'] ? foreman_host(:id => hostgroup['puppet_ca_proxy_id']) : nil\n-            # TODO: http://projects.theforeman.org/issues/7597\n-            # content_source = hostgroup['content_source_id'] ? foreman_host(:id => hostgroup['content_source_id']) : nil\n-            content_source = nil\n+            content_source = hostgroup['content_source_id'] ? foreman_host(:id => hostgroup['content_source_id']) : nil\n             parent = hostgroup['ancestry'] ? foreman_hostgroup(:id => hostgroup['ancestry']) : nil\n+            password = nil\n+            puppet_classes = export_column(hostgroup, 'puppetclasses') do |puppet_class|\n+              \"#{puppet_class['module_name']}/#{puppet_class['name']}\"\n+            end\n+\n+            # TODO: http://projects.theforeman.org/issues/6273\n+            # API call to get the smart class variable override values\n \n             csv << [name, parent, organizations, locations, subnet, domain, operating_system,\n                     puppet_environment, compute_profile, partition_table, medium, architecture,\n-                    realm, puppet_proxy, puppet_ca_proxy, content_source]\n+                    realm, puppet_proxy, puppet_ca_proxy, content_source, password, puppet_classes]\n           end\n         end\n       end\n \n       def import\n         @existing = {}\n-        @api.resource(:hostgroups).call(:index, {:per_page => 999999})['results'].each do |host|\n-          @existing[host['name']] = host['id'] if host\n+        @api.resource(:hostgroups).call(:index, {:per_page => 999999})['results'].each do |host_group|\n+          @existing[host_group['name']] = host_group['id'] if host_group\n         end\n \n         thread_import do |line|\n-          create_hosts_from_csv(line)\n+          create_from_csv(line)\n         end\n       end\n \n-      def create_hosts_from_csv(line)\n+      def create_from_csv(line)\n         return if option_organization && !CSV.parse_line(line[ORGANIZATIONS], {:skip_blanks => true}).include?(option_organization)\n \n+        params = {\n+          'hostgroup' => {\n+            'architecture_id' => foreman_architecture(:name => line[ARCHITECTURE]),\n+            'operatingsystem_id' => foreman_operatingsystem(:name => line[OPERATING_SYSTEM]),\n+            'medium_id' => foreman_medium(:name => line[MEDIUM]),\n+            'ptable_id' => foreman_partitiontable(:name => line[PARTITION_TABLE]),\n+            'root_pass' => line[PASSWORD],\n+            'organization_ids' => collect_column(line[ORGANIZATIONS]) do |organization|\n+              foreman_organization(:name => organization)\n+            end,\n+            'location_ids' => collect_column(line[LOCATIONS]) do |location|\n+              foreman_location(:name => location)\n+            end\n+          }\n+        }\n+\n         count(line[COUNT]).times do |number|\n           name = namify(line[NAME], number)\n+          params['hostgroup']['name'] = name\n+\n           if !@existing.include? name\n             print \"Creating host group '#{name}'...\" if option_verbose?\n-            # @api.resource(:hosts).call(:create, {\n-            #     'host' => {\n-            #       'name' => name,\n-            #       'root_pass' => 'changeme',\n-            #       'mac' => namify(line[MACADDRESS], number),\n-            #       'organization_id' => foreman_organization(:name => line[ORGANIZATION]),\n-            #       'location_id' => foreman_location(:name => line[LOCATION]),\n-            #       'environment_id' => foreman_environment(:name => line[ENVIRONMENT]),\n-            #       'operatingsystem_id' => foreman_operatingsystem(:name => line[OPERATINGSYSTEM]),\n-            #       'architecture_id' => foreman_architecture(:name => line[ARCHITECTURE]),\n-            #       'domain_id' => foreman_domain(:name => line[DOMAIN]),\n-            #       'ptable_id' => foreman_partitiontable(:name => line[PARTITIONTABLE])\n-            #     }\n-            # })\n+            hostgroup = @api.resource(:hostgroups).call(:create, params)\n+            @existing[name] = hostgroup['id']\n           else\n             print \"Updating host '#{name}'...\" if option_verbose?\n-            # @api.resource(:hosts).call(:update, {\n-            #     'id' => @existing[name],\n-            #     'host' => {\n-            #       'name' => name,\n-            #       'mac' => namify(line[MACADDRESS], number),\n-            #       'organization_id' => foreman_organization(:name => line[ORGANIZATION]),\n-            #       'environment_id' => foreman_environment(:name => line[ENVIRONMENT]),\n-            #       'operatingsystem_id' => foreman_operatingsystem(:name => line[OPERATINGSYSTEM]),\n-            #       'architecture_id' => foreman_architecture(:name => line[ARCHITECTURE]),\n-            #       'domain_id' => foreman_domain(:name => line[DOMAIN]),\n-            #       'ptable_id' => foreman_partitiontable(:name => line[PARTITIONTABLE])\n-            #     }\n-            # })\n+            params['id'] = @existing[name]\n+            hostgroup = @api.resource(:hostgroups).call(:update, params)\n           end\n+\n+          # TODO: puppet classes\n+          puppetclass_ids = collect_column(line[PUPPET_CLASSES]) do |puppet_class|\n+            module_name, name = puppet_class.split('/')\n+            foreman_puppet_class(:name => name)\n+          end\n+          existing_ids = hostgroup['puppet_classes'].collect { |puppet_class| puppet_class['id'] }\n+          # DELETE existing_ids - puppetclass_ids\n+          # POST puppetclass_ids - existing_ids","path":"lib/hammer_cli_csv/host_groups.rb","position":123,"original_position":123,"commit_id":"1192ff19374a435aa2850d137c7ab96e726a523d","original_commit_id":"1192ff19374a435aa2850d137c7ab96e726a523d","user":{"login":"thomasmckay","id":338096,"avatar_url":"https://avatars.githubusercontent.com/u/338096?v=3","gravatar_id":"","url":"https://api.github.com/users/thomasmckay","html_url":"https://github.com/thomasmckay","followers_url":"https://api.github.com/users/thomasmckay/followers","following_url":"https://api.github.com/users/thomasmckay/following{/other_user}","gists_url":"https://api.github.com/users/thomasmckay/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasmckay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasmckay/subscriptions","organizations_url":"https://api.github.com/users/thomasmckay/orgs","repos_url":"https://api.github.com/users/thomasmckay/repos","events_url":"https://api.github.com/users/thomasmckay/events{/privacy}","received_events_url":"https://api.github.com/users/thomasmckay/received_events","type":"User","site_admin":false},"body":"Export/import host groups is pretty complicated and will remain in the \"unsupported\" category for a while. The TODO comment above will remain unfixed in this PR and the two comments are what needs to happen. I think. Not all the foreman APIs accept adding relationships versus fully resetting them.\r\n\r\ntl;dr - more work to do in future","created_at":"2016-04-11T17:51:02Z","updated_at":"2016-04-11T17:51:02Z","html_url":"https://github.com/Katello/hammer-cli-csv/pull/104#discussion_r59249522","pull_request_url":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/104","_links":{"self":{"href":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/comments/59249522"},"html":{"href":"https://github.com/Katello/hammer-cli-csv/pull/104#discussion_r59249522"},"pull_request":{"href":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/104"}}},"pull_request":{"url":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/104","id":64554653,"html_url":"https://github.com/Katello/hammer-cli-csv/pull/104","diff_url":"https://github.com/Katello/hammer-cli-csv/pull/104.diff","patch_url":"https://github.com/Katello/hammer-cli-csv/pull/104.patch","issue_url":"https://api.github.com/repos/Katello/hammer-cli-csv/issues/104","number":104,"state":"open","locked":false,"title":"fixes #14389 - import/export host groups","user":{"login":"thomasmckay","id":338096,"avatar_url":"https://avatars.githubusercontent.com/u/338096?v=3","gravatar_id":"","url":"https://api.github.com/users/thomasmckay","html_url":"https://github.com/thomasmckay","followers_url":"https://api.github.com/users/thomasmckay/followers","following_url":"https://api.github.com/users/thomasmckay/following{/other_user}","gists_url":"https://api.github.com/users/thomasmckay/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasmckay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasmckay/subscriptions","organizations_url":"https://api.github.com/users/thomasmckay/orgs","repos_url":"https://api.github.com/users/thomasmckay/repos","events_url":"https://api.github.com/users/thomasmckay/events{/privacy}","received_events_url":"https://api.github.com/users/thomasmckay/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-30T00:18:09Z","updated_at":"2016-04-11T17:51:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de0eeb774bf16f09a9a2dfc3f790f69137f9daa5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/104/commits","review_comments_url":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/104/comments","review_comment_url":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Katello/hammer-cli-csv/issues/104/comments","statuses_url":"https://api.github.com/repos/Katello/hammer-cli-csv/statuses/1192ff19374a435aa2850d137c7ab96e726a523d","head":{"label":"thomasmckay:hostgroup-export","ref":"hostgroup-export","sha":"1192ff19374a435aa2850d137c7ab96e726a523d","user":{"login":"thomasmckay","id":338096,"avatar_url":"https://avatars.githubusercontent.com/u/338096?v=3","gravatar_id":"","url":"https://api.github.com/users/thomasmckay","html_url":"https://github.com/thomasmckay","followers_url":"https://api.github.com/users/thomasmckay/followers","following_url":"https://api.github.com/users/thomasmckay/following{/other_user}","gists_url":"https://api.github.com/users/thomasmckay/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasmckay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasmckay/subscriptions","organizations_url":"https://api.github.com/users/thomasmckay/orgs","repos_url":"https://api.github.com/users/thomasmckay/repos","events_url":"https://api.github.com/users/thomasmckay/events{/privacy}","received_events_url":"https://api.github.com/users/thomasmckay/received_events","type":"User","site_admin":false},"repo":{"id":17438548,"name":"hammer-cli-csv","full_name":"thomasmckay/hammer-cli-csv","owner":{"login":"thomasmckay","id":338096,"avatar_url":"https://avatars.githubusercontent.com/u/338096?v=3","gravatar_id":"","url":"https://api.github.com/users/thomasmckay","html_url":"https://github.com/thomasmckay","followers_url":"https://api.github.com/users/thomasmckay/followers","following_url":"https://api.github.com/users/thomasmckay/following{/other_user}","gists_url":"https://api.github.com/users/thomasmckay/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasmckay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasmckay/subscriptions","organizations_url":"https://api.github.com/users/thomasmckay/orgs","repos_url":"https://api.github.com/users/thomasmckay/repos","events_url":"https://api.github.com/users/thomasmckay/events{/privacy}","received_events_url":"https://api.github.com/users/thomasmckay/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/thomasmckay/hammer-cli-csv","description":"","fork":true,"url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv","forks_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/forks","keys_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/teams","hooks_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/hooks","issue_events_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/issues/events{/number}","events_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/events","assignees_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/assignees{/user}","branches_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/branches{/branch}","tags_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/tags","blobs_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/git/refs{/sha}","trees_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/statuses/{sha}","languages_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/languages","stargazers_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/stargazers","contributors_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/contributors","subscribers_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/subscribers","subscription_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/subscription","commits_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/commits{/sha}","git_commits_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/git/commits{/sha}","comments_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/comments{/number}","issue_comment_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/issues/comments{/number}","contents_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/contents/{+path}","compare_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/merges","archive_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/downloads","issues_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/issues{/number}","pulls_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/pulls{/number}","milestones_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/milestones{/number}","notifications_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/labels{/name}","releases_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/releases{/id}","deployments_url":"https://api.github.com/repos/thomasmckay/hammer-cli-csv/deployments","created_at":"2014-03-05T11:22:07Z","updated_at":"2016-03-11T16:17:31Z","pushed_at":"2016-04-11T17:17:04Z","git_url":"git://github.com/thomasmckay/hammer-cli-csv.git","ssh_url":"git@github.com:thomasmckay/hammer-cli-csv.git","clone_url":"https://github.com/thomasmckay/hammer-cli-csv.git","svn_url":"https://github.com/thomasmckay/hammer-cli-csv","homepage":null,"size":732,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Katello:master","ref":"master","sha":"f37b38bebed231ba11a9b55f3c60bc7f028b8f64","user":{"login":"Katello","id":1316386,"avatar_url":"https://avatars.githubusercontent.com/u/1316386?v=3","gravatar_id":"","url":"https://api.github.com/users/Katello","html_url":"https://github.com/Katello","followers_url":"https://api.github.com/users/Katello/followers","following_url":"https://api.github.com/users/Katello/following{/other_user}","gists_url":"https://api.github.com/users/Katello/gists{/gist_id}","starred_url":"https://api.github.com/users/Katello/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Katello/subscriptions","organizations_url":"https://api.github.com/users/Katello/orgs","repos_url":"https://api.github.com/users/Katello/repos","events_url":"https://api.github.com/users/Katello/events{/privacy}","received_events_url":"https://api.github.com/users/Katello/received_events","type":"Organization","site_admin":false},"repo":{"id":14110969,"name":"hammer-cli-csv","full_name":"Katello/hammer-cli-csv","owner":{"login":"Katello","id":1316386,"avatar_url":"https://avatars.githubusercontent.com/u/1316386?v=3","gravatar_id":"","url":"https://api.github.com/users/Katello","html_url":"https://github.com/Katello","followers_url":"https://api.github.com/users/Katello/followers","following_url":"https://api.github.com/users/Katello/following{/other_user}","gists_url":"https://api.github.com/users/Katello/gists{/gist_id}","starred_url":"https://api.github.com/users/Katello/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Katello/subscriptions","organizations_url":"https://api.github.com/users/Katello/orgs","repos_url":"https://api.github.com/users/Katello/repos","events_url":"https://api.github.com/users/Katello/events{/privacy}","received_events_url":"https://api.github.com/users/Katello/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Katello/hammer-cli-csv","description":"Foretello data convenience utility: Import and export CSV data","fork":false,"url":"https://api.github.com/repos/Katello/hammer-cli-csv","forks_url":"https://api.github.com/repos/Katello/hammer-cli-csv/forks","keys_url":"https://api.github.com/repos/Katello/hammer-cli-csv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Katello/hammer-cli-csv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Katello/hammer-cli-csv/teams","hooks_url":"https://api.github.com/repos/Katello/hammer-cli-csv/hooks","issue_events_url":"https://api.github.com/repos/Katello/hammer-cli-csv/issues/events{/number}","events_url":"https://api.github.com/repos/Katello/hammer-cli-csv/events","assignees_url":"https://api.github.com/repos/Katello/hammer-cli-csv/assignees{/user}","branches_url":"https://api.github.com/repos/Katello/hammer-cli-csv/branches{/branch}","tags_url":"https://api.github.com/repos/Katello/hammer-cli-csv/tags","blobs_url":"https://api.github.com/repos/Katello/hammer-cli-csv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Katello/hammer-cli-csv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Katello/hammer-cli-csv/git/refs{/sha}","trees_url":"https://api.github.com/repos/Katello/hammer-cli-csv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Katello/hammer-cli-csv/statuses/{sha}","languages_url":"https://api.github.com/repos/Katello/hammer-cli-csv/languages","stargazers_url":"https://api.github.com/repos/Katello/hammer-cli-csv/stargazers","contributors_url":"https://api.github.com/repos/Katello/hammer-cli-csv/contributors","subscribers_url":"https://api.github.com/repos/Katello/hammer-cli-csv/subscribers","subscription_url":"https://api.github.com/repos/Katello/hammer-cli-csv/subscription","commits_url":"https://api.github.com/repos/Katello/hammer-cli-csv/commits{/sha}","git_commits_url":"https://api.github.com/repos/Katello/hammer-cli-csv/git/commits{/sha}","comments_url":"https://api.github.com/repos/Katello/hammer-cli-csv/comments{/number}","issue_comment_url":"https://api.github.com/repos/Katello/hammer-cli-csv/issues/comments{/number}","contents_url":"https://api.github.com/repos/Katello/hammer-cli-csv/contents/{+path}","compare_url":"https://api.github.com/repos/Katello/hammer-cli-csv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Katello/hammer-cli-csv/merges","archive_url":"https://api.github.com/repos/Katello/hammer-cli-csv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Katello/hammer-cli-csv/downloads","issues_url":"https://api.github.com/repos/Katello/hammer-cli-csv/issues{/number}","pulls_url":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls{/number}","milestones_url":"https://api.github.com/repos/Katello/hammer-cli-csv/milestones{/number}","notifications_url":"https://api.github.com/repos/Katello/hammer-cli-csv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Katello/hammer-cli-csv/labels{/name}","releases_url":"https://api.github.com/repos/Katello/hammer-cli-csv/releases{/id}","deployments_url":"https://api.github.com/repos/Katello/hammer-cli-csv/deployments","created_at":"2013-11-04T13:55:06Z","updated_at":"2016-01-22T17:49:40Z","pushed_at":"2016-04-11T17:17:02Z","git_url":"git://github.com/Katello/hammer-cli-csv.git","ssh_url":"git@github.com:Katello/hammer-cli-csv.git","clone_url":"https://github.com/Katello/hammer-cli-csv.git","svn_url":"https://github.com/Katello/hammer-cli-csv","homepage":"","size":664,"stargazers_count":9,"watchers_count":9,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":6,"forks":13,"open_issues":6,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/104"},"html":{"href":"https://github.com/Katello/hammer-cli-csv/pull/104"},"issue":{"href":"https://api.github.com/repos/Katello/hammer-cli-csv/issues/104"},"comments":{"href":"https://api.github.com/repos/Katello/hammer-cli-csv/issues/104/comments"},"review_comments":{"href":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/104/comments"},"review_comment":{"href":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Katello/hammer-cli-csv/pulls/104/commits"},"statuses":{"href":"https://api.github.com/repos/Katello/hammer-cli-csv/statuses/1192ff19374a435aa2850d137c7ab96e726a523d"}}}}