Esempio n. 1
0
def main():
    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    argument_spec = nae_argument_spec()
    argument_spec.update(  # Not required for querying all objects
        name=dict(type='str', aliases=['fab_name']),
        description=dict(type='str'),
        apic_hostnames=dict(type='str', default=""),
        apic_username=dict(type='str', default=""),
        apic_password=dict(type='str', default="", no_log=True),
        online=dict(type='bool', default=False),
        validate_certs=dict(type='bool', default=False),
        run=dict(type='bool', default=None),
        run_iterations=dict(type='int', default=None),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query', 'modify']),
        export_apic_policy=dict(type='bool', default=False))

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True,
                           required_if=[['state', 'absent', ['name']],
                                        ['state', 'present', ['name']]])

    state = module.params.get('state')
    name = module.params.get('name')
    online = module.params.get('online')
    run = module.params.get('run')
    nae = NAEModule(module)

    if state == 'query' and name:
        ag = nae.get_assurance_group(name)
        if ag is None:
            module.exit_json(
                msg='Assurance group {0} does not exist'.format(name),
                **nae.result)
        nae.result['Result'] = ag
        module.exit_json(**nae.result)
    elif state == 'query' and not name:
        nae.get_all_assurance_groups()
        nae.result['Result'] = nae.assuranceGroups
        module.exit_json(**nae.result)
    elif state == 'present' and run is not None:
        nae.start_stop_ag()
        nae.result['changed'] = True
        module.exit_json(**nae.result)
    elif state == 'absent' and name:
        nae.deleteAG()
        nae.result['changed'] = True
        module.exit_json(**nae.result)
    elif state == 'present' and online:
        nae.newOnlineAG()
        nae.result['changed'] = True
        module.exit_json(**nae.result)
    elif state == 'present' and name:
        nae.newOfflineAG()
        nae.result['changed'] = True
        module.exit_json(**nae.result)

    module.fail_json(msg='Incorrect params passed', **nae.result)
Esempio n. 2
0
def main():
    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    result = dict(changed=False, resp='')
    argument_spec = nae_argument_spec()
    argument_spec.update(  # Not required for querying all objects
        name=dict(type='str', aliases=['name']),
        description=dict(type='str'),
        apic_hostnames=dict(type='str', default=""),
        apic_username=dict(type='str', default=""),
        apic_password=dict(type='str', default=""),
        online=dict(type='bool', default=False),
        validate_certs=dict(type='bool', default=False),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query', 'modify']),
    )

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True,
                           required_if=[['state', 'absent', ['name']],
                                        ['state', 'present', ['name']]])

    description = module.params.get('description')
    state = module.params.get('state')
    name = module.params.get('name')
    online = module.params.get('online')
    apic_hostname = module.params.get('apic_hostname')
    apic_username = module.params.get('apic_username')
    apic_password = module.params.get('apic_password')
    nae = NAEModule(module)

    if state == 'query' and name:
        ag = nae.get_assurance_group(name)
        if ag is None:
            module.exit_json(msg='No such Assurance Group exists',
                             **nae.result)
        nae.result['Result'] = ag
        module.exit_json(**nae.result)
    elif state == 'query' and not name:
        nae.get_all_assurance_groups()
        nae.result['Result'] = nae.assuranceGroups
        module.exit_json(**nae.result)
    elif state == 'absent' and name:
        nae.deleteAG()
        result['changed'] = True
        module.exit_json(**nae.result)
    elif state == 'present' and online:
        nae.newOnlineAG()
        result['changed'] = True
        module.exit_json(**nae.result)
    elif state == 'present' and name:
        nae.newOfflineAG()
        result['changed'] = True
        module.exit_json(**nae.result)

    module.fail_json(msg='Incorrect params passed', **self.result)