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.
pull/18777/head
Tim Rupp 8 years ago committed by Matt Clay
parent fead7d5e84
commit 8659082857

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (c) 2013, Matt Hite <mhite@hotmail.com>
#
# This file is part of Ansible
@ -21,107 +21,113 @@
DOCUMENTATION = '''
---
module: bigip_facts
short_description: "Collect facts from F5 BIG-IP devices"
short_description: Collect facts from F5 BIG-IP devices
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"
author:
- Matt Hite (@mhite)
- Tim Rupp (@caphrim007)
- Matt Hite (@mhite)
- 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"
- 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
- bigsuds
options:
server:
description:
- BIG-IP host
required: true
default: null
choices: []
aliases: []
server_port:
description:
- BIG-IP server port
required: false
default: 443
version_added: "2.2"
user:
description:
- BIG-IP username
required: true
default: null
choices: []
aliases: []
password:
description:
- BIG-IP password
required: true
default: null
choices: []
aliases: []
validate_certs:
description:
- If C(no), SSL certificates will not be validated. This should only be used
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
required: false
default: 'yes'
choices: ['yes', 'no']
version_added: 1.9.1
session:
description:
- BIG-IP session support; may be useful to avoid concurrency
issues in certain circumstances.
required: false
default: true
choices: []
aliases: []
include:
description:
- Fact category or list of categories to collect
required: true
default: null
choices: ['address_class', 'certificate', '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: []
filter:
description:
- Shell-style glob matching string used to filter fact keys. Not
applicable for software and system_info fact categories.
required: false
default: null
choices: []
aliases: []
server:
description:
- BIG-IP host
required: true
default: null
choices: []
aliases: []
server_port:
description:
- BIG-IP server port
required: false
default: 443
version_added: "2.2"
user:
description:
- BIG-IP username
required: true
default: null
choices: []
aliases: []
password:
description:
- BIG-IP password
required: true
default: null
choices: []
aliases: []
validate_certs:
description:
- If C(no), SSL certificates will not be validated. This should only be used
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
required: false
default: yes
choices:
- yes
- no
version_added: 2.0
session:
description:
- BIG-IP session support; may be useful to avoid concurrency
issues in certain circumstances.
required: false
default: true
choices: []
aliases: []
include:
description:
- Fact category or list of categories to collect
required: true
default: null
choices:
- address_class
- certificate
- 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: []
filter:
description:
- Shell-style glob matching string used to filter fact keys. Not
applicable for software and system_info fact categories.
required: false
default: null
choices: []
aliases: []
'''
EXAMPLES = '''
## playbook task examples:
---
# file bigip-test.yml
# ...
- hosts: bigip-test
tasks:
- name: Collect BIG-IP facts
local_action: >
bigip_facts
server=lb.mydomain.com
user=admin
password=mysecret
include=interface,vlan
- name: Collect BIG-IP facts
bigip_facts:
server: "lb.mydomain.com"
user: "admin"
password: "secret"
include: "interface,vlan"
delegate_to: localhost
'''
try:
import bigsuds
from suds import MethodNotFound, WebFault
except ImportError:
bigsuds_found = False
@ -129,12 +135,9 @@ else:
bigsuds_found = True
import fnmatch
import traceback
import re
import traceback
# ===========================================
# bigip_facts module specific support methods.
#
class F5(object):
"""F5 iControl class.
@ -976,6 +979,7 @@ class Rules(object):
def get_definition(self):
return [x['rule_definition'] for x in self.api.LocalLB.Rule.query_rule(rule_names=self.rules)]
class Nodes(object):
"""Nodes class.
@ -1392,6 +1396,7 @@ def generate_dict(api_obj, fields):
result_dict[j] = temp
return result_dict
def generate_simple_dict(api_obj, fields):
result_dict = {}
for field in fields:
@ -1403,6 +1408,7 @@ def generate_simple_dict(api_obj, fields):
result_dict[field] = api_response
return result_dict
def generate_interface_dict(f5, regex):
interfaces = Interfaces(f5.get_api(), regex)
fields = ['active_media', 'actual_flow_control', 'bundle_state',
@ -1417,6 +1423,7 @@ def generate_interface_dict(f5, regex):
'stp_protocol_detection_reset_state']
return generate_dict(interfaces, fields)
def generate_self_ip_dict(f5, regex):
self_ips = SelfIPs(f5.get_api(), regex)
fields = ['address', 'allow_access_list', 'description',
@ -1425,6 +1432,7 @@ def generate_self_ip_dict(f5, regex):
'vlan', 'is_traffic_group_inherited']
return generate_dict(self_ips, fields)
def generate_trunk_dict(f5, regex):
trunks = Trunks(f5.get_api(), regex)
fields = ['active_lacp_state', 'configured_member_count', 'description',
@ -1434,6 +1442,7 @@ def generate_trunk_dict(f5, regex):
'stp_protocol_detection_reset_state']
return generate_dict(trunks, fields)
def generate_vlan_dict(f5, regex):
vlans = Vlans(f5.get_api(), regex)
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']
return generate_dict(vlans, fields)
def generate_vs_dict(f5, regex):
virtual_servers = VirtualServers(f5.get_api(), regex)
fields = ['actual_hardware_acceleration', 'authentication_profile',
@ -1465,6 +1475,7 @@ def generate_vs_dict(f5, regex):
'translate_port_state', 'type', 'vlan', 'wildmask']
return generate_dict(virtual_servers, fields)
def generate_pool_dict(f5, regex):
pools = Pools(f5.get_api(), regex)
fields = ['action_on_service_down', 'active_member_count',
@ -1481,6 +1492,7 @@ def generate_pool_dict(f5, regex):
'simple_timeout', 'slow_ramp_time']
return generate_dict(pools, fields)
def generate_device_dict(f5, regex):
devices = Devices(f5.get_api(), regex)
fields = ['active_modules', 'base_mac_address', 'blade_addresses',
@ -1493,14 +1505,16 @@ def generate_device_dict(f5, regex):
'timelimited_modules', 'timezone', 'unicast_addresses']
return generate_dict(devices, fields)
def generate_device_group_dict(f5, regex):
device_groups = DeviceGroups(f5.get_api(), regex)
fields = ['all_preferred_active', 'autosync_enabled_state','description',
fields = ['all_preferred_active', 'autosync_enabled_state', 'description',
'device', 'full_load_on_sync_state',
'incremental_config_sync_size_maximum',
'network_failover_enabled_state', 'sync_status', 'type']
return generate_dict(device_groups, fields)
def generate_traffic_group_dict(f5, regex):
traffic_groups = TrafficGroups(f5.get_api(), regex)
fields = ['auto_failback_enabled_state', 'auto_failback_time',
@ -1509,12 +1523,14 @@ def generate_traffic_group_dict(f5, regex):
'unit_id']
return generate_dict(traffic_groups, fields)
def generate_rule_dict(f5, regex):
rules = Rules(f5.get_api(), regex)
fields = ['definition', 'description', 'ignore_vertification',
'verification_status']
return generate_dict(rules, fields)
def generate_node_dict(f5, regex):
nodes = Nodes(f5.get_api(), regex)
fields = ['address', 'connection_limit', 'description', 'dynamic_ratio',
@ -1522,6 +1538,7 @@ def generate_node_dict(f5, regex):
'object_status', 'rate_limit', 'ratio', 'session_status']
return generate_dict(nodes, fields)
def generate_virtual_address_dict(f5, regex):
virtual_addresses = VirtualAddresses(f5.get_api(), regex)
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']
return generate_dict(virtual_addresses, fields)
def generate_address_class_dict(f5, regex):
address_classes = AddressClasses(f5.get_api(), regex)
fields = ['address_class', 'description']
return generate_dict(address_classes, fields)
def generate_certificate_dict(f5, regex):
certificates = Certificates(f5.get_api(), regex)
return dict(zip(certificates.get_list(), certificates.get_certificate_list()))
def generate_key_dict(f5, regex):
keys = Keys(f5.get_api(), regex)
return dict(zip(keys.get_list(), keys.get_key_list()))
def generate_client_ssl_profile_dict(f5, regex):
profiles = ProfileClientSSL(f5.get_api(), regex)
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']
return generate_dict(profiles, fields)
def generate_system_info_dict(f5):
system_info = SystemInfo(f5.get_api())
fields = ['base_mac_address',
@ -1578,6 +1600,7 @@ def generate_system_info_dict(f5):
'time_zone', 'uptime']
return generate_simple_dict(system_info, fields)
def generate_software_list(f5):
software = Software(f5.get_api())
software_list = software.get_all_software_status()
@ -1585,16 +1608,17 @@ def generate_software_list(f5):
def main():
argument_spec = f5_argument_spec()
meta_args = dict(
session=dict(type='bool', default=False),
include=dict(type='list', required=True),
filter=dict(type='str', required=False),
)
argument_spec.update(meta_args)
module = AnsibleModule(
argument_spec = dict(
server = dict(type='str', required=True),
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),
include = dict(type='list', required=True),
filter = dict(type='str', required=False),
)
argument_spec=argument_spec
)
if not bigsuds_found:
@ -1685,7 +1709,7 @@ def main():
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.exit_json(**result)

Loading…
Cancel
Save