-->

ObjectFilter in SoftLayer doesn't work

2020-04-23 06:28发布

问题:

I find ObjectFilter doesn't work in SoftLayer.

I even tried the example provided in the SoftLayer webpage here:

https://sldn.softlayer.com/article/object-filters

REST:

List the ID and hostname of all servers in dal05

https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectMask=mask[id,hostname]&objectFilter={"datacenter":{"name":{"operation":"dal05"}}}

When I ran this command, it still returns all the virtual guests, regardless what data center that virtual guest belongs to.

回答1:

try this request:

GET https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectMask=mask[id,hostname,datacenter]&objectFilter={"virtualGuests":{"datacenter":{"name":{"operation":"dal05"}}}}

The issue with your request is that you are missing the "virtualGuests" property, keep in mind that the objectFilter is filtering over the data in the database, so you need to tell it over what table work and over what record of the table work. e.g. using the "SoftLayer_Account" that implies that all the work will be over the "SoftLayer_Account" table now you need to tell id over what property/record of that table work in this case you need to work over the "virtualGuests" and so on. Please keep in mind that and you review the documentation about the valid properties/records e.g. these are the valid properties/record for Softlayer_Account:

http://sldn.softlayer.com/reference/datatypes/SoftLayer_Account

Regards



回答2:

Maybe you can try adding virtualGuestsin the filter, something like this:

objectFilter={ "virtualGuests": { "datacenter": { "longName": { "operation": "Dallas 6" } } } }

or please see the first examples of https://sldn.softlayer.com/article/object-filters, like this:

object_filter = {
    'virtualGuests': {
        'datacenter': {
            'name': {'operation': 'dal05'}
        }
    }
}