From fde4244d04cc6f67a03d84a6cf14a70c87c403b3 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Fri, 29 Sep 2017 07:51:23 +0200 Subject: [PATCH] kubernetes: PEP8 compliancy and doc fixes (#30914) This PR includes: - PEP8 compliancy fixes - Documentation fixes --- lib/ansible/modules/clustering/kubernetes.py | 98 +++++++++----------- test/sanity/pep8/legacy-files.txt | 1 - 2 files changed, 46 insertions(+), 53 deletions(-) diff --git a/lib/ansible/modules/clustering/kubernetes.py b/lib/ansible/modules/clustering/kubernetes.py index b4a76cb38f..d92ac810fd 100755 --- a/lib/ansible/modules/clustering/kubernetes.py +++ b/lib/ansible/modules/clustering/kubernetes.py @@ -1,54 +1,51 @@ #!/usr/bin/python -# Copyright 2015 Google Inc. All Rights Reserved. + +# Copyright: (c) 2015, Google Inc. All Rights Reserved. # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type - ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} - DOCUMENTATION = ''' --- module: kubernetes version_added: "2.1" -short_description: Manage Kubernetes resources. +short_description: Manage Kubernetes resources description: - This module can manage Kubernetes resources on an existing cluster using the Kubernetes server API. Users can specify in-line API data, or - specify an existing Kubernetes YAML file. Currently, this module, - Only supports HTTP Basic Auth - Only supports 'strategic merge' for update, http://goo.gl/fCPYxT - SSL certs are not working, use 'validate_certs=off' to disable + specify an existing Kubernetes YAML file. + - Currently, this module + (1) Only supports HTTP Basic Auth + (2) Only supports 'strategic merge' for update, http://goo.gl/fCPYxT + SSL certs are not working, use C(validate_certs=off) to disable. options: api_endpoint: description: - The IPv4 API endpoint of the Kubernetes cluster. required: true - default: null - aliases: ["endpoint"] + aliases: [ endpoint ] inline_data: description: - The Kubernetes YAML data to send to the API I(endpoint). This option is mutually exclusive with C('file_reference'). required: true - default: null file_reference: description: - Specify full path to a Kubernets YAML file to send to API I(endpoint). This option is mutually exclusive with C('inline_data'). - required: false - default: null patch_operation: - description: > - - Specify patch operation for Kubernetes resource update. For details, see the description of PATCH operations at + description: + - Specify patch operation for Kubernetes resource update. + - For details, see the description of PATCH operations at U(https://github.com/kubernetes/kubernetes/blob/release-1.5/docs/devel/api-conventions.md#patch-operations). default: Strategic Merge Patch - aliases: ["patch_strategy"] - choices: ["JSON Patch", "Merge Patch", "Strategic Merge Patch"] + choices: [ JSON Patch, Merge Patch, Strategic Merge Patch ] + aliases: [ patch_strategy ] version_added: 2.4 certificate_authority_data: description: @@ -56,40 +53,37 @@ options: standard PEM format or base64 encoded PEM data. Note that certificate verification is broken until ansible supports a version of 'match_hostname' that can match the IP address against the CA data. - required: false - default: null state: description: - The desired action to take on the Kubernetes data. required: true - default: "present" - choices: ["present", "absent", "update", "replace"] + choices: [ absent, present, replace, update ] + default: present url_password: description: - The HTTP Basic Auth password for the API I(endpoint). This should be set unless using the C('insecure') option. - default: null - aliases: ["password"] + aliases: [ password ] url_username: description: - The HTTP Basic Auth username for the API I(endpoint). This should be set unless using the C('insecure') option. - default: "admin" - aliases: ["username"] + default: admin + aliases: [ username ] insecure: description: - - "Reverts the connection to using HTTP instead of HTTPS. This option should + - Reverts the connection to using HTTP instead of HTTPS. This option should only be used when execuing the M('kubernetes') module local to the Kubernetes - cluster using the insecure local port (locahost:8080 by default)." + cluster using the insecure local port (locahost:8080 by default). validate_certs: description: - Enable/disable certificate validation. Note that this is set to C(false) until Ansible can support IP address based certificate hostname matching (exists in >= python3.5.0). - required: false - default: false - -author: "Eric Johnson (@erjohnso) " + type: bool + default: 'no' +author: +- Eric Johnson (@erjohnso) ''' EXAMPLES = ''' @@ -158,9 +152,9 @@ import json try: import yaml - has_lib_yaml = True + HAS_LIB_YAML = True except ImportError: - has_lib_yaml = False + HAS_LIB_YAML = False from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url @@ -334,27 +328,27 @@ def k8s_update_resource(module, url, data, patch_operation): def main(): module = AnsibleModule( argument_spec=dict( - http_agent=dict(default=USER_AGENT), - - url_username=dict(default="admin", aliases=["username"]), - url_password=dict(default="", no_log=True, aliases=["password"]), - force_basic_auth=dict(default="yes"), - validate_certs=dict(default=False, type='bool'), - certificate_authority_data=dict(required=False), - insecure=dict(default=False, type='bool'), - api_endpoint=dict(required=True), - patch_operation=dict(default='Strategic Merge Patch', aliases=['patch_strategy'], choices=['JSON Patch', 'Merge Patch', 'Strategic Merge Patch']), - file_reference=dict(required=False), - inline_data=dict(required=False), - state=dict(default="present", choices=["present", "absent", "update", "replace"]) + http_agent=dict(type='str', default=USER_AGENT), + url_username=dict(type='str', default='admin', aliases=['username']), + url_password=dict(type='str', default='', no_log=True, aliases=['password']), + force_basic_auth=dict(type='bool', default=True), + validate_certs=dict(type='bool', default=False), + certificate_authority_data=dict(type='str'), + insecure=dict(type='bool', default=False), + api_endpoint=dict(type='str', required=True), + patch_operation=dict(type='str', default='Strategic Merge Patch', aliases=['patch_strategy'], + choices=['JSON Patch', 'Merge Patch', 'Strategic Merge Patch']), + file_reference=dict(type='str'), + inline_data=dict(type='str'), + state=dict(type='str', default='present', choices=['absent', 'present', 'replace', 'update']) ), - mutually_exclusive = (('file_reference', 'inline_data'), - ('url_username', 'insecure'), - ('url_password', 'insecure')), - required_one_of = (('file_reference', 'inline_data'),), + mutually_exclusive=(('file_reference', 'inline_data'), + ('url_username', 'insecure'), + ('url_password', 'insecure')), + required_one_of=(('file_reference', 'inline_data')), ) - if not has_lib_yaml: + if not HAS_LIB_YAML: module.fail_json(msg="missing python library: yaml") decode_cert_data(module) @@ -393,7 +387,7 @@ def main(): # make sure the data is a list if not isinstance(data, list): - data = [ data ] + data = [data] for item in data: namespace = "default" diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 74198145e7..4edacdbb8b 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -175,7 +175,6 @@ lib/ansible/modules/cloud/webfaction/webfaction_domain.py lib/ansible/modules/cloud/webfaction/webfaction_site.py lib/ansible/modules/clustering/consul_kv.py lib/ansible/modules/clustering/consul_session.py -lib/ansible/modules/clustering/kubernetes.py lib/ansible/modules/clustering/pacemaker_cluster.py lib/ansible/modules/database/misc/kibana_plugin.py lib/ansible/modules/database/misc/riak.py