Skip to content

WIP: demo black and flake8 failures #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .zuul.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- project:
check:
jobs:
- ansible-tox-linters
261 changes: 182 additions & 79 deletions plugins/connection/vmware_tools.py

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions plugins/doc_fragments/VmwareRestModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
# 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


class ModuleDocFragment(object):
# Parameters for VMware ReST HTTPAPI modules omits filters and state
DOCUMENTATION = r'''
DOCUMENTATION = r"""
options:
allow_multiples:
description:
Expand All @@ -29,4 +30,4 @@ class ModuleDocFragment(object):
required: true
type: list
default: [200]
'''
"""
5 changes: 3 additions & 2 deletions plugins/doc_fragments/VmwareRestModule_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
# 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


class ModuleDocFragment(object):
# Parameters for VMware ReST HTTPAPI modules includes filters
DOCUMENTATION = r'''
DOCUMENTATION = r"""
options:
allow_multiples:
description:
Expand All @@ -34,4 +35,4 @@ class ModuleDocFragment(object):
required: true
type: list
default: [200]
'''
"""
5 changes: 3 additions & 2 deletions plugins/doc_fragments/VmwareRestModule_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
# 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


class ModuleDocFragment(object):
# Parameters for VMware ReST HTTPAPI modules includes filters and state
DOCUMENTATION = r'''
DOCUMENTATION = r"""
options:
allow_multiples:
description:
Expand Down Expand Up @@ -41,4 +42,4 @@ class ModuleDocFragment(object):
required: true
type: list
default: [200]
'''
"""
5 changes: 3 additions & 2 deletions plugins/doc_fragments/VmwareRestModule_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
# 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


class ModuleDocFragment(object):
# Parameters for VMware ReST HTTPAPI modules includes filters and state
DOCUMENTATION = r'''
DOCUMENTATION = r"""
options:
allow_multiples:
description:
Expand Down Expand Up @@ -36,4 +37,4 @@ class ModuleDocFragment(object):
required: true
type: list
default: [200]
'''
"""
8 changes: 4 additions & 4 deletions plugins/doc_fragments/vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ModuleDocFragment(object):
# Parameters for VMware modules
DOCUMENTATION = r'''
DOCUMENTATION = r"""
options:
hostname:
description:
Expand Down Expand Up @@ -59,10 +59,10 @@ class ModuleDocFragment(object):
- If the value is not specified in the task, the value of environment variable C(VMWARE_PROXY_PORT) will be used instead.
type: int
required: False
'''
"""

# This doc fragment is specific to vcenter modules like vcenter_license
VCENTER_DOCUMENTATION = r'''
VCENTER_DOCUMENTATION = r"""
options:
hostname:
description:
Expand Down Expand Up @@ -115,4 +115,4 @@ class ModuleDocFragment(object):
type: int
version_added: '2.9'
required: False
'''
"""
4 changes: 2 additions & 2 deletions plugins/doc_fragments/vmware_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ModuleDocFragment(object):
# Parameters for VMware REST Client based modules
DOCUMENTATION = r'''
DOCUMENTATION = r"""
options:
hostname:
description:
Expand Down Expand Up @@ -45,4 +45,4 @@ class ModuleDocFragment(object):
type: str
choices: [ http, https ]
default: https
'''
"""
56 changes: 37 additions & 19 deletions plugins/httpapi/vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
# Copyright: (c) 2019, Abhijeet Kasurde <[email protected]>
# 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)
from __future__ import absolute_import, division, print_function

__metaclass__ = type

DOCUMENTATION = '''
DOCUMENTATION = """
---
author: Abhijeet Kasurde (Akasurde)
httpapi : vmware
short_description: HttpApi Plugin for VMware REST API
description:
- This HttpApi plugin provides methods to connect to VMware vCenter over a HTTP(S)-based APIs.
'''
"""

import json

Expand All @@ -24,54 +25,71 @@
from ansible.module_utils.connection import ConnectionError

BASE_HEADERS = {
'Content-Type': 'application/json',
'Accept': 'application/json',
"Content-Type": "application/json",
"Accept": "application/json",
}


class HttpApi(HttpApiBase):
def login(self, username, password):
if username and password:
payload = {}
url = '/rest/com/vmware/cis/session'
url = "/rest/com/vmware/cis/session"
response, response_data = self.send_request(url, payload)
else:
raise AnsibleConnectionFailure('Username and password are required for login')
raise AnsibleConnectionFailure(
"Username and password are required for login"
)

if response == 404:
raise ConnectionError(response_data)

if not response_data.get('value'):
raise ConnectionError('Server returned response without token info during connection authentication: %s' % response)
if not response_data.get("value"):
raise ConnectionError(
"Server returned response without token info during connection authentication: %s"
% response
)

self.connection._session_uid = "vmware-api-session-id:%s" % response_data['value']
self.connection._token = response_data['value']
self.connection._session_uid = (
"vmware-api-session-id:%s" % response_data["value"]
)
self.connection._token = response_data["value"]

def logout(self):
response, dummy = self.send_request('/rest/com/vmware/cis/session', None, method='DELETE')
response, dummy = self.send_request(
"/rest/com/vmware/cis/session", None, method="DELETE"
)

def get_session_uid(self):
return self.connection._session_uid

def get_session_token(self):
return self.connection._token

def send_request(self, path, body_params, method='POST'):
data = json.dumps(body_params) if body_params else '{}'
def send_request(self, path, body_params, method="POST"):
data = json.dumps(body_params) if body_params else "{}"

try:
self._display_request(method=method)
response, response_data = self.connection.send(path, data, method=method, headers=BASE_HEADERS, force_basic_auth=True)
response, response_data = self.connection.send(
path,
data,
method=method,
headers=BASE_HEADERS,
force_basic_auth=True,
)
response_value = self._get_response_value(response_data)

return response.getcode(), self._response_to_json(response_value)
except AnsibleConnectionFailure as e:
return 404, 'Object not found'
return 404, "Object not found"
except HTTPError as e:
return e.code, json.loads(e.read())

def _display_request(self, method='POST'):
self.connection.queue_message('vvvv', 'Web Services: %s %s' % (method, self.connection._url))
def _display_request(self, method="POST"):
self.connection.queue_message(
"vvvv", "Web Services: %s %s" % (method, self.connection._url)
)

def _get_response_value(self, response_data):
return to_text(response_data.getvalue())
Expand All @@ -81,4 +99,4 @@ def _response_to_json(self, response_text):
return json.loads(response_text) if response_text else {}
# JSONDecodeError only available on Python 3.5+
except ValueError:
raise ConnectionError('Invalid JSON response: %s' % response_text)
raise ConnectionError("Invalid JSON response: %s" % response_text)
Loading