{"action":"created","comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments/33729361","id":33729361,"diff_hunk":"@@ -0,0 +1,405 @@\n+#!/usr/bin/python\n+# -*- coding: utf-8 -*-\n+\n+# (c) 2015, Etienne Carriere <etienne.carriere@gmail.com>\n+#\n+# This file is part of Ansible\n+#\n+# Ansible is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License as published by\n+# the Free Software Foundation, either version 3 of the License, or\n+# (at your option) any later version.\n+#\n+# Ansible is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n+\n+DOCUMENTATION = '''\n+---\n+module: bigip_virtual_server\n+short_description: \"Manages F5 BIG-IP LTM virtual servers\"\n+description:\n+    - \"Manages F5 BIG-IP LTM virtual servers via iControl SOAP API\"\n+version_added: \"2.0\"\n+author: Etienne Carriere\n+notes:\n+    - \"Requires BIG-IP software version >= 11\"\n+    - \"F5 developed module 'bigsuds' required (see http://devcentral.f5.com)\"\n+    - \"Best run as a local_action in your playbook\"\n+requirements:\n+    - bigsuds\n+options:\n+    server:\n+        description:\n+            - BIG-IP host\n+        required: true\n+    user:\n+        description:\n+            - BIG-IP username\n+        required: true\n+    password:\n+        description:\n+            - BIG-IP password\n+        required: true\n+    validate_certs:\n+        description:\n+            - If C(no), SSL certificates will not be validated. This should only be used\n+              on personally controlled sites using self-signed certificates.\n+        required: false\n+        default: 'yes'\n+        choices: ['yes', 'no']\n+    state:\n+        description:\n+            - Pool member state\n+        required: false\n+        default: present\n+        choices: ['present', 'absent', 'enabled', 'disabled']\n+        aliases: []\n+    partition:\n+        description:\n+            - Partition\n+        required: false\n+        default: 'Common'\n+    name:\n+        description:\n+            - \"Virtual server name.\"\n+        required: true\n+        aliases: ['vs']\n+    destination:\n+        description:\n+            - \"Destination IP of the virtual server (only host is currently supported) . Required when state=present and vs does not exist. Error when state=absent.\"\n+        required: true\n+        aliases: ['address', 'ip']\n+    port:\n+        description:\n+            - \"Port of the virtual server . Required when state=present and vs does not exist\"\n+        required: true\n+    all_profiles:\n+        description:\n+            - \"List of all Profiles (HTTP,ClientSSL,ServerSSL,etc) that must be used by the virtual server\"\n+        required: false\n+        default: null\n+    pool:\n+        description:\n+            - \"Default pool for the virtual server\"\n+        required: false\n+        default: null\n+    snat:\n+        description:\n+            - \"Source network address policy\"\n+        required: false\n+        default: None\n+\n+    description:\n+        description:\n+            - \"Virtual server description.\"\n+        required: false\n+        default: null\n+'''\n+\n+EXAMPLES = '''\n+\n+## playbook task examples:\n+\n+---\n+# file bigip-test.yml\n+# ...\n+  - name: Add VS\n+    local_action:\n+        module: bigip_virtual_server\n+        server: lb.mydomain.net\n+        user: admin\n+        password: secret\n+        state: present\n+        partition: MyPartition\n+        name: myvirtualserver\n+        destination: \"{{ ansible_default_ipv4[\"address\"] }}\"\n+        port: 443\n+        pool: \"{{ mypool }}\"\n+        snat: Automap\n+        description: Test Virtual Server\n+        all_profiles:\n+            - http\n+            - clientssl\n+\n+  - name: Modify Port of the Virtual Server\n+    local_action:\n+        module: bigip_virtual_server\n+        server: lb.mydomain.net\n+        user: admin\n+        password: secret\n+        state: present\n+        partition: MyPartition\n+        name: myvirtualserver\n+        port: 8080\n+\n+  - name: Delete pool\n+    local_action:\n+        module: bigip_virtual_server\n+        server: lb.mydomain.net\n+        user: admin\n+        password: secret\n+        state: absent\n+        partition: MyPartition\n+        name: myvirtualserver\n+'''\n+\n+\n+# ==========================\n+# bigip_virtual_server module specific\n+#\n+\n+# map of state values\n+STATES={'enabled': 'STATE_ENABLED',\n+        'disabled': 'STATE_DISABLED'}\n+STATUSES={'enabled': 'SESSION_STATUS_ENABLED',\n+          'disabled': 'SESSION_STATUS_DISABLED',\n+          'offline': 'SESSION_STATUS_FORCED_DISABLED'}\n+\n+def vs_exists(api, vs):\n+    # hack to determine if pool exists\n+    result = False\n+    try:\n+        api.LocalLB.VirtualServer.get_object_status(virtual_servers=[vs])\n+        result = True\n+    except bigsuds.OperationFailed, e:\n+        if \"was not found\" in str(e):\n+            result = False\n+        else:\n+            # genuine exception\n+            raise\n+    return result\n+\n+def vs_create(api,name,destination,port,pool):\n+    _profiles=[[{'profile_context': 'PROFILE_CONTEXT_TYPE_ALL', 'profile_name': 'tcp'}]]\n+    try:\n+        api.LocalLB.VirtualServer.create(\n+            definitions = [{'name': [name], 'address': [destination], 'port': port, 'protocol': 'PROTOCOL_TCP'}],\n+            wildmasks = ['255.255.255.255'],\n+            resources = [{'type': 'RESOURCE_TYPE_POOL', 'default_pool_name': pool}],\n+            profiles = _profiles)\n+        result = True \n+        desc = 0\n+    except Exception, e :\n+        print e.args","path":"network/f5/bigip_virtual_server.py","position":188,"original_position":188,"commit_id":"3d9fd24d62b4513495dc2606022691683473332b","original_commit_id":"3d9fd24d62b4513495dc2606022691683473332b","user":{"login":"bcoca","id":836171,"avatar_url":"https://avatars.githubusercontent.com/u/836171?v=3","gravatar_id":"","url":"https://api.github.com/users/bcoca","html_url":"https://github.com/bcoca","followers_url":"https://api.github.com/users/bcoca/followers","following_url":"https://api.github.com/users/bcoca/following{/other_user}","gists_url":"https://api.github.com/users/bcoca/gists{/gist_id}","starred_url":"https://api.github.com/users/bcoca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcoca/subscriptions","organizations_url":"https://api.github.com/users/bcoca/orgs","repos_url":"https://api.github.com/users/bcoca/repos","events_url":"https://api.github.com/users/bcoca/events{/privacy}","received_events_url":"https://api.github.com/users/bcoca/received_events","type":"User","site_admin":false},"body":"Don't use print in modules, use either exit or fail json functions.  Also the point of having localized exceptions is to add an error message on top that is more helpful than most library exception messages + traceback (but we also want to include those), if you are just going to pass the exception message, there is really no difference with using the general catchall exception.","created_at":"2015-07-01T21:58:39Z","updated_at":"2015-07-01T21:58:39Z","html_url":"https://github.com/ansible/ansible-modules-extras/pull/582#discussion_r33729361","pull_request_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/582","_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments/33729361"},"html":{"href":"https://github.com/ansible/ansible-modules-extras/pull/582#discussion_r33729361"},"pull_request":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/582"}}},"pull_request":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/582","id":36905867,"html_url":"https://github.com/ansible/ansible-modules-extras/pull/582","diff_url":"https://github.com/ansible/ansible-modules-extras/pull/582.diff","patch_url":"https://github.com/ansible/ansible-modules-extras/pull/582.patch","issue_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/582","number":582,"state":"open","locked":false,"title":"Creation of F5 virtual_server module","user":{"login":"Etienne-Carriere","id":2909360,"avatar_url":"https://avatars.githubusercontent.com/u/2909360?v=3","gravatar_id":"","url":"https://api.github.com/users/Etienne-Carriere","html_url":"https://github.com/Etienne-Carriere","followers_url":"https://api.github.com/users/Etienne-Carriere/followers","following_url":"https://api.github.com/users/Etienne-Carriere/following{/other_user}","gists_url":"https://api.github.com/users/Etienne-Carriere/gists{/gist_id}","starred_url":"https://api.github.com/users/Etienne-Carriere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Etienne-Carriere/subscriptions","organizations_url":"https://api.github.com/users/Etienne-Carriere/orgs","repos_url":"https://api.github.com/users/Etienne-Carriere/repos","events_url":"https://api.github.com/users/Etienne-Carriere/events{/privacy}","received_events_url":"https://api.github.com/users/Etienne-Carriere/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-06-04T06:31:54Z","updated_at":"2015-07-01T21:58:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"08c82131ab0991729d646ea6c1d5285681a61e76","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/582/commits","review_comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/582/comments","review_comment_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/582/comments","statuses_url":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/3d9fd24d62b4513495dc2606022691683473332b","head":{"label":"Etienne-Carriere:f5_vs","ref":"f5_vs","sha":"3d9fd24d62b4513495dc2606022691683473332b","user":{"login":"Etienne-Carriere","id":2909360,"avatar_url":"https://avatars.githubusercontent.com/u/2909360?v=3","gravatar_id":"","url":"https://api.github.com/users/Etienne-Carriere","html_url":"https://github.com/Etienne-Carriere","followers_url":"https://api.github.com/users/Etienne-Carriere/followers","following_url":"https://api.github.com/users/Etienne-Carriere/following{/other_user}","gists_url":"https://api.github.com/users/Etienne-Carriere/gists{/gist_id}","starred_url":"https://api.github.com/users/Etienne-Carriere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Etienne-Carriere/subscriptions","organizations_url":"https://api.github.com/users/Etienne-Carriere/orgs","repos_url":"https://api.github.com/users/Etienne-Carriere/repos","events_url":"https://api.github.com/users/Etienne-Carriere/events{/privacy}","received_events_url":"https://api.github.com/users/Etienne-Carriere/received_events","type":"User","site_admin":false},"repo":{"id":35044950,"name":"ansible-modules-extras","full_name":"Etienne-Carriere/ansible-modules-extras","owner":{"login":"Etienne-Carriere","id":2909360,"avatar_url":"https://avatars.githubusercontent.com/u/2909360?v=3","gravatar_id":"","url":"https://api.github.com/users/Etienne-Carriere","html_url":"https://github.com/Etienne-Carriere","followers_url":"https://api.github.com/users/Etienne-Carriere/followers","following_url":"https://api.github.com/users/Etienne-Carriere/following{/other_user}","gists_url":"https://api.github.com/users/Etienne-Carriere/gists{/gist_id}","starred_url":"https://api.github.com/users/Etienne-Carriere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Etienne-Carriere/subscriptions","organizations_url":"https://api.github.com/users/Etienne-Carriere/orgs","repos_url":"https://api.github.com/users/Etienne-Carriere/repos","events_url":"https://api.github.com/users/Etienne-Carriere/events{/privacy}","received_events_url":"https://api.github.com/users/Etienne-Carriere/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Etienne-Carriere/ansible-modules-extras","description":"Ansible extra modules - these modules ship with ansible","fork":true,"url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras","forks_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/forks","keys_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/teams","hooks_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/hooks","issue_events_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/issues/events{/number}","events_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/events","assignees_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/assignees{/user}","branches_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/branches{/branch}","tags_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/tags","blobs_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/git/refs{/sha}","trees_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/statuses/{sha}","languages_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/languages","stargazers_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/stargazers","contributors_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/contributors","subscribers_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/subscribers","subscription_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/subscription","commits_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/commits{/sha}","git_commits_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/git/commits{/sha}","comments_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/comments{/number}","issue_comment_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/issues/comments{/number}","contents_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/contents/{+path}","compare_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/merges","archive_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/downloads","issues_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/issues{/number}","pulls_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/pulls{/number}","milestones_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/milestones{/number}","notifications_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/labels{/name}","releases_url":"https://api.github.com/repos/Etienne-Carriere/ansible-modules-extras/releases{/id}","created_at":"2015-05-04T16:07:21Z","updated_at":"2015-05-04T16:07:22Z","pushed_at":"2015-07-01T20:27:05Z","git_url":"git://github.com/Etienne-Carriere/ansible-modules-extras.git","ssh_url":"git@github.com:Etienne-Carriere/ansible-modules-extras.git","clone_url":"https://github.com/Etienne-Carriere/ansible-modules-extras.git","svn_url":"https://github.com/Etienne-Carriere/ansible-modules-extras","homepage":"","size":6501,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"devel"}},"base":{"label":"ansible:devel","ref":"devel","sha":"a6bb41fd3d98e65aae380bf99eb4ccd1d345b5b0","user":{"login":"ansible","id":1507452,"avatar_url":"https://avatars.githubusercontent.com/u/1507452?v=3","gravatar_id":"","url":"https://api.github.com/users/ansible","html_url":"https://github.com/ansible","followers_url":"https://api.github.com/users/ansible/followers","following_url":"https://api.github.com/users/ansible/following{/other_user}","gists_url":"https://api.github.com/users/ansible/gists{/gist_id}","starred_url":"https://api.github.com/users/ansible/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansible/subscriptions","organizations_url":"https://api.github.com/users/ansible/orgs","repos_url":"https://api.github.com/users/ansible/repos","events_url":"https://api.github.com/users/ansible/events{/privacy}","received_events_url":"https://api.github.com/users/ansible/received_events","type":"Organization","site_admin":false},"repo":{"id":24474138,"name":"ansible-modules-extras","full_name":"ansible/ansible-modules-extras","owner":{"login":"ansible","id":1507452,"avatar_url":"https://avatars.githubusercontent.com/u/1507452?v=3","gravatar_id":"","url":"https://api.github.com/users/ansible","html_url":"https://github.com/ansible","followers_url":"https://api.github.com/users/ansible/followers","following_url":"https://api.github.com/users/ansible/following{/other_user}","gists_url":"https://api.github.com/users/ansible/gists{/gist_id}","starred_url":"https://api.github.com/users/ansible/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansible/subscriptions","organizations_url":"https://api.github.com/users/ansible/orgs","repos_url":"https://api.github.com/users/ansible/repos","events_url":"https://api.github.com/users/ansible/events{/privacy}","received_events_url":"https://api.github.com/users/ansible/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ansible/ansible-modules-extras","description":"Ansible extra modules - these modules ship with ansible","fork":false,"url":"https://api.github.com/repos/ansible/ansible-modules-extras","forks_url":"https://api.github.com/repos/ansible/ansible-modules-extras/forks","keys_url":"https://api.github.com/repos/ansible/ansible-modules-extras/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ansible/ansible-modules-extras/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ansible/ansible-modules-extras/teams","hooks_url":"https://api.github.com/repos/ansible/ansible-modules-extras/hooks","issue_events_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/events{/number}","events_url":"https://api.github.com/repos/ansible/ansible-modules-extras/events","assignees_url":"https://api.github.com/repos/ansible/ansible-modules-extras/assignees{/user}","branches_url":"https://api.github.com/repos/ansible/ansible-modules-extras/branches{/branch}","tags_url":"https://api.github.com/repos/ansible/ansible-modules-extras/tags","blobs_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/refs{/sha}","trees_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/{sha}","languages_url":"https://api.github.com/repos/ansible/ansible-modules-extras/languages","stargazers_url":"https://api.github.com/repos/ansible/ansible-modules-extras/stargazers","contributors_url":"https://api.github.com/repos/ansible/ansible-modules-extras/contributors","subscribers_url":"https://api.github.com/repos/ansible/ansible-modules-extras/subscribers","subscription_url":"https://api.github.com/repos/ansible/ansible-modules-extras/subscription","commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/commits{/sha}","git_commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/commits{/sha}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/comments{/number}","issue_comment_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/comments{/number}","contents_url":"https://api.github.com/repos/ansible/ansible-modules-extras/contents/{+path}","compare_url":"https://api.github.com/repos/ansible/ansible-modules-extras/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ansible/ansible-modules-extras/merges","archive_url":"https://api.github.com/repos/ansible/ansible-modules-extras/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ansible/ansible-modules-extras/downloads","issues_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues{/number}","pulls_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls{/number}","milestones_url":"https://api.github.com/repos/ansible/ansible-modules-extras/milestones{/number}","notifications_url":"https://api.github.com/repos/ansible/ansible-modules-extras/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ansible/ansible-modules-extras/labels{/name}","releases_url":"https://api.github.com/repos/ansible/ansible-modules-extras/releases{/id}","created_at":"2014-09-25T20:28:42Z","updated_at":"2015-07-01T17:58:28Z","pushed_at":"2015-07-01T20:27:06Z","git_url":"git://github.com/ansible/ansible-modules-extras.git","ssh_url":"git@github.com:ansible/ansible-modules-extras.git","clone_url":"https://github.com/ansible/ansible-modules-extras.git","svn_url":"https://github.com/ansible/ansible-modules-extras","homepage":"","size":22319,"stargazers_count":254,"watchers_count":254,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":521,"mirror_url":null,"open_issues_count":196,"forks":521,"open_issues":196,"watchers":254,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/582"},"html":{"href":"https://github.com/ansible/ansible-modules-extras/pull/582"},"issue":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/582"},"comments":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/582/comments"},"review_comments":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/582/comments"},"review_comment":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/582/commits"},"statuses":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/3d9fd24d62b4513495dc2606022691683473332b"}}}}