def main(): """ Main function :returns: VIP Listener Information """ module = AnsibleModule( argument_spec=dict( auth=dict(type='dict'), region=dict(default='na', type='str'), datacenter=dict(required=True, type='str'), network_domain=dict(required=True, type='str'), id=dict(default=None, required=False, type='str'), name=dict(default=None, required=False, type='str'), ), supports_check_mode=True ) try: credentials = get_credentials(module) except ImportError as e: module.fail_json(msg='{0}'.format(e)) network_domain_name = module.params.get('network_domain') datacenter = module.params.get('datacenter') object_id = module.params.get('id') name = module.params.get('name') return_data = return_object('vip_listener') # Check the region supplied is valid regions = get_regions() if module.params.get('region') not in regions: module.fail_json(msg='Invalid region. Regions must be one of {0}'.format(regions)) if credentials is False: module.fail_json(msg='Could not load the user credentials') try: client = NTTMCPClient(credentials, module.params.get('region')) except NTTMCPAPIException as e: module.fail_json(msg=e.msg) # Get the CND try: network = client.get_network_domain_by_name(name=network_domain_name, datacenter=datacenter) network_domain_id = network.get('id') except (KeyError, IndexError, AttributeError, NTTMCPAPIException): module.fail_json(msg='Could not find the Cloud Network Domain: {0}'.format(network_domain_name)) if object_id: try: return_data['vip_listener'] = client.get_vip_listener(object_id) module.exit_json(data=return_data) except NTTMCPAPIException as exc: module.fail_json(msg='Could not find the Virtual Listener {0}: {1}'.format(object_id, exc)) else: return_data['vip_listener'] = client.list_vip_listener(network_domain_id, name) return_data['count'] = len(return_data.get('vip_listener')) module.exit_json(data=return_data)
def main(): """ Main function :returns: VIP Listener Information """ module = AnsibleModule(argument_spec=dict( auth=dict(type='dict'), region=dict(default='na', type='str'), datacenter=dict(required=True, type='str'), network_domain=dict(required=True, type='str'), id=dict(default=None, required=False, type='str'), name=dict(default=None, required=False, type='str'), description=dict(required=False, default=None, type='str'), type=dict(required=False, default='STANDARD', choices=VIP_LISTENER_TYPES), protocol=dict(required=False, default='ANY', type='str'), ip_address=dict(required=False, default=None, type='str'), port=dict(required=False, default=None, type='int'), enabled=dict(required=False, default=True, type='bool'), preservation=dict(required=False, default='PRESERVE', choices=VIP_LISTENER_PRESERVATION), connection_limit=dict(required=False, default=100000, type='int'), connection_rate_limit=dict(required=False, default=4000, type='int'), pool=dict(required=False, default=None, type='str'), client_pool=dict(required=False, default=None, type='str'), persistence_profile=dict(required=False, default=None, type='str'), fallback_persistence_profile=dict(required=False, default=None, type='str'), optimization_profile=dict(required=False, default=None, type='str'), ssl_offload_profile=dict(required=False, default=None, type='str'), irules=dict(required=False, default=None, type='list', elements='str'), state=dict(default='present', required=False, choices=['present', 'absent'])), supports_check_mode=True) try: credentials = get_credentials(module) except ImportError as e: module.fail_json(msg='{0}'.format(e)) network_domain_name = module.params.get('network_domain') datacenter = module.params.get('datacenter') state = module.params.get('state') v_listener = None # Check the region supplied is valid regions = get_regions() if module.params.get('region') not in regions: module.fail_json( msg='Invalid region. Regions must be one of {0}'.format(regions)) # Check port input value if state == 'present': if module.params.get('port') not in range(1, 65535): module.fail_json(msg='port must be between 1 and 65535') # Check connection input values if module.params.get('connection_limit') not in range(1, 100001): module.fail_json( msg='connection_limit must be between 1 and 100000') if module.params.get('connection_rate_limit') not in range(1, 4001): module.fail_json( msg='connection_rate_limit must be between 1 and 4000') if credentials is False: module.fail_json(msg='Could not load the user credentials') try: client = NTTMCPClient(credentials, module.params.get('region')) except NTTMCPAPIException as e: module.fail_json(msg=e.msg) # Get the CND try: network = client.get_network_domain_by_name(name=network_domain_name, datacenter=datacenter) network_domain_id = network.get('id') except (KeyError, IndexError, AttributeError, NTTMCPAPIException): module.fail_json(msg='Could not find the Cloud Network Domain: {0}'. format(network_domain_name)) # Check if the Listener already exists try: if module.params.get('id'): v_listener = client.get_vip_listener(module.params.get('id')) else: v_listeners = client.list_vip_listener( network_domain_id=network_domain_id, name=module.params.get('name')) if len(v_listeners) == 1: v_listener = v_listeners[0] except (KeyError, IndexError, AttributeError, NTTMCPAPIException) as exc: module.fail_json( msg= 'Could not get a list of existing Virtual Listeners to check against - {0}' .format(exc)) if state == 'present': if not v_listener: # Implement Check Mode if module.check_mode: module.exit_json(msg='A new Virtual Listener will be created') create_vip_listener(module, client, network_domain_id) else: if compare_vip_listener(module, client, network_domain_id, v_listener): update_vip_listener(module, client, network_domain_id, v_listener) module.exit_json(data=v_listener.get('id')) elif state == 'absent': if not v_listener: module.exit_json( msg='No Virtual Listener found. Nothing to remove.') # Implement Check Mode if module.check_mode: module.exit_json( msg='The Virtual Listener with ID {0} will be deleted'.format( v_listener.get('id'))) delete_vip_listener(module, client, v_listener.get('id'))