{"action":"created","comment":{"url":"https://api.github.com/repos/hudl/Tyr/pulls/comments/34602237","id":34602237,"diff_hunk":"@@ -0,0 +1,115 @@\n+from boto.ec2.autoscale import AutoScaleConnection\n+from boto.ec2.autoscale import LaunchConfiguration\n+from boto.ec2.autoscale import AutoScalingGroup\n+import boto.ec2\n+import logging\n+\n+\n+class AutoScaler(object):\n+    '''\n+    Autoscaler setup class\n+    '''\n+\n+    log = logging.getLogger('Clusters.AutoScaler')\n+    log.setLevel(logging.DEBUG)\n+    ch = logging.StreamHandler()\n+    ch.setLevel(logging.DEBUG)\n+    formatter = logging.Formatter(\n+        '%(asctime)s [%(name)s] %(levelname)s: %(message)s',\n+        datefmt='%H:%M:%S')\n+    ch.setFormatter(formatter)\n+    log.addHandler(ch)\n+\n+    def __init__(self, launch_configuration,\n+                 autoscaling_group,\n+                 node_obj,\n+                 desired_capacity=1,\n+                 max_size=1,\n+                 min_size=1,\n+                 default_cooldown=300,\n+                 availability_zones=None,\n+                 subnet_ids=None,\n+                 health_check_grace_period=300):\n+\n+        self.launch_configuration = launch_configuration\n+        self.autoscaling_group = autoscaling_group\n+        self.desired_capacity = desired_capacity\n+\n+        # You can set a list of availability zones explicitly, else it will\n+        # just use the one from the node object\n+        if availability_zones:\n+            self.autoscale_availability_zones = availability_zones\n+        else:\n+            self.autoscale_availability_zones = None\n+\n+        # If you set these they must match the availability zones\n+        if subnet_ids:\n+            self.autoscale_subnets = subnet_ids\n+        else:\n+            self.autoscale_subnets = None #(get the subnet IDs)\n+\n+        if not subnet_ids and not availability_zones:\n+            raise ValueError(\"Must specify either availability_zones or subnets.\")\n+\n+        if subnet_ids and availability_zones:\n+            self.log.warning(\"Specified both availability_zones and subnets.\")\n+\n+        self.node_obj = node_obj\n+        self.max_size = max_size\n+        self.min_size = min_size\n+        self.default_cooldown = default_cooldown\n+        self.health_check_grace_period = health_check_grace_period\n+\n+    def establish_autoscale_connection(self):\n+        try:\n+            self.conn = boto.ec2.autoscale.connect_to_region(self.node_obj.region)\n+            self.log.info('Established connection to autoscale')\n+        except:\n+            raise\n+\n+    def create_launch_configuration(self):\n+        self.log.info(\"Getting launch_configuration: {0}\"\n+            .format(self.launch_configuration))\n+\n+        lc = self.conn.get_all_launch_configurations(\n+            names=[self.launch_configuration])\n+        if not lc:\n+            self.log.info(\"Creating new launch_configuration: {0}\"\n+                          .format(self.launch_configuration))\n+            lc = LaunchConfiguration(name=self.launch_configuration,\n+                                     image_id=self.node_obj.ami,\n+                                     key_name=self.node_obj.keypair,\n+                                     security_groups=self.node_obj.get_security_group_ids(\n+                                         self.node_obj.security_groups),\n+                                     user_data=self.node_obj.user_data,\n+                                     instance_profile_name=self.node_obj.role)\n+            self.conn.create_launch_configuration(lc)\n+            self.launch_configuration = lc\n+\n+    def create_autoscaling_group(self):\n+        existing_asg = self.conn.get_all_groups(\n+            names=[self.autoscaling_group])\n+\n+        if not existing_asg:\n+            self.log.info(\"Creating new autoscaling group: {0}\"\n+                          .format(self.autoscaling_group))\n+\n+            ag = AutoScalingGroup(name=self.autoscaling_group,\n+                                  availability_zones=self.autoscale_availability_zones,","path":"tyr/autoscaler/autoscaler.py","position":98,"original_position":98,"commit_id":"0a5736bb2df5cf8d9d19b87216987a542a3a1f41","original_commit_id":"0a5736bb2df5cf8d9d19b87216987a542a3a1f41","user":{"login":"citruspi","id":2125849,"avatar_url":"https://avatars.githubusercontent.com/u/2125849?v=3","gravatar_id":"","url":"https://api.github.com/users/citruspi","html_url":"https://github.com/citruspi","followers_url":"https://api.github.com/users/citruspi/followers","following_url":"https://api.github.com/users/citruspi/following{/other_user}","gists_url":"https://api.github.com/users/citruspi/gists{/gist_id}","starred_url":"https://api.github.com/users/citruspi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citruspi/subscriptions","organizations_url":"https://api.github.com/users/citruspi/orgs","repos_url":"https://api.github.com/users/citruspi/repos","events_url":"https://api.github.com/users/citruspi/events{/privacy}","received_events_url":"https://api.github.com/users/citruspi/received_events","type":"User","site_admin":false},"body":"This line is over 79 characters.","created_at":"2015-07-14T18:30:26Z","updated_at":"2015-07-14T18:30:26Z","html_url":"https://github.com/hudl/Tyr/pull/58#discussion_r34602237","pull_request_url":"https://api.github.com/repos/hudl/Tyr/pulls/58","_links":{"self":{"href":"https://api.github.com/repos/hudl/Tyr/pulls/comments/34602237"},"html":{"href":"https://github.com/hudl/Tyr/pull/58#discussion_r34602237"},"pull_request":{"href":"https://api.github.com/repos/hudl/Tyr/pulls/58"}}},"pull_request":{"url":"https://api.github.com/repos/hudl/Tyr/pulls/58","id":39835288,"html_url":"https://github.com/hudl/Tyr/pull/58","diff_url":"https://github.com/hudl/Tyr/pull/58.diff","patch_url":"https://github.com/hudl/Tyr/pull/58.patch","issue_url":"https://api.github.com/repos/hudl/Tyr/issues/58","number":58,"state":"open","locked":false,"title":"Add IISNode IICluster and Autoscaler classes","user":{"login":"chrisgilbert","id":361112,"avatar_url":"https://avatars.githubusercontent.com/u/361112?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisgilbert","html_url":"https://github.com/chrisgilbert","followers_url":"https://api.github.com/users/chrisgilbert/followers","following_url":"https://api.github.com/users/chrisgilbert/following{/other_user}","gists_url":"https://api.github.com/users/chrisgilbert/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisgilbert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisgilbert/subscriptions","organizations_url":"https://api.github.com/users/chrisgilbert/orgs","repos_url":"https://api.github.com/users/chrisgilbert/repos","events_url":"https://api.github.com/users/chrisgilbert/events{/privacy}","received_events_url":"https://api.github.com/users/chrisgilbert/received_events","type":"User","site_admin":false},"body":"I have been using the following to test.  \r\n\r\n```\r\nfrom tyr.clusters.iis import IISCluster\r\nIISCluster(group='chrisgtest', environment='stage', ami='ami-bea09bd6', subnet_ids=[\"subnet-961652e1\", \"subnet-9a41d9c3\"], desired_capacity=2, min_size=1, max_size=3).autorun()\r\n```\r\n\r\nThere are a few issues that need ironing out:\r\n\r\n- Problem spinning up servers once in ASG.  Need to diagnose","created_at":"2015-07-13T17:23:56Z","updated_at":"2015-07-14T18:30:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"baec8de480e02fce79259c7a30084b7f035aea47","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hudl/Tyr/pulls/58/commits","review_comments_url":"https://api.github.com/repos/hudl/Tyr/pulls/58/comments","review_comment_url":"https://api.github.com/repos/hudl/Tyr/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hudl/Tyr/issues/58/comments","statuses_url":"https://api.github.com/repos/hudl/Tyr/statuses/0a5736bb2df5cf8d9d19b87216987a542a3a1f41","head":{"label":"hudl:STRUCT-AddIISNodeType","ref":"STRUCT-AddIISNodeType","sha":"0a5736bb2df5cf8d9d19b87216987a542a3a1f41","user":{"login":"hudl","id":123340,"avatar_url":"https://avatars.githubusercontent.com/u/123340?v=3","gravatar_id":"","url":"https://api.github.com/users/hudl","html_url":"https://github.com/hudl","followers_url":"https://api.github.com/users/hudl/followers","following_url":"https://api.github.com/users/hudl/following{/other_user}","gists_url":"https://api.github.com/users/hudl/gists{/gist_id}","starred_url":"https://api.github.com/users/hudl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hudl/subscriptions","organizations_url":"https://api.github.com/users/hudl/orgs","repos_url":"https://api.github.com/users/hudl/repos","events_url":"https://api.github.com/users/hudl/events{/privacy}","received_events_url":"https://api.github.com/users/hudl/received_events","type":"Organization","site_admin":false},"repo":{"id":31391696,"name":"Tyr","full_name":"hudl/Tyr","owner":{"login":"hudl","id":123340,"avatar_url":"https://avatars.githubusercontent.com/u/123340?v=3","gravatar_id":"","url":"https://api.github.com/users/hudl","html_url":"https://github.com/hudl","followers_url":"https://api.github.com/users/hudl/followers","following_url":"https://api.github.com/users/hudl/following{/other_user}","gists_url":"https://api.github.com/users/hudl/gists{/gist_id}","starred_url":"https://api.github.com/users/hudl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hudl/subscriptions","organizations_url":"https://api.github.com/users/hudl/orgs","repos_url":"https://api.github.com/users/hudl/repos","events_url":"https://api.github.com/users/hudl/events{/privacy}","received_events_url":"https://api.github.com/users/hudl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hudl/Tyr","description":"","fork":false,"url":"https://api.github.com/repos/hudl/Tyr","forks_url":"https://api.github.com/repos/hudl/Tyr/forks","keys_url":"https://api.github.com/repos/hudl/Tyr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hudl/Tyr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hudl/Tyr/teams","hooks_url":"https://api.github.com/repos/hudl/Tyr/hooks","issue_events_url":"https://api.github.com/repos/hudl/Tyr/issues/events{/number}","events_url":"https://api.github.com/repos/hudl/Tyr/events","assignees_url":"https://api.github.com/repos/hudl/Tyr/assignees{/user}","branches_url":"https://api.github.com/repos/hudl/Tyr/branches{/branch}","tags_url":"https://api.github.com/repos/hudl/Tyr/tags","blobs_url":"https://api.github.com/repos/hudl/Tyr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hudl/Tyr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hudl/Tyr/git/refs{/sha}","trees_url":"https://api.github.com/repos/hudl/Tyr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hudl/Tyr/statuses/{sha}","languages_url":"https://api.github.com/repos/hudl/Tyr/languages","stargazers_url":"https://api.github.com/repos/hudl/Tyr/stargazers","contributors_url":"https://api.github.com/repos/hudl/Tyr/contributors","subscribers_url":"https://api.github.com/repos/hudl/Tyr/subscribers","subscription_url":"https://api.github.com/repos/hudl/Tyr/subscription","commits_url":"https://api.github.com/repos/hudl/Tyr/commits{/sha}","git_commits_url":"https://api.github.com/repos/hudl/Tyr/git/commits{/sha}","comments_url":"https://api.github.com/repos/hudl/Tyr/comments{/number}","issue_comment_url":"https://api.github.com/repos/hudl/Tyr/issues/comments{/number}","contents_url":"https://api.github.com/repos/hudl/Tyr/contents/{+path}","compare_url":"https://api.github.com/repos/hudl/Tyr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hudl/Tyr/merges","archive_url":"https://api.github.com/repos/hudl/Tyr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hudl/Tyr/downloads","issues_url":"https://api.github.com/repos/hudl/Tyr/issues{/number}","pulls_url":"https://api.github.com/repos/hudl/Tyr/pulls{/number}","milestones_url":"https://api.github.com/repos/hudl/Tyr/milestones{/number}","notifications_url":"https://api.github.com/repos/hudl/Tyr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hudl/Tyr/labels{/name}","releases_url":"https://api.github.com/repos/hudl/Tyr/releases{/id}","created_at":"2015-02-26T22:15:08Z","updated_at":"2015-05-08T19:46:22Z","pushed_at":"2015-07-14T11:22:30Z","git_url":"git://github.com/hudl/Tyr.git","ssh_url":"git@github.com:hudl/Tyr.git","clone_url":"https://github.com/hudl/Tyr.git","svn_url":"https://github.com/hudl/Tyr","homepage":null,"size":995,"stargazers_count":4,"watchers_count":4,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":17,"forks":1,"open_issues":17,"watchers":4,"default_branch":"master"}},"base":{"label":"hudl:master","ref":"master","sha":"88249d23500577db2302e68ce81e2bc94a26edd9","user":{"login":"hudl","id":123340,"avatar_url":"https://avatars.githubusercontent.com/u/123340?v=3","gravatar_id":"","url":"https://api.github.com/users/hudl","html_url":"https://github.com/hudl","followers_url":"https://api.github.com/users/hudl/followers","following_url":"https://api.github.com/users/hudl/following{/other_user}","gists_url":"https://api.github.com/users/hudl/gists{/gist_id}","starred_url":"https://api.github.com/users/hudl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hudl/subscriptions","organizations_url":"https://api.github.com/users/hudl/orgs","repos_url":"https://api.github.com/users/hudl/repos","events_url":"https://api.github.com/users/hudl/events{/privacy}","received_events_url":"https://api.github.com/users/hudl/received_events","type":"Organization","site_admin":false},"repo":{"id":31391696,"name":"Tyr","full_name":"hudl/Tyr","owner":{"login":"hudl","id":123340,"avatar_url":"https://avatars.githubusercontent.com/u/123340?v=3","gravatar_id":"","url":"https://api.github.com/users/hudl","html_url":"https://github.com/hudl","followers_url":"https://api.github.com/users/hudl/followers","following_url":"https://api.github.com/users/hudl/following{/other_user}","gists_url":"https://api.github.com/users/hudl/gists{/gist_id}","starred_url":"https://api.github.com/users/hudl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hudl/subscriptions","organizations_url":"https://api.github.com/users/hudl/orgs","repos_url":"https://api.github.com/users/hudl/repos","events_url":"https://api.github.com/users/hudl/events{/privacy}","received_events_url":"https://api.github.com/users/hudl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hudl/Tyr","description":"","fork":false,"url":"https://api.github.com/repos/hudl/Tyr","forks_url":"https://api.github.com/repos/hudl/Tyr/forks","keys_url":"https://api.github.com/repos/hudl/Tyr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hudl/Tyr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hudl/Tyr/teams","hooks_url":"https://api.github.com/repos/hudl/Tyr/hooks","issue_events_url":"https://api.github.com/repos/hudl/Tyr/issues/events{/number}","events_url":"https://api.github.com/repos/hudl/Tyr/events","assignees_url":"https://api.github.com/repos/hudl/Tyr/assignees{/user}","branches_url":"https://api.github.com/repos/hudl/Tyr/branches{/branch}","tags_url":"https://api.github.com/repos/hudl/Tyr/tags","blobs_url":"https://api.github.com/repos/hudl/Tyr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hudl/Tyr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hudl/Tyr/git/refs{/sha}","trees_url":"https://api.github.com/repos/hudl/Tyr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hudl/Tyr/statuses/{sha}","languages_url":"https://api.github.com/repos/hudl/Tyr/languages","stargazers_url":"https://api.github.com/repos/hudl/Tyr/stargazers","contributors_url":"https://api.github.com/repos/hudl/Tyr/contributors","subscribers_url":"https://api.github.com/repos/hudl/Tyr/subscribers","subscription_url":"https://api.github.com/repos/hudl/Tyr/subscription","commits_url":"https://api.github.com/repos/hudl/Tyr/commits{/sha}","git_commits_url":"https://api.github.com/repos/hudl/Tyr/git/commits{/sha}","comments_url":"https://api.github.com/repos/hudl/Tyr/comments{/number}","issue_comment_url":"https://api.github.com/repos/hudl/Tyr/issues/comments{/number}","contents_url":"https://api.github.com/repos/hudl/Tyr/contents/{+path}","compare_url":"https://api.github.com/repos/hudl/Tyr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hudl/Tyr/merges","archive_url":"https://api.github.com/repos/hudl/Tyr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hudl/Tyr/downloads","issues_url":"https://api.github.com/repos/hudl/Tyr/issues{/number}","pulls_url":"https://api.github.com/repos/hudl/Tyr/pulls{/number}","milestones_url":"https://api.github.com/repos/hudl/Tyr/milestones{/number}","notifications_url":"https://api.github.com/repos/hudl/Tyr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hudl/Tyr/labels{/name}","releases_url":"https://api.github.com/repos/hudl/Tyr/releases{/id}","created_at":"2015-02-26T22:15:08Z","updated_at":"2015-05-08T19:46:22Z","pushed_at":"2015-07-14T11:22:30Z","git_url":"git://github.com/hudl/Tyr.git","ssh_url":"git@github.com:hudl/Tyr.git","clone_url":"https://github.com/hudl/Tyr.git","svn_url":"https://github.com/hudl/Tyr","homepage":null,"size":995,"stargazers_count":4,"watchers_count":4,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":17,"forks":1,"open_issues":17,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hudl/Tyr/pulls/58"},"html":{"href":"https://github.com/hudl/Tyr/pull/58"},"issue":{"href":"https://api.github.com/repos/hudl/Tyr/issues/58"},"comments":{"href":"https://api.github.com/repos/hudl/Tyr/issues/58/comments"},"review_comments":{"href":"https://api.github.com/repos/hudl/Tyr/pulls/58/comments"},"review_comment":{"href":"https://api.github.com/repos/hudl/Tyr/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hudl/Tyr/pulls/58/commits"},"statuses":{"href":"https://api.github.com/repos/hudl/Tyr/statuses/0a5736bb2df5cf8d9d19b87216987a542a3a1f41"}}}}