Various errors and formatting fixes (#33503)

* Various errors and formatting fixes

Mostly formatting fixes and small changes to better support debugging

* Fixes upstream errors
pull/33504/head
Tim Rupp 7 years ago committed by GitHub
parent 9f544cf926
commit 18aca48075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,81 +5,79 @@
# Copyright (c) 2015 Michael Perzel
# 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 = '''
DOCUMENTATION = r'''
---
module: bigip_gtm_virtual_server
short_description: "Manages F5 BIG-IP GTM virtual servers"
short_description: Manages F5 BIG-IP GTM virtual servers
description:
- "Manages F5 BIG-IP GTM virtual servers"
- Manages F5 BIG-IP GTM virtual servers.
version_added: "2.2"
author:
- Michael Perzel (@perzizzle)
- Tim Rupp (@caphrim007)
notes:
- "Requires BIG-IP software version >= 11.4"
- "F5 developed module 'bigsuds' required (see http://devcentral.f5.com)"
- "Best run as a local_action in your playbook"
- "Tested with manager and above account privilege level"
requirements:
- bigsuds
options:
state:
description:
- Virtual server state
required: false
default: present
choices: ['present', 'absent','enabled','disabled']
virtual_server_name:
description:
- Virtual server name
required: True
virtual_server_server:
description:
- Virtual server server
required: true
host:
description:
- Virtual server host
required: false
default: None
aliases: ['address']
port:
description:
- Virtual server port
required: false
default: None
state:
description:
- Virtual server state.
default: present
choices: ['present', 'absent','enabled','disabled']
virtual_server_name:
description:
- Virtual server name.
required: True
virtual_server_server:
description:
- Virtual server server.
required: true
host:
description:
- Virtual server host.
aliases: ['address']
port:
description:
- Virtual server port.
extends_documentation_fragment: f5
notes:
- Requires BIG-IP software version >= 11.4
- F5 developed module 'bigsuds' required (see http://devcentral.f5.com)"
- Best run as a local_action in your playbook
- Tested with manager and above account privilege level
requirements:
- bigsuds
author:
- Michael Perzel (@perzizzle)
- Tim Rupp (@caphrim007)
'''
EXAMPLES = '''
- name: Enable virtual server
local_action: >
bigip_gtm_virtual_server
server=192.0.2.1
user=admin
password=mysecret
virtual_server_name=myname
virtual_server_server=myserver
state=enabled
EXAMPLES = r'''
- name: Enable virtual server
bigip_gtm_virtual_server:
server: lb.mydomain.com
user: admin
password: secret
virtual_server_name: myname
virtual_server_server: myserver
state: enabled
delegate_to: localhost
'''
RETURN = '''# '''
import traceback
try:
import bigsuds
except ImportError:
bigsuds_found = False
else:
bigsuds_found = True
pass # Handled by f5_utils.bigsuds_found
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.f5_utils import bigip_api, f5_argument_spec
from ansible.module_utils.f5_utils import bigip_api, bigsuds_found, f5_argument_spec
from ansible.module_utils._text import to_native
def server_exists(api, server):
@ -88,9 +86,8 @@ def server_exists(api, server):
try:
api.GlobalLB.Server.get_object_status([server])
result = True
except bigsuds.OperationFailed:
e = get_exception()
if "was not found" in str(e):
except bigsuds.OperationFailed as e:
if "was not found" in to_native(e):
result = False
else:
# genuine exception
@ -105,9 +102,8 @@ def virtual_server_exists(api, name, server):
virtual_server_id = {'name': name, 'server': server}
api.GlobalLB.VirtualServerV2.get_object_status([virtual_server_id])
result = True
except bigsuds.OperationFailed:
e = get_exception()
if "was not found" in str(e):
except bigsuds.OperationFailed as e:
if "was not found" in to_native(e):
result = False
else:
# genuine exception
@ -219,9 +215,8 @@ def main():
else:
result = {'changed': True}
except Exception:
e = get_exception()
module.fail_json(msg="received exception: %s" % e)
except Exception as e:
module.fail_json(msg="received exception: %s" % to_native(e), exception=traceback.format_exc())
module.exit_json(**result)

@ -161,7 +161,7 @@ EXAMPLES = r'''
state: absent
register: result
failed_when:
- result is not successful
- result is not success
- "'referenced by one or more applications' not in result.msg"
- name: Configure a service using more complicated parameters

@ -48,6 +48,7 @@ notes:
requirements:
- f5-sdk >= 2.2.3
- Requires BIG-IP >= 12.1.0
- The 'rpm' tool installed on the Ansible controller
extends_documentation_fragment: f5
author:
- Tim Rupp (@caphrim007)
@ -134,14 +135,12 @@ class Parameters(AnsibleF5Parameters):
:return:
"""
p = subprocess.Popen(
['rpm', '-qp', '--queryformat', '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}', self.package],
stdout=subprocess.PIPE
)
cmd = ['rpm', '-qp', '--queryformat', '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}', self.package]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
if not stdout:
return self.package_file
return stdout
return str(self.package_file)
return stdout.decode('utf-8')
@property
def package_root(self):

@ -1,17 +1,21 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 F5 Networks Inc.
# Copyright (c) 2016 F5 Networks Inc.
# 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 = '''
DOCUMENTATION = r'''
---
module: bigip_sys_global
short_description: Manage BIG-IP global settings.
short_description: Manage BIG-IP global settings
description:
- Manage BIG-IP global settings.
version_added: "2.3"
@ -84,75 +88,80 @@ author:
- Tim Rupp (@caphrim007)
'''
EXAMPLES = '''
EXAMPLES = r'''
- name: Disable the setup utility
bigip_sys_global:
gui_setup: "disabled"
password: "secret"
server: "lb.mydomain.com"
user: "admin"
state: "present"
gui_setup: disabled
password: secret
server: lb.mydomain.com
user: admin
state: present
delegate_to: localhost
'''
RETURN = '''
RETURN = r'''
banner_text:
description: The new text to present in the advisory banner.
returned: changed
type: string
sample: "This is a corporate device. Do not touch."
description: The new text to present in the advisory banner.
returned: changed
type: string
sample: This is a corporate device. Do not touch.
console_timeout:
description: >
The new number of seconds of inactivity before the system
logs off a user that is logged on.
returned: changed
type: int
sample: 600
description: >
The new number of seconds of inactivity before the system
logs off a user that is logged on.
returned: changed
type: int
sample: 600
gui_setup:
description: The new setting for the Setup utility.
returned: changed
type: string
sample: enabled
description: The new setting for the Setup utility.
returned: changed
type: string
sample: enabled
lcd_display:
description: The new setting for displaying the system menu on the LCD.
returned: changed
type: string
sample: enabled
description: The new setting for displaying the system menu on the LCD.
returned: changed
type: string
sample: enabled
mgmt_dhcp:
description: >
The new setting for whether the mgmt interface should DHCP
or not
returned: changed
type: string
sample: enabled
description: The new setting for whether the mgmt interface should DHCP or not.
returned: changed
type: string
sample: enabled
net_reboot:
description: >
The new setting for whether the system should boot to an ISO on the
network or not
returned: changed
type: string
sample: enabled
description: The new setting for whether the system should boot to an ISO on the network or not.
returned: changed
type: string
sample: enabled
quiet_boot:
description: >
The new setting for whether the system should suppress information to
the console during boot or not.
returned: changed
type: string
sample: enabled
description: >
The new setting for whether the system should suppress information to
the console during boot or not.
returned: changed
type: string
sample: enabled
security_banner:
description: >
The new setting for whether the system should display an advisory message
on the login screen or not
returned: changed
type: string
sample: enabled
description: >
The new setting for whether the system should display an advisory message
on the login screen or not.
returned: changed
type: string
sample: enabled
'''
try:
from f5.bigip.contexts import TransactionContextManager
from f5.bigip import ManagementRoot
from icontrol.session import iControlUnexpectedHTTPError
HAS_F5SDK = True
except ImportError:
pass # Handled via f5_utils.HAS_F5SDK
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
from ansible.module_utils.f5_utils import F5ModuleError
from ansible.module_utils.f5_utils import HAS_F5SDK
from ansible.module_utils.f5_utils import f5_argument_spec
try:
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
except ImportError:
HAS_F5SDK = False
@ -345,35 +354,23 @@ class BigIpSysGlobalModuleConfig(object):
def initialize_meta_args(self):
args = dict(
security_banner=dict(
required=False,
choices=self.on_off_choices,
default=None
choices=self.on_off_choices
),
banner_text=dict(required=False, default=None),
banner_text=dict(),
gui_setup=dict(
required=False,
choices=self.on_off_choices,
default=None
choices=self.on_off_choices
),
lcd_display=dict(
required=False,
choices=self.on_off_choices,
default=None
choices=self.on_off_choices
),
mgmt_dhcp=dict(
required=False,
choices=self.on_off_choices,
default=None
choices=self.on_off_choices
),
net_reboot=dict(
required=False,
choices=self.on_off_choices,
default=None
choices=self.on_off_choices
),
quiet_boot=dict(
required=False,
choices=self.on_off_choices,
default=None
choices=self.on_off_choices
),
console_timeout=dict(required=False, type='int', default=None),
state=dict(default='present', choices=['present'])
@ -408,9 +405,6 @@ def main():
except F5ModuleError as e:
module.fail_json(msg=str(e))
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()

@ -15,21 +15,23 @@ if sys.version_info < (2, 7):
raise SkipTest("F5 Ansible modules require Python >= 2.7")
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch, Mock
from ansible.compat.tests.mock import Mock
from ansible.compat.tests.mock import patch
from ansible.module_utils.f5_utils import AnsibleF5Client
from units.modules.utils import set_module_args
try:
from library.bigip_iapp_service import Parameters
from library.bigip_iapp_service import ModuleManager
from library.bigip_iapp_service import ArgumentSpec
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
from test.unit.modules.utils import set_module_args
except ImportError:
try:
from ansible.modules.network.f5.bigip_iapp_service import Parameters
from ansible.modules.network.f5.bigip_iapp_service import ModuleManager
from ansible.modules.network.f5.bigip_iapp_service import ArgumentSpec
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
from units.modules.utils import set_module_args
except ImportError:
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")

@ -15,21 +15,23 @@ if sys.version_info < (2, 7):
raise SkipTest("F5 Ansible modules require Python >= 2.7")
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch, Mock
from ansible.compat.tests.mock import Mock
from ansible.compat.tests.mock import patch
from ansible.module_utils.f5_utils import AnsibleF5Client
from units.modules.utils import set_module_args
try:
from library.bigip_iapp_template import Parameters
from library.bigip_iapp_template import ModuleManager
from library.bigip_iapp_template import ArgumentSpec
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
from test.unit.modules.utils import set_module_args
except ImportError:
try:
from ansible.modules.network.f5.bigip_iapp_template import Parameters
from ansible.modules.network.f5.bigip_iapp_template import ArgumentSpec
from ansible.modules.network.f5.bigip_iapp_template import ModuleManager
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
from units.modules.utils import set_module_args
except ImportError:
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")

Loading…
Cancel
Save