CiscoDevNet / FMCAnsible

GNU General Public License v3.0
21 stars 25 forks source link

query_params for createMultipleAccessrule operation failure #14

Closed vjsaisha closed 1 year ago

vjsaisha commented 2 years ago

Trying to add the section query parameter to the code it's throwing the error in code.

- hosts: all
  connection: httpapi
  tasks:
    - name: Get Domain UUID
      cisco.fmcansible.fmc_configuration:
        operation: getAllDomain
        register_as: domain

    - name: create auxilary network object
      cisco.fmcansible.fmc_configuration:
        operation: createMultipleNetworkObject
        path_params:
          domainUUID: '{{ domain[0].uuid }}'
        data:
          name: "ansible-test-network467"
          value: "192.22.21.0/24"
          type: "networkobject"
        register_as: net1

    - name: Get Access Policy
      cisco.fmcansible.fmc_configuration:
        operation: getAllAccessPolicy
        path_params:
          domainUUID: '{{ domain[0].uuid }}'
        filters:
          name: ftdpolicy
        register_as: accesspolicy

    - name: print details
      debug:
        msg: '{{accesspolicy}}'

    - name: Create an access rule allowing trafic from Cisco DevNet
      cisco.fmcansible.fmc_configuration:
        operation: createMultipleAccessRule
        data:
          name: AllowCiscoTraffic9
          type: accessrule
          sourceNetworks:
            objects:
              - id: '{{ net1.id }}'
                name: '{{net1.name }}'
                type: '{{ net1.type }}'
          action: ALLOW
        path_params:
          containerUUID: '{{ accesspolicy[0].id }}'
          domainUUID: '{{ domain[0].uuid }}'
        query_params:
          section: "mandatory"

Error

TASK [Create an access rule allowing trafic from Cisco DevNet] ** fatal: [ciscofmc]: FAILED! => {"changed": false, "msg": "Server returned an error trying to execute upsertAccessRule operation. Status code: 400. Server response: Invalid query parameter for the GETALL operation."}

vjsaisha commented 2 years ago

Problem lies on the following code function

    def get_objects_by_filter_func(self, operation_name, params, filter_func):
        # extract query and path params for list operation
        __, query_params, path_params = _get_user_params(params)
        # copy required params to avoid mutation of passed `params` dict
        url_params = {ParamName.QUERY_PARAMS: dict(query_params), ParamName.PATH_PARAMS: dict(path_params)}

        # load list items
        item_generator = iterate_over_pageable_resource(
            partial(self.send_general_request, operation_name=operation_name), url_params
        )
        return (i for i in item_generator if filter_func(i))

if we delete the section key from query_params dictionary in this function then it's working .

Qwiko commented 1 year ago

I also have this issue. I am trying to upsertAccessRules but it fails when it tries to do a GET request in the background with the same query parameters that can only be used for the POST/PUT request.

jeroenwittock commented 1 year ago

Closing this, fix will go into version 1.0, planned to be released this month.