{"action":"created","comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments/68232206","id":68232206,"diff_hunk":"@@ -0,0 +1,365 @@\n+#!/usr/bin/python\n+# -*- coding: utf-8 -*-\n+#\n+# Copyright (C) 2016, Roland Wolters <rwolters@redhat.com>\n+#\n+# This program is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License as published by\n+# the Free Software Foundation, either version 3 of the License, or\n+# (at your option) any later version.\n+#\n+# This program is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+#\n+DOCUMENTATION = '''\n+---\n+module: satellite_activation_keys\n+version_added: \"2.2\"\n+author: \"Roland Wolters (@liquidat)\"\n+short_description: Manage Satellite activation keys\n+requirements:\n+    - satellite_activation_keys\n+description:\n+    - This module provides Satellite activation key management via the REST API for Red Hat Satellite system management servers.\n+options:\n+    user:\n+        description:\n+            - The name of the Satellite user.\n+        required: true\n+    pwd:\n+        description:\n+            - The password assigned to the username.\n+        required: true\n+    satellite:\n+        description:\n+            - The host name of Satellite.\n+        required: true\n+    organization:\n+        description:\n+            - The organization identifier used in Satellite\n+        required: true\n+    key_action:\n+        description:\n+            - The actual action performed on a key.\n+        required: true\n+        choices: ['create','update','delete']\n+    key_name:\n+        description:\n+            - The name of the managed key.\n+        required: true\n+    validate_certs:\n+        description:\n+            - If SSL vertificate errors should be ignored or not.\n+        default: true\n+        required: false\n+    key_description:\n+        description:\n+            - Description of the purpose for the key.\n+        default: null\n+        required: false\n+    environment:\n+        description:\n+            - The environment of the activation key.\n+        default: null\n+        required: false\n+    content_view:\n+        description:\n+            - The content view of the activation key.\n+        default: null\n+        required: false\n+    max_content_hosts:\n+        description:\n+            - The maximum number of registered hosts.\n+        default: null\n+        required: false\n+    unlimited_content_hosts:\n+        description:\n+            - Describe if the activation key can have unlimited hosts.\n+        default: null\n+        required: false\n+    release_version:\n+        description:\n+            - Content release version of the authorization key.\n+        default: null\n+        required: false\n+    service_level:\n+        description:\n+            - Service level of the authorization key.\n+        default: null\n+        required: false\n+    auto_attach:\n+        description:\n+            - Auto attach subscription upon registration.\n+        default: null\n+        required: false\n+'''\n+\n+EXAMPLES = '''\n+Example playbook entries using the satellite_activation_keys module to manage Satellite activation keys.\n+\n+    tasks:\n+\n+    - name: create new key\n+      satellite_activation_keys:\n+        user: admin\n+        pwd: secret\n+        satellite: \"satellite.example.com\"\n+        key_action: create\n+        key_name: mynewkey\n+        organization: my_organization\n+'''\n+\n+RETURN = '''\n+msg:\n+    description: status response of the REST call\n+    returned: success\n+    type: string\n+    sample: {\\\"organization\\\":{\\\"name\\\":\\\"myorg\\\"}}\n+'''\n+\n+def get_content_view_id(module,orga_id):\n+    \"\"\"Looks up content view ID for a given content view name.\n+    \"\"\"\n+\n+    url_action = 'https://' + module.params.get('satellite') + '/katello/api/v2/content_views/'\n+    payload = {\"organization_id\":orga_id,\"name\":module.params.get('content_view')}\n+    headers = {'Content-Type':'application/json'}\n+\n+    resp = open_url(url_action,method=\"GET\",headers=headers,url_username=module.params.get('user'),url_password=module.params.get('pwd'),force_basic_auth=True,data=json.dumps(payload),validate_certs=module.params.get('validate_certs'))\n+    resp_json = json.loads(resp.read())\n+\n+    if resp_json[\"total\"] == 0:\n+        module.fail_json(msg=\"Content View %s not found.\" % module.params.get('content_view'))\n+    elif resp_json[\"total\"] > 1:\n+        module.fail_json(msg=\"Content View name %s not specific enough, more than one found.\" % module.params.get('content_view'))\n+    cv_id = resp_json[\"results\"][0][\"id\"]\n+\n+    return cv_id\n+\n+def get_environment_id(module,orga_id):\n+    \"\"\"Looks up environment ID for a given environment name.\n+    \"\"\"\n+\n+    env_name = module.params.get('environment')\n+\n+    url_action = 'https://' + module.params.get('satellite') + '/katello/api/v2/environments/'\n+    payload = {\"organization_id\":orga_id,\"name\":env_name}\n+    headers = {'Content-Type':'application/json'}\n+\n+    resp = open_url(url_action,method=\"GET\",headers=headers,url_username=module.params.get('user'),url_password=module.params.get('pwd'),force_basic_auth=True,data=json.dumps(payload),validate_certs=module.params.get('validate_certs'))\n+    resp_json = json.loads(resp.read())\n+\n+    if resp_json[\"total\"] == 0:","path":"cloud/satellite/satellite_activation_keys.py","position":136,"original_position":157,"commit_id":"19aa0e37da3b2a74d4aa76d181a98d13b601ff77","original_commit_id":"19aa0e37da3b2a74d4aa76d181a98d13b601ff77","user":{"login":"liquidat","id":1998084,"avatar_url":"https://avatars.githubusercontent.com/u/1998084?v=3","gravatar_id":"","url":"https://api.github.com/users/liquidat","html_url":"https://github.com/liquidat","followers_url":"https://api.github.com/users/liquidat/followers","following_url":"https://api.github.com/users/liquidat/following{/other_user}","gists_url":"https://api.github.com/users/liquidat/gists{/gist_id}","starred_url":"https://api.github.com/users/liquidat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liquidat/subscriptions","organizations_url":"https://api.github.com/users/liquidat/orgs","repos_url":"https://api.github.com/users/liquidat/repos","events_url":"https://api.github.com/users/liquidat/events{/privacy}","received_events_url":"https://api.github.com/users/liquidat/received_events","type":"User","site_admin":false},"body":"The problem is that there are small, but important differences between error handling in the functions. It would require at least two small helper functions, but I will look into it.","created_at":"2016-06-23T13:19:20Z","updated_at":"2016-06-23T13:19:20Z","html_url":"https://github.com/ansible/ansible-modules-extras/pull/2265#discussion_r68232206","pull_request_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/2265","_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments/68232206"},"html":{"href":"https://github.com/ansible/ansible-modules-extras/pull/2265#discussion_r68232206"},"pull_request":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/2265"}}},"pull_request":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/2265","id":70831354,"html_url":"https://github.com/ansible/ansible-modules-extras/pull/2265","diff_url":"https://github.com/ansible/ansible-modules-extras/pull/2265.diff","patch_url":"https://github.com/ansible/ansible-modules-extras/pull/2265.patch","issue_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/2265","number":2265,"state":"open","locked":false,"title":"Satellite module to manage activation keys","user":{"login":"liquidat","id":1998084,"avatar_url":"https://avatars.githubusercontent.com/u/1998084?v=3","gravatar_id":"","url":"https://api.github.com/users/liquidat","html_url":"https://github.com/liquidat","followers_url":"https://api.github.com/users/liquidat/followers","following_url":"https://api.github.com/users/liquidat/following{/other_user}","gists_url":"https://api.github.com/users/liquidat/gists{/gist_id}","starred_url":"https://api.github.com/users/liquidat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liquidat/subscriptions","organizations_url":"https://api.github.com/users/liquidat/orgs","repos_url":"https://api.github.com/users/liquidat/repos","events_url":"https://api.github.com/users/liquidat/events{/privacy}","received_events_url":"https://api.github.com/users/liquidat/received_events","type":"User","site_admin":false},"body":"##### ISSUE TYPE\r\n - New Module Pull Request\r\n\r\n##### COMPONENT NAME\r\nsatellite_activation_keys (in the cloud subdirectory)\r\n\r\n##### ANSIBLE VERSION\r\n```\r\nansible 2.0.2.0\r\n```\r\n\r\n##### SUMMARY\r\nThis is a module to manage Satellite, specifically the so called _activation keys_. The technical basis is to manage everything via REST calls, the Python module needed for the REST API is the requests module.\r\n\r\nIf the module is accepted, the plan is to use it as a blueprint for other Satellite modules since it already implements:\r\n- structure to generally query Satellite via REST API\r\n- sub functions to lookup core information in Satellite like organizations, environments, content views, etc.\r\n\r\nFrom the commit changelog:\r\n\r\nDONE:\r\n- manages Red Hat Satellite and thus Katello REST API calls\r\n- uses Python requests library\r\n- all major parameters for create and update are covered\r\n- check_mode supported\r\n- catches errors when parameters cannot be found\r\n- no pep8 errors\r\n\r\nTODO:\r\n- Return is sometimes JSON code, sometimes string, could be improved","created_at":"2016-05-20T10:12:57Z","updated_at":"2016-06-23T13:19:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e0ea408456f0278a513b43f43a6cb3d60f10ca09","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/2265/commits","review_comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/2265/comments","review_comment_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/2265/comments","statuses_url":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/19aa0e37da3b2a74d4aa76d181a98d13b601ff77","head":{"label":"liquidat:satellite_activation_keys","ref":"satellite_activation_keys","sha":"19aa0e37da3b2a74d4aa76d181a98d13b601ff77","user":{"login":"liquidat","id":1998084,"avatar_url":"https://avatars.githubusercontent.com/u/1998084?v=3","gravatar_id":"","url":"https://api.github.com/users/liquidat","html_url":"https://github.com/liquidat","followers_url":"https://api.github.com/users/liquidat/followers","following_url":"https://api.github.com/users/liquidat/following{/other_user}","gists_url":"https://api.github.com/users/liquidat/gists{/gist_id}","starred_url":"https://api.github.com/users/liquidat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liquidat/subscriptions","organizations_url":"https://api.github.com/users/liquidat/orgs","repos_url":"https://api.github.com/users/liquidat/repos","events_url":"https://api.github.com/users/liquidat/events{/privacy}","received_events_url":"https://api.github.com/users/liquidat/received_events","type":"User","site_admin":false},"repo":{"id":53586953,"name":"ansible-modules-extras","full_name":"liquidat/ansible-modules-extras","owner":{"login":"liquidat","id":1998084,"avatar_url":"https://avatars.githubusercontent.com/u/1998084?v=3","gravatar_id":"","url":"https://api.github.com/users/liquidat","html_url":"https://github.com/liquidat","followers_url":"https://api.github.com/users/liquidat/followers","following_url":"https://api.github.com/users/liquidat/following{/other_user}","gists_url":"https://api.github.com/users/liquidat/gists{/gist_id}","starred_url":"https://api.github.com/users/liquidat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liquidat/subscriptions","organizations_url":"https://api.github.com/users/liquidat/orgs","repos_url":"https://api.github.com/users/liquidat/repos","events_url":"https://api.github.com/users/liquidat/events{/privacy}","received_events_url":"https://api.github.com/users/liquidat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/liquidat/ansible-modules-extras","description":"Ansible extra modules - these modules ship with ansible","fork":true,"url":"https://api.github.com/repos/liquidat/ansible-modules-extras","forks_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/forks","keys_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/keys{/key_id}","collaborators_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/teams","hooks_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/hooks","issue_events_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/issues/events{/number}","events_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/events","assignees_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/assignees{/user}","branches_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/branches{/branch}","tags_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/tags","blobs_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/git/refs{/sha}","trees_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/git/trees{/sha}","statuses_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/statuses/{sha}","languages_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/languages","stargazers_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/stargazers","contributors_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/contributors","subscribers_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/subscribers","subscription_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/subscription","commits_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/commits{/sha}","git_commits_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/git/commits{/sha}","comments_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/comments{/number}","issue_comment_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/issues/comments{/number}","contents_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/contents/{+path}","compare_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/compare/{base}...{head}","merges_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/merges","archive_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/downloads","issues_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/issues{/number}","pulls_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/pulls{/number}","milestones_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/milestones{/number}","notifications_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/labels{/name}","releases_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/releases{/id}","deployments_url":"https://api.github.com/repos/liquidat/ansible-modules-extras/deployments","created_at":"2016-03-10T13:36:37Z","updated_at":"2016-05-18T13:29:45Z","pushed_at":"2016-06-22T23:05:57Z","git_url":"git://github.com/liquidat/ansible-modules-extras.git","ssh_url":"git@github.com:liquidat/ansible-modules-extras.git","clone_url":"https://github.com/liquidat/ansible-modules-extras.git","svn_url":"https://github.com/liquidat/ansible-modules-extras","homepage":"","size":7438,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"devel"}},"base":{"label":"ansible:devel","ref":"devel","sha":"65fe9eb2b018993841620e506482dc699a892263","user":{"login":"ansible","id":1507452,"avatar_url":"https://avatars.githubusercontent.com/u/1507452?v=3","gravatar_id":"","url":"https://api.github.com/users/ansible","html_url":"https://github.com/ansible","followers_url":"https://api.github.com/users/ansible/followers","following_url":"https://api.github.com/users/ansible/following{/other_user}","gists_url":"https://api.github.com/users/ansible/gists{/gist_id}","starred_url":"https://api.github.com/users/ansible/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansible/subscriptions","organizations_url":"https://api.github.com/users/ansible/orgs","repos_url":"https://api.github.com/users/ansible/repos","events_url":"https://api.github.com/users/ansible/events{/privacy}","received_events_url":"https://api.github.com/users/ansible/received_events","type":"Organization","site_admin":false},"repo":{"id":24474138,"name":"ansible-modules-extras","full_name":"ansible/ansible-modules-extras","owner":{"login":"ansible","id":1507452,"avatar_url":"https://avatars.githubusercontent.com/u/1507452?v=3","gravatar_id":"","url":"https://api.github.com/users/ansible","html_url":"https://github.com/ansible","followers_url":"https://api.github.com/users/ansible/followers","following_url":"https://api.github.com/users/ansible/following{/other_user}","gists_url":"https://api.github.com/users/ansible/gists{/gist_id}","starred_url":"https://api.github.com/users/ansible/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansible/subscriptions","organizations_url":"https://api.github.com/users/ansible/orgs","repos_url":"https://api.github.com/users/ansible/repos","events_url":"https://api.github.com/users/ansible/events{/privacy}","received_events_url":"https://api.github.com/users/ansible/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ansible/ansible-modules-extras","description":"Ansible extra modules - these modules ship with ansible","fork":false,"url":"https://api.github.com/repos/ansible/ansible-modules-extras","forks_url":"https://api.github.com/repos/ansible/ansible-modules-extras/forks","keys_url":"https://api.github.com/repos/ansible/ansible-modules-extras/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ansible/ansible-modules-extras/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ansible/ansible-modules-extras/teams","hooks_url":"https://api.github.com/repos/ansible/ansible-modules-extras/hooks","issue_events_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/events{/number}","events_url":"https://api.github.com/repos/ansible/ansible-modules-extras/events","assignees_url":"https://api.github.com/repos/ansible/ansible-modules-extras/assignees{/user}","branches_url":"https://api.github.com/repos/ansible/ansible-modules-extras/branches{/branch}","tags_url":"https://api.github.com/repos/ansible/ansible-modules-extras/tags","blobs_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/refs{/sha}","trees_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/{sha}","languages_url":"https://api.github.com/repos/ansible/ansible-modules-extras/languages","stargazers_url":"https://api.github.com/repos/ansible/ansible-modules-extras/stargazers","contributors_url":"https://api.github.com/repos/ansible/ansible-modules-extras/contributors","subscribers_url":"https://api.github.com/repos/ansible/ansible-modules-extras/subscribers","subscription_url":"https://api.github.com/repos/ansible/ansible-modules-extras/subscription","commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/commits{/sha}","git_commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/commits{/sha}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/comments{/number}","issue_comment_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/comments{/number}","contents_url":"https://api.github.com/repos/ansible/ansible-modules-extras/contents/{+path}","compare_url":"https://api.github.com/repos/ansible/ansible-modules-extras/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ansible/ansible-modules-extras/merges","archive_url":"https://api.github.com/repos/ansible/ansible-modules-extras/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ansible/ansible-modules-extras/downloads","issues_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues{/number}","pulls_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls{/number}","milestones_url":"https://api.github.com/repos/ansible/ansible-modules-extras/milestones{/number}","notifications_url":"https://api.github.com/repos/ansible/ansible-modules-extras/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ansible/ansible-modules-extras/labels{/name}","releases_url":"https://api.github.com/repos/ansible/ansible-modules-extras/releases{/id}","deployments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/deployments","created_at":"2014-09-25T20:28:42Z","updated_at":"2016-06-23T12:43:05Z","pushed_at":"2016-06-23T11:50:29Z","git_url":"git://github.com/ansible/ansible-modules-extras.git","ssh_url":"git@github.com:ansible/ansible-modules-extras.git","clone_url":"https://github.com/ansible/ansible-modules-extras.git","svn_url":"https://github.com/ansible/ansible-modules-extras","homepage":"","size":44779,"stargazers_count":618,"watchers_count":618,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1291,"mirror_url":null,"open_issues_count":620,"forks":1291,"open_issues":620,"watchers":618,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/2265"},"html":{"href":"https://github.com/ansible/ansible-modules-extras/pull/2265"},"issue":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/2265"},"comments":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/2265/comments"},"review_comments":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/2265/comments"},"review_comment":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/2265/commits"},"statuses":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/19aa0e37da3b2a74d4aa76d181a98d13b601ff77"}}}}
{"actor":{"display_login":"liquidat"}}