Пример #1
0
def run_module():
    argspec = argspec_common.copy()
    argspec.update(config_path=dict(required=False, type='str', default=None))
    module = AnsibleModule(argument_spec=argspec, supports_check_mode=True)

    with ArubaOsApi(module) as api:

        if module.check_mode:
            pending_config = api.get_config(
                config_path=module.params.get('config_path'),
                config_type='pending')
            if pending_config:
                api.module_result.update(changed=True,
                                         msg='Configuration commited.',
                                         commited=pending_config)
            else:
                api.module_result.update(changed=False,
                                         skipped=True,
                                         msg='Nothing to commit.')
            module.exit_json(**api.module_result)

        commit_status, commit_data = api.write_memory(
            config_path=module.params.get('config_path'))

        if commit_status == STATUS_SUCCESS:
            api.module_result.update(changed=True,
                                     msg='Configuration commited.',
                                     commited=commit_data)

        if commit_status == STATUS_SKIPPED:
            api.module_result.update(change=False,
                                     skipped=True,
                                     msg='Nothing to commit.')

        module.exit_json(**api.module_result)
def run_module():
    argspec = argspec_common.copy()
    argspec.update(object=dict(required=True, type='str'),
                   config_path=dict(required=False, type='str', default=None),
                   sort=dict(required=False, type='str', default=None),
                   offset=dict(required=False, type='int', default=None),
                   limit=dict(required=False, type='int', default=None),
                   total=dict(required=False, type='int', default=None),
                   count=dict(required=False,
                              type='list',
                              default=list(),
                              elements='str'),
                   data_types=dict(required=False,
                                   type='list',
                                   default=list(),
                                   elements='str',
                                   choices=CHOICES_DATA_TYPE),
                   object_filters=dict(
                       required=False,
                       type='list',
                       default=list(),
                       elements='dict',
                       options=dict(oper=dict(required=True,
                                              type='str',
                                              choices=CHOICES_OBJECT_OPER),
                                    values=dict(required=True,
                                                type='list',
                                                elements='str'))),
                   data_filters=dict(required=False,
                                     type='list',
                                     default=list(),
                                     elements='dict',
                                     options=dict(
                                         param_name=dict(required=True,
                                                         type='str'),
                                         oper=dict(required=True,
                                                   type='str',
                                                   choices=CHOICES_DATA_OPER),
                                         values=dict(required=True,
                                                     type='list',
                                                     element='str'))))

    module = AnsibleModule(
        argument_spec=argspec,
        supports_check_mode=True,
        required_together=[['offset', 'limit']],
        mutually_exclusive=[['data_types', 'object_filters'],
                            ['data_types', 'data_filters']])

    path = '/configuration/object/{}'.format(module.params.get('object'))

    with ArubaOsApi(module) as api:

        url = api.get_url(path, params=url_params(module))
        _, response_json = api.send_request(url, 'GET')

        module.exit_json(changed=False, msg='Success', response=response_json)
Пример #3
0
def run_module():
    argspec = argspec_common.copy()
    argspec.update(command=dict(required=True, type='str'))

    module = AnsibleModule(argument_spec=argspec, supports_check_mode=True)

    with ArubaOsApi(module) as api:

        url = api.get_url('/configuration/showcommand',
                          params={'command': module.params.get('command')})
        _, response_json = api.send_request(url, 'GET')

        module.exit_json(changed=False, msg='Success', response=response_json)
def run_module():
    argspec = argspec_common.copy()
    argspec.update(data=dict(required=False, type='dict', default=dict()),
                   multipart_data=dict(required=False,
                                       type='list',
                                       elements='dict',
                                       default=list()),
                   config_path=dict(required=False, type='str', default=None),
                   commit=dict(required=False, type='bool', default=False),
                   commit_force=dict(required=False,
                                     type='bool',
                                     default=False))

    module = AnsibleModule(argument_spec=argspec,
                           supports_check_mode=True,
                           mutually_exclusive=[['commit', 'commit_force'],
                                               ['data', 'multipart_data']])

    with ArubaOsApi(module) as api:

        if check_pending_required(module):
            check_pending_config(api, module)

        response_json, changed, diff = set_operation(api, module)

        global_status, global_status_str, _ = global_result(response_json)

        errors = (global_status != STATUS_SUCCESS)

        api.module_result.update(changed=changed,
                                 msg=global_status_str,
                                 response=response_json,
                                 diff=diff)

        if errors:
            api.module_result.setdefault(
                'warnings',
                []).append('One or more config blocks returned with errors.')

        if changed and module.check_mode:
            api.purge_pending(module.params.get('config_path'))

        if changed and commit_requested(module):
            commit_status, _ = commit_config(api, module, errors=errors)
            # For the sake of not confusing the end user, we alter the original _pending status if commit was successful
            if commit_status == STATUS_SUCCESS:
                response_json['_global_result']['_pending'] = False

        module.exit_json(**api.module_result)
def run_module():
    argspec = argspec_common.copy()

    module = AnsibleModule(
        argument_spec=argspec,
        supports_check_mode=True
    )

    with ArubaOsApi(module) as api:

        _, response_json = api.send_request(api.get_url('/configuration/object/sys_info'), 'GET')

        module.exit_json(
            changed=False,
            ansible_facts={'arubaos': response_json}
        )
Пример #6
0
def run_module():
    argspec = argspec_common.copy()
    argspec.update(
        config_path=dict(required=False, type='str', default=None),
        type=dict(required=False, type='str', choices=CHOICES_CONFIG_TYPE, default=None)
    )

    module = AnsibleModule(
        argument_spec=argspec,
        supports_check_mode=True
    )

    with ArubaOsApi(module) as api:

        response_json = api.get_config(
            config_path=module.params.get('config_path'),
            config_type=module.params.get('type')
        )

        module.exit_json(
            changed=False,
            msg='Success',
            response=response_json
        )
def run_module():
    argspec = argspec_common.copy()
    argspec.update(api_name=dict(required=True, type='str'),
                   method=dict(required=True,
                               type='str',
                               choices=['GET', 'POST']),
                   config_path=dict(required=False, type='str', default=None),
                   data=dict(required=False, type='dict', default=None))
    module = AnsibleModule(argument_spec=argspec, supports_check_mode=True)

    if module.check_mode:
        module.exit_json(changed=False,
                         skipped=True,
                         msg='Check mode is not implemented.')

    method = module.params.get('method')
    path = '/configuration/object/{}'.format(module.params.get('api_name'))
    data = module.params.get('data')
    params = {'config_path': module.params.get('config_path')}
    if data is not None:
        if method == 'GET':
            params.update(data)
            data = None
        if method == 'POST':
            data = json.dumps(data)

    api_call = {
        'host': module.params.get('host'),
        'username': module.params.get('username'),
        'password': module.params.get('password'),
        'api_name': module.params.get('api_name'),
        'method': module.params.get('method'),
        'config_path': module.params.get('config_path'),
        'data': module.params.get('data')
    }

    with ArubaOsApi(module) as api:

        url = api.get_url(path, params=params)
        api_call.update(url=url)
        response, response_json = api.send_request(url, method, data=data)

    try:
        if method == 'GET':
            result = response_json['_data']
            module.exit_json(changed=False,
                             msg=result,
                             status_code=response.getcode(),
                             response=response_json)
        if method == 'POST':
            result = response_json['_global_result']
            if result['status'] == 0:
                module.exit_json(changed=True,
                                 msg=result['status_str'],
                                 status_code=response.getcode())
            if result['status'] in [1, 2]:
                module.exit_json(skipped=True,
                                 msg=str(result['status_str']),
                                 status_code=response.status)
        module.fail_json(changed=False,
                         msg="API Call failed!",
                         reason=result['status_str'],
                         api_call=api_call)
    except Exception as exc:
        module.fail_json(changed=False,
                         msg='Exception while processing response.',
                         exception=to_native(exc))