{"action":"created","comment":{"url":"https://api.github.com/repos/edx/testeng-ci/pulls/comments/49365161","id":49365161,"diff_hunk":"@@ -0,0 +1,105 @@\n+\"\"\"\n+Use boto to deregister AMIs that match a given tag key-value pair.\n+\n+That tag key-value pair is hardcoded to:\n+    delete_or_keep: delete\n+\n+Usage:\n+    If you've defined the AWS credentials as environment variables or in a\n+    .boto file, then use:\n+        `python deregister_amis.py\n+\n+    Else, you can add the aws keys as arguments to the above command:\n+        ** '--aws-access-key-id' or '-i'\n+        ** '--aws-secret-access-key' or '-s'\n+\n+    If you don't want to deregister AMIs, but you'd like to know which ones\n+    you'd deregister if you ran the command, then use the --dry-run switch.\n+\n+\"\"\"\n+import argparse\n+import boto\n+import logging\n+import os\n+import sys\n+\n+logger = logging.getLogger(__name__)\n+\n+\n+def get_ec2_connection(aws_access_key_id, aws_secret_access_key):\n+    return boto.connect_ec2(aws_access_key_id, aws_secret_access_key)\n+\n+\n+def deregister_amis_by_tag(tag_key, tag_value, dry_run, connection):\n+    \"\"\"\n+    Deregisters AMIs that are found according to tag key/value pairs.\n+    \"\"\"\n+\n+    tag_key_string = \"tag:{tag_key}\".format(tag_key=tag_key)\n+\n+    logger.info(\"Finding AMIs tagged with {key}: {value}\".format(\n+        key=tag_key,\n+        value=tag_value,\n+    ))\n+    amis = connection.get_all_images(filters={tag_key_string: tag_value})\n+    for i in amis:\n+        logger.info(\"Deregistering {image}\".format(image=str(i)))","path":"aws/deregister_amis.py","position":46,"original_position":46,"commit_id":"3c1f5e4962ee045bd3464860e41106cb4fe8d9e2","original_commit_id":"3c1f5e4962ee045bd3464860e41106cb4fe8d9e2","user":{"login":"jzoldak","id":2338889,"avatar_url":"https://avatars.githubusercontent.com/u/2338889?v=3","gravatar_id":"","url":"https://api.github.com/users/jzoldak","html_url":"https://github.com/jzoldak","followers_url":"https://api.github.com/users/jzoldak/followers","following_url":"https://api.github.com/users/jzoldak/following{/other_user}","gists_url":"https://api.github.com/users/jzoldak/gists{/gist_id}","starred_url":"https://api.github.com/users/jzoldak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jzoldak/subscriptions","organizations_url":"https://api.github.com/users/jzoldak/orgs","repos_url":"https://api.github.com/users/jzoldak/repos","events_url":"https://api.github.com/users/jzoldak/events{/privacy}","received_events_url":"https://api.github.com/users/jzoldak/received_events","type":"User","site_admin":false},"body":"Nit: you might want to here log \"Found image {image}\". Then do not log anything for 'dry_run', but after the deregister is successful, log \"Deregistered {image}\"","created_at":"2016-01-11T19:22:14Z","updated_at":"2016-01-11T19:22:14Z","html_url":"https://github.com/edx/testeng-ci/pull/39#discussion_r49365161","pull_request_url":"https://api.github.com/repos/edx/testeng-ci/pulls/39","_links":{"self":{"href":"https://api.github.com/repos/edx/testeng-ci/pulls/comments/49365161"},"html":{"href":"https://github.com/edx/testeng-ci/pull/39#discussion_r49365161"},"pull_request":{"href":"https://api.github.com/repos/edx/testeng-ci/pulls/39"}}},"pull_request":{"url":"https://api.github.com/repos/edx/testeng-ci/pulls/39","id":55553953,"html_url":"https://github.com/edx/testeng-ci/pull/39","diff_url":"https://github.com/edx/testeng-ci/pull/39.diff","patch_url":"https://github.com/edx/testeng-ci/pull/39.patch","issue_url":"https://api.github.com/repos/edx/testeng-ci/issues/39","number":39,"state":"open","locked":false,"title":"Benp/deregister amis","user":{"login":"benpatterson","id":2004678,"avatar_url":"https://avatars.githubusercontent.com/u/2004678?v=3","gravatar_id":"","url":"https://api.github.com/users/benpatterson","html_url":"https://github.com/benpatterson","followers_url":"https://api.github.com/users/benpatterson/followers","following_url":"https://api.github.com/users/benpatterson/following{/other_user}","gists_url":"https://api.github.com/users/benpatterson/gists{/gist_id}","starred_url":"https://api.github.com/users/benpatterson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benpatterson/subscriptions","organizations_url":"https://api.github.com/users/benpatterson/orgs","repos_url":"https://api.github.com/users/benpatterson/repos","events_url":"https://api.github.com/users/benpatterson/events{/privacy}","received_events_url":"https://api.github.com/users/benpatterson/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-09T23:48:34Z","updated_at":"2016-01-11T19:22:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1b97443d4aad2c19a45af81fccd574834387ed75","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/testeng-ci/pulls/39/commits","review_comments_url":"https://api.github.com/repos/edx/testeng-ci/pulls/39/comments","review_comment_url":"https://api.github.com/repos/edx/testeng-ci/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/testeng-ci/issues/39/comments","statuses_url":"https://api.github.com/repos/edx/testeng-ci/statuses/3c1f5e4962ee045bd3464860e41106cb4fe8d9e2","head":{"label":"edx:benp/deregister-amis","ref":"benp/deregister-amis","sha":"3c1f5e4962ee045bd3464860e41106cb4fe8d9e2","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":32744541,"name":"testeng-ci","full_name":"edx/testeng-ci","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/testeng-ci","description":"","fork":false,"url":"https://api.github.com/repos/edx/testeng-ci","forks_url":"https://api.github.com/repos/edx/testeng-ci/forks","keys_url":"https://api.github.com/repos/edx/testeng-ci/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/testeng-ci/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/testeng-ci/teams","hooks_url":"https://api.github.com/repos/edx/testeng-ci/hooks","issue_events_url":"https://api.github.com/repos/edx/testeng-ci/issues/events{/number}","events_url":"https://api.github.com/repos/edx/testeng-ci/events","assignees_url":"https://api.github.com/repos/edx/testeng-ci/assignees{/user}","branches_url":"https://api.github.com/repos/edx/testeng-ci/branches{/branch}","tags_url":"https://api.github.com/repos/edx/testeng-ci/tags","blobs_url":"https://api.github.com/repos/edx/testeng-ci/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/testeng-ci/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/testeng-ci/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/testeng-ci/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/testeng-ci/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/testeng-ci/languages","stargazers_url":"https://api.github.com/repos/edx/testeng-ci/stargazers","contributors_url":"https://api.github.com/repos/edx/testeng-ci/contributors","subscribers_url":"https://api.github.com/repos/edx/testeng-ci/subscribers","subscription_url":"https://api.github.com/repos/edx/testeng-ci/subscription","commits_url":"https://api.github.com/repos/edx/testeng-ci/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/testeng-ci/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/testeng-ci/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/testeng-ci/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/testeng-ci/contents/{+path}","compare_url":"https://api.github.com/repos/edx/testeng-ci/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/testeng-ci/merges","archive_url":"https://api.github.com/repos/edx/testeng-ci/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/testeng-ci/downloads","issues_url":"https://api.github.com/repos/edx/testeng-ci/issues{/number}","pulls_url":"https://api.github.com/repos/edx/testeng-ci/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/testeng-ci/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/testeng-ci/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/testeng-ci/labels{/name}","releases_url":"https://api.github.com/repos/edx/testeng-ci/releases{/id}","created_at":"2015-03-23T16:30:53Z","updated_at":"2016-01-11T14:53:44Z","pushed_at":"2016-01-11T14:53:43Z","git_url":"git://github.com/edx/testeng-ci.git","ssh_url":"git@github.com:edx/testeng-ci.git","clone_url":"https://github.com/edx/testeng-ci.git","svn_url":"https://github.com/edx/testeng-ci","homepage":null,"size":114,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"359aae86c9b5099104f02741d9900aa9746be789","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":32744541,"name":"testeng-ci","full_name":"edx/testeng-ci","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/testeng-ci","description":"","fork":false,"url":"https://api.github.com/repos/edx/testeng-ci","forks_url":"https://api.github.com/repos/edx/testeng-ci/forks","keys_url":"https://api.github.com/repos/edx/testeng-ci/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/testeng-ci/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/testeng-ci/teams","hooks_url":"https://api.github.com/repos/edx/testeng-ci/hooks","issue_events_url":"https://api.github.com/repos/edx/testeng-ci/issues/events{/number}","events_url":"https://api.github.com/repos/edx/testeng-ci/events","assignees_url":"https://api.github.com/repos/edx/testeng-ci/assignees{/user}","branches_url":"https://api.github.com/repos/edx/testeng-ci/branches{/branch}","tags_url":"https://api.github.com/repos/edx/testeng-ci/tags","blobs_url":"https://api.github.com/repos/edx/testeng-ci/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/testeng-ci/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/testeng-ci/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/testeng-ci/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/testeng-ci/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/testeng-ci/languages","stargazers_url":"https://api.github.com/repos/edx/testeng-ci/stargazers","contributors_url":"https://api.github.com/repos/edx/testeng-ci/contributors","subscribers_url":"https://api.github.com/repos/edx/testeng-ci/subscribers","subscription_url":"https://api.github.com/repos/edx/testeng-ci/subscription","commits_url":"https://api.github.com/repos/edx/testeng-ci/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/testeng-ci/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/testeng-ci/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/testeng-ci/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/testeng-ci/contents/{+path}","compare_url":"https://api.github.com/repos/edx/testeng-ci/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/testeng-ci/merges","archive_url":"https://api.github.com/repos/edx/testeng-ci/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/testeng-ci/downloads","issues_url":"https://api.github.com/repos/edx/testeng-ci/issues{/number}","pulls_url":"https://api.github.com/repos/edx/testeng-ci/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/testeng-ci/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/testeng-ci/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/testeng-ci/labels{/name}","releases_url":"https://api.github.com/repos/edx/testeng-ci/releases{/id}","created_at":"2015-03-23T16:30:53Z","updated_at":"2016-01-11T14:53:44Z","pushed_at":"2016-01-11T14:53:43Z","git_url":"git://github.com/edx/testeng-ci.git","ssh_url":"git@github.com:edx/testeng-ci.git","clone_url":"https://github.com/edx/testeng-ci.git","svn_url":"https://github.com/edx/testeng-ci","homepage":null,"size":114,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/testeng-ci/pulls/39"},"html":{"href":"https://github.com/edx/testeng-ci/pull/39"},"issue":{"href":"https://api.github.com/repos/edx/testeng-ci/issues/39"},"comments":{"href":"https://api.github.com/repos/edx/testeng-ci/issues/39/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/testeng-ci/pulls/39/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/testeng-ci/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/testeng-ci/pulls/39/commits"},"statuses":{"href":"https://api.github.com/repos/edx/testeng-ci/statuses/3c1f5e4962ee045bd3464860e41106cb4fe8d9e2"}}}}