Search code examples
command-line-interfaceibm-cloudibm-cloud-infrastructure

IBM Cloud CLI Softlayer plugin: How to pass filters?


I am using the Softlayer commands in the IBM Cloud CLI to manager classic infrastructure. Following the documentation about the Softlayer API I want to filter for specific data centers and their regions.

In general, the commands allow to pass in the following parameters:

OPTIONS:
   --init value        Init parameter (default: 0)
   --mask value        Object mask: use to limit fields returned
   --parameters value  Append parameters to web call
   --limit value       Result limit (default: 0)
   --offset value      Result offset (default: 0)

So I am trying to use --parameters to apply a filter like shown here.

The following is returning all objects and not filtering. Other variations do not work either:

ibmcloud sl call-api SoftLayer_Location_Group getAllObjects --parameters 'object_filter={"locationGroupTypeId":1}'

How do I apply filters to the API call using the IBM Cloud CLI command?


Solution

  • It seems that the ibmcloud cli does not support object filters.

    I suggest you to try using slcli:

    Use the following slcli command to see the object filter option:

    slcli call-api --help
    

    Output:

    Usage: slcli call-api [OPTIONS] SERVICE METHOD [PARAMETERS]...
    
      Call arbitrary API endpoints with the given SERVICE and METHOD.
    
      Example::
    
          slcli call-api Account getObject     slcli call-api Account getVirtualGuests --limit=10 --mask=id,hostname
          slcli call-api Virtual_Guest getObject --id=12345     slcli call-api Metric_Tracking_Object getBandwidthData
          --id=1234 \         "2015-01-01 00:00:00" "2015-01-1 12:00:00" public     slcli call-api Account
          getVirtualGuests \         -f 'virtualGuests.datacenter.name=dal05' \         -f 'virtualGuests.maxCpu=4' \
          --mask=id,hostname,datacenter.name,maxCpu     slcli call-api Account getVirtualGuests \         -f
          'virtualGuests.datacenter.name IN dal05,sng01'
    
    Options:
      --id TEXT                       Init parameter
      -f, --filter TEXT               Object filters. This should be of the form: 'property=value' or
                                      'nested.property=value'. Complex filters like betweenDate are not currently
                                      supported. (multiple occurrence permitted)
      --mask TEXT                     String-based object mask
      --limit INTEGER                 Result limit
      --offset INTEGER                Result offset
      --output-python / --no-output-python
                                      Show python example code instead of executing the call
      -h, --help                      Show this message and exit.
    

    Reference:

    https://softlayer-api-python-client.readthedocs.io/en/latest/cli/