From 59c30595c1ac8640406a3b0803baa32773b7f85e Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Wed, 8 Nov 2017 23:16:49 +0100 Subject: [PATCH] stacki_host: PEP8 compliancy and documentation changes (#32651) This PR includes: - PEP8 compliancy changes - Documentation changes --- .../remote_management/stacki/stacki_host.py | 104 +++++++----------- test/sanity/pep8/legacy-files.txt | 1 - 2 files changed, 40 insertions(+), 65 deletions(-) diff --git a/lib/ansible/modules/remote_management/stacki/stacki_host.py b/lib/ansible/modules/remote_management/stacki/stacki_host.py index 2093e1b8e37..a8947c0356a 100644 --- a/lib/ansible/modules/remote_management/stacki/stacki_host.py +++ b/lib/ansible/modules/remote_management/stacki/stacki_host.py @@ -1,24 +1,22 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# (c) 2016, Hugh Ma +# Copyright: (c) 2016, Hugh Ma # 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: stacki_host short_description: Add or remove host to stacki front-end description: - - Use this module to add or remove hosts to a stacki front-end via API + - Use this module to add or remove hosts to a stacki front-end via API. - U(https://github.com/StackIQ/stacki) version_added: "2.3" options: @@ -43,21 +41,17 @@ options: prim_intf_mac: description: - MAC Address for the primary PXE boot network interface. - required: False prim_intf_ip: description: - IP Address for the primary network interface. - required: False prim_intf: description: - Name of the primary network interface. - required: False force_install: description: - Set value to True to force node into install state if it already exists in stacki. - required: False - -author: "Hugh Ma " +author: +- Hugh Ma ''' EXAMPLES = ''' @@ -112,18 +106,18 @@ class StackiHost(object): def __init__(self, module): self.module = module - self.hostname = module.params['name'] - self.rack = module.params['rack'] - self.rank = module.params['rank'] - self.appliance = module.params['appliance'] - self.prim_intf = module.params['prim_intf'] - self.prim_intf_ip = module.params['prim_intf_ip'] - self.network = module.params['network'] - self.prim_intf_mac = module.params['prim_intf_mac'] - self.endpoint = module.params['stacki_endpoint'] - - auth_creds = {'USERNAME': module.params['stacki_user'], - 'PASSWORD': module.params['stacki_password']} + self.hostname = module.params['name'] + self.rack = module.params['rack'] + self.rank = module.params['rank'] + self.appliance = module.params['appliance'] + self.prim_intf = module.params['prim_intf'] + self.prim_intf_ip = module.params['prim_intf_ip'] + self.network = module.params['network'] + self.prim_intf_mac = module.params['prim_intf_mac'] + self.endpoint = module.params['stacki_endpoint'] + + auth_creds = {'USERNAME': module.params['stacki_user'], + 'PASSWORD': module.params['stacki_password']} # Get Initial CSRF cred_a = self.do_request(self.module, self.endpoint, method="GET") @@ -161,7 +155,6 @@ class StackiHost(object): 'Content-type': 'application/json', 'Cookie': login_req.headers.get('Set-Cookie')} - def do_request(self, module, url, payload=None, headers=None, method=None): res, info = fetch_url(module, url, data=payload, headers=headers, method=method) @@ -170,36 +163,25 @@ class StackiHost(object): return res - def stack_check_host(self): - - res = self.do_request(self.module, self.endpoint, payload=json.dumps({"cmd": "list host"}), - headers=self.header, method="POST") + res = self.do_request(self.module, self.endpoint, payload=json.dumps({"cmd": "list host"}), headers=self.header, method="POST") if self.hostname in res.read(): return True else: return False - def stack_sync(self): - - self.do_request(self.module, self.endpoint, payload=json.dumps({ "cmd": "sync config"}), - headers=self.header, method="POST") - - self.do_request(self.module, self.endpoint, payload=json.dumps({"cmd": "sync host config"}), - headers=self.header, method="POST") - + self.do_request(self.module, self.endpoint, payload=json.dumps({"cmd": "sync config"}), headers=self.header, method="POST") + self.do_request(self.module, self.endpoint, payload=json.dumps({"cmd": "sync host config"}), headers=self.header, method="POST") def stack_force_install(self, result): - data = dict() changed = False data['cmd'] = "set host boot {0} action=install" \ .format(self.hostname) - self.do_request(self.module, self.endpoint, payload=json.dumps(data), - headers=self.header, method="POST") + self.do_request(self.module, self.endpoint, payload=json.dumps(data), headers=self.header, method="POST") changed = True self.stack_sync() @@ -208,29 +190,24 @@ class StackiHost(object): result['stdout'] = "api call successful".rstrip("\r\n") def stack_add(self, result): - - data = dict() - changed = False + data = dict() + changed = False data['cmd'] = "add host {0} rack={1} rank={2} appliance={3}"\ .format(self.hostname, self.rack, self.rank, self.appliance) - self.do_request(self.module, self.endpoint, payload=json.dumps(data), - headers=self.header, method="POST") + self.do_request(self.module, self.endpoint, payload=json.dumps(data), headers=self.header, method="POST") self.stack_sync() result['changed'] = changed result['stdout'] = "api call successful".rstrip("\r\n") - def stack_remove(self, result): - - data = dict() + data = dict() data['cmd'] = "remove host {0}"\ .format(self.hostname) - self.do_request(self.module, self.endpoint, payload=json.dumps(data), - headers=self.header, method="POST") + self.do_request(self.module, self.endpoint, payload=json.dumps(data), headers=self.header, method="POST") self.stack_sync() @@ -239,24 +216,23 @@ class StackiHost(object): def main(): - module = AnsibleModule( - argument_spec = dict( - state=dict(type='str', default='present', choices=['present', 'absent']), - name=dict(required=True, type='str'), - rack=dict(required=False, type='int', default=0), - rank=dict(required=False, type='int', default=0), - appliance=dict(required=False, type='str', default='backend'), - prim_intf=dict(required=False, type='str', default=None), - prim_intf_ip=dict(required=False, type='str', default=None), - network=dict(required=False, type='str', default='private'), - prim_intf_mac=dict(required=False, type='str', default=None), - stacki_user=dict(required=True, type='str', default=os.environ.get('stacki_user')), - stacki_password=dict(required=True, no_log=True, type='str', default=os.environ.get('stacki_password')), - stacki_endpoint=dict(required=True, type='str', default=os.environ.get('stacki_endpoint')), - force_install=dict(required=False, type='bool', default=False) + argument_spec=dict( + state=dict(type='str', default='present', choices=['absent', 'present']), + name=dict(type='str', required=True), + rack=dict(type='int', default=0), + rank=dict(type='int', default=0), + appliance=dict(type='str', default='backend'), + prim_intf=dict(type='str'), + prim_intf_ip=dict(type='str'), + network=dict(type='str', default='private'), + prim_intf_mac=dict(type='str'), + stacki_user=dict(type='str', required=True, default=os.environ.get('stacki_user')), + stacki_password=dict(type='str', required=True, default=os.environ.get('stacki_password'), no_log=True), + stacki_endpoint=dict(type='str', required=True, default=os.environ.get('stacki_endpoint')), + force_install=dict(type='bool', default=False), ), - supports_check_mode=False + supports_check_mode=False, ) result = {'changed': False} diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 4fb26669071..aa676d78092 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -286,7 +286,6 @@ lib/ansible/modules/packaging/os/urpmi.py lib/ansible/modules/packaging/os/yum.py lib/ansible/modules/packaging/os/zypper.py lib/ansible/modules/packaging/os/zypper_repository.py -lib/ansible/modules/remote_management/stacki/stacki_host.py lib/ansible/modules/storage/infinidat/infini_export.py lib/ansible/modules/storage/infinidat/infini_export_client.py lib/ansible/modules/storage/infinidat/infini_fs.py