{"action":"created","comment":{"url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/comments/208623468","pull_request_review_id":144471095,"id":208623468,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwODYyMzQ2OA==","diff_hunk":"@@ -112,5 +121,69 @@ def pick_random_instance(filters: List[Dict[str, Any]],\n     Select an instance at random based on the returned list of instances\n     matching the given filter.\n     \"\"\"\n-    instance_ids = list_instance_ids(filters, client)\n-    return random.choice(instance_ids)\n+    instances_type = list_instances_by_type(filters, client)\n+    random_id = random.choice([item for sublist in instances_type.values()\n+                              for item in sublist])\n+    for inst_type in instances_type:\n+        if random_id in instances_type[inst_type]:\n+            return {inst_type: [random_id]}\n+\n+\n+def get_instance_type_from_response(response: dict):\n+    \"\"\"\n+    Transform list of instance IDs to a dict with IDs by instance type\n+    \"\"\"\n+    instances_type = defaultdict(list)\n+    # reservations are instances that were started together\n+    for reservation in response['Reservations']:\n+        for inst in reservation['Instances']:\n+            if inst['InstanceLifecycle'] not in instances_type.keys():\n+                # adding empty list (value) for new instance type (key)\n+                instances_type[inst['InstanceLifecycle']] = []\n+            instances_type[inst['InstanceLifecycle']].append(\n+                    inst['InstanceId'])\n+    return instances_type\n+\n+\n+def get_spot_request_ids_from_response(response: dict):\n+    spot_request_ids = []\n+    for reservation in response['Reservations']:\n+        for inst in reservation['Instances']:\n+            spot_request_ids.append(inst['SpotInstanceRequestId'])\n+    return spot_request_ids\n+\n+\n+def get_instance_type_by_id(instance_ids: List[str], client: boto3.client):\n+    print('1')","path":"chaosaws/ec2/actions.py","position":null,"original_position":134,"commit_id":"abff0ad3b380c7e48b4dda33b31338cde992a3d9","original_commit_id":"9084bcdddb1961999c8292ea7f2947011bbc02b1","user":{"login":"Lawouach","id":769982,"node_id":"MDQ6VXNlcjc2OTk4Mg==","avatar_url":"https://avatars1.githubusercontent.com/u/769982?v=4","gravatar_id":"","url":"https://api.github.com/users/Lawouach","html_url":"https://github.com/Lawouach","followers_url":"https://api.github.com/users/Lawouach/followers","following_url":"https://api.github.com/users/Lawouach/following{/other_user}","gists_url":"https://api.github.com/users/Lawouach/gists{/gist_id}","starred_url":"https://api.github.com/users/Lawouach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lawouach/subscriptions","organizations_url":"https://api.github.com/users/Lawouach/orgs","repos_url":"https://api.github.com/users/Lawouach/repos","events_url":"https://api.github.com/users/Lawouach/events{/privacy}","received_events_url":"https://api.github.com/users/Lawouach/received_events","type":"User","site_admin":false},"body":"Probably to be removed ;)","created_at":"2018-08-08T15:19:08Z","updated_at":"2018-08-08T15:19:08Z","html_url":"https://github.com/chaostoolkit-incubator/chaostoolkit-aws/pull/15#discussion_r208623468","pull_request_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/15","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/comments/208623468"},"html":{"href":"https://github.com/chaostoolkit-incubator/chaostoolkit-aws/pull/15#discussion_r208623468"},"pull_request":{"href":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/15"}}},"pull_request":{"url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/15","id":207003260,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA3MDAzMjYw","html_url":"https://github.com/chaostoolkit-incubator/chaostoolkit-aws/pull/15","diff_url":"https://github.com/chaostoolkit-incubator/chaostoolkit-aws/pull/15.diff","patch_url":"https://github.com/chaostoolkit-incubator/chaostoolkit-aws/pull/15.patch","issue_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/issues/15","number":15,"state":"open","locked":false,"title":"Spot instances support","user":{"login":"0rc","id":6602581,"node_id":"MDQ6VXNlcjY2MDI1ODE=","avatar_url":"https://avatars0.githubusercontent.com/u/6602581?v=4","gravatar_id":"","url":"https://api.github.com/users/0rc","html_url":"https://github.com/0rc","followers_url":"https://api.github.com/users/0rc/followers","following_url":"https://api.github.com/users/0rc/following{/other_user}","gists_url":"https://api.github.com/users/0rc/gists{/gist_id}","starred_url":"https://api.github.com/users/0rc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/0rc/subscriptions","organizations_url":"https://api.github.com/users/0rc/orgs","repos_url":"https://api.github.com/users/0rc/repos","events_url":"https://api.github.com/users/0rc/events{/privacy}","received_events_url":"https://api.github.com/users/0rc/received_events","type":"User","site_admin":false},"body":"Hi,\r\n\r\nThis is proposal of refactoring I did to support different instance types ('spot' is implemented here, 'scheduled' will be super easy to add) as original implementation didn't have support for spot.\r\n\r\nThe idea is to introduce internal dict with instance ids grouped by type ('normal', 'spot') instead of just list with instance IDs. Interfaces not changed and implementation is fully backward compatible.\r\n\r\nThe difference is that for spot we need to cancel spot request first (in case spot request type is 'permanent' and to keep things clean) and terminate the instance as 'stop' action is not supported for spot due to it's temporary nature.\r\n\r\nTests are added/modified for spot instances support.\r\n\r\nAlso adding count_instances probe with a simple test, this can be further extended to validate if filter returns more than X instances.\r\n\r\nAll tests passing, style check has no issues.","created_at":"2018-08-08T13:13:35Z","updated_at":"2018-08-08T15:19:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9ccc56230979090e1930f7eabc37fca2489c24fd","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/15/commits","review_comments_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/15/comments","review_comment_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/comments{/number}","comments_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/issues/15/comments","statuses_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/statuses/abff0ad3b380c7e48b4dda33b31338cde992a3d9","head":{"label":"0rc:spot_instances_support","ref":"spot_instances_support","sha":"abff0ad3b380c7e48b4dda33b31338cde992a3d9","user":{"login":"0rc","id":6602581,"node_id":"MDQ6VXNlcjY2MDI1ODE=","avatar_url":"https://avatars0.githubusercontent.com/u/6602581?v=4","gravatar_id":"","url":"https://api.github.com/users/0rc","html_url":"https://github.com/0rc","followers_url":"https://api.github.com/users/0rc/followers","following_url":"https://api.github.com/users/0rc/following{/other_user}","gists_url":"https://api.github.com/users/0rc/gists{/gist_id}","starred_url":"https://api.github.com/users/0rc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/0rc/subscriptions","organizations_url":"https://api.github.com/users/0rc/orgs","repos_url":"https://api.github.com/users/0rc/repos","events_url":"https://api.github.com/users/0rc/events{/privacy}","received_events_url":"https://api.github.com/users/0rc/received_events","type":"User","site_admin":false},"repo":{"id":143740734,"node_id":"MDEwOlJlcG9zaXRvcnkxNDM3NDA3MzQ=","name":"chaostoolkit-aws","full_name":"0rc/chaostoolkit-aws","owner":{"login":"0rc","id":6602581,"node_id":"MDQ6VXNlcjY2MDI1ODE=","avatar_url":"https://avatars0.githubusercontent.com/u/6602581?v=4","gravatar_id":"","url":"https://api.github.com/users/0rc","html_url":"https://github.com/0rc","followers_url":"https://api.github.com/users/0rc/followers","following_url":"https://api.github.com/users/0rc/following{/other_user}","gists_url":"https://api.github.com/users/0rc/gists{/gist_id}","starred_url":"https://api.github.com/users/0rc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/0rc/subscriptions","organizations_url":"https://api.github.com/users/0rc/orgs","repos_url":"https://api.github.com/users/0rc/repos","events_url":"https://api.github.com/users/0rc/events{/privacy}","received_events_url":"https://api.github.com/users/0rc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/0rc/chaostoolkit-aws","description":"Chaos Toolkit Extension for AWS","fork":true,"url":"https://api.github.com/repos/0rc/chaostoolkit-aws","forks_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/forks","keys_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/keys{/key_id}","collaborators_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/teams","hooks_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/hooks","issue_events_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/issues/events{/number}","events_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/events","assignees_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/assignees{/user}","branches_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/branches{/branch}","tags_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/tags","blobs_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/git/refs{/sha}","trees_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/git/trees{/sha}","statuses_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/statuses/{sha}","languages_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/languages","stargazers_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/stargazers","contributors_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/contributors","subscribers_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/subscribers","subscription_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/subscription","commits_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/commits{/sha}","git_commits_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/git/commits{/sha}","comments_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/comments{/number}","issue_comment_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/issues/comments{/number}","contents_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/contents/{+path}","compare_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/compare/{base}...{head}","merges_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/merges","archive_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/downloads","issues_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/issues{/number}","pulls_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/pulls{/number}","milestones_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/milestones{/number}","notifications_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/labels{/name}","releases_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/releases{/id}","deployments_url":"https://api.github.com/repos/0rc/chaostoolkit-aws/deployments","created_at":"2018-08-06T14:32:34Z","updated_at":"2018-08-06T14:32:35Z","pushed_at":"2018-08-08T13:17:53Z","git_url":"git://github.com/0rc/chaostoolkit-aws.git","ssh_url":"git@github.com:0rc/chaostoolkit-aws.git","clone_url":"https://github.com/0rc/chaostoolkit-aws.git","svn_url":"https://github.com/0rc/chaostoolkit-aws","homepage":"","size":64,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"chaostoolkit-incubator:master","ref":"master","sha":"fb3dbe845f03b93682dcc58dc97c51a51b4a3667","user":{"login":"chaostoolkit-incubator","id":35833757,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM1ODMzNzU3","avatar_url":"https://avatars1.githubusercontent.com/u/35833757?v=4","gravatar_id":"","url":"https://api.github.com/users/chaostoolkit-incubator","html_url":"https://github.com/chaostoolkit-incubator","followers_url":"https://api.github.com/users/chaostoolkit-incubator/followers","following_url":"https://api.github.com/users/chaostoolkit-incubator/following{/other_user}","gists_url":"https://api.github.com/users/chaostoolkit-incubator/gists{/gist_id}","starred_url":"https://api.github.com/users/chaostoolkit-incubator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chaostoolkit-incubator/subscriptions","organizations_url":"https://api.github.com/users/chaostoolkit-incubator/orgs","repos_url":"https://api.github.com/users/chaostoolkit-incubator/repos","events_url":"https://api.github.com/users/chaostoolkit-incubator/events{/privacy}","received_events_url":"https://api.github.com/users/chaostoolkit-incubator/received_events","type":"Organization","site_admin":false},"repo":{"id":119553934,"node_id":"MDEwOlJlcG9zaXRvcnkxMTk1NTM5MzQ=","name":"chaostoolkit-aws","full_name":"chaostoolkit-incubator/chaostoolkit-aws","owner":{"login":"chaostoolkit-incubator","id":35833757,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM1ODMzNzU3","avatar_url":"https://avatars1.githubusercontent.com/u/35833757?v=4","gravatar_id":"","url":"https://api.github.com/users/chaostoolkit-incubator","html_url":"https://github.com/chaostoolkit-incubator","followers_url":"https://api.github.com/users/chaostoolkit-incubator/followers","following_url":"https://api.github.com/users/chaostoolkit-incubator/following{/other_user}","gists_url":"https://api.github.com/users/chaostoolkit-incubator/gists{/gist_id}","starred_url":"https://api.github.com/users/chaostoolkit-incubator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chaostoolkit-incubator/subscriptions","organizations_url":"https://api.github.com/users/chaostoolkit-incubator/orgs","repos_url":"https://api.github.com/users/chaostoolkit-incubator/repos","events_url":"https://api.github.com/users/chaostoolkit-incubator/events{/privacy}","received_events_url":"https://api.github.com/users/chaostoolkit-incubator/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chaostoolkit-incubator/chaostoolkit-aws","description":"Chaos Toolkit Extension for AWS","fork":false,"url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws","forks_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/forks","keys_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/teams","hooks_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/hooks","issue_events_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/issues/events{/number}","events_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/events","assignees_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/assignees{/user}","branches_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/branches{/branch}","tags_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/tags","blobs_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/git/refs{/sha}","trees_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/statuses/{sha}","languages_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/languages","stargazers_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/stargazers","contributors_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/contributors","subscribers_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/subscribers","subscription_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/subscription","commits_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/commits{/sha}","git_commits_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/git/commits{/sha}","comments_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/comments{/number}","issue_comment_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/issues/comments{/number}","contents_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/contents/{+path}","compare_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/merges","archive_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/downloads","issues_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/issues{/number}","pulls_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls{/number}","milestones_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/milestones{/number}","notifications_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/labels{/name}","releases_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/releases{/id}","deployments_url":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/deployments","created_at":"2018-01-30T15:19:21Z","updated_at":"2018-07-09T11:40:34Z","pushed_at":"2018-08-08T13:17:55Z","git_url":"git://github.com/chaostoolkit-incubator/chaostoolkit-aws.git","ssh_url":"git@github.com:chaostoolkit-incubator/chaostoolkit-aws.git","clone_url":"https://github.com/chaostoolkit-incubator/chaostoolkit-aws.git","svn_url":"https://github.com/chaostoolkit-incubator/chaostoolkit-aws","homepage":"","size":71,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":5,"open_issues":1,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/15"},"html":{"href":"https://github.com/chaostoolkit-incubator/chaostoolkit-aws/pull/15"},"issue":{"href":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/issues/15"},"comments":{"href":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/issues/15/comments"},"review_comments":{"href":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/15/comments"},"review_comment":{"href":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/pulls/15/commits"},"statuses":{"href":"https://api.github.com/repos/chaostoolkit-incubator/chaostoolkit-aws/statuses/abff0ad3b380c7e48b4dda33b31338cde992a3d9"}},"author_association":"NONE"}}
{"actor":{"display_login":"Lawouach"}}