{"action":"created","comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/comments/57085221","id":57085221,"diff_hunk":"@@ -349,14 +417,93 @@ def update_image(module, ec2):\n         else:\n             module.exit_json(msg=\"AMI not updated\", launch_permissions=set_permissions, changed=False)\n \n-    except boto.exception.BotoServerError, e:\n+    except boto.exception.BotoServerError:\n+        e = sys.exc_info()[1]\n         module.fail_json(msg = \"%s: %s\" % (e.error_code, e.error_message))\n \n+def register_image(module, ec2):\n+    \"\"\"\n+    Registers AMI\n+    \"\"\"\n+\n+    name = module.params.get('name')\n+    description = module.params.get('description')\n+    image_location = module.params.get('image_location')\n+    architecture = module.params.get('architecture')\n+    kernel_id = module.params.get('kernel_id')\n+    root_device_name = module.params.get('root_device_name')\n+    virtualization_type = module.params.get('virtualization_type')\n+    wait = module.params.get('wait')\n+    wait_timeout = int(module.params.get('wait_timeout'))\n+    device_mapping = module.params.get('device_mapping')\n+\n+    try:\n+        params = {'name': name,\n+                  'description': description,\n+                  'architecture': architecture,\n+                  'virtualization_type': virtualization_type}\n+        if image_location:\n+            params['image_location'] = image_location\n+        if kernel_id:\n+            params['kernel_id'] = kernel_id\n+        if root_device_name:\n+            params['root_device_name'] = root_device_name\n+\n+        if device_mapping:\n+            bdm = BlockDeviceMapping()\n+            for device in device_mapping:\n+                if 'device_name' not in device:\n+                    module.fail_json(msg = 'Device name must be set for volume')\n+                device_name = device['device_name']\n+                del device['device_name']\n+                bd = BlockDeviceType(**device)\n+                bdm[device_name] = bd\n+            params['block_device_map'] = bdm\n+\n+        image_id = ec2.register_image(**params)\n+    except boto.exception.BotoServerError:\n+        e = sys.exc_info()[1]\n+        if e.error_code == 'InvalidAMIName.Duplicate':\n+            img = get_image_with_name(name, ec2)\n+            if img.name == name:\n+                module.exit_json(msg=\"AMI name already present\", image_id=img.id, state=img.state, changed=False)\n+                sys.exit(0)\n+            else:\n+                module.fail_json(msg=\"Error in retrieving duplicate AMI details\")\n+        else:\n+            module.fail_json(msg=\"%s: %s\" % (e.error_code, e.error_message))\n+\n+    # wait here until the image is gone\n+    wait_timeout = time.time() + wait_timeout\n+    while wait and wait_timeout > time.time():\n+        try:\n+            img = ec2.get_image(image_id)\n+            if img is None:\n+                continue\n+            break\n+        except boto.exception.BotoServerError:\n+            e = sys.exc_info()[1]\n+            if e.error_code != 'InvalidAMIID.NotFound':\n+                raise\n+        time.sleep(3)\n+","path":"cloud/amazon/ec2_ami.py","position":233,"original_position":233,"commit_id":"a4b4e39895c7e7234b2111567cd713680085f4b5","original_commit_id":"a4b4e39895c7e7234b2111567cd713680085f4b5","user":{"login":"alxnov","id":680802,"avatar_url":"https://avatars.githubusercontent.com/u/680802?v=3","gravatar_id":"","url":"https://api.github.com/users/alxnov","html_url":"https://github.com/alxnov","followers_url":"https://api.github.com/users/alxnov/followers","following_url":"https://api.github.com/users/alxnov/following{/other_user}","gists_url":"https://api.github.com/users/alxnov/gists{/gist_id}","starred_url":"https://api.github.com/users/alxnov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alxnov/subscriptions","organizations_url":"https://api.github.com/users/alxnov/orgs","repos_url":"https://api.github.com/users/alxnov/repos","events_url":"https://api.github.com/users/alxnov/events{/privacy}","received_events_url":"https://api.github.com/users/alxnov/received_events","type":"User","site_admin":false},"body":"    if tags:\r\n        try:\r\n            ec2.create_tags(image_id, tags)\r\n        except boto.exception.EC2ResponseError:\r\n            e = sys.exc_info()[1]\r\n            module.fail_json(msg = \"Image tagging failed => %s: %s\" % (e.error_code, e.error_message))\r\n","created_at":"2016-03-22T23:05:03Z","updated_at":"2016-03-22T23:05:03Z","html_url":"https://github.com/ansible/ansible-modules-core/pull/2029#discussion_r57085221","pull_request_url":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/2029","_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/comments/57085221"},"html":{"href":"https://github.com/ansible/ansible-modules-core/pull/2029#discussion_r57085221"},"pull_request":{"href":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/2029"}}},"pull_request":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/2029","id":44413940,"html_url":"https://github.com/ansible/ansible-modules-core/pull/2029","diff_url":"https://github.com/ansible/ansible-modules-core/pull/2029.diff","patch_url":"https://github.com/ansible/ansible-modules-core/pull/2029.patch","issue_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/2029","number":2029,"state":"open","locked":false,"title":"New AMI image registration support to ec2_ami","user":{"login":"rosmo","id":988648,"avatar_url":"https://avatars.githubusercontent.com/u/988648?v=3","gravatar_id":"","url":"https://api.github.com/users/rosmo","html_url":"https://github.com/rosmo","followers_url":"https://api.github.com/users/rosmo/followers","following_url":"https://api.github.com/users/rosmo/following{/other_user}","gists_url":"https://api.github.com/users/rosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/rosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rosmo/subscriptions","organizations_url":"https://api.github.com/users/rosmo/orgs","repos_url":"https://api.github.com/users/rosmo/repos","events_url":"https://api.github.com/users/rosmo/events{/privacy}","received_events_url":"https://api.github.com/users/rosmo/received_events","type":"User","site_admin":false},"body":"Added new register -state, which enables the module to register new AMI images from a S3 bucket containing the AMI manifest file.","created_at":"2015-09-08T10:07:06Z","updated_at":"2016-03-22T23:05:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"37d53ed5b84a15f820de8f624e7d60dc4baa606a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/2029/commits","review_comments_url":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/2029/comments","review_comment_url":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/2029/comments","statuses_url":"https://api.github.com/repos/ansible/ansible-modules-core/statuses/a4b4e39895c7e7234b2111567cd713680085f4b5","head":{"label":"rosmo:ec2-ami-register","ref":"ec2-ami-register","sha":"a4b4e39895c7e7234b2111567cd713680085f4b5","user":{"login":"rosmo","id":988648,"avatar_url":"https://avatars.githubusercontent.com/u/988648?v=3","gravatar_id":"","url":"https://api.github.com/users/rosmo","html_url":"https://github.com/rosmo","followers_url":"https://api.github.com/users/rosmo/followers","following_url":"https://api.github.com/users/rosmo/following{/other_user}","gists_url":"https://api.github.com/users/rosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/rosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rosmo/subscriptions","organizations_url":"https://api.github.com/users/rosmo/orgs","repos_url":"https://api.github.com/users/rosmo/repos","events_url":"https://api.github.com/users/rosmo/events{/privacy}","received_events_url":"https://api.github.com/users/rosmo/received_events","type":"User","site_admin":false},"repo":{"id":42104408,"name":"ansible-modules-core","full_name":"rosmo/ansible-modules-core","owner":{"login":"rosmo","id":988648,"avatar_url":"https://avatars.githubusercontent.com/u/988648?v=3","gravatar_id":"","url":"https://api.github.com/users/rosmo","html_url":"https://github.com/rosmo","followers_url":"https://api.github.com/users/rosmo/followers","following_url":"https://api.github.com/users/rosmo/following{/other_user}","gists_url":"https://api.github.com/users/rosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/rosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rosmo/subscriptions","organizations_url":"https://api.github.com/users/rosmo/orgs","repos_url":"https://api.github.com/users/rosmo/repos","events_url":"https://api.github.com/users/rosmo/events{/privacy}","received_events_url":"https://api.github.com/users/rosmo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rosmo/ansible-modules-core","description":"Ansible modules - these modules ship with ansible","fork":true,"url":"https://api.github.com/repos/rosmo/ansible-modules-core","forks_url":"https://api.github.com/repos/rosmo/ansible-modules-core/forks","keys_url":"https://api.github.com/repos/rosmo/ansible-modules-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rosmo/ansible-modules-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rosmo/ansible-modules-core/teams","hooks_url":"https://api.github.com/repos/rosmo/ansible-modules-core/hooks","issue_events_url":"https://api.github.com/repos/rosmo/ansible-modules-core/issues/events{/number}","events_url":"https://api.github.com/repos/rosmo/ansible-modules-core/events","assignees_url":"https://api.github.com/repos/rosmo/ansible-modules-core/assignees{/user}","branches_url":"https://api.github.com/repos/rosmo/ansible-modules-core/branches{/branch}","tags_url":"https://api.github.com/repos/rosmo/ansible-modules-core/tags","blobs_url":"https://api.github.com/repos/rosmo/ansible-modules-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rosmo/ansible-modules-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rosmo/ansible-modules-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/rosmo/ansible-modules-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rosmo/ansible-modules-core/statuses/{sha}","languages_url":"https://api.github.com/repos/rosmo/ansible-modules-core/languages","stargazers_url":"https://api.github.com/repos/rosmo/ansible-modules-core/stargazers","contributors_url":"https://api.github.com/repos/rosmo/ansible-modules-core/contributors","subscribers_url":"https://api.github.com/repos/rosmo/ansible-modules-core/subscribers","subscription_url":"https://api.github.com/repos/rosmo/ansible-modules-core/subscription","commits_url":"https://api.github.com/repos/rosmo/ansible-modules-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/rosmo/ansible-modules-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/rosmo/ansible-modules-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/rosmo/ansible-modules-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/rosmo/ansible-modules-core/contents/{+path}","compare_url":"https://api.github.com/repos/rosmo/ansible-modules-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rosmo/ansible-modules-core/merges","archive_url":"https://api.github.com/repos/rosmo/ansible-modules-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rosmo/ansible-modules-core/downloads","issues_url":"https://api.github.com/repos/rosmo/ansible-modules-core/issues{/number}","pulls_url":"https://api.github.com/repos/rosmo/ansible-modules-core/pulls{/number}","milestones_url":"https://api.github.com/repos/rosmo/ansible-modules-core/milestones{/number}","notifications_url":"https://api.github.com/repos/rosmo/ansible-modules-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rosmo/ansible-modules-core/labels{/name}","releases_url":"https://api.github.com/repos/rosmo/ansible-modules-core/releases{/id}","deployments_url":"https://api.github.com/repos/rosmo/ansible-modules-core/deployments","created_at":"2015-09-08T09:58:23Z","updated_at":"2015-09-08T09:58:24Z","pushed_at":"2016-03-17T18:32:31Z","git_url":"git://github.com/rosmo/ansible-modules-core.git","ssh_url":"git@github.com:rosmo/ansible-modules-core.git","clone_url":"https://github.com/rosmo/ansible-modules-core.git","svn_url":"https://github.com/rosmo/ansible-modules-core","homepage":"","size":7842,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"devel"}},"base":{"label":"ansible:devel","ref":"devel","sha":"d7422c02ad5014217d23cd875fa20fb9b2d592c8","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":24474126,"name":"ansible-modules-core","full_name":"ansible/ansible-modules-core","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-core","description":"Ansible modules - these modules ship with ansible","fork":false,"url":"https://api.github.com/repos/ansible/ansible-modules-core","forks_url":"https://api.github.com/repos/ansible/ansible-modules-core/forks","keys_url":"https://api.github.com/repos/ansible/ansible-modules-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ansible/ansible-modules-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ansible/ansible-modules-core/teams","hooks_url":"https://api.github.com/repos/ansible/ansible-modules-core/hooks","issue_events_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/events{/number}","events_url":"https://api.github.com/repos/ansible/ansible-modules-core/events","assignees_url":"https://api.github.com/repos/ansible/ansible-modules-core/assignees{/user}","branches_url":"https://api.github.com/repos/ansible/ansible-modules-core/branches{/branch}","tags_url":"https://api.github.com/repos/ansible/ansible-modules-core/tags","blobs_url":"https://api.github.com/repos/ansible/ansible-modules-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ansible/ansible-modules-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ansible/ansible-modules-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/ansible/ansible-modules-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ansible/ansible-modules-core/statuses/{sha}","languages_url":"https://api.github.com/repos/ansible/ansible-modules-core/languages","stargazers_url":"https://api.github.com/repos/ansible/ansible-modules-core/stargazers","contributors_url":"https://api.github.com/repos/ansible/ansible-modules-core/contributors","subscribers_url":"https://api.github.com/repos/ansible/ansible-modules-core/subscribers","subscription_url":"https://api.github.com/repos/ansible/ansible-modules-core/subscription","commits_url":"https://api.github.com/repos/ansible/ansible-modules-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/ansible/ansible-modules-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/ansible/ansible-modules-core/contents/{+path}","compare_url":"https://api.github.com/repos/ansible/ansible-modules-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ansible/ansible-modules-core/merges","archive_url":"https://api.github.com/repos/ansible/ansible-modules-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ansible/ansible-modules-core/downloads","issues_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues{/number}","pulls_url":"https://api.github.com/repos/ansible/ansible-modules-core/pulls{/number}","milestones_url":"https://api.github.com/repos/ansible/ansible-modules-core/milestones{/number}","notifications_url":"https://api.github.com/repos/ansible/ansible-modules-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ansible/ansible-modules-core/labels{/name}","releases_url":"https://api.github.com/repos/ansible/ansible-modules-core/releases{/id}","deployments_url":"https://api.github.com/repos/ansible/ansible-modules-core/deployments","created_at":"2014-09-25T20:28:25Z","updated_at":"2016-03-21T19:30:07Z","pushed_at":"2016-03-22T20:13:03Z","git_url":"git://github.com/ansible/ansible-modules-core.git","ssh_url":"git@github.com:ansible/ansible-modules-core.git","clone_url":"https://github.com/ansible/ansible-modules-core.git","svn_url":"https://github.com/ansible/ansible-modules-core","homepage":"","size":14676,"stargazers_count":619,"watchers_count":619,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1419,"mirror_url":null,"open_issues_count":991,"forks":1419,"open_issues":991,"watchers":619,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/2029"},"html":{"href":"https://github.com/ansible/ansible-modules-core/pull/2029"},"issue":{"href":"https://api.github.com/repos/ansible/ansible-modules-core/issues/2029"},"comments":{"href":"https://api.github.com/repos/ansible/ansible-modules-core/issues/2029/comments"},"review_comments":{"href":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/2029/comments"},"review_comment":{"href":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/2029/commits"},"statuses":{"href":"https://api.github.com/repos/ansible/ansible-modules-core/statuses/a4b4e39895c7e7234b2111567cd713680085f4b5"}}}}