def main()

in src/ansible_collections/alibaba/apsarastack/plugins/modules/ali_slb_listener_info.py [0:0]


def main():
    argument_spec = common_argument_spec()
    argument_spec.update(dict(
        listener_port=dict(type='int', required=True),
        load_balancer_id=dict(type='str', required=True, aliases=['lb_id']),
        listener_type=dict(type='str', required=True, choices=['http', 'https', 'tcp', 'udp'])
    ))
    module = AnsibleModule(argument_spec=argument_spec)

    if HAS_FOOTMARK is False:
        module.fail_json(msg="Package 'footmark' required for this module.")

    load_balancer_id = module.params['load_balancer_id']
    listener_port = module.params['listener_port']
    listener_type = module.params['listener_type']

    try:
        slb = slb_connect(module)

        # check whether server load balancer exist or not
        laod_balancer = slb.describe_load_balancers(load_balancer_id=load_balancer_id)
        if laod_balancer and len(laod_balancer) == 1:

            # list load balancers listeners
            listener = slb.describe_load_balancer_listener_attribute(load_balancer_id,
                                                                     listener_port,
                                                                     listener_type)
            if listener is None:
                module.fail_json(msg="Unable to describe slb listeners, no listeners found")
            else:
                module.exit_json(changed=False, listener=get_info(listener))
        else:
            module.fail_json(msg="Unable to describe slb listeners, invalid load balancer id")
    except Exception as e:
        module.fail_json(msg="Unable to describe slb listeners, and got an error: {0}.".format(e))