Group filter_expression not setting thru API

Can’t create a group with filter_expression set thru API. No errors returned, group is successfully created, but no filters set on it. I’ve found that a record is created in “entitlements” table in both cases. But if through WebUI, filter_expression is ruby/object:MiqExpression. Аnd if through API, it’s ruby/hash:ActiveSupport::HashWithIndifferentAccess. Seems than it isn’t parsed if created through API.

Through API:

vmdb_production=# select miq_group_id, filter_expression from entitlements;
 miq_group_id |                        filter_expression
--------------+-----------------------------------------------------------------
.......
           80 | --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess        +
              | exp: !ruby/hash:ActiveSupport::HashWithIndifferentAccess       +
              |   CONTAINS: !ruby/hash:ActiveSupport::HashWithIndifferentAccess+
              |     tag: managed-prov_scope                                    +
              |     value: all                                                 +

Through WebUI:

vmdb_production=# select miq_group_id, filter_expression from entitlements;
 miq_group_id |       filter_expression
--------------+--------------------------------
......
           80 | --- !ruby/object:MiqExpression+
              | exp:                          +
              |   CONTAINS:                   +
              |     tag: managed-prov_scope   +
              |     value: all                +
              | context_type:                 +

Can you post your API payload body that you’re using to create the group?

@pemcg

{
  "action": "create",
  "resource": {
    "description": "test_group_1",
    "tenant": {
      "href": "/api/tenants/1"
    },
    "role": {
      "id": "2"
    },
    "filter_expression": {
      "exp": {
        "CONTAINS": {
          "tag": "managed-prov_scope",
          "value": "all"
        }
      }
    }
  }
}

Hmm, it looks like a valid payload body, it might be worth creating an issue for this in Issues · ManageIQ/manageiq-api · GitHub

pemcg

Hi,

I had some issue in the past with creating groups with filters.
Please note that in my case the process is done in 2 steps:

  1. First create the group
  2. Second edit the group and add a filter. (Provisioning Scope Tag in my case)

This code snippet belongs to the group edit action step 2.
The correct line of code was pointed out in a support case to me.

update_group_w_filter = {
    "action" => "edit",
    "resource" => {
                   "description" => "#{target_cf_group_desc}",
                   "filters"     => {
                                     # this was my incorrect code
                                     # "managed" => [ [ "/#{tgt_tag_category}/#{tgt_provscope_desc}" ] ]
                                     
                                     # this is the fixed code
                                     "managed" => [ [ "managed/#{tgt_tag_category}/#{tgt_provscope_desc}" ] ]
                                    }
                  }
}

I hope it helps.

@pemcg

@Guillermo_Reartes
Thank you. Yes, “filters” is working well. But we need to create an expression with OR, that’s not possible with simple tag filtering.