{"action":"created","comment":{"url":"https://api.github.com/repos/saltstack/salt/pulls/comments/108308389","pull_request_review_id":29331315,"id":108308389,"diff_hunk":"@@ -0,0 +1,195 @@\n+# -*- coding: utf-8 -*-\n+'''\n+Manage AWS Application Load Balancer\n+\n+.. versionadded:: TBD\n+\n+Add and remove targets from an ALB target group.\n+\n+This module uses ``boto3``, which can be installed via package, or pip.\n+\n+This module accepts explicit alb credentials but can also utilize\n+IAM roles assigned to the instance through Instance Profiles. Dynamic\n+credentials are then automatically obtained from AWS API and no further\n+configuration is necessary. More information available `here\n+<http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html>`_.\n+\n+If IAM roles are not used you need to specify them either in a pillar file or\n+in the minion's config file:\n+\n+.. code-block:: yaml\n+\n+    elbv2.keyid: GKTADJGHEIQSXMKKRBJ08H\n+    elbv2.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs\n+    elbv2.region: us-west-2\n+\n+It's also possible to specify ``key``, ``keyid`` and ``region`` via a profile, either\n+passed in as a dict, or as a string to pull from pillars or minion config:\n+\n+.. code-block:: yaml\n+\n+    myprofile:\n+        keyid: GKTADJGHEIQSXMKKRBJ08H\n+        key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs\n+        region: us-east-1\n+'''\n+\n+from __future__ import absolute_import\n+\n+# Import Python Libs\n+import logging\n+import copy\n+\n+# Import Salt Libs\n+log = logging.getLogger(__name__)\n+\n+\n+def __virtual__():\n+    '''\n+    Only load if boto is available.\n+    '''\n+    return 'boto_elbv2' if 'boto_elbv2.target_group_exists' in __salt__ else False\n+\n+\n+def targets_registered(name, targets, region=None, key=None, keyid=None,\n+                       profile=None):\n+    '''\n+    Add targets to an Application Load Balancer target group. This state will not remove targets.\n+\n+    name\n+        The ARN of the Application Load Balancer Target Group to add targets to.\n+\n+    targets\n+        A list of target IDs or a string of a single target that this target group should\n+        distribute traffic to.\n+\n+    .. versionadded:: TBD\n+\n+    .. code-block:: yaml\n+\n+        add-targets:\n+          boto_elb.targets_registered:\n+            - name: arn:myloadbalancer\n+            - targets:\n+              - instance-id1\n+              - instance-id2\n+    '''\n+    ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}\n+    tg = __salt__['boto_elbv2.target_group_exists'](name, region, key, keyid, profile)\n+\n+    if tg:\n+        health = __salt__['boto_elbv2.describe_target_health'](name, region=region, key=key, keyid=keyid, profile=profile)\n+        failure = False\n+        changes = False\n+        newhealth_mock = copy.copy(health)\n+\n+        if isinstance(targets, str):\n+            targets = [targets]\n+\n+        for target in targets:\n+            if target in health and health.get(target) != \"draining\":\n+                ret['comment'] = ret['comment'] + 'Target/s {0} already registered and is {1}.\\n'.format(target, health[target])\n+                ret['result'] = True\n+            else:\n+                if __opts__['test']:\n+                    changes = True\n+                    newhealth_mock.update({target: \"initial\"})\n+                else:\n+                    state = __salt__['boto_elbv2.register_targets'](name,\n+                                                                    targets,\n+                                                                    region,\n+                                                                    key,\n+                                                                    keyid,\n+                                                                    profile)\n+                    if state:\n+                        changes = True\n+                        ret['result'] = True\n+                    else:\n+                        ret['comment'] = 'Target Group {0} failed to add targets'.format(name)\n+                        failure = True\n+        if failure:\n+            ret['result'] = False\n+        if changes:\n+            ret['changes']['old'] = health\n+            if __opts__['test']:\n+                ret['comment'] = 'Target Group {0} would be changed'.format(name)\n+                ret['result'] = None\n+                ret['changes']['new'] = newhealth_mock\n+            else:\n+                ret['comment'] = 'Target Group {0} has been changed'.format(name)\n+                newhealth = __salt__['boto_elbv2.describe_target_health'](name, region=region, key=key, keyid=keyid, profile=profile)\n+                ret['changes']['new'] = newhealth\n+        return ret\n+    else:\n+        ret['comment'] = 'Could not find target group {0}'.format(name)\n+    return ret\n+\n+\n+def targets_deregistered(name, targets, region=None, key=None, keyid=None,\n+                       profile=None):\n+    '''\n+    Remove targets to an Application Load Balancer target group.\n+\n+    name\n+        The ARN of the Application Load Balancer Target Group to remove targets from.\n+\n+    targets\n+        A list of target IDs or a string of a single target registered to the target group to be removed\n+\n+    .. versionadded:: Unknown\n+\n+    .. code-block:: yaml\n+\n+        remove-targets:\n+          boto_elb.targets_deregistered:\n+            - name: arn:myloadbalancer\n+            - targets:\n+              - instance-id1\n+              - instance-id2\n+    '''\n+    ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}\n+    tg = __salt__['boto_elbv2.target_group_exists'](name, region, key, keyid, profile)\n+    if tg:\n+        health = __salt__['boto_elbv2.describe_target_health'](name, region, key, keyid, profile)\n+        failure = False\n+        changes = False","path":"salt/states/boto_elbv2.py","position":155,"original_position":155,"commit_id":"9b714ef0083c387013a546593a6e03e4f64b5f3c","original_commit_id":"9b714ef0083c387013a546593a6e03e4f64b5f3c","user":{"login":"cachedout","id":111616,"avatar_url":"https://avatars0.githubusercontent.com/u/111616?v=3","gravatar_id":"","url":"https://api.github.com/users/cachedout","html_url":"https://github.com/cachedout","followers_url":"https://api.github.com/users/cachedout/followers","following_url":"https://api.github.com/users/cachedout/following{/other_user}","gists_url":"https://api.github.com/users/cachedout/gists{/gist_id}","starred_url":"https://api.github.com/users/cachedout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cachedout/subscriptions","organizations_url":"https://api.github.com/users/cachedout/orgs","repos_url":"https://api.github.com/users/cachedout/repos","events_url":"https://api.github.com/users/cachedout/events{/privacy}","received_events_url":"https://api.github.com/users/cachedout/received_events","type":"User","site_admin":false},"body":"This could just be `failure = changes = False` if you like.","created_at":"2017-03-27T23:59:37Z","updated_at":"2017-03-28T00:01:44Z","html_url":"https://github.com/saltstack/salt/pull/40263#discussion_r108308389","pull_request_url":"https://api.github.com/repos/saltstack/salt/pulls/40263","_links":{"self":{"href":"https://api.github.com/repos/saltstack/salt/pulls/comments/108308389"},"html":{"href":"https://github.com/saltstack/salt/pull/40263#discussion_r108308389"},"pull_request":{"href":"https://api.github.com/repos/saltstack/salt/pulls/40263"}}},"pull_request":{"url":"https://api.github.com/repos/saltstack/salt/pulls/40263","id":112281139,"html_url":"https://github.com/saltstack/salt/pull/40263","diff_url":"https://github.com/saltstack/salt/pull/40263.diff","patch_url":"https://github.com/saltstack/salt/pull/40263.patch","issue_url":"https://api.github.com/repos/saltstack/salt/issues/40263","number":40263,"state":"open","locked":false,"title":"Add boto_elbv2 states and modules for de/registering targets and chec…","user":{"login":"deuscapturus","id":5497572,"avatar_url":"https://avatars1.githubusercontent.com/u/5497572?v=3","gravatar_id":"","url":"https://api.github.com/users/deuscapturus","html_url":"https://github.com/deuscapturus","followers_url":"https://api.github.com/users/deuscapturus/followers","following_url":"https://api.github.com/users/deuscapturus/following{/other_user}","gists_url":"https://api.github.com/users/deuscapturus/gists{/gist_id}","starred_url":"https://api.github.com/users/deuscapturus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deuscapturus/subscriptions","organizations_url":"https://api.github.com/users/deuscapturus/orgs","repos_url":"https://api.github.com/users/deuscapturus/repos","events_url":"https://api.github.com/users/deuscapturus/events{/privacy}","received_events_url":"https://api.github.com/users/deuscapturus/received_events","type":"User","site_admin":false},"body":"Add boto_elbv2 states and modules for de/registering targets and checking health of AWS Application Load Balancer target groups.\r\n\r\n### What does this PR do?\r\n\r\nAdd module and state for boto elbv2\r\n\r\n### Tests written?\r\n\r\nNo\r\n\r\nPlease review [Salt's Contributing Guide](https://docs.saltstack.com/en/latest/topics/development/contributing.html) for best practices.\r\n","created_at":"2017-03-23T16:29:34Z","updated_at":"2017-03-28T00:01:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a0e1d967cda7a4cb484d9689521d429dd9d5493c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/saltstack/salt/pulls/40263/commits","review_comments_url":"https://api.github.com/repos/saltstack/salt/pulls/40263/comments","review_comment_url":"https://api.github.com/repos/saltstack/salt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/40263/comments","statuses_url":"https://api.github.com/repos/saltstack/salt/statuses/9b714ef0083c387013a546593a6e03e4f64b5f3c","head":{"label":"deuscapturus:boto_elbv2","ref":"boto_elbv2","sha":"9b714ef0083c387013a546593a6e03e4f64b5f3c","user":{"login":"deuscapturus","id":5497572,"avatar_url":"https://avatars1.githubusercontent.com/u/5497572?v=3","gravatar_id":"","url":"https://api.github.com/users/deuscapturus","html_url":"https://github.com/deuscapturus","followers_url":"https://api.github.com/users/deuscapturus/followers","following_url":"https://api.github.com/users/deuscapturus/following{/other_user}","gists_url":"https://api.github.com/users/deuscapturus/gists{/gist_id}","starred_url":"https://api.github.com/users/deuscapturus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deuscapturus/subscriptions","organizations_url":"https://api.github.com/users/deuscapturus/orgs","repos_url":"https://api.github.com/users/deuscapturus/repos","events_url":"https://api.github.com/users/deuscapturus/events{/privacy}","received_events_url":"https://api.github.com/users/deuscapturus/received_events","type":"User","site_admin":false},"repo":{"id":70626118,"name":"salt","full_name":"deuscapturus/salt","owner":{"login":"deuscapturus","id":5497572,"avatar_url":"https://avatars1.githubusercontent.com/u/5497572?v=3","gravatar_id":"","url":"https://api.github.com/users/deuscapturus","html_url":"https://github.com/deuscapturus","followers_url":"https://api.github.com/users/deuscapturus/followers","following_url":"https://api.github.com/users/deuscapturus/following{/other_user}","gists_url":"https://api.github.com/users/deuscapturus/gists{/gist_id}","starred_url":"https://api.github.com/users/deuscapturus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deuscapturus/subscriptions","organizations_url":"https://api.github.com/users/deuscapturus/orgs","repos_url":"https://api.github.com/users/deuscapturus/repos","events_url":"https://api.github.com/users/deuscapturus/events{/privacy}","received_events_url":"https://api.github.com/users/deuscapturus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/deuscapturus/salt","description":"Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt Open software package repository here: ","fork":true,"url":"https://api.github.com/repos/deuscapturus/salt","forks_url":"https://api.github.com/repos/deuscapturus/salt/forks","keys_url":"https://api.github.com/repos/deuscapturus/salt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/deuscapturus/salt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/deuscapturus/salt/teams","hooks_url":"https://api.github.com/repos/deuscapturus/salt/hooks","issue_events_url":"https://api.github.com/repos/deuscapturus/salt/issues/events{/number}","events_url":"https://api.github.com/repos/deuscapturus/salt/events","assignees_url":"https://api.github.com/repos/deuscapturus/salt/assignees{/user}","branches_url":"https://api.github.com/repos/deuscapturus/salt/branches{/branch}","tags_url":"https://api.github.com/repos/deuscapturus/salt/tags","blobs_url":"https://api.github.com/repos/deuscapturus/salt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/deuscapturus/salt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/deuscapturus/salt/git/refs{/sha}","trees_url":"https://api.github.com/repos/deuscapturus/salt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/deuscapturus/salt/statuses/{sha}","languages_url":"https://api.github.com/repos/deuscapturus/salt/languages","stargazers_url":"https://api.github.com/repos/deuscapturus/salt/stargazers","contributors_url":"https://api.github.com/repos/deuscapturus/salt/contributors","subscribers_url":"https://api.github.com/repos/deuscapturus/salt/subscribers","subscription_url":"https://api.github.com/repos/deuscapturus/salt/subscription","commits_url":"https://api.github.com/repos/deuscapturus/salt/commits{/sha}","git_commits_url":"https://api.github.com/repos/deuscapturus/salt/git/commits{/sha}","comments_url":"https://api.github.com/repos/deuscapturus/salt/comments{/number}","issue_comment_url":"https://api.github.com/repos/deuscapturus/salt/issues/comments{/number}","contents_url":"https://api.github.com/repos/deuscapturus/salt/contents/{+path}","compare_url":"https://api.github.com/repos/deuscapturus/salt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/deuscapturus/salt/merges","archive_url":"https://api.github.com/repos/deuscapturus/salt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/deuscapturus/salt/downloads","issues_url":"https://api.github.com/repos/deuscapturus/salt/issues{/number}","pulls_url":"https://api.github.com/repos/deuscapturus/salt/pulls{/number}","milestones_url":"https://api.github.com/repos/deuscapturus/salt/milestones{/number}","notifications_url":"https://api.github.com/repos/deuscapturus/salt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/deuscapturus/salt/labels{/name}","releases_url":"https://api.github.com/repos/deuscapturus/salt/releases{/id}","deployments_url":"https://api.github.com/repos/deuscapturus/salt/deployments","created_at":"2016-10-11T19:02:19Z","updated_at":"2016-10-11T19:02:35Z","pushed_at":"2017-03-26T14:30:52Z","git_url":"git://github.com/deuscapturus/salt.git","ssh_url":"git@github.com:deuscapturus/salt.git","clone_url":"https://github.com/deuscapturus/salt.git","svn_url":"https://github.com/deuscapturus/salt","homepage":"https://repo.saltstack.com/","size":159561,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"saltstack:develop","ref":"develop","sha":"877183c048d3be03dc0ff2015dcb9d2414611371","user":{"login":"saltstack","id":1147473,"avatar_url":"https://avatars0.githubusercontent.com/u/1147473?v=3","gravatar_id":"","url":"https://api.github.com/users/saltstack","html_url":"https://github.com/saltstack","followers_url":"https://api.github.com/users/saltstack/followers","following_url":"https://api.github.com/users/saltstack/following{/other_user}","gists_url":"https://api.github.com/users/saltstack/gists{/gist_id}","starred_url":"https://api.github.com/users/saltstack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saltstack/subscriptions","organizations_url":"https://api.github.com/users/saltstack/orgs","repos_url":"https://api.github.com/users/saltstack/repos","events_url":"https://api.github.com/users/saltstack/events{/privacy}","received_events_url":"https://api.github.com/users/saltstack/received_events","type":"Organization","site_admin":false},"repo":{"id":1390248,"name":"salt","full_name":"saltstack/salt","owner":{"login":"saltstack","id":1147473,"avatar_url":"https://avatars0.githubusercontent.com/u/1147473?v=3","gravatar_id":"","url":"https://api.github.com/users/saltstack","html_url":"https://github.com/saltstack","followers_url":"https://api.github.com/users/saltstack/followers","following_url":"https://api.github.com/users/saltstack/following{/other_user}","gists_url":"https://api.github.com/users/saltstack/gists{/gist_id}","starred_url":"https://api.github.com/users/saltstack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saltstack/subscriptions","organizations_url":"https://api.github.com/users/saltstack/orgs","repos_url":"https://api.github.com/users/saltstack/repos","events_url":"https://api.github.com/users/saltstack/events{/privacy}","received_events_url":"https://api.github.com/users/saltstack/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/saltstack/salt","description":"Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here: ","fork":false,"url":"https://api.github.com/repos/saltstack/salt","forks_url":"https://api.github.com/repos/saltstack/salt/forks","keys_url":"https://api.github.com/repos/saltstack/salt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/saltstack/salt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/saltstack/salt/teams","hooks_url":"https://api.github.com/repos/saltstack/salt/hooks","issue_events_url":"https://api.github.com/repos/saltstack/salt/issues/events{/number}","events_url":"https://api.github.com/repos/saltstack/salt/events","assignees_url":"https://api.github.com/repos/saltstack/salt/assignees{/user}","branches_url":"https://api.github.com/repos/saltstack/salt/branches{/branch}","tags_url":"https://api.github.com/repos/saltstack/salt/tags","blobs_url":"https://api.github.com/repos/saltstack/salt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/saltstack/salt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/saltstack/salt/git/refs{/sha}","trees_url":"https://api.github.com/repos/saltstack/salt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/saltstack/salt/statuses/{sha}","languages_url":"https://api.github.com/repos/saltstack/salt/languages","stargazers_url":"https://api.github.com/repos/saltstack/salt/stargazers","contributors_url":"https://api.github.com/repos/saltstack/salt/contributors","subscribers_url":"https://api.github.com/repos/saltstack/salt/subscribers","subscription_url":"https://api.github.com/repos/saltstack/salt/subscription","commits_url":"https://api.github.com/repos/saltstack/salt/commits{/sha}","git_commits_url":"https://api.github.com/repos/saltstack/salt/git/commits{/sha}","comments_url":"https://api.github.com/repos/saltstack/salt/comments{/number}","issue_comment_url":"https://api.github.com/repos/saltstack/salt/issues/comments{/number}","contents_url":"https://api.github.com/repos/saltstack/salt/contents/{+path}","compare_url":"https://api.github.com/repos/saltstack/salt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/saltstack/salt/merges","archive_url":"https://api.github.com/repos/saltstack/salt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/saltstack/salt/downloads","issues_url":"https://api.github.com/repos/saltstack/salt/issues{/number}","pulls_url":"https://api.github.com/repos/saltstack/salt/pulls{/number}","milestones_url":"https://api.github.com/repos/saltstack/salt/milestones{/number}","notifications_url":"https://api.github.com/repos/saltstack/salt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/saltstack/salt/labels{/name}","releases_url":"https://api.github.com/repos/saltstack/salt/releases{/id}","deployments_url":"https://api.github.com/repos/saltstack/salt/deployments","created_at":"2011-02-20T20:16:56Z","updated_at":"2017-03-27T21:49:26Z","pushed_at":"2017-03-27T23:52:51Z","git_url":"git://github.com/saltstack/salt.git","ssh_url":"git@github.com:saltstack/salt.git","clone_url":"https://github.com/saltstack/salt.git","svn_url":"https://github.com/saltstack/salt","homepage":"https://repo.saltstack.com/","size":160815,"stargazers_count":7515,"watchers_count":7515,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3464,"mirror_url":null,"open_issues_count":4432,"forks":3464,"open_issues":4432,"watchers":7515,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/saltstack/salt/pulls/40263"},"html":{"href":"https://github.com/saltstack/salt/pull/40263"},"issue":{"href":"https://api.github.com/repos/saltstack/salt/issues/40263"},"comments":{"href":"https://api.github.com/repos/saltstack/salt/issues/40263/comments"},"review_comments":{"href":"https://api.github.com/repos/saltstack/salt/pulls/40263/comments"},"review_comment":{"href":"https://api.github.com/repos/saltstack/salt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/saltstack/salt/pulls/40263/commits"},"statuses":{"href":"https://api.github.com/repos/saltstack/salt/statuses/9b714ef0083c387013a546593a6e03e4f64b5f3c"}}}}
{"actor":{"display_login":"cachedout"}}