{"action":"created","comment":{"url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/comments/52261329","id":52261329,"diff_hunk":"@@ -537,6 +506,76 @@ def add_cloudwatch_alarm(self,\n \n         return self.add_resource(alarm)\n \n+    @staticmethod\n+    def image_map_name(image_label):\n+        \"\"\"\n+        Each image map is a concatenation of a custom label and a prefix. This function\n+        provides a consistant way to get the correct image map name from the custom label.\n+        @returns string\n+        \"\"\"\n+        return Template.IMAGE_MAP_PREFIX + image_label.title()\n+\n+    def get_instancetype_param(self, instance_type, image_name, layer_name):\n+        \"\"\"\n+        @param instance_type [string] Default instance_type value.\n+        @param image_name [string] Key from config.image_map, used to create Parameter name\n+        @param layer_name [string] Functional name for the template, also used in Parameter name\n+        Returns a troposphere.Parameter configured to take instance types.  The parameter is only\n+        created if it does not already exist.\n+        \"\"\"\n+        if not isinstance(instance_type, basestring):\n+            raise Exception('Template.get_instancetype_param::instance_type should be string')\n+\n+        param_name = layer_name.title() + 'InstanceTypeFor' + image_name.title()\n+\n+        # Return parameter if it already exists\n+        if param_name in self.parameters:\n+            return self.parameters.get(param_name)\n+\n+        sorted_instancetypes = sorted(Template.instancetype_to_arch.keys())\n+        return self.add_parameter(Parameter(\n+            param_name,\n+            Description='AWS instance type',\n+            Default=instance_type,\n+            Type='String',\n+            AllowedValues=sorted_instancetypes))\n+\n+    def get_ami(self, instance_type, image_name, layer_name):\n+        \"\"\"\n+        @param instance_type [string] Default instance_type value.\n+        @param image_name [string] Key from config.image_map, used to create Parameter name\n+        @param layer_name [string] Functional name for the template, also used in Parameter name\n+        Returns a CloudFormation expression which will evaluate to an AMI id.  This is done by\n+        attaching a single instancetype_to_arch map and a region_to_ami_id map (per image type).\n+        Note: Resulting templates can deploy with different instance_types into differnet regions\n+        without any modification.\n+        \"\"\"\n+        if not isinstance(instance_type, basestring):\n+            raise Exception('Template.get_ami::instance_type should be string')\n+\n+        # Static validation of instance type\n+        if instance_type not in Template.instancetype_to_arch.keys():\n+            raise Exception('Unrecognized instance type: \"%s\"' % instance_type)\n+\n+        # Add input parameter (\\w runtime validation) for instance_type\n+        instancetype_param = self.get_instancetype_param(instance_type, image_name, layer_name)\n+\n+        # Lazy-add instancetype_to_arch map\n+        if Template.ARCH_MAP not in self.mappings:\n+            arch_map = {inst_type: {\"Arch\": arch} for inst_type, arch in Template.instancetype_to_arch.items()}\n+            self.mappings[Template.ARCH_MAP] = arch_map","path":"src/environmentbase/template.py","position":153,"original_position":153,"commit_id":"b54a055200356041375403731d0c82a486f89d33","original_commit_id":"b54a055200356041375403731d0c82a486f89d33","user":{"login":"sesas","id":554988,"avatar_url":"https://avatars.githubusercontent.com/u/554988?v=3","gravatar_id":"","url":"https://api.github.com/users/sesas","html_url":"https://github.com/sesas","followers_url":"https://api.github.com/users/sesas/followers","following_url":"https://api.github.com/users/sesas/following{/other_user}","gists_url":"https://api.github.com/users/sesas/gists{/gist_id}","starred_url":"https://api.github.com/users/sesas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sesas/subscriptions","organizations_url":"https://api.github.com/users/sesas/orgs","repos_url":"https://api.github.com/users/sesas/repos","events_url":"https://api.github.com/users/sesas/events{/privacy}","received_events_url":"https://api.github.com/users/sesas/received_events","type":"User","site_admin":false},"body":"I would put this into a different helper function since it has a well defined purpose that is separable from the purpose of this function.","created_at":"2016-02-09T02:37:52Z","updated_at":"2016-02-09T02:37:52Z","html_url":"https://github.com/DualSpark/cloudformation-environmentbase/pull/27#discussion_r52261329","pull_request_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/comments/52261329"},"html":{"href":"https://github.com/DualSpark/cloudformation-environmentbase/pull/27#discussion_r52261329"},"pull_request":{"href":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/27","id":58696358,"html_url":"https://github.com/DualSpark/cloudformation-environmentbase/pull/27","diff_url":"https://github.com/DualSpark/cloudformation-environmentbase/pull/27.diff","patch_url":"https://github.com/DualSpark/cloudformation-environmentbase/pull/27.patch","issue_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/issues/27","number":27,"state":"open","locked":false,"title":"Ami map cleanup","user":{"login":"gimballock","id":4082456,"avatar_url":"https://avatars.githubusercontent.com/u/4082456?v=3","gravatar_id":"","url":"https://api.github.com/users/gimballock","html_url":"https://github.com/gimballock","followers_url":"https://api.github.com/users/gimballock/followers","following_url":"https://api.github.com/users/gimballock/following{/other_user}","gists_url":"https://api.github.com/users/gimballock/gists{/gist_id}","starred_url":"https://api.github.com/users/gimballock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gimballock/subscriptions","organizations_url":"https://api.github.com/users/gimballock/orgs","repos_url":"https://api.github.com/users/gimballock/repos","events_url":"https://api.github.com/users/gimballock/events{/privacy}","received_events_url":"https://api.github.com/users/gimballock/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-09T02:03:12Z","updated_at":"2016-02-09T02:37:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cd5c7f9dfc106d472a03ec9235e370c0935d2586","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/27/commits","review_comments_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/27/comments","review_comment_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/issues/27/comments","statuses_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/statuses/b54a055200356041375403731d0c82a486f89d33","head":{"label":"DualSpark:ami_map_cleanup","ref":"ami_map_cleanup","sha":"b54a055200356041375403731d0c82a486f89d33","user":{"login":"DualSpark","id":7940266,"avatar_url":"https://avatars.githubusercontent.com/u/7940266?v=3","gravatar_id":"","url":"https://api.github.com/users/DualSpark","html_url":"https://github.com/DualSpark","followers_url":"https://api.github.com/users/DualSpark/followers","following_url":"https://api.github.com/users/DualSpark/following{/other_user}","gists_url":"https://api.github.com/users/DualSpark/gists{/gist_id}","starred_url":"https://api.github.com/users/DualSpark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DualSpark/subscriptions","organizations_url":"https://api.github.com/users/DualSpark/orgs","repos_url":"https://api.github.com/users/DualSpark/repos","events_url":"https://api.github.com/users/DualSpark/events{/privacy}","received_events_url":"https://api.github.com/users/DualSpark/received_events","type":"Organization","site_admin":false},"repo":{"id":31571108,"name":"cloudformation-environmentbase","full_name":"DualSpark/cloudformation-environmentbase","owner":{"login":"DualSpark","id":7940266,"avatar_url":"https://avatars.githubusercontent.com/u/7940266?v=3","gravatar_id":"","url":"https://api.github.com/users/DualSpark","html_url":"https://github.com/DualSpark","followers_url":"https://api.github.com/users/DualSpark/followers","following_url":"https://api.github.com/users/DualSpark/following{/other_user}","gists_url":"https://api.github.com/users/DualSpark/gists{/gist_id}","starred_url":"https://api.github.com/users/DualSpark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DualSpark/subscriptions","organizations_url":"https://api.github.com/users/DualSpark/orgs","repos_url":"https://api.github.com/users/DualSpark/repos","events_url":"https://api.github.com/users/DualSpark/events{/privacy}","received_events_url":"https://api.github.com/users/DualSpark/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DualSpark/cloudformation-environmentbase","description":"Troposphere-based environment generator","fork":false,"url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase","forks_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/forks","keys_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/teams","hooks_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/hooks","issue_events_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/issues/events{/number}","events_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/events","assignees_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/assignees{/user}","branches_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/branches{/branch}","tags_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/tags","blobs_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/git/refs{/sha}","trees_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/statuses/{sha}","languages_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/languages","stargazers_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/stargazers","contributors_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/contributors","subscribers_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/subscribers","subscription_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/subscription","commits_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/commits{/sha}","git_commits_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/git/commits{/sha}","comments_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/comments{/number}","issue_comment_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/issues/comments{/number}","contents_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/contents/{+path}","compare_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/merges","archive_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/downloads","issues_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/issues{/number}","pulls_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls{/number}","milestones_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/milestones{/number}","notifications_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/labels{/name}","releases_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/releases{/id}","deployments_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/deployments","created_at":"2015-03-03T00:28:14Z","updated_at":"2016-02-09T02:33:41Z","pushed_at":"2016-02-09T02:09:40Z","git_url":"git://github.com/DualSpark/cloudformation-environmentbase.git","ssh_url":"git@github.com:DualSpark/cloudformation-environmentbase.git","clone_url":"https://github.com/DualSpark/cloudformation-environmentbase.git","svn_url":"https://github.com/DualSpark/cloudformation-environmentbase","homepage":null,"size":900,"stargazers_count":10,"watchers_count":10,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":4,"forks":4,"open_issues":4,"watchers":10,"default_branch":"master"}},"base":{"label":"DualSpark:0.9.1.branch","ref":"0.9.1.branch","sha":"b52a5704b24b31038d23077c26fdbbd71c96f82e","user":{"login":"DualSpark","id":7940266,"avatar_url":"https://avatars.githubusercontent.com/u/7940266?v=3","gravatar_id":"","url":"https://api.github.com/users/DualSpark","html_url":"https://github.com/DualSpark","followers_url":"https://api.github.com/users/DualSpark/followers","following_url":"https://api.github.com/users/DualSpark/following{/other_user}","gists_url":"https://api.github.com/users/DualSpark/gists{/gist_id}","starred_url":"https://api.github.com/users/DualSpark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DualSpark/subscriptions","organizations_url":"https://api.github.com/users/DualSpark/orgs","repos_url":"https://api.github.com/users/DualSpark/repos","events_url":"https://api.github.com/users/DualSpark/events{/privacy}","received_events_url":"https://api.github.com/users/DualSpark/received_events","type":"Organization","site_admin":false},"repo":{"id":31571108,"name":"cloudformation-environmentbase","full_name":"DualSpark/cloudformation-environmentbase","owner":{"login":"DualSpark","id":7940266,"avatar_url":"https://avatars.githubusercontent.com/u/7940266?v=3","gravatar_id":"","url":"https://api.github.com/users/DualSpark","html_url":"https://github.com/DualSpark","followers_url":"https://api.github.com/users/DualSpark/followers","following_url":"https://api.github.com/users/DualSpark/following{/other_user}","gists_url":"https://api.github.com/users/DualSpark/gists{/gist_id}","starred_url":"https://api.github.com/users/DualSpark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DualSpark/subscriptions","organizations_url":"https://api.github.com/users/DualSpark/orgs","repos_url":"https://api.github.com/users/DualSpark/repos","events_url":"https://api.github.com/users/DualSpark/events{/privacy}","received_events_url":"https://api.github.com/users/DualSpark/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DualSpark/cloudformation-environmentbase","description":"Troposphere-based environment generator","fork":false,"url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase","forks_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/forks","keys_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/teams","hooks_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/hooks","issue_events_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/issues/events{/number}","events_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/events","assignees_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/assignees{/user}","branches_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/branches{/branch}","tags_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/tags","blobs_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/git/refs{/sha}","trees_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/statuses/{sha}","languages_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/languages","stargazers_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/stargazers","contributors_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/contributors","subscribers_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/subscribers","subscription_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/subscription","commits_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/commits{/sha}","git_commits_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/git/commits{/sha}","comments_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/comments{/number}","issue_comment_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/issues/comments{/number}","contents_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/contents/{+path}","compare_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/merges","archive_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/downloads","issues_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/issues{/number}","pulls_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls{/number}","milestones_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/milestones{/number}","notifications_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/labels{/name}","releases_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/releases{/id}","deployments_url":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/deployments","created_at":"2015-03-03T00:28:14Z","updated_at":"2016-02-09T02:33:41Z","pushed_at":"2016-02-09T02:09:40Z","git_url":"git://github.com/DualSpark/cloudformation-environmentbase.git","ssh_url":"git@github.com:DualSpark/cloudformation-environmentbase.git","clone_url":"https://github.com/DualSpark/cloudformation-environmentbase.git","svn_url":"https://github.com/DualSpark/cloudformation-environmentbase","homepage":null,"size":900,"stargazers_count":10,"watchers_count":10,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":4,"forks":4,"open_issues":4,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/27"},"html":{"href":"https://github.com/DualSpark/cloudformation-environmentbase/pull/27"},"issue":{"href":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/issues/27"},"comments":{"href":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/DualSpark/cloudformation-environmentbase/statuses/b54a055200356041375403731d0c82a486f89d33"}}}}