def main()

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


def main():
    argument_spec = common_argument_spec()
    argument_spec.update(dict(
        load_balancer_id=dict(type='str', aliases=['lb_id'], required=True),
        vserver_group_ids=dict(type='list', elements='str', aliases=['group_ids', 'ids']),
        name_prefix=dict(type='str')
    ))
    module = AnsibleModule(argument_spec=argument_spec)

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

    vsg_ids = module.params['vserver_group_ids']
    name_prefix = module.params['name_prefix']

    ids = []
    vsgs = []
    names = []

    try:
        slb = slb_connect(module)
        groups = slb.describe_vserver_groups(**{'load_balancer_id': module.params['load_balancer_id']})

        if groups:
            for group in groups:
                if vsg_ids and group.id not in vsg_ids:
                    continue
                if name_prefix and not str(group.name).startswith(name_prefix):
                    continue
                vsgs.append(group.read())
                ids.append(group.id)
                names.append(group.name)

        module.exit_json(changed=False, vserver_groups=vsgs, ids=ids, names=names)
    except Exception as e:
        module.fail_json(msg=str("Unable to describe slb vserver groups, error:{0}".format(e)))