mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adds coding conventions to the bigip_facts module (#2515)
A number of coding conventions have been adopted for new F5 modules that are in development. To ensure common usage across the modules, this module needed to be updated to reflect those conventions. No functional code changes were made.
This commit is contained in:
parent
fead7d5e84
commit
8659082857
1 changed files with 129 additions and 105 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
# (c) 2013, Matt Hite <mhite@hotmail.com>
|
# (c) 2013, Matt Hite <mhite@hotmail.com>
|
||||||
#
|
#
|
||||||
# This file is part of Ansible
|
# This file is part of Ansible
|
||||||
|
@ -21,19 +21,18 @@
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: bigip_facts
|
module: bigip_facts
|
||||||
short_description: "Collect facts from F5 BIG-IP devices"
|
short_description: Collect facts from F5 BIG-IP devices
|
||||||
description:
|
description:
|
||||||
- "Collect facts from F5 BIG-IP devices via iControl SOAP API"
|
- Collect facts from F5 BIG-IP devices via iControl SOAP API
|
||||||
version_added: "1.6"
|
version_added: "1.6"
|
||||||
author:
|
author:
|
||||||
- Matt Hite (@mhite)
|
- Matt Hite (@mhite)
|
||||||
- Tim Rupp (@caphrim007)
|
- Tim Rupp (@caphrim007)
|
||||||
notes:
|
notes:
|
||||||
- "Requires BIG-IP software version >= 11.4"
|
- Requires BIG-IP software version >= 11.4
|
||||||
- "F5 developed module 'bigsuds' required (see http://devcentral.f5.com)"
|
- F5 developed module 'bigsuds' required (see http://devcentral.f5.com)
|
||||||
- "Best run as a local_action in your playbook"
|
- Best run as a local_action in your playbook
|
||||||
- "Tested with manager and above account privilege level"
|
- Tested with manager and above account privilege level
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- bigsuds
|
- bigsuds
|
||||||
options:
|
options:
|
||||||
|
@ -70,9 +69,11 @@ options:
|
||||||
on personally controlled sites. Prior to 2.0, this module would always
|
on personally controlled sites. Prior to 2.0, this module would always
|
||||||
validate on python >= 2.7.9 and never validate on python <= 2.7.8
|
validate on python >= 2.7.9 and never validate on python <= 2.7.8
|
||||||
required: false
|
required: false
|
||||||
default: 'yes'
|
default: yes
|
||||||
choices: ['yes', 'no']
|
choices:
|
||||||
version_added: 1.9.1
|
- yes
|
||||||
|
- no
|
||||||
|
version_added: 2.0
|
||||||
session:
|
session:
|
||||||
description:
|
description:
|
||||||
- BIG-IP session support; may be useful to avoid concurrency
|
- BIG-IP session support; may be useful to avoid concurrency
|
||||||
|
@ -86,10 +87,25 @@ options:
|
||||||
- Fact category or list of categories to collect
|
- Fact category or list of categories to collect
|
||||||
required: true
|
required: true
|
||||||
default: null
|
default: null
|
||||||
choices: ['address_class', 'certificate', 'client_ssl_profile',
|
choices:
|
||||||
'device', 'device_group', 'interface', 'key', 'node', 'pool',
|
- address_class
|
||||||
'rule', 'self_ip', 'software', 'system_info', 'traffic_group',
|
- certificate
|
||||||
'trunk', 'virtual_address', 'virtual_server', 'vlan']
|
- client_ssl_profile
|
||||||
|
- device
|
||||||
|
- device_group
|
||||||
|
- interface
|
||||||
|
- key
|
||||||
|
- node
|
||||||
|
- pool
|
||||||
|
- rule
|
||||||
|
- self_ip
|
||||||
|
- software
|
||||||
|
- system_info
|
||||||
|
- traffic_group
|
||||||
|
- trunk
|
||||||
|
- virtual_address
|
||||||
|
- virtual_server
|
||||||
|
- vlan
|
||||||
aliases: []
|
aliases: []
|
||||||
filter:
|
filter:
|
||||||
description:
|
description:
|
||||||
|
@ -102,26 +118,16 @@ options:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
|
||||||
## playbook task examples:
|
|
||||||
|
|
||||||
---
|
|
||||||
# file bigip-test.yml
|
|
||||||
# ...
|
|
||||||
- hosts: bigip-test
|
|
||||||
tasks:
|
|
||||||
- name: Collect BIG-IP facts
|
- name: Collect BIG-IP facts
|
||||||
local_action: >
|
bigip_facts:
|
||||||
bigip_facts
|
server: "lb.mydomain.com"
|
||||||
server=lb.mydomain.com
|
user: "admin"
|
||||||
user=admin
|
password: "secret"
|
||||||
password=mysecret
|
include: "interface,vlan"
|
||||||
include=interface,vlan
|
delegate_to: localhost
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import bigsuds
|
|
||||||
from suds import MethodNotFound, WebFault
|
from suds import MethodNotFound, WebFault
|
||||||
except ImportError:
|
except ImportError:
|
||||||
bigsuds_found = False
|
bigsuds_found = False
|
||||||
|
@ -129,12 +135,9 @@ else:
|
||||||
bigsuds_found = True
|
bigsuds_found = True
|
||||||
|
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import traceback
|
|
||||||
import re
|
import re
|
||||||
|
import traceback
|
||||||
|
|
||||||
# ===========================================
|
|
||||||
# bigip_facts module specific support methods.
|
|
||||||
#
|
|
||||||
|
|
||||||
class F5(object):
|
class F5(object):
|
||||||
"""F5 iControl class.
|
"""F5 iControl class.
|
||||||
|
@ -976,6 +979,7 @@ class Rules(object):
|
||||||
def get_definition(self):
|
def get_definition(self):
|
||||||
return [x['rule_definition'] for x in self.api.LocalLB.Rule.query_rule(rule_names=self.rules)]
|
return [x['rule_definition'] for x in self.api.LocalLB.Rule.query_rule(rule_names=self.rules)]
|
||||||
|
|
||||||
|
|
||||||
class Nodes(object):
|
class Nodes(object):
|
||||||
"""Nodes class.
|
"""Nodes class.
|
||||||
|
|
||||||
|
@ -1392,6 +1396,7 @@ def generate_dict(api_obj, fields):
|
||||||
result_dict[j] = temp
|
result_dict[j] = temp
|
||||||
return result_dict
|
return result_dict
|
||||||
|
|
||||||
|
|
||||||
def generate_simple_dict(api_obj, fields):
|
def generate_simple_dict(api_obj, fields):
|
||||||
result_dict = {}
|
result_dict = {}
|
||||||
for field in fields:
|
for field in fields:
|
||||||
|
@ -1403,6 +1408,7 @@ def generate_simple_dict(api_obj, fields):
|
||||||
result_dict[field] = api_response
|
result_dict[field] = api_response
|
||||||
return result_dict
|
return result_dict
|
||||||
|
|
||||||
|
|
||||||
def generate_interface_dict(f5, regex):
|
def generate_interface_dict(f5, regex):
|
||||||
interfaces = Interfaces(f5.get_api(), regex)
|
interfaces = Interfaces(f5.get_api(), regex)
|
||||||
fields = ['active_media', 'actual_flow_control', 'bundle_state',
|
fields = ['active_media', 'actual_flow_control', 'bundle_state',
|
||||||
|
@ -1417,6 +1423,7 @@ def generate_interface_dict(f5, regex):
|
||||||
'stp_protocol_detection_reset_state']
|
'stp_protocol_detection_reset_state']
|
||||||
return generate_dict(interfaces, fields)
|
return generate_dict(interfaces, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_self_ip_dict(f5, regex):
|
def generate_self_ip_dict(f5, regex):
|
||||||
self_ips = SelfIPs(f5.get_api(), regex)
|
self_ips = SelfIPs(f5.get_api(), regex)
|
||||||
fields = ['address', 'allow_access_list', 'description',
|
fields = ['address', 'allow_access_list', 'description',
|
||||||
|
@ -1425,6 +1432,7 @@ def generate_self_ip_dict(f5, regex):
|
||||||
'vlan', 'is_traffic_group_inherited']
|
'vlan', 'is_traffic_group_inherited']
|
||||||
return generate_dict(self_ips, fields)
|
return generate_dict(self_ips, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_trunk_dict(f5, regex):
|
def generate_trunk_dict(f5, regex):
|
||||||
trunks = Trunks(f5.get_api(), regex)
|
trunks = Trunks(f5.get_api(), regex)
|
||||||
fields = ['active_lacp_state', 'configured_member_count', 'description',
|
fields = ['active_lacp_state', 'configured_member_count', 'description',
|
||||||
|
@ -1434,6 +1442,7 @@ def generate_trunk_dict(f5, regex):
|
||||||
'stp_protocol_detection_reset_state']
|
'stp_protocol_detection_reset_state']
|
||||||
return generate_dict(trunks, fields)
|
return generate_dict(trunks, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_vlan_dict(f5, regex):
|
def generate_vlan_dict(f5, regex):
|
||||||
vlans = Vlans(f5.get_api(), regex)
|
vlans = Vlans(f5.get_api(), regex)
|
||||||
fields = ['auto_lasthop', 'cmp_hash_algorithm', 'description',
|
fields = ['auto_lasthop', 'cmp_hash_algorithm', 'description',
|
||||||
|
@ -1445,6 +1454,7 @@ def generate_vlan_dict(f5, regex):
|
||||||
'source_check_state', 'true_mac_address', 'vlan_id']
|
'source_check_state', 'true_mac_address', 'vlan_id']
|
||||||
return generate_dict(vlans, fields)
|
return generate_dict(vlans, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_vs_dict(f5, regex):
|
def generate_vs_dict(f5, regex):
|
||||||
virtual_servers = VirtualServers(f5.get_api(), regex)
|
virtual_servers = VirtualServers(f5.get_api(), regex)
|
||||||
fields = ['actual_hardware_acceleration', 'authentication_profile',
|
fields = ['actual_hardware_acceleration', 'authentication_profile',
|
||||||
|
@ -1465,6 +1475,7 @@ def generate_vs_dict(f5, regex):
|
||||||
'translate_port_state', 'type', 'vlan', 'wildmask']
|
'translate_port_state', 'type', 'vlan', 'wildmask']
|
||||||
return generate_dict(virtual_servers, fields)
|
return generate_dict(virtual_servers, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_pool_dict(f5, regex):
|
def generate_pool_dict(f5, regex):
|
||||||
pools = Pools(f5.get_api(), regex)
|
pools = Pools(f5.get_api(), regex)
|
||||||
fields = ['action_on_service_down', 'active_member_count',
|
fields = ['action_on_service_down', 'active_member_count',
|
||||||
|
@ -1481,6 +1492,7 @@ def generate_pool_dict(f5, regex):
|
||||||
'simple_timeout', 'slow_ramp_time']
|
'simple_timeout', 'slow_ramp_time']
|
||||||
return generate_dict(pools, fields)
|
return generate_dict(pools, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_device_dict(f5, regex):
|
def generate_device_dict(f5, regex):
|
||||||
devices = Devices(f5.get_api(), regex)
|
devices = Devices(f5.get_api(), regex)
|
||||||
fields = ['active_modules', 'base_mac_address', 'blade_addresses',
|
fields = ['active_modules', 'base_mac_address', 'blade_addresses',
|
||||||
|
@ -1493,6 +1505,7 @@ def generate_device_dict(f5, regex):
|
||||||
'timelimited_modules', 'timezone', 'unicast_addresses']
|
'timelimited_modules', 'timezone', 'unicast_addresses']
|
||||||
return generate_dict(devices, fields)
|
return generate_dict(devices, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_device_group_dict(f5, regex):
|
def generate_device_group_dict(f5, regex):
|
||||||
device_groups = DeviceGroups(f5.get_api(), regex)
|
device_groups = DeviceGroups(f5.get_api(), regex)
|
||||||
fields = ['all_preferred_active', 'autosync_enabled_state', 'description',
|
fields = ['all_preferred_active', 'autosync_enabled_state', 'description',
|
||||||
|
@ -1501,6 +1514,7 @@ def generate_device_group_dict(f5, regex):
|
||||||
'network_failover_enabled_state', 'sync_status', 'type']
|
'network_failover_enabled_state', 'sync_status', 'type']
|
||||||
return generate_dict(device_groups, fields)
|
return generate_dict(device_groups, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_traffic_group_dict(f5, regex):
|
def generate_traffic_group_dict(f5, regex):
|
||||||
traffic_groups = TrafficGroups(f5.get_api(), regex)
|
traffic_groups = TrafficGroups(f5.get_api(), regex)
|
||||||
fields = ['auto_failback_enabled_state', 'auto_failback_time',
|
fields = ['auto_failback_enabled_state', 'auto_failback_time',
|
||||||
|
@ -1509,12 +1523,14 @@ def generate_traffic_group_dict(f5, regex):
|
||||||
'unit_id']
|
'unit_id']
|
||||||
return generate_dict(traffic_groups, fields)
|
return generate_dict(traffic_groups, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_rule_dict(f5, regex):
|
def generate_rule_dict(f5, regex):
|
||||||
rules = Rules(f5.get_api(), regex)
|
rules = Rules(f5.get_api(), regex)
|
||||||
fields = ['definition', 'description', 'ignore_vertification',
|
fields = ['definition', 'description', 'ignore_vertification',
|
||||||
'verification_status']
|
'verification_status']
|
||||||
return generate_dict(rules, fields)
|
return generate_dict(rules, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_node_dict(f5, regex):
|
def generate_node_dict(f5, regex):
|
||||||
nodes = Nodes(f5.get_api(), regex)
|
nodes = Nodes(f5.get_api(), regex)
|
||||||
fields = ['address', 'connection_limit', 'description', 'dynamic_ratio',
|
fields = ['address', 'connection_limit', 'description', 'dynamic_ratio',
|
||||||
|
@ -1522,6 +1538,7 @@ def generate_node_dict(f5, regex):
|
||||||
'object_status', 'rate_limit', 'ratio', 'session_status']
|
'object_status', 'rate_limit', 'ratio', 'session_status']
|
||||||
return generate_dict(nodes, fields)
|
return generate_dict(nodes, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_virtual_address_dict(f5, regex):
|
def generate_virtual_address_dict(f5, regex):
|
||||||
virtual_addresses = VirtualAddresses(f5.get_api(), regex)
|
virtual_addresses = VirtualAddresses(f5.get_api(), regex)
|
||||||
fields = ['address', 'arp_state', 'auto_delete_state', 'connection_limit',
|
fields = ['address', 'arp_state', 'auto_delete_state', 'connection_limit',
|
||||||
|
@ -1530,19 +1547,23 @@ def generate_virtual_address_dict(f5, regex):
|
||||||
'route_advertisement_state', 'traffic_group']
|
'route_advertisement_state', 'traffic_group']
|
||||||
return generate_dict(virtual_addresses, fields)
|
return generate_dict(virtual_addresses, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_address_class_dict(f5, regex):
|
def generate_address_class_dict(f5, regex):
|
||||||
address_classes = AddressClasses(f5.get_api(), regex)
|
address_classes = AddressClasses(f5.get_api(), regex)
|
||||||
fields = ['address_class', 'description']
|
fields = ['address_class', 'description']
|
||||||
return generate_dict(address_classes, fields)
|
return generate_dict(address_classes, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_certificate_dict(f5, regex):
|
def generate_certificate_dict(f5, regex):
|
||||||
certificates = Certificates(f5.get_api(), regex)
|
certificates = Certificates(f5.get_api(), regex)
|
||||||
return dict(zip(certificates.get_list(), certificates.get_certificate_list()))
|
return dict(zip(certificates.get_list(), certificates.get_certificate_list()))
|
||||||
|
|
||||||
|
|
||||||
def generate_key_dict(f5, regex):
|
def generate_key_dict(f5, regex):
|
||||||
keys = Keys(f5.get_api(), regex)
|
keys = Keys(f5.get_api(), regex)
|
||||||
return dict(zip(keys.get_list(), keys.get_key_list()))
|
return dict(zip(keys.get_list(), keys.get_key_list()))
|
||||||
|
|
||||||
|
|
||||||
def generate_client_ssl_profile_dict(f5, regex):
|
def generate_client_ssl_profile_dict(f5, regex):
|
||||||
profiles = ProfileClientSSL(f5.get_api(), regex)
|
profiles = ProfileClientSSL(f5.get_api(), regex)
|
||||||
fields = ['alert_timeout', 'allow_nonssl_state', 'authenticate_depth',
|
fields = ['alert_timeout', 'allow_nonssl_state', 'authenticate_depth',
|
||||||
|
@ -1566,6 +1587,7 @@ def generate_client_ssl_profile_dict(f5, regex):
|
||||||
'unclean_shutdown_state', 'is_base_profile', 'is_system_profile']
|
'unclean_shutdown_state', 'is_base_profile', 'is_system_profile']
|
||||||
return generate_dict(profiles, fields)
|
return generate_dict(profiles, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_system_info_dict(f5):
|
def generate_system_info_dict(f5):
|
||||||
system_info = SystemInfo(f5.get_api())
|
system_info = SystemInfo(f5.get_api())
|
||||||
fields = ['base_mac_address',
|
fields = ['base_mac_address',
|
||||||
|
@ -1578,6 +1600,7 @@ def generate_system_info_dict(f5):
|
||||||
'time_zone', 'uptime']
|
'time_zone', 'uptime']
|
||||||
return generate_simple_dict(system_info, fields)
|
return generate_simple_dict(system_info, fields)
|
||||||
|
|
||||||
|
|
||||||
def generate_software_list(f5):
|
def generate_software_list(f5):
|
||||||
software = Software(f5.get_api())
|
software = Software(f5.get_api())
|
||||||
software_list = software.get_all_software_status()
|
software_list = software.get_all_software_status()
|
||||||
|
@ -1585,16 +1608,17 @@ def generate_software_list(f5):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
argument_spec = f5_argument_spec()
|
||||||
argument_spec = dict(
|
|
||||||
server = dict(type='str', required=True),
|
meta_args = dict(
|
||||||
user = dict(type='str', required=True),
|
|
||||||
password = dict(type='str', required=True),
|
|
||||||
validate_certs = dict(default='yes', type='bool'),
|
|
||||||
session=dict(type='bool', default=False),
|
session=dict(type='bool', default=False),
|
||||||
include=dict(type='list', required=True),
|
include=dict(type='list', required=True),
|
||||||
filter=dict(type='str', required=False),
|
filter=dict(type='str', required=False),
|
||||||
)
|
)
|
||||||
|
argument_spec.update(meta_args)
|
||||||
|
|
||||||
|
module = AnsibleModule(
|
||||||
|
argument_spec=argument_spec
|
||||||
)
|
)
|
||||||
|
|
||||||
if not bigsuds_found:
|
if not bigsuds_found:
|
||||||
|
@ -1685,7 +1709,7 @@ def main():
|
||||||
|
|
||||||
result = {'ansible_facts': facts}
|
result = {'ansible_facts': facts}
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
module.fail_json(msg="received exception: %s\ntraceback: %s" % (e, traceback.format_exc()))
|
module.fail_json(msg="received exception: %s\ntraceback: %s" % (e, traceback.format_exc()))
|
||||||
|
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
Loading…
Reference in a new issue